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=202512 header.b=VSIgUBPa; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 9DA0B5A004E for ; Mon, 08 Dec 2025 03:16:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1765160214; bh=SWMzZL52KR1soSNgjs8V0XtT04lG9fyz8YWr14+N/4Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VSIgUBPaym7sH1iQxmXMATo7Lifk5LoXH06Z6T6fAPTnAwZfFYloU9weEfqCXlDOP NztWXDNcahTMbpkUDMPdHHs5B3LSlsMwOrSlVjIBt4mQq89WeTRFokZRBPxWM+jYTB wwoD/ozf5WRNsogiOKQT3quKnz7vUXHdOJH988wkmZJW+dUqJP8UIlXPtkfn8je7br M7svWTnxHm9eISfrSoCnCFLRmx4LNqr8riZjQ0iHRlzxF24FJR0MWtDWG6F8k7lde3 7Cqz9Czw0k0R3ngF85xCjGmUyO1HZzjqECrLaxnN64XdXLEcKZnH9IpOWikmE2oRzX +szrgZpFDw6bA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dPlwk0BN1z4wM8; Mon, 08 Dec 2025 13:16:54 +1100 (AEDT) Date: Mon, 8 Dec 2025 13:04:22 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v3 4/5] tcp, udp: Pad batched frames to 60 bytes (802.3 minimum) in non-vhost-user modes Message-ID: References: <20251206012657.553742-1-sbrivio@redhat.com> <20251206012657.553742-5-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="/rpve0HyCZs0ODeB" Content-Disposition: inline In-Reply-To: <20251206012657.553742-5-sbrivio@redhat.com> Message-ID-Hash: P3CISBRFPW6OHHBAUKS4WFFSYL4KSL4N X-Message-ID-Hash: P3CISBRFPW6OHHBAUKS4WFFSYL4KSL4N 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, Laurent Vivier 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: --/rpve0HyCZs0ODeB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Dec 06, 2025 at 02:26:56AM +0100, Stefano Brivio wrote: > Add a further iovec frame part, TCP_IOV_ETH_PAD for TCP and > UDP_IOV_ETH_PAD for UDP, after the payload, make that point to a > zero-filled buffer, and send out a part of it if needed to reach > the minimum frame length given by 802.3, that is, 60 bytes altogether. >=20 > The frames we might need to pad are IPv4 only (the IPv6 header is > larger), and are typically TCP ACK segments but can also be small > data segments or datagrams. >=20 > Link: https://bugs.passt.top/show_bug.cgi?id=3D166 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > tcp.c | 2 +- > tcp_buf.c | 23 +++++++++++++++++++++++ > tcp_internal.h | 2 ++ > udp.c | 33 ++++++++++++++++++++++++++++++--- > util.c | 3 +++ > util.h | 3 +++ > 6 files changed, 62 insertions(+), 4 deletions(-) >=20 > diff --git a/tcp.c b/tcp.c > index d6a5337..a582e4b 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1037,7 +1037,7 @@ void tcp_fill_headers(const struct ctx *c, struct t= cp_tap_conn *conn, > else > tcp_update_csum(psum, th, payload); > =20 > - tap_hdr_update(taph, l3len + sizeof(struct ethhdr)); > + tap_hdr_update(taph, MAX(l3len + sizeof(struct ethhdr), ETH_ZLEN)); > } > =20 > /** > diff --git a/tcp_buf.c b/tcp_buf.c > index 2058225..5d419d3 100644 > --- a/tcp_buf.c > +++ b/tcp_buf.c > @@ -96,6 +96,7 @@ void tcp_sock_iov_init(const struct ctx *c) > iov[TCP_IOV_TAP] =3D tap_hdr_iov(c, &tcp_payload_tap_hdr[i]); > iov[TCP_IOV_ETH].iov_len =3D sizeof(struct ethhdr); > iov[TCP_IOV_PAYLOAD].iov_base =3D &tcp_payload[i]; > + iov[TCP_IOV_ETH_PAD].iov_base =3D eth_pad; > } > } > =20 > @@ -144,6 +145,22 @@ void tcp_payload_flush(const struct ctx *c) > tcp_payload_used =3D 0; > } > =20 > +/** > + * tcp_l2_buf_pad() - Calculate padding to send out of padding (zero) bu= ffer > + * @iov: Pointer to iovec of frame parts we're about to send > + */ > +static void tcp_l2_buf_pad(struct iovec *iov) > +{ > + size_t l2len =3D iov[TCP_IOV_ETH].iov_len + > + iov[TCP_IOV_IP].iov_len + > + iov[TCP_IOV_PAYLOAD].iov_len; > + > + if (l2len < ETH_ZLEN) > + iov[TCP_IOV_ETH_PAD].iov_len =3D ETH_ZLEN - l2len; > + else > + iov[TCP_IOV_ETH_PAD].iov_len =3D 0; > +} > + > /** > * tcp_l2_buf_fill_headers() - Fill 802.3, IP, TCP headers in pre-cooked= buffers > * @c: Execution context > @@ -212,6 +229,8 @@ int tcp_buf_send_flag(const struct ctx *c, struct tcp= _tap_conn *conn, int flags) > iov[TCP_IOV_PAYLOAD].iov_len =3D l4len; > tcp_l2_buf_fill_headers(c, conn, iov, NULL, seq, false); > =20 > + tcp_l2_buf_pad(iov); > + > if (flags & DUP_ACK) { > struct iovec *dup_iov =3D tcp_l2_iov[tcp_payload_used]; > tcp_frame_conns[tcp_payload_used++] =3D conn; > @@ -223,6 +242,7 @@ int tcp_buf_send_flag(const struct ctx *c, struct tcp= _tap_conn *conn, int flags) > memcpy(dup_iov[TCP_IOV_PAYLOAD].iov_base, > iov[TCP_IOV_PAYLOAD].iov_base, l4len); > dup_iov[TCP_IOV_PAYLOAD].iov_len =3D l4len; > + dup_iov[TCP_IOV_ETH_PAD].iov_len =3D iov[TCP_IOV_ETH_PAD].iov_len; > } > =20 > if (tcp_payload_used > TCP_FRAMES_MEM - 2) > @@ -270,6 +290,9 @@ static void tcp_data_to_tap(const struct ctx *c, stru= ct tcp_tap_conn *conn, > payload->th.psh =3D push; > iov[TCP_IOV_PAYLOAD].iov_len =3D dlen + sizeof(struct tcphdr); > tcp_l2_buf_fill_headers(c, conn, iov, check, seq, false); > + > + tcp_l2_buf_pad(iov); > + > if (++tcp_payload_used > TCP_FRAMES_MEM - 1) > tcp_payload_flush(c); > } > diff --git a/tcp_internal.h b/tcp_internal.h > index 19e8922..5f8fb35 100644 > --- a/tcp_internal.h > +++ b/tcp_internal.h > @@ -63,6 +63,7 @@ > * @TCP_IOV_ETH Ethernet header > * @TCP_IOV_IP IP (v4/v6) header > * @TCP_IOV_PAYLOAD IP payload (TCP header + data) > + * @TCP_IOV_ETH_PAD Ethernet (802.3) padding to 60 bytes > * @TCP_NUM_IOVS the number of entries in the iovec array > */ > enum tcp_iov_parts { > @@ -70,6 +71,7 @@ enum tcp_iov_parts { > TCP_IOV_ETH =3D 1, > TCP_IOV_IP =3D 2, > TCP_IOV_PAYLOAD =3D 3, > + TCP_IOV_ETH_PAD =3D 4, > TCP_NUM_IOVS > }; > =20 > diff --git a/udp.c b/udp.c > index b93c18b..08bec50 100644 > --- a/udp.c > +++ b/udp.c > @@ -168,6 +168,7 @@ udp_meta[UDP_MAX_FRAMES]; > * @UDP_IOV_ETH Ethernet header > * @UDP_IOV_IP IP (v4/v6) header > * @UDP_IOV_PAYLOAD IP payload (UDP header + data) > + * @UDP_IOV_ETH_PAD Ethernet (802.3) padding to 60 bytes > * @UDP_NUM_IOVS the number of entries in the iovec array > */ > enum udp_iov_idx { > @@ -175,6 +176,7 @@ enum udp_iov_idx { > UDP_IOV_ETH, > UDP_IOV_IP, > UDP_IOV_PAYLOAD, > + UDP_IOV_ETH_PAD, > UDP_NUM_IOVS, > }; > =20 > @@ -239,6 +241,7 @@ static void udp_iov_init_one(const struct ctx *c, siz= e_t i) > tiov[UDP_IOV_ETH] =3D IOV_OF_LVALUE(udp_eth_hdr[i]); > tiov[UDP_IOV_TAP] =3D tap_hdr_iov(c, &meta->taph); > tiov[UDP_IOV_PAYLOAD].iov_base =3D payload; > + tiov[UDP_IOV_ETH_PAD].iov_base =3D eth_pad; > =20 > mh->msg_iov =3D siov; > mh->msg_iovlen =3D 1; > @@ -344,6 +347,22 @@ size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct = udp_payload_t *bp, > return l4len; > } > =20 > +/** > + * udp_tap_pad() - Calculate padding to send out of padding (zero) buffer > + * @iov: Pointer to iovec of frame parts we're about to send > + */ > +static void udp_tap_pad(struct iovec *iov) > +{ > + size_t l2len =3D iov[UDP_IOV_ETH].iov_len + > + iov[UDP_IOV_IP].iov_len + > + iov[UDP_IOV_PAYLOAD].iov_len; > + > + if (l2len < ETH_ZLEN) > + iov[UDP_IOV_ETH_PAD].iov_len =3D ETH_ZLEN - l2len; > + else > + iov[UDP_IOV_ETH_PAD].iov_len =3D 0; > +} > + > /** > * udp_tap_prepare() - Convert one datagram into a tap frame > * @mmh: Receiving mmsghdr array > @@ -362,23 +381,31 @@ static void udp_tap_prepare(const struct mmsghdr *m= mh, > struct ethhdr *eh =3D (*tap_iov)[UDP_IOV_ETH].iov_base; > struct udp_payload_t *bp =3D &udp_payload[idx]; > struct udp_meta_t *bm =3D &udp_meta[idx]; > - size_t l4len; > + size_t l4len, l2len; > =20 > eth_update_mac(eh, NULL, tap_omac); > if (!inany_v4(&toside->eaddr) || !inany_v4(&toside->oaddr)) { > l4len =3D udp_update_hdr6(&bm->ip6h, bp, toside, > mmh[idx].msg_len, no_udp_csum); > - tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip6h) + ETH_HLEN); > + > + l2len =3D MAX(l4len + sizeof(bm->ip6h) + ETH_HLEN, ETH_ZLEN); > + tap_hdr_update(&bm->taph, l2len); > + > eh->h_proto =3D htons_constant(ETH_P_IPV6); > (*tap_iov)[UDP_IOV_IP] =3D IOV_OF_LVALUE(bm->ip6h); > } else { > l4len =3D udp_update_hdr4(&bm->ip4h, bp, toside, > mmh[idx].msg_len, no_udp_csum); > - tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip4h) + ETH_HLEN); > + > + l2len =3D MAX(l4len + sizeof(bm->ip4h) + ETH_HLEN, ETH_ZLEN); > + tap_hdr_update(&bm->taph, l2len); > + > eh->h_proto =3D htons_constant(ETH_P_IP); > (*tap_iov)[UDP_IOV_IP] =3D IOV_OF_LVALUE(bm->ip4h); > } > (*tap_iov)[UDP_IOV_PAYLOAD].iov_len =3D l4len; > + > + udp_tap_pad(*tap_iov); > } > =20 > /** > diff --git a/util.c b/util.c > index 590373d..d2039df 100644 > --- a/util.c > +++ b/util.c > @@ -39,6 +39,9 @@ > #include > #endif > =20 > +/* Zero-filled buffer to pad 802.3 frames, up to 60 (ETH_ZLEN) bytes */ > +uint8_t eth_pad[ETH_ZLEN] =3D { 0 }; > + > /** > * sock_l4_() - Create and bind socket to socket address > * @c: Execution context > diff --git a/util.h b/util.h > index 40de694..326012c 100644 > --- a/util.h > +++ b/util.h > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > =20 > #include "log.h" > =20 > @@ -152,6 +153,8 @@ void abort_with_msg(const char *fmt, ...) > #define ntohll(x) (be64toh((x))) > #define htonll(x) (htobe64((x))) > =20 > +extern uint8_t eth_pad[ETH_ZLEN]; > + > /** > * ntohl_unaligned() - Read 32-bit BE value from a possibly unaligned ad= dress > * @p: Pointer to the BE value in memory > --=20 > 2.43.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 --/rpve0HyCZs0ODeB Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmk2MhsACgkQzQJF27ox 2Gc5KRAAiMVWw769HCR/854vReEF0GLRLNY0q9BVnNst6d/fC/HXgy8Yh24GV9vR +bizrIpAPs4P6d+nkAmuWoxt6NYYpEXCXiOYA3Mi4xCrQjdi2EwOhidThP8hWBGb ka/GAonzzopIAsKue7z1Rj5iBJNm4mEVUO7ofogIMFOr1x6w6ytu9h2wS3qe+1Gn qNka1sgDhtfMlwVC6Bcl6KiFCb+NAu/FZjcyGK0AxIamyBNq0hT1TAH1qmOZFiUW 6mKNyoU2ihl0eP5ywKUoL6izuuPxDjSMdrwQAR/M8uKbF0Q9zd8+ghAMbpB5Yq3l dj4k3TSo373zepoAVRJRW/gBqOgNvv89cEM7rTHNMZkBGUy7G7UfLPcCEXUyI0Mr 4Akt1Rse9BdXbpE6Es0Xh/+CI9LaWABMSUAdkLgLLP25nEU8USpxj3dtrqoADyrW FzEx9v2SDncfoH+60w11U9/a10fgmk37eoxsO3/7x4osQ7+vWrOSUU4mTufs5aIR zOKIt5icX0V17ne7UJOlt5MAi+n3XyKsZJmHAt7i4gLpLd3gIOVVXUwhX/7Jhdii oFwfYASjy8yEEY+p30I1whpgOq167LtDRSXS6aloys5X8kppvzvkFWk8phOdVZol jK6ciTa1JjFg4z8OG8IieNztLmJdigFEhSBUsOXMglB8NOymlDE= =OYRh -----END PGP SIGNATURE----- --/rpve0HyCZs0ODeB--