I'm working on some vio(4) stuff and found that the virtio_alloc_vq function defined in sys/dev/pv/virtiovar.h contains a vestigal function arg "int maxsegsize" that was inherited from the original NetBSD code imported.
It's original use was to set a vq_maxsegsize struct member to advise drivers on how large their virtio queue buffers should be, but in practice drivers have used their own local logic when calling things like dma_alloc(9). Setting vq_maxsegsize in the virtio_alloc_vq function was removed just under 4 years ago by sf@ in virtio.c [1] and the struct member was removed in virtiovar.h [2]. I checked NetBSD out of curiousity. The same struct member has lingered for ~10 years in their tree [3]. They set a vq_maxsegsize member on their virtio queue struct, but nothing ever references it. They also carry this unused arg. The diff below removes the argument and updates all callers. No new functionality is added. I've only had a chance to test by booting a kernel under vmm(4)/vmd(8) and not on other hypervisors and didn't find any regressions. OK? Or more testing? -dv [1] https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/pv/virtio.c.diff?r1=1.4&r2=1.5 [2] https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/pv/virtio.c.diff?r1=1.4&r2=1.5 [3] https://github.com/NetBSD/src/search?q=vq_maxsegsize Index: sys/dev/pv/if_vio.c =================================================================== RCS file: /cvs/src/sys/dev/pv/if_vio.c,v retrieving revision 1.19 diff -u -p -r1.19 if_vio.c --- sys/dev/pv/if_vio.c 12 Dec 2020 11:48:53 -0000 1.19 +++ sys/dev/pv/if_vio.c 25 May 2021 03:03:30 -0000 @@ -555,12 +555,11 @@ vio_attach(struct device *parent, struct else ifp->if_hardmtu = MCLBYTES - sc->sc_hdr_size - ETHER_HDR_LEN; - if (virtio_alloc_vq(vsc, &sc->sc_vq[VQRX], 0, MCLBYTES, 2, "rx") != 0) + if (virtio_alloc_vq(vsc, &sc->sc_vq[VQRX], 0, 2, "rx") != 0) goto err; vsc->sc_nvqs = 1; sc->sc_vq[VQRX].vq_done = vio_rx_intr; if (virtio_alloc_vq(vsc, &sc->sc_vq[VQTX], 1, - sc->sc_hdr_size + ifp->if_hardmtu + ETHER_HDR_LEN, VIRTIO_NET_TX_MAXNSEGS + 1, "tx") != 0) { goto err; } @@ -573,7 +572,7 @@ vio_attach(struct device *parent, struct virtio_stop_vq_intr(vsc, &sc->sc_vq[VQTX]); if (virtio_has_feature(vsc, VIRTIO_NET_F_CTRL_VQ) && virtio_has_feature(vsc, VIRTIO_NET_F_CTRL_RX)) { - if (virtio_alloc_vq(vsc, &sc->sc_vq[VQCTL], 2, NBPG, 1, + if (virtio_alloc_vq(vsc, &sc->sc_vq[VQCTL], 2, 1, "control") == 0) { sc->sc_vq[VQCTL].vq_done = vio_ctrleof; virtio_start_vq_intr(vsc, &sc->sc_vq[VQCTL]); Index: sys/dev/pv/vioblk.c =================================================================== RCS file: /cvs/src/sys/dev/pv/vioblk.c,v retrieving revision 1.32 diff -u -p -r1.32 vioblk.c --- sys/dev/pv/vioblk.c 15 Oct 2020 13:22:13 -0000 1.32 +++ sys/dev/pv/vioblk.c 25 May 2021 03:03:30 -0000 @@ -207,8 +207,8 @@ vioblk_attach(struct device *parent, str sc->sc_capacity = virtio_read_device_config_8(vsc, VIRTIO_BLK_CONFIG_CAPACITY); - if (virtio_alloc_vq(vsc, &sc->sc_vq[0], 0, MAXPHYS, ALLOC_SEGS, - "I/O request") != 0) { + if (virtio_alloc_vq(vsc, &sc->sc_vq[0], 0, ALLOC_SEGS, "I/O request") + != 0) { printf("\nCan't alloc virtqueue\n"); goto err; } Index: sys/dev/pv/viomb.c =================================================================== RCS file: /cvs/src/sys/dev/pv/viomb.c,v retrieving revision 1.7 diff -u -p -r1.7 viomb.c --- sys/dev/pv/viomb.c 4 Sep 2020 13:10:16 -0000 1.7 +++ sys/dev/pv/viomb.c 25 May 2021 03:03:30 -0000 @@ -162,12 +162,12 @@ viomb_attach(struct device *parent, stru if (virtio_negotiate_features(vsc, viomb_feature_names) != 0) goto err; - if ((virtio_alloc_vq(vsc, &sc->sc_vq[VQ_INFLATE], VQ_INFLATE, - sizeof(u_int32_t) * PGS_PER_REQ, 1, "inflate") != 0)) + if ((virtio_alloc_vq(vsc, &sc->sc_vq[VQ_INFLATE], VQ_INFLATE, 1, + "inflate") != 0)) goto err; vsc->sc_nvqs++; - if ((virtio_alloc_vq(vsc, &sc->sc_vq[VQ_DEFLATE], VQ_DEFLATE, - sizeof(u_int32_t) * PGS_PER_REQ, 1, "deflate") != 0)) + if ((virtio_alloc_vq(vsc, &sc->sc_vq[VQ_DEFLATE], VQ_DEFLATE, 1, + "deflate") != 0)) goto err; vsc->sc_nvqs++; Index: sys/dev/pv/viornd.c =================================================================== RCS file: /cvs/src/sys/dev/pv/viornd.c,v retrieving revision 1.4 diff -u -p -r1.4 viornd.c --- sys/dev/pv/viornd.c 29 May 2020 04:42:25 -0000 1.4 +++ sys/dev/pv/viornd.c 25 May 2021 03:03:30 -0000 @@ -126,8 +126,7 @@ viornd_attach(struct device *parent, str goto err2; } - if (virtio_alloc_vq(vsc, &sc->sc_vq, 0, VIORND_BUFSIZE, 1, - "Entropy request") != 0) { + if (virtio_alloc_vq(vsc, &sc->sc_vq, 0, 1, "Entropy request") != 0) { printf(": Can't alloc virtqueue\n"); goto err2; } Index: sys/dev/pv/vioscsi.c =================================================================== RCS file: /cvs/src/sys/dev/pv/vioscsi.c,v retrieving revision 1.26 diff -u -p -r1.26 vioscsi.c --- sys/dev/pv/vioscsi.c 22 Sep 2020 19:32:53 -0000 1.26 +++ sys/dev/pv/vioscsi.c 25 May 2021 03:03:30 -0000 @@ -136,8 +136,8 @@ vioscsi_attach(struct device *parent, st } for (i = 0; i < nitems(sc->sc_vqs); i++) { - rv = virtio_alloc_vq(vsc, &sc->sc_vqs[i], i, MAXPHYS, - ALLOC_SEGS, vioscsi_vq_names[i]); + rv = virtio_alloc_vq(vsc, &sc->sc_vqs[i], i, ALLOC_SEGS, + vioscsi_vq_names[i]); if (rv) { printf(": failed to allocate virtqueue %d\n", i); goto err; Index: sys/dev/pv/virtio.c =================================================================== RCS file: /cvs/src/sys/dev/pv/virtio.c,v retrieving revision 1.20 diff -u -p -r1.20 virtio.c --- sys/dev/pv/virtio.c 16 May 2021 15:10:20 -0000 1.20 +++ sys/dev/pv/virtio.c 25 May 2021 03:03:30 -0000 @@ -284,7 +284,7 @@ virtio_init_vq(struct virtio_softc *sc, */ int virtio_alloc_vq(struct virtio_softc *sc, struct virtqueue *vq, int index, - int maxsegsize, int maxnsegs, const char *name) + int maxnsegs, const char *name) { int vq_size, allocsize1, allocsize2, allocsize3, allocsize = 0; int rsegs, r, hdrlen; Index: sys/dev/pv/virtiovar.h =================================================================== RCS file: /cvs/src/sys/dev/pv/virtiovar.h,v retrieving revision 1.14 diff -u -p -r1.14 virtiovar.h --- sys/dev/pv/virtiovar.h 26 May 2019 15:22:31 -0000 1.14 +++ sys/dev/pv/virtiovar.h 25 May 2021 03:03:30 -0000 @@ -210,8 +210,8 @@ virtio_has_feature(struct virtio_softc * return 0; } -int virtio_alloc_vq(struct virtio_softc*, struct virtqueue*, int, int, int, - const char*); +int virtio_alloc_vq(struct virtio_softc*, struct virtqueue*, 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 *);
