From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=bApFageu; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 971475A026D for ; Fri, 10 Apr 2026 09:21:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1775805703; bh=F2dksmsaqunf2wOJr4YDbXm24tNToTZ6g+wqfLNXGzY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bApFageu2ljEAq4Wffltgc4Wx7sQCbO63aR581J4wkl42Yy5DJqeeo3uQk3DIe+S9 OYFxvpt8kvMWWM9lTm9f268mpTkM8cXTpa0dlxQqtBkGRsOsR31/aT0a+Xuc99jYNd zkrR6u4zJ3Ju5/6DAnjqwbQR7BsqB9joLPD1DvzvEk0QsHLw+wc7S6niPliwhk54hE iC34BhXrq2aoK0rpqt1k+RLu0x+SJE+L8CAn/+MIPgaC2LK4ECs8/POtqjTmglYGRF a7C3GzsOFNrVjZmuBaiek9+NxNXiaLuqmp65N+5x2SWC/WnbSzHJ0cVR4+Yswg+Ebm A9BM6uZ6LeN2g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fsSsg2PF9z4wK5; Fri, 10 Apr 2026 17:21:43 +1000 (AEST) Date: Fri, 10 Apr 2026 17:21:39 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 08/10] vu_common: Pass explicit frame length to vu_flush() Message-ID: References: <20260403163811.3209635-1-lvivier@redhat.com> <20260403163811.3209635-9-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="pUUje9vO7baDMOHI" Content-Disposition: inline In-Reply-To: <20260403163811.3209635-9-lvivier@redhat.com> Message-ID-Hash: SVLALIRJTY35NRC2H7XSMCWIELHIPZW6 X-Message-ID-Hash: SVLALIRJTY35NRC2H7XSMCWIELHIPZW6 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --pUUje9vO7baDMOHI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 03, 2026 at 06:38:09PM +0200, Laurent Vivier wrote: > Currently vu_flush() derives the frame size from the iov, but in > preparation for iov arrays that may be larger than the actual frame, > pass the total length (including vnet header) explicitly so that only > the relevant portion is reported to the virtqueue. >=20 > Ensure a minimum frame size of ETH_ZLEN + VNET_HLEN to handle short > frames. All elements are still flushed to avoid descriptor leaks, > but trailing elements beyond frame_len will report a zero length. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > tcp_vu.c | 6 +++--- > udp_vu.c | 2 +- > vu_common.c | 16 ++++++++++++---- > vu_common.h | 2 +- > 4 files changed, 17 insertions(+), 9 deletions(-) >=20 > diff --git a/tcp_vu.c b/tcp_vu.c > index 7b7ea9c789b1..4eba7b8a5190 100644 > --- a/tcp_vu.c > +++ b/tcp_vu.c > @@ -140,7 +140,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_= tap_conn *conn, int flags) > =20 > vu_pad(&flags_elem[0].in_sg[0], l2len); > =20 > - vu_flush(vdev, vq, flags_elem, 1); > + vu_flush(vdev, vq, flags_elem, 1, hdrlen + optlen); > =20 > if (*c->pcap) > pcap_iov(&flags_elem[0].in_sg[0], 1, VNET_HLEN, l2len); > @@ -156,7 +156,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_= tap_conn *conn, int flags) > flags_elem[0].in_sg[0].iov_base, > flags_elem[0].in_sg[0].iov_len); > =20 > - vu_flush(vdev, vq, &flags_elem[1], 1); > + vu_flush(vdev, vq, &flags_elem[1], 1, hdrlen + optlen); > =20 > if (*c->pcap) { > pcap_iov(&flags_elem[1].in_sg[0], 1, VNET_HLEN, > @@ -463,7 +463,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct= tcp_tap_conn *conn) > l2len =3D dlen + hdrlen - VNET_HLEN; > vu_pad(iov, l2len); > =20 > - vu_flush(vdev, vq, &elem[head[i]], buf_cnt); > + vu_flush(vdev, vq, &elem[head[i]], buf_cnt, dlen + hdrlen); > =20 > if (*c->pcap) > pcap_iov(iov, buf_cnt, VNET_HLEN, l2len); > diff --git a/udp_vu.c b/udp_vu.c > index 81491afa7e6a..4641f42eb5c4 100644 > --- a/udp_vu.c > +++ b/udp_vu.c > @@ -234,7 +234,7 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, i= nt n, flow_sidx_t tosidx) > pcap_iov(iov_vu, iov_cnt, VNET_HLEN, > hdrlen + dlen - VNET_HLEN); > } > - vu_flush(vdev, vq, elem, elem_used); > + vu_flush(vdev, vq, elem, elem_used, hdrlen + dlen); > vu_queue_notify(vdev, vq); > } > } > diff --git a/vu_common.c b/vu_common.c > index f254cb67ec78..704e908aa02c 100644 > --- a/vu_common.c > +++ b/vu_common.c > @@ -134,18 +134,26 @@ static void vu_set_vnethdr(struct virtio_net_hdr_mr= g_rxbuf *vnethdr, > * @vq: vhost-user virtqueue > * @elem: virtqueue elements array to send back to the virtqueue > * @elem_cnt: Length of the array > + * @frame_len: Total frame length including vnet header > */ > void vu_flush(const struct vu_dev *vdev, struct vu_virtq *vq, > - struct vu_virtq_element *elem, int elem_cnt) > + struct vu_virtq_element *elem, int elem_cnt, size_t frame_len) > { > + size_t len; > int i; > =20 > vu_set_vnethdr(elem[0].in_sg[0].iov_base, elem_cnt); > =20 > + len =3D MAX(ETH_ZLEN + VNET_HLEN, frame_len); > for (i =3D 0; i < elem_cnt; i++) { > - size_t elem_size =3D iov_size(elem[i].in_sg, elem[i].in_num); > + size_t elem_size, fill_size; > =20 > - vu_queue_fill(vdev, vq, &elem[i], elem_size, i); > + elem_size =3D iov_size(elem[i].in_sg, elem[i].in_num); > + fill_size =3D MIN(elem_size, len); > + > + vu_queue_fill(vdev, vq, &elem[i], fill_size, i); > + > + len -=3D fill_size; > } > =20 > vu_queue_flush(vdev, vq, elem_cnt); > @@ -270,7 +278,7 @@ int vu_send_single(const struct ctx *c, const void *b= uf, size_t size) > if (*c->pcap) > pcap_iov(in_sg, in_total, VNET_HLEN, size); > =20 > - vu_flush(vdev, vq, elem, elem_cnt); > + vu_flush(vdev, vq, elem, elem_cnt, VNET_HLEN + size); > vu_queue_notify(vdev, vq); > =20 > trace("vhost-user sent %zu", total); > diff --git a/vu_common.h b/vu_common.h > index 4037ab765b7d..77d1849e6115 100644 > --- a/vu_common.h > +++ b/vu_common.h > @@ -40,7 +40,7 @@ int vu_collect(const struct vu_dev *vdev, struct vu_vir= tq *vq, > struct iovec *in_sg, size_t max_in_sg, size_t *in_total, > size_t size, size_t *collected); > void vu_flush(const struct vu_dev *vdev, struct vu_virtq *vq, > - struct vu_virtq_element *elem, int elem_cnt); > + struct vu_virtq_element *elem, int elem_cnt, size_t frame_len); > void vu_kick_cb(struct vu_dev *vdev, union epoll_ref ref, > const struct timespec *now); > int vu_send_single(const struct ctx *c, const void *buf, size_t size); > --=20 > 2.53.0 >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --pUUje9vO7baDMOHI Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnYpQIACgkQzQJF27ox 2Gcvsw//ULToCQsLChQaMEnwg/NuYbKR1U+B+qulJCIlzUozL4p4qQZpV8MBSP88 xIHLKu+N7x5pF9iWKPhFplrAQO9f5W9FoSmXb/qQagGPXTIY4kxEJe1kig2Lw4NO Kc5pP4W68bDpUPi8Y6p5QdiZ5/DGGRZ7MF93RVospFmA095y5MyxLwm0BFb36s4g N8xxHMNzjV/x5aPyIai0nwcBo/Lj6ISrBY4IXPsh6edkBkFBzL1VthZi/1y2cgBF Op1lug+GjgUgIIDlBkruUa4JLnujr+HRbUSHWc2gex87ScnK+B/VH5dSeSBYbM7u wOnZ00RU/autTGw+C7tIKuPNnoYXvpF8cu0y2otUB1R6WlC85bYB0OSB3L1o07KH jXximhXkjznPsCY5cbvrf8Pov8J20qZI/oooOrv9HvYcQF3IJ7t2BDwhlbP3igiV zC3/5hoF1J7bUzHSxbqeCXbOpVUpys1TGPE9qWuPzKTn408m20d3iZGphPDHfDOz qV3D21Uv9KaWit/GcH9quxxfV0JS5tF/T8mFUz3nlyUdgDV3cfvajdOR9uPej7Ws brc217vlISCDcNw3lJKBrPiHLKrVXy4Gp4H0bdHqy7htqcAktLStcrtPOp3KmIqj nQsceRRYbTRtPx92Z4kkbe2NOkDVoZchhnD/LKPQP82q/jTmHiE= =IDya -----END PGP SIGNATURE----- --pUUje9vO7baDMOHI--