Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci virtio: stop reinit for safety when a device res...
details: https://anonhg.NetBSD.org/src/rev/aeb21c2372dd
branches: trunk
changeset: 990461:aeb21c2372dd
user: yamaguchi <yamaguchi%NetBSD.org@localhost>
date: Thu Oct 28 01:36:43 2021 +0000
description:
virtio: stop reinit for safety when a device resetting is failed
diffstat:
sys/dev/pci/if_vioif.c | 12 +++++++++---
sys/dev/pci/virtio.c | 19 ++++++++++++-------
sys/dev/pci/virtio_pci.c | 43 +++++++++++++++++++++++--------------------
sys/dev/pci/virtiovar.h | 4 ++--
4 files changed, 46 insertions(+), 32 deletions(-)
diffs (218 lines):
diff -r 5a609efa36bd -r aeb21c2372dd sys/dev/pci/if_vioif.c
--- a/sys/dev/pci/if_vioif.c Wed Oct 27 21:42:58 2021 +0000
+++ b/sys/dev/pci/if_vioif.c Thu Oct 28 01:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_vioif.c,v 1.70 2021/02/08 06:56:26 skrll Exp $ */
+/* $NetBSD: if_vioif.c,v 1.71 2021/10/28 01:36:43 yamaguchi Exp $ */
/*
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.70 2021/02/08 06:56:26 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.71 2021/10/28 01:36:43 yamaguchi Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -46,6 +46,7 @@
#include <sys/mbuf.h>
#include <sys/mutex.h>
#include <sys/sockio.h>
+#include <sys/syslog.h>
#include <sys/cpu.h>
#include <sys/module.h>
#include <sys/pcq.h>
@@ -1155,7 +1156,12 @@
vioif_stop(ifp, 0);
- virtio_reinit_start(vsc);
+ r = virtio_reinit_start(vsc);
+ if (r != 0) {
+ log(LOG_ERR, "%s: reset failed\n", ifp->if_xname);
+ return EIO;
+ }
+
virtio_negotiate_features(vsc, virtio_features(vsc));
for (i = 0; i < sc->sc_req_nvq_pairs; i++) {
diff -r 5a609efa36bd -r aeb21c2372dd sys/dev/pci/virtio.c
--- a/sys/dev/pci/virtio.c Wed Oct 27 21:42:58 2021 +0000
+++ b/sys/dev/pci/virtio.c Thu Oct 28 01:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio.c,v 1.52 2021/10/21 07:08:55 yamaguchi Exp $ */
+/* $NetBSD: virtio.c,v 1.53 2021/10/28 01:36:43 yamaguchi Exp $ */
/*
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.52 2021/10/21 07:08:55 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.53 2021/10/28 01:36:43 yamaguchi Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -90,7 +90,7 @@
virtio_device_reset(sc);
}
-void
+int
virtio_reinit_start(struct virtio_softc *sc)
{
int i, r;
@@ -114,10 +114,15 @@
}
r = sc->sc_ops->setup_interrupts(sc, 1);
- if (r != 0) {
- printf("%s: failed to setup interrupts\n",
- device_xname(sc->sc_dev));
- }
+ if (r != 0)
+ goto fail;
+
+ return 0;
+
+fail:
+ virtio_set_status(sc, VIRTIO_CONFIG_DEVICE_STATUS_FAILED);
+
+ return 1;
}
void
diff -r 5a609efa36bd -r aeb21c2372dd sys/dev/pci/virtio_pci.c
--- a/sys/dev/pci/virtio_pci.c Wed Oct 27 21:42:58 2021 +0000
+++ b/sys/dev/pci/virtio_pci.c Thu Oct 28 01:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.32 2021/10/21 05:37:43 yamaguchi Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.33 2021/10/28 01:36:43 yamaguchi Exp $ */
/*
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.32 2021/10/21 05:37:43 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.33 2021/10/28 01:36:43 yamaguchi Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -36,6 +36,7 @@
#include <sys/module.h>
#include <sys/endian.h>
#include <sys/interrupt.h>
+#include <sys/syslog.h>
#include <sys/device.h>
@@ -50,6 +51,18 @@
#include <dev/pci/virtiovar.h> /* XXX: move to non-pci */
+#define VIRTIO_PCI_LOG(_sc, _use_log, _fmt, _args...) \
+do { \
+ if ((_use_log)) { \
+ log(LOG_DEBUG, "%s: " _fmt, \
+ device_xname((_sc)->sc_dev), \
+ ##_args); \
+ } else { \
+ aprint_error_dev((_sc)->sc_dev, \
+ _fmt, ##_args); \
+ } \
+} while(0)
+
static int virtio_pci_match(device_t, cfdata_t, void *);
static void virtio_pci_attach(device_t, device_t, void *);
static int virtio_pci_rescan(device_t, const char *, const int *);
@@ -808,7 +821,6 @@
virtio_pci_setup_interrupts_10(struct virtio_softc *sc, int reinit)
{
struct virtio_pci_softc * const psc = (struct virtio_pci_softc *)sc;
- device_t self = sc->sc_dev;
bus_space_tag_t iot = psc->sc_iot;
bus_space_handle_t ioh = psc->sc_ioh;
int vector, ret, qid;
@@ -821,10 +833,8 @@
VIRTIO_CONFIG1_CONFIG_MSIX_VECTOR, vector);
ret = bus_space_read_2(iot, ioh, VIRTIO_CONFIG1_CONFIG_MSIX_VECTOR);
if (ret != vector) {
- if (reinit == 0) {
- aprint_error_dev(self,
- "can't set config msix vector\n");
- }
+ VIRTIO_PCI_LOG(sc, reinit,
+ "can't set config msix vector\n");
return -1;
}
@@ -839,10 +849,8 @@
ret = bus_space_read_2(iot, ioh,
VIRTIO_CONFIG1_QUEUE_MSIX_VECTOR);
if (ret != vector) {
- if (reinit == 0) {
- aprint_error_dev(self, "can't set queue %d "
- "msix vector\n", qid);
- }
+ VIRTIO_PCI_LOG(sc, reinit, "can't set queue %d "
+ "msix vector\n", qid);
return -1;
}
}
@@ -854,7 +862,6 @@
virtio_pci_setup_interrupts_09(struct virtio_softc *sc, int reinit)
{
struct virtio_pci_softc * const psc = (struct virtio_pci_softc *)sc;
- device_t self = sc->sc_dev;
int offset, vector, ret, qid;
if (!virtio_pci_msix_enabled(psc))
@@ -868,10 +875,8 @@
aprint_debug_dev(sc->sc_dev, "expected=%d, actual=%d\n",
vector, ret);
if (ret != vector) {
- if (reinit == 0) {
- aprint_error_dev(self,
- "can't set config msix vector\n");
- }
+ VIRTIO_PCI_LOG(sc, reinit,
+ "can't set config msix vector\n");
return -1;
}
@@ -890,10 +895,8 @@
aprint_debug_dev(sc->sc_dev, "expected=%d, actual=%d\n",
vector, ret);
if (ret != vector) {
- if (reinit == 0) {
- aprint_error_dev(self, "can't set queue %d "
- "msix vector\n", qid);
- }
+ VIRTIO_PCI_LOG(sc, reinit, "can't set queue %d "
+ "msix vector\n", qid);
return -1;
}
}
diff -r 5a609efa36bd -r aeb21c2372dd sys/dev/pci/virtiovar.h
--- a/sys/dev/pci/virtiovar.h Wed Oct 27 21:42:58 2021 +0000
+++ b/sys/dev/pci/virtiovar.h Thu Oct 28 01:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: virtiovar.h,v 1.22 2021/10/21 05:37:43 yamaguchi Exp $ */
+/* $NetBSD: virtiovar.h,v 1.23 2021/10/28 01:36:43 yamaguchi Exp $ */
/*
* Copyright (c) 2010 Minoura Makoto.
@@ -208,7 +208,7 @@
const char*);
int virtio_free_vq(struct virtio_softc*, struct virtqueue*);
void virtio_reset(struct virtio_softc *);
-void virtio_reinit_start(struct virtio_softc *);
+int virtio_reinit_start(struct virtio_softc *);
void virtio_reinit_end(struct virtio_softc *);
void virtio_child_attach_start(struct virtio_softc *, device_t, int,
struct virtqueue *,
Home |
Main Index |
Thread Index |
Old Index