diff options
| author | yamaguchi <yamaguchi@NetBSD.org> | 2021-10-28 01:36:43 +0000 |
|---|---|---|
| committer | yamaguchi <yamaguchi@NetBSD.org> | 2021-10-28 01:36:43 +0000 |
| commit | acbc2459cc2c9ae06a32cd121d69eedcda813992 (patch) | |
| tree | 3b93f06071d72462554955e162ca30c66f6f96ed /sys | |
| parent | d7b49bc02f55521b943459715f87beac01a870b2 (diff) | |
virtio: stop reinit for safety when a device resetting is failed
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/dev/pci/if_vioif.c | 12 | ||||
| -rw-r--r-- | sys/dev/pci/virtio.c | 19 | ||||
| -rw-r--r-- | sys/dev/pci/virtio_pci.c | 43 | ||||
| -rw-r--r-- | sys/dev/pci/virtiovar.h | 4 |
4 files changed, 46 insertions, 32 deletions
diff --git a/sys/dev/pci/if_vioif.c b/sys/dev/pci/if_vioif.c index 33f42ab38bd..17b3f9155a7 100644 --- a/sys/dev/pci/if_vioif.c +++ b/sys/dev/pci/if_vioif.c @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.70 2021/02/08 06:56:26 skrll Exp $"); #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_init(struct ifnet *ifp) 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 --git a/sys/dev/pci/virtio.c b/sys/dev/pci/virtio.c index b1c87656e18..ffc146e8e89 100644 --- a/sys/dev/pci/virtio.c +++ b/sys/dev/pci/virtio.c @@ -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_reset(struct virtio_softc *sc) virtio_device_reset(sc); } -void +int virtio_reinit_start(struct virtio_softc *sc) { int i, r; @@ -114,10 +114,15 @@ virtio_reinit_start(struct virtio_softc *sc) } 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 --git a/sys/dev/pci/virtio_pci.c b/sys/dev/pci/virtio_pci.c index dbb7a5d3197..34903a7f8b6 100644 --- a/sys/dev/pci/virtio_pci.c +++ b/sys/dev/pci/virtio_pci.c @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.32 2021/10/21 05:37:43 yamaguchi Ex #include <sys/module.h> #include <sys/endian.h> #include <sys/interrupt.h> +#include <sys/syslog.h> #include <sys/device.h> @@ -50,6 +51,18 @@ __KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.32 2021/10/21 05:37:43 yamaguchi Ex #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 @@ static int 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_pci_setup_interrupts_10(struct virtio_softc *sc, int reinit) 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 @@ virtio_pci_setup_interrupts_10(struct virtio_softc *sc, int reinit) 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 @@ static int 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 @@ virtio_pci_setup_interrupts_09(struct virtio_softc *sc, int reinit) 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 @@ virtio_pci_setup_interrupts_09(struct virtio_softc *sc, int reinit) 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 --git a/sys/dev/pci/virtiovar.h b/sys/dev/pci/virtiovar.h index 7e17abe0adc..dba925dd44e 100644 --- a/sys/dev/pci/virtiovar.h +++ b/sys/dev/pci/virtiovar.h @@ -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 @@ int virtio_alloc_vq(struct virtio_softc*, struct virtqueue*, int, int, int, 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 *, |
