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=OlqcMTR+; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id D2C7C5A0269 for ; Thu, 14 May 2026 03:10:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1778721049; bh=v0AZ8/M5ufUEnAiXsRHhTlccwAzrN7BRx8pl+Y4epOU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OlqcMTR+QmMGT1Ysx6KYXnm/skBudc26+Ga+fZSPKIisY6WHKn6Oy7LQ7OjOUVTJy kcFG4N+J30KAQkAzQyV75TCdaKcMp4OD/hyIBkLBvyJUobLsGdSmrjxgzPOVnNactE nAg4ZcoQ5w7v5WoX+cwnIo6+zohTpbEvtLJwP4BgKSGQcMt8BYeKSsAVyagD4mR52E VwgPg3z8onkLeRpKJolFfksxghzyIjwbcHS115ZsPBy+iyJg+0s7QNRTd85PMfEBIV vkoQ/Ggr4T6Cxl1nM/aQp/qwuQbmVN5cSgrhkT4yiIf6GGXeLF1goaIxz8oc8+0BT4 qDZKr2UwLIA2g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gGC211xlQz4wKR; Thu, 14 May 2026 11:10:49 +1000 (AEST) Date: Thu, 14 May 2026 11:06:46 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v3 10/10] vhost-user: Centralise Ethernet frame padding in vu_collect() and vu_pad() Message-ID: References: <20260416155721.3807225-1-lvivier@redhat.com> <20260416155721.3807225-11-lvivier@redhat.com> <003a0da1-47b9-42fd-8a0a-bc07af0051f5@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="EQQK9JUd8bchYqXX" Content-Disposition: inline In-Reply-To: <003a0da1-47b9-42fd-8a0a-bc07af0051f5@redhat.com> Message-ID-Hash: EW6NEJRECO4BIEFBB3XPCUAX22SVOSEO X-Message-ID-Hash: EW6NEJRECO4BIEFBB3XPCUAX22SVOSEO 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: --EQQK9JUd8bchYqXX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 13, 2026 at 11:17:12AM +0200, Laurent Vivier wrote: > On 5/11/26 04:01, David Gibson wrote: > > On Thu, Apr 16, 2026 at 05:57:21PM +0200, Laurent Vivier wrote: > > > The previous per-protocol padding done by vu_pad() in tcp_vu.c and > > > udp_vu.c was only correct for single-buffer frames: it assumed the > > > padding area always fell within the first iov, writing past its end > > > with a plain memset(). > > >=20 > > > It also required each caller to compute MAX(..., ETH_ZLEN + VNET_HLEN) > > > for vu_collect() and to call vu_pad() at the right point, duplicating > > > the minimum-size logic across protocols. > > >=20 > > > Move the Ethernet minimum size enforcement into vu_collect() itself, = so > > > that enough buffer space is always reserved for padding regardless of > > > the requested frame size. > > >=20 > > > Rewrite vu_pad() to take a full iovec array and use iov_memset(), > > > making it safe for multi-buffer (mergeable rx buffer) frames. > > >=20 > > > In tcp_vu_sock_recv(), replace iov_truncate() with iov_skip_bytes(): > > > now that all consumers receive explicit data lengths, truncating the > > > iovecs is no longer needed. In tcp_vu_data_from_sock(), cap each > > > frame's data length against the remaining bytes actually received from > > > the socket, so that the last partial frame gets correct headers and > > > sequence number advancement. > > >=20 > > > Signed-off-by: Laurent Vivier > >=20 > > LGTM, except for what looks like one minor bug. > >=20 > > [snip] > > > index 704e908aa02c..d07f584f228a 100644 > > > --- a/vu_common.c > > > +++ b/vu_common.c > > > @@ -74,6 +74,7 @@ int vu_collect(const struct vu_dev *vdev, struct vu= _virtq *vq, > > > size_t current_iov =3D 0; > > > int elem_cnt =3D 0; > > > + size =3D MAX(size, ETH_ZLEN /* Ethernet minimum size */ + VNET_HLEN= ); > >=20 > > This seems to imply size should include the vnet header... >=20 > size is the max of "size" provided below by vu_single() to vu_collect() (= and > you noted includes vnet header) and the the minimum frame size (Ethernet > minimum + vnet header) >=20 > >=20 > > > while (current_size < size && elem_cnt < max_elem && > > > current_iov < max_in_sg) { > > > int ret; > > > @@ -261,29 +262,27 @@ int vu_send_single(const struct ctx *c, const v= oid *buf, size_t size) > > > return -1; > > > } > > > - size +=3D VNET_HLEN; > > > elem_cnt =3D vu_collect(vdev, vq, elem, ARRAY_SIZE(elem), in_sg, > > > - ARRAY_SIZE(in_sg), &in_total, size, &total); > > > - if (elem_cnt =3D=3D 0 || total < size) { > > > + ARRAY_SIZE(in_sg), &in_total, VNET_HLEN + size, &total); > >=20 > > ...but this seems to imply it doesn't. >=20 > This is not the same "size". Here "size" is without vnet header, but we n= eed > to provide a size with vnet header to vu_collect(). Oops. I thought I'd checked that these were the same function, but clearly I got myself confused. Naming tweaks might make this harder to mistake - I think l2len would be appropriate for this one. We don't have a standard name for the length including VNET_LEN (or whatever "device" level header/descriptor we have, like the qemu frame length), maybe we should invent one? >=20 > >=20 > > > + if (elem_cnt =3D=3D 0 || total < VNET_HLEN + size) { > > > debug("vu_send_single: no space to send the data " > > > "elem_cnt %d size %zu", elem_cnt, total); > > > goto err; > > > } > > > - total -=3D VNET_HLEN; > > > - > > > /* copy data from the buffer to the iovec */ > > > - iov_from_buf(in_sg, in_total, VNET_HLEN, buf, total); > > > + iov_from_buf(in_sg, in_total, VNET_HLEN, buf, size); > > > if (*c->pcap) > > > pcap_iov(in_sg, in_total, VNET_HLEN, size); > > > + vu_pad(in_sg, in_total, VNET_HLEN + size); > >=20 > > As does this. >=20 > Same here (see vu_pad() comment header) >=20 > >=20 > > > vu_flush(vdev, vq, elem, elem_cnt, VNET_HLEN + size); > >=20 > > And this. >=20 > See vu_flush() comment header >=20 > >=20 > > > vu_queue_notify(vdev, vq); > > > - trace("vhost-user sent %zu", total); > > > + trace("vhost-user sent %zu", size); > > > - return total; > > > + return size; > > > err: > > > for (i =3D 0; i < elem_cnt; i++) > > > vu_queue_detach_element(vq); > > > @@ -292,15 +291,15 @@ err: > > > } > > > /** > > > - * vu_pad() - Pad 802.3 frame to minimum length (60 bytes) if needed > > > - * @iov: Buffer in iovec array where end of 802.3 frame is stored > > > - * @l2len: Layer-2 length already filled in frame > > > + * vu_pad() - Pad short frames to minimum Ethernet length and trunca= te iovec > > > + * @iov: Pointer to iovec array > > > + * @cnt: Number of entries in @iov > > > + * @frame_len: Data length in @iov (including virtio-net header) > > > */ > > > -void vu_pad(struct iovec *iov, size_t l2len) > > > +void vu_pad(const struct iovec *iov, size_t cnt, size_t frame_len) > > > { > > > - if (l2len >=3D ETH_ZLEN) > > > - return; > > > + size_t min_frame_len =3D ETH_ZLEN + VNET_HLEN; > > > - memset((char *)iov->iov_base + iov->iov_len, 0, ETH_ZLEN - l2len); > > > - iov->iov_len +=3D ETH_ZLEN - l2len; > > > + if (frame_len < min_frame_len) > > > + iov_memset(iov, cnt, frame_len, 0, min_frame_len - frame_len); > > > } > > > diff --git a/vu_common.h b/vu_common.h > > > index 77d1849e6115..51f70084a7cb 100644 > > > --- a/vu_common.h > > > +++ b/vu_common.h > > > @@ -44,6 +44,6 @@ void vu_flush(const struct vu_dev *vdev, struct vu_= virtq *vq, > > > 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 siz= e); > > > -void vu_pad(struct iovec *iov, size_t l2len); > > > +void vu_pad(const struct iovec *iov, size_t cnt, size_t frame_len); > > > #endif /* VU_COMMON_H */ > > > --=20 > > > 2.53.0 > > >=20 > >=20 >=20 > Thanks, > Laurent >=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 --EQQK9JUd8bchYqXX Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoFICUACgkQzQJF27ox 2GdzmA/+It9JC0cVJM6oiIuhlfOHVlS0XlpX0q8rSQnLcoRDVmadLyLbWmiAyZq7 1GuaczjpInZV6VGv7vmk963k9sZDqZBXeJYlupAx9o9OmMy3Z37RzjK9MCSmPG/V 3rJ6oAHpcRT3rasl1ZH9L9zpxC3FiFzw/ne5xe2blxg6Ojsq/0C5XgBpX2xK9zas byoC98I6PLw1ihhZeqBu8EtVShSwhpudjNL192RzPWddzj62zyLWfsDhxqKK6akk /n9VVnvo90gTbukfEN63w+/+JF1uUrnL5zIA9YLxBWFVAA5PLSjvviXFlUqYnhgf 4/t9fHMRluGpOU3XjH+l+ihO+9T8+xmIAfXWZbBpg5kPSgZwWtO55uCrQOQ64aw1 Zrv8wfWVn0s3TErNYctvRlN70Zero/+Gq/VU8zePOIr0toJ2OGvzyeuKgaG+Ssyz DIXFO4bNWJyJkOdH9GlfX3rpAYdtM0SV4/TBnuVdyVwCxxoEb+O/JeJzUAs7c84k GmkA4Vw5fDe8cjK5t8VcX0irgZy1uvf53JoNfQQToQs5CsAgC4pSDHgJo2IeRyvO xnyQaOhBNhw7BWCz175NqdYy+BOGcoOVOB2ioEV74zmUvLFcVFXdN8YxXXeQnxbf 72cUmx8NzZPGAsF4gjPblxFvjwmBeMaF4/DGoKey8MKqjWKfjHA= =fyBC -----END PGP SIGNATURE----- --EQQK9JUd8bchYqXX--