Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-10]: src/sys/dev Pull up following revision(s) (requested by yama...



details:   https://anonhg.NetBSD.org/src/rev/56da705c524a
branches:  netbsd-10
changeset: 374805:56da705c524a
user:      martin <martin%NetBSD.org@localhost>
date:      Sat May 13 10:56:10 2023 +0000

description:
Pull up following revision(s) (requested by yamaguchi in ticket #139):

        sys/dev/pci/vioscsi.c: revision 1.31
        sys/dev/pci/vio9p.c: revision 1.10
        sys/dev/pci/vioscsi.c: revision 1.32
        sys/dev/pci/vio9p.c: revision 1.11
        sys/dev/pci/vioscsi.c: revision 1.33
        sys/dev/pci/ld_virtio.c: revision 1.31
        sys/dev/virtio/viocon.c: revision 1.6
        sys/dev/pci/vioscsi.c: revision 1.34
        sys/dev/pci/ld_virtio.c: revision 1.32
        sys/dev/virtio/viocon.c: revision 1.7
        sys/dev/virtio/viocon.c: revision 1.8
        sys/dev/pci/vioscsi.c: revision 1.36
        sys/dev/pci/virtioreg.h: revision 1.12
        sys/dev/pci/viornd.c: revision 1.19
        sys/dev/pci/virtio.c: revision 1.66
        sys/dev/pci/virtio.c: revision 1.67
        sys/dev/pci/virtio.c: revision 1.68
        sys/dev/pci/if_vioif.c: revision 1.103
        sys/dev/pci/virtio.c: revision 1.69
        sys/dev/pci/if_vioif.c: revision 1.104
        sys/dev/pci/virtio_pci.c: revision 1.40
        sys/dev/virtio/virtio_mmio.c: revision 1.8
        sys/dev/virtio/virtio_mmio.c: revision 1.9
        sys/dev/pci/viomb.c: revision 1.14
        sys/dev/pci/viomb.c: revision 1.15
        sys/dev/pci/viomb.c: revision 1.17
        sys/dev/pci/viornd.c: revision 1.20
        sys/dev/pci/viornd.c: revision 1.21
        sys/dev/pci/virtiovar.h: revision 1.25
        sys/dev/pci/virtiovar.h: revision 1.26
        sys/dev/pci/virtiovar.h: revision 1.27
        sys/dev/pci/virtiovar.h: revision 1.28
        sys/dev/pci/virtio.c: revision 1.70
        sys/dev/pci/virtio.c: revision 1.71
        sys/dev/pci/virtio.c: revision 1.72
        sys/dev/pci/virtio.c: revision 1.73
        sys/dev/pci/virtio.c: revision 1.74
        sys/dev/pci/virtio_pci.c: revision 1.39

Set virtqueues in virtio_child_attach_finish

The number of virtqueue maybe change in a part of VirtIO devices
(e.g. vioif(4)). And it is fixed after negotiation of features.
So the configuration is moved into the function.

viocon(4): fix not to allocate unused virtqueue

viocon(4) allocates 4 virtqueues but it only uses 2 (0 and 1) queues.

Added functions to set interrupt handler and index into virtqueue

Added check of pointer for allocated memory before release of resource

Setup virtqueues after registering them to virtio_softc
restore fetch of qsize.

Mark as MPSAFE.

virtio(4): Avoid name collision with global intrhand on sparc64.

Pacifies -Werror=shadow.
No functional change intended.

Use PRIuBUSSIZE to print bus_size_t variables.

virtio(4): Fix sizing of virtqueue allocation.
vq->vq_avail[0].ring is a zero-length array, and thus sizeof is zero;
likewise vq->vq_used[0].ring.
Use vq->vq_avail[0].ring[0] and vq->vq_used[0].ring[0] to fix this
and restore the previous allocation sizing logic.
XXX We shouldn't use zero-length arrays here -- they are asking for
trouble like this, and C99 has a standard way to express what we're
actually trying to get at it, flexible array members.
PR kern/57304

virtio(4): Use flexible array members, not zero-length arrays.
This enables the compiler to detect sizeof mistakes like
PR kern/57304.

Use descriptor chain for free slots instead of vq_entry list
Descriptors can be chained by themself. And descriptors added to
avail ring or used ring are already chained. But it was not used
for unused descriptors and another linked list structure named
vq_entry was used.

The chain is also used for unused descriptors to make virtio(4)
simpler.

Added flags to store status of attaching a virtio device

This prevents a panic on reboot after a virtio device had called
virtio_child_attach_failed().

Fix wrong variable names
This fixes build errors in virtio_mmio.c

diffstat:

 sys/dev/pci/if_vioif.c       |   49 +-
 sys/dev/pci/ld_virtio.c      |   16 +-
 sys/dev/pci/vio9p.c          |   22 +-
 sys/dev/pci/viomb.c          |   22 +-
 sys/dev/pci/viornd.c         |   13 +-
 sys/dev/pci/vioscsi.c        |   19 +-
 sys/dev/pci/virtio.c         |  593 ++++++++++++++++++++++++------------------
 sys/dev/pci/virtio_pci.c     |   40 +-
 sys/dev/pci/virtioreg.h      |    6 +-
 sys/dev/pci/virtiovar.h      |   61 ++--
 sys/dev/virtio/viocon.c      |   39 +-
 sys/dev/virtio/virtio_mmio.c |   15 +-
 12 files changed, 487 insertions(+), 408 deletions(-)

diffs (truncated from 1846 to 300 lines):

diff -r e9c38c5eb7df -r 56da705c524a sys/dev/pci/if_vioif.c
--- a/sys/dev/pci/if_vioif.c    Thu May 04 18:57:28 2023 +0000
+++ b/sys/dev/pci/if_vioif.c    Sat May 13 10:56:10 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vioif.c,v 1.82.4.2 2023/04/01 10:31:06 martin Exp $ */
+/*     $NetBSD: if_vioif.c,v 1.82.4.3 2023/05/13 10:56:10 martin 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.82.4.2 2023/04/01 10:31:06 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.82.4.3 2023/05/13 10:56:10 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -465,7 +465,7 @@ vioif_attach(device_t parent, device_t s
        u_int softint_flags;
        int r, i, req_flags;
        char xnamebuf[MAXCOMLEN];
-       size_t netq_num;
+       size_t nvqs;
 
        if (virtio_child(vsc) != NULL) {
                aprint_normal(": child already attached for %s; "
@@ -509,11 +509,11 @@ vioif_attach(device_t parent, device_t s
 #ifdef VIOIF_MULTIQ
        req_features |= VIRTIO_NET_F_MQ;
 #endif
-       virtio_child_attach_start(vsc, self, IPL_NET, NULL,
-           vioif_config_change, virtio_vq_intrhand, req_flags,
+
+       virtio_child_attach_start(vsc, self, IPL_NET,
            req_features, VIRTIO_NET_FLAG_BITS);
-
        features = virtio_features(vsc);
+
        if (features == 0)
                goto err;
 
@@ -565,10 +565,12 @@ vioif_attach(device_t parent, device_t s
 
                /* Limit the number of queue pairs to use */
                sc->sc_req_nvq_pairs = MIN(sc->sc_max_nvq_pairs, ncpu);
+
+               if (sc->sc_max_nvq_pairs > 1)
+                       req_flags |= VIRTIO_F_INTR_PERVQ;
        }
 
        vioif_alloc_queues(sc);
-       virtio_child_attach_set_vqs(vsc, sc->sc_vqs, sc->sc_req_nvq_pairs);
 
 #ifdef VIOIF_MPSAFE
        softint_flags = SOFTINT_NET | SOFTINT_MPSAFE;
@@ -579,21 +581,25 @@ vioif_attach(device_t parent, device_t s
        /*
         * Initialize network queues
         */
-       netq_num = sc->sc_max_nvq_pairs * 2;
-       for (i = 0; i < netq_num; i++) {
+       nvqs = sc->sc_max_nvq_pairs * 2;
+       for (i = 0; i < nvqs; i++) {
                r = vioif_netqueue_init(sc, vsc, i, softint_flags);
                if (r != 0)
                        goto err;
        }
 
        if (sc->sc_has_ctrl) {
-               int ctrlq_idx = sc->sc_max_nvq_pairs * 2;
+               int ctrlq_idx = nvqs;
+
+               nvqs++;
                /*
                 * Allocating a virtqueue for control channel
                 */
                sc->sc_ctrlq.ctrlq_vq = &sc->sc_vqs[ctrlq_idx];
-               r = virtio_alloc_vq(vsc, ctrlq->ctrlq_vq, ctrlq_idx,
-                   NBPG, 1, "control");
+               virtio_init_vq(vsc, ctrlq->ctrlq_vq, ctrlq_idx,
+                   vioif_ctrl_intr, ctrlq);
+
+               r = virtio_alloc_vq(vsc, ctrlq->ctrlq_vq, NBPG, 1, "control");
                if (r != 0) {
                        aprint_error_dev(self, "failed to allocate "
                            "a virtqueue for control channel, error code %d\n",
@@ -602,9 +608,6 @@ vioif_attach(device_t parent, device_t s
                        sc->sc_has_ctrl = false;
                        cv_destroy(&ctrlq->ctrlq_wait);
                        mutex_destroy(&ctrlq->ctrlq_wait_lock);
-               } else {
-                       ctrlq->ctrlq_vq->vq_intrhand = vioif_ctrl_intr;
-                       ctrlq->ctrlq_vq->vq_intrhand_arg = (void *) ctrlq;
                }
        }
 
@@ -618,7 +621,9 @@ vioif_attach(device_t parent, device_t s
        if (vioif_alloc_mems(sc) < 0)
                goto err;
 
-       if (virtio_child_attach_finish(vsc) != 0)
+       r = virtio_child_attach_finish(vsc, sc->sc_vqs, nvqs,
+           vioif_config_change, req_flags);
+       if (r != 0)
                goto err;
 
        if (vioif_setup_sysctl(sc) != 0) {
@@ -656,8 +661,8 @@ vioif_attach(device_t parent, device_t s
        return;
 
 err:
-       netq_num = sc->sc_max_nvq_pairs * 2;
-       for (i = 0; i < netq_num; i++) {
+       nvqs = sc->sc_max_nvq_pairs * 2;
+       for (i = 0; i < nvqs; i++) {
                vioif_netqueue_teardown(sc, vsc, i);
        }
 
@@ -1468,15 +1473,15 @@ vioif_netqueue_init(struct vioif_softc *
            "%s-%s", device_xname(sc->sc_dev), qname);
 
        mutex_init(&netq->netq_lock, MUTEX_DEFAULT, IPL_NET);
-       r = virtio_alloc_vq(vsc, vq, qid,
+       virtio_init_vq(vsc, vq, qid, params[dir].intrhand, netq);
+
+       r = virtio_alloc_vq(vsc, vq,
            params[dir].segsize + sc->sc_hdr_size,
            params[dir].nsegs, qname);
        if (r != 0)
                goto err;
        netq->netq_vq = vq;
 
-       netq->netq_vq->vq_intrhand = params[dir].intrhand;
-       netq->netq_vq->vq_intrhand_arg = netq;
        netq->netq_softint = softint_establish(softint_flags,
            params[dir].sihand, netq);
        if (netq->netq_softint == NULL) {
@@ -1532,8 +1537,6 @@ err:
                softint_disestablish(netq->netq_softint);
                netq->netq_softint = NULL;
        }
-       netq->netq_vq->vq_intrhand = NULL;
-       netq->netq_vq->vq_intrhand_arg = NULL;
 
        virtio_free_vq(vsc, vq);
        mutex_destroy(&netq->netq_lock);
diff -r e9c38c5eb7df -r 56da705c524a sys/dev/pci/ld_virtio.c
--- a/sys/dev/pci/ld_virtio.c   Thu May 04 18:57:28 2023 +0000
+++ b/sys/dev/pci/ld_virtio.c   Sat May 13 10:56:10 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld_virtio.c,v 1.30 2022/04/13 10:42:12 uwe Exp $       */
+/*     $NetBSD: ld_virtio.c,v 1.30.4.1 2023/05/13 10:56:10 martin Exp $        */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.30 2022/04/13 10:42:12 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_virtio.c,v 1.30.4.1 2023/05/13 10:56:10 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -275,8 +275,7 @@ ld_virtio_attach(device_t parent, device
        sc->sc_dev = self;
        sc->sc_virtio = vsc;
 
-       virtio_child_attach_start(vsc, self, IPL_BIO, &sc->sc_vq,
-           NULL, virtio_vq_intr, VIRTIO_F_INTR_MSIX,
+       virtio_child_attach_start(vsc, self, IPL_BIO,
            (VIRTIO_BLK_F_SIZE_MAX | VIRTIO_BLK_F_SEG_MAX |
             VIRTIO_BLK_F_GEOMETRY | VIRTIO_BLK_F_RO | VIRTIO_BLK_F_BLK_SIZE |
             VIRTIO_BLK_F_FLUSH | VIRTIO_BLK_F_CONFIG_WCE),
@@ -333,14 +332,17 @@ ld_virtio_attach(device_t parent, device
        /* 2 for the minimum size */
        maxnsegs += VIRTIO_BLK_MIN_SEGMENTS;
 
-       if (virtio_alloc_vq(vsc, &sc->sc_vq, 0, maxxfersize, maxnsegs,
+       virtio_init_vq_vqdone(vsc, &sc->sc_vq, 0,
+           ld_virtio_vq_done);
+
+       if (virtio_alloc_vq(vsc, &sc->sc_vq, maxxfersize, maxnsegs,
            "I/O request") != 0) {
                goto err;
        }
        qsize = sc->sc_vq.vq_num;
-       sc->sc_vq.vq_done = ld_virtio_vq_done;
 
-       if (virtio_child_attach_finish(vsc) != 0)
+       if (virtio_child_attach_finish(vsc, &sc->sc_vq, 1,
+           NULL, VIRTIO_F_INTR_MSIX) != 0)
                goto err;
 
        ld->sc_dv = self;
diff -r e9c38c5eb7df -r 56da705c524a sys/dev/pci/vio9p.c
--- a/sys/dev/pci/vio9p.c       Thu May 04 18:57:28 2023 +0000
+++ b/sys/dev/pci/vio9p.c       Sat May 13 10:56:10 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vio9p.c,v 1.9 2022/04/20 22:08:10 uwe Exp $    */
+/*     $NetBSD: vio9p.c,v 1.9.4.1 2023/05/13 10:56:10 martin Exp $     */
 
 /*
  * Copyright (c) 2019 Internet Initiative Japan, Inc.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vio9p.c,v 1.9 2022/04/20 22:08:10 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vio9p.c,v 1.9.4.1 2023/05/13 10:56:10 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -500,25 +500,19 @@ vio9p_attach(device_t parent, device_t s
        sc->sc_dev = self;
        sc->sc_virtio = vsc;
 
-       virtio_child_attach_start(vsc, self, IPL_VM, sc->sc_vq,
-           NULL, virtio_vq_intr,
-           VIRTIO_F_INTR_MPSAFE | VIRTIO_F_INTR_SOFTINT,
-           VIO9P_F_MOUNT_TAG,
-           VIO9P_FLAG_BITS);
+       virtio_child_attach_start(vsc, self, IPL_VM,
+           VIO9P_F_MOUNT_TAG, VIO9P_FLAG_BITS);
 
        features = virtio_features(vsc);
        if ((features & VIO9P_F_MOUNT_TAG) == 0)
                goto err_none;
 
-       error = virtio_alloc_vq(vsc, &sc->sc_vq[0], 0, VIO9P_MAX_REQLEN,
+       virtio_init_vq_vqdone(vsc, &sc->sc_vq[0], 0, vio9p_request_done);
+       error = virtio_alloc_vq(vsc, &sc->sc_vq[0], VIO9P_MAX_REQLEN,
            VIO9P_N_SEGMENTS * 2, "vio9p");
        if (error != 0)
                goto err_none;
 
-       sc->sc_vq[0].vq_done = vio9p_request_done;
-
-       virtio_child_attach_set_vqs(vsc, sc->sc_vq, 1);
-
        sc->sc_buf_tx = kmem_alloc(VIO9P_MAX_REQLEN, KM_SLEEP);
        sc->sc_buf_rx = kmem_alloc(VIO9P_MAX_REQLEN, KM_SLEEP);
 
@@ -559,7 +553,9 @@ vio9p_attach(device_t parent, device_t s
        vio9p_read_config(sc);
        aprint_normal_dev(self, "tagged as %s\n", sc->sc_tag);
 
-       error = virtio_child_attach_finish(vsc);
+       error = virtio_child_attach_finish(vsc, sc->sc_vq,
+           __arraycount(sc->sc_vq), NULL,
+           VIRTIO_F_INTR_MPSAFE | VIRTIO_F_INTR_SOFTINT);
        if (error != 0)
                goto err_mutex;
 
diff -r e9c38c5eb7df -r 56da705c524a sys/dev/pci/viomb.c
--- a/sys/dev/pci/viomb.c       Thu May 04 18:57:28 2023 +0000
+++ b/sys/dev/pci/viomb.c       Sat May 13 10:56:10 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: viomb.c,v 1.13 2022/04/13 10:42:12 uwe Exp $   */
+/*     $NetBSD: viomb.c,v 1.13.4.1 2023/05/13 10:56:10 martin Exp $    */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: viomb.c,v 1.13 2022/04/13 10:42:12 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: viomb.c,v 1.13.4.1 2023/05/13 10:56:10 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -148,8 +148,7 @@ viomb_attach(device_t parent, device_t s
        sc->sc_dev = self;
        sc->sc_virtio = vsc;
 
-       virtio_child_attach_start(vsc, self, IPL_VM, sc->sc_vq,
-           viomb_config_change, virtio_vq_intr, 0,
+       virtio_child_attach_start(vsc, self, IPL_VM,
            VIRTIO_BALLOON_F_MUST_TELL_HOST, VIRTIO_BALLOON_FLAG_BITS);
 
        features = virtio_features(vsc);
@@ -164,18 +163,20 @@ viomb_attach(device_t parent, device_t s
        mutex_init(&sc->sc_waitlock, MUTEX_DEFAULT, IPL_VM); /* spin */
        cv_init(&sc->sc_wait, "balloon");
 
-       if (virtio_alloc_vq(vsc, &sc->sc_vq[VQ_INFLATE], 0,
+       virtio_init_vq_vqdone(vsc, &sc->sc_vq[VQ_INFLATE], VQ_INFLATE,
+           inflateq_done);
+       virtio_init_vq_vqdone(vsc, &sc->sc_vq[VQ_DEFLATE], VQ_DEFLATE,
+           deflateq_done);
+
+       if (virtio_alloc_vq(vsc, &sc->sc_vq[VQ_INFLATE],
                             sizeof(uint32_t)*PGS_PER_REQ, 1,
                             "inflate") != 0)
                goto err_mutex;
-       if (virtio_alloc_vq(vsc, &sc->sc_vq[VQ_DEFLATE], 1,
+       if (virtio_alloc_vq(vsc, &sc->sc_vq[VQ_DEFLATE],
                             sizeof(uint32_t)*PGS_PER_REQ, 1,



Home | Main Index | Thread Index | Old Index