From: sf Date: Mon, 29 May 2023 08:13:35 +0000 (+0000) Subject: virtio: Set DRIVER_OK earlier X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=cdd248411fe303b936d5a056fde97097bd7015f0;p=openbsd virtio: Set DRIVER_OK earlier The DRIVER_OK bit must be set before using any virt-queues. To allow virtio device drivers to use the virt-queues in their attach functions, set the bit there and not in the virtio transport attach function. Only vioscsi and viogpu really need this, but let's only have one standard way to do this. Noticed because of hangs with vioscsi on qemu/windows and in the Oracle cloud. With much debugging help by Aaron Mason. Also revert vioscsi.c 1.31 "Temporarily workaround double calls into vioscsi_req_done()" ok krw@ --- diff --git a/sys/dev/fdt/virtio_mmio.c b/sys/dev/fdt/virtio_mmio.c index 12f5a6cdeb6..4f1e9eba9b7 100644 --- a/sys/dev/fdt/virtio_mmio.c +++ b/sys/dev/fdt/virtio_mmio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio_mmio.c,v 1.10 2021/10/24 17:52:27 mpi Exp $ */ +/* $OpenBSD: virtio_mmio.c,v 1.11 2023/05/29 08:13:35 sf Exp $ */ /* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */ /* @@ -293,7 +293,6 @@ virtio_mmio_attach(struct device *parent, struct device *self, void *aux) goto fail_2; } - virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); return; fail_2: diff --git a/sys/dev/pci/virtio_pci.c b/sys/dev/pci/virtio_pci.c index 236120cf5a6..1e543983466 100644 --- a/sys/dev/pci/virtio_pci.c +++ b/sys/dev/pci/virtio_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio_pci.c,v 1.32 2023/04/13 02:19:05 jsg Exp $ */ +/* $OpenBSD: virtio_pci.c,v 1.33 2023/05/29 08:13:35 sf Exp $ */ /* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */ /* @@ -651,7 +651,6 @@ virtio_pci_attach(struct device *parent, struct device *self, void *aux) } printf("%s: %s\n", vsc->sc_dev.dv_xname, intrstr); - virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); return; fail_2: diff --git a/sys/dev/pv/if_vio.c b/sys/dev/pv/if_vio.c index be53ccaf7c3..8c2e97d8073 100644 --- a/sys/dev/pv/if_vio.c +++ b/sys/dev/pv/if_vio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vio.c,v 1.22 2022/03/07 18:52:16 dv Exp $ */ +/* $OpenBSD: if_vio.c,v 1.23 2023/05/29 08:13:35 sf Exp $ */ /* * Copyright (c) 2012 Stefan Fritsch, Alexander Fiveg. @@ -600,6 +600,7 @@ vio_attach(struct device *parent, struct device *self, void *aux) timeout_set(&sc->sc_txtick, vio_txtick, &sc->sc_vq[VQTX]); timeout_set(&sc->sc_rxtick, vio_rxtick, &sc->sc_vq[VQRX]); + virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); if_attach(ifp); ether_ifattach(ifp); diff --git a/sys/dev/pv/vioblk.c b/sys/dev/pv/vioblk.c index 093ce9b5a58..2a8d2677848 100644 --- a/sys/dev/pv/vioblk.c +++ b/sys/dev/pv/vioblk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vioblk.c,v 1.35 2022/04/16 19:19:59 naddy Exp $ */ +/* $OpenBSD: vioblk.c,v 1.36 2023/05/29 08:13:35 sf Exp $ */ /* * Copyright (c) 2012 Stefan Fritsch. @@ -251,6 +251,7 @@ vioblk_attach(struct device *parent, struct device *self, void *aux) saa.saa_quirks = 0; saa.saa_wwpn = saa.saa_wwnn = 0; + virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); config_found(self, &saa, scsiprint); return; diff --git a/sys/dev/pv/viocon.c b/sys/dev/pv/viocon.c index bd96467c810..4d154c34bf7 100644 --- a/sys/dev/pv/viocon.c +++ b/sys/dev/pv/viocon.c @@ -1,4 +1,4 @@ -/* $OpenBSD: viocon.c,v 1.8 2021/11/05 11:38:29 mpi Exp $ */ +/* $OpenBSD: viocon.c,v 1.9 2023/05/29 08:13:35 sf Exp $ */ /* * Copyright (c) 2013-2015 Stefan Fritsch @@ -203,6 +203,7 @@ viocon_attach(struct device *parent, struct device *self, void *aux) goto err; } viocon_rx_fill(sc->sc_ports[0]); + virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); return; err: diff --git a/sys/dev/pv/viogpu.c b/sys/dev/pv/viogpu.c index e8a91c34310..d0af88f66f1 100644 --- a/sys/dev/pv/viogpu.c +++ b/sys/dev/pv/viogpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: viogpu.c,v 1.2 2023/04/23 10:29:35 patrick Exp $ */ +/* $OpenBSD: viogpu.c,v 1.3 2023/05/29 08:13:35 sf Exp $ */ /* * Copyright (c) 2021-2023 joshua stein @@ -235,6 +235,8 @@ viogpu_attach(struct device *parent, struct device *self, void *aux) sc->sc_fb_dma_kva, sc->sc_fb_dma_size, NULL, BUS_DMA_NOWAIT) != 0) goto fb_unmap; + virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); + if (viogpu_create_2d(sc, 1, sc->sc_fb_width, sc->sc_fb_height) != 0) goto fb_unmap; diff --git a/sys/dev/pv/viomb.c b/sys/dev/pv/viomb.c index 8169770553e..a14d085c3e1 100644 --- a/sys/dev/pv/viomb.c +++ b/sys/dev/pv/viomb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: viomb.c,v 1.8 2021/11/05 11:38:29 mpi Exp $ */ +/* $OpenBSD: viomb.c,v 1.9 2023/05/29 08:13:35 sf Exp $ */ /* $NetBSD: viomb.c,v 1.1 2011/10/30 12:12:21 hannken Exp $ */ /* @@ -220,6 +220,7 @@ viomb_attach(struct device *parent, struct device *self, void *aux) sensordev_install(&sc->sc_sensdev); printf("\n"); + virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); return; err_dmamap: bus_dmamap_destroy(vsc->sc_dmat, sc->sc_req.bl_dmamap); diff --git a/sys/dev/pv/viornd.c b/sys/dev/pv/viornd.c index 39442bc8391..eb129743be7 100644 --- a/sys/dev/pv/viornd.c +++ b/sys/dev/pv/viornd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: viornd.c,v 1.5 2021/11/05 11:38:29 mpi Exp $ */ +/* $OpenBSD: viornd.c,v 1.6 2023/05/29 08:13:35 sf Exp $ */ /* * Copyright (c) 2014 Stefan Fritsch @@ -138,6 +138,7 @@ viornd_attach(struct device *parent, struct device *self, void *aux) timeout_add(&sc->sc_tick, 1); printf("\n"); + virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); return; err2: bus_dmamap_destroy(vsc->sc_dmat, sc->sc_dmamap); diff --git a/sys/dev/pv/vioscsi.c b/sys/dev/pv/vioscsi.c index 20802c8bc7a..a9246eb2317 100644 --- a/sys/dev/pv/vioscsi.c +++ b/sys/dev/pv/vioscsi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vioscsi.c,v 1.31 2023/04/27 13:52:58 krw Exp $ */ +/* $OpenBSD: vioscsi.c,v 1.32 2023/05/29 08:13:35 sf Exp $ */ /* * Copyright (c) 2013 Google Inc. * @@ -166,6 +166,7 @@ vioscsi_attach(struct device *parent, struct device *self, void *aux) saa.saa_quirks = saa.saa_flags = 0; saa.saa_wwpn = saa.saa_wwnn = 0; + virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); config_found(self, &saa, scsiprint); return; @@ -296,6 +297,7 @@ vioscsi_req_done(struct vioscsi_softc *sc, struct virtio_softc *vsc, struct scsi_xfer *xs = vr->vr_xs; DPRINTF("vioscsi_req_done: enter vr: %p xs: %p\n", vr, xs); + int isread = !!(xs->flags & SCSI_DATA_IN); bus_dmamap_sync(vsc->sc_dmat, vr->vr_control, offsetof(struct vioscsi_req, vr_req), sizeof(struct virtio_scsi_req_hdr), @@ -304,18 +306,6 @@ vioscsi_req_done(struct vioscsi_softc *sc, struct virtio_softc *vsc, offsetof(struct vioscsi_req, vr_res), sizeof(struct virtio_scsi_res_hdr), BUS_DMASYNC_POSTREAD); - - /* - * XXX Should be impossible but somehow happens on Oracle Cloud and - * particular QEMU configurations. - * - * Stop the crashing while investigation into - * the apparent queuing/dequeuing issue proceeds. - */ - if (xs == NULL) - return; - - int isread = !!(xs->flags & SCSI_DATA_IN); if (xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT)) { bus_dmamap_sync(vsc->sc_dmat, vr->vr_data, 0, xs->datalen, isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); diff --git a/sys/dev/pv/vmmci.c b/sys/dev/pv/vmmci.c index 461df5801a1..2f3539e96eb 100644 --- a/sys/dev/pv/vmmci.c +++ b/sys/dev/pv/vmmci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmmci.c,v 1.9 2021/11/05 11:38:29 mpi Exp $ */ +/* $OpenBSD: vmmci.c,v 1.10 2023/05/29 08:13:35 sf Exp $ */ /* * Copyright (c) 2017 Reyk Floeter @@ -120,6 +120,7 @@ vmmci_attach(struct device *parent, struct device *self, void *aux) } printf("\n"); + virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); } int