Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/virtio viocon(4): fix not to allocate unused virtqueue



details:   https://anonhg.NetBSD.org/src/rev/6301f20f96e4
branches:  trunk
changeset: 373974:6301f20f96e4
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Thu Mar 23 03:44:28 2023 +0000

description:
viocon(4): fix not to allocate unused virtqueue

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

diffstat:

 sys/dev/virtio/viocon.c |  22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diffs (77 lines):

diff -r 28a8ceb6310e -r 6301f20f96e4 sys/dev/virtio/viocon.c
--- a/sys/dev/virtio/viocon.c   Thu Mar 23 03:29:28 2023 +0000
+++ b/sys/dev/virtio/viocon.c   Thu Mar 23 03:44:28 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: viocon.c,v 1.6 2023/03/23 03:27:48 yamaguchi Exp $     */
+/*     $NetBSD: viocon.c,v 1.7 2023/03/23 03:44:28 yamaguchi Exp $     */
 /*     $OpenBSD: viocon.c,v 1.8 2021/11/05 11:38:29 mpi Exp $  */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: viocon.c,v 1.6 2023/03/23 03:27:48 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: viocon.c,v 1.7 2023/03/23 03:44:28 yamaguchi Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -123,6 +123,9 @@
        struct device           *sc_dev;
        struct virtio_softc     *sc_virtio;
        struct virtqueue        *sc_vqs;
+#define VIOCON_PORT_RX 0
+#define VIOCON_PORT_TX 1
+#define VIOCON_PORT_NQS        2
 
        struct virtqueue        *sc_c_vq_rx;
        struct virtqueue        *sc_c_vq_tx;
@@ -194,6 +197,7 @@
        struct viocon_softc *sc = device_private(self);
        struct virtio_softc *vsc = device_private(parent);
        int maxports = 1;
+       size_t nvqs;
 
        sc->sc_dev = self;
        if (virtio_child(vsc) != NULL) {
@@ -203,8 +207,9 @@
        }
        sc->sc_virtio = vsc;
        sc->sc_max_ports = maxports;
+       nvqs = VIOCON_PORT_NQS * maxports;
 
-       sc->sc_vqs = kmem_zalloc(2 * (maxports + 1) * sizeof(sc->sc_vqs[0]),
+       sc->sc_vqs = kmem_zalloc(nvqs * sizeof(sc->sc_vqs[0]),
            KM_SLEEP);
        sc->sc_ports = kmem_zalloc(maxports * sizeof(sc->sc_ports[0]),
            KM_SLEEP);
@@ -219,13 +224,13 @@
        }
        viocon_rx_fill(sc->sc_ports[0]);
 
-       if (virtio_child_attach_finish(vsc, sc->sc_vqs, sc->sc_max_ports * 2,
+       if (virtio_child_attach_finish(vsc, sc->sc_vqs, nvqs,
            /*config_change*/NULL, virtio_vq_intr, /*req_flags*/0) != 0)
                goto err;
 
        return;
 err:
-       kmem_free(sc->sc_vqs, 2 * (maxports + 1) * sizeof(sc->sc_vqs[0]));
+       kmem_free(sc->sc_vqs, nvqs * sizeof(sc->sc_vqs[0]));
        kmem_free(sc->sc_ports, maxports * sizeof(sc->sc_ports[0]));
        virtio_child_attach_failed(vsc);
 }
@@ -247,11 +252,8 @@
        vp->vp_sc = sc;
        DPRINTF("%s: vp: %p\n", __func__, vp);
 
-       if (portidx == 0)
-               rxidx = 0;
-       else
-               rxidx = 2 * (portidx + 1);
-       txidx = rxidx + 1;
+       rxidx = (portidx * VIOCON_PORT_NQS) + VIOCON_PORT_RX;
+       txidx = (portidx * VIOCON_PORT_NQS) + VIOCON_PORT_TX;
 
        snprintf(name, sizeof(name), "p%drx", portidx);
        if (virtio_alloc_vq(vsc, &sc->sc_vqs[rxidx], rxidx, BUFSIZE, 1,



Home | Main Index | Thread Index | Old Index