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=LQFzIIZV; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 7C1905A061B for ; Mon, 02 Mar 2026 01:13:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1772410422; bh=C4WSbtH4tkOBO8LTXgKQ8aHMKetZSCaY9d6aEofIHy4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LQFzIIZVPTCKYGsf0dInHk8Sh1oly/nsC/ZP4gmeer6tClbCEsoe0aeK6UwESs5Xp u2WfWEAQPEOUcVS7bAQJiTiaK7zUcOqpcBSdolsU8uKI01/LB1dtuNWn5viidYP2DK J/243GrhupXpu8CkfERvjKkvsYQ+bCyj4urnBhPJG8gvvDyCgxBCYoqiH+REuB3TO2 qQSbG5S3BYdlCZ+LPspsARg/REg14euxB5tHPzQvk7+Hr8UyMxvksV9fEFgEbND9bU miPYCEIz0JolHm3hmxmeieaJ8glRnGTBLBSYFMWDgUauK1uuxxIJNGGKJuVNqHqqu+ JAbGhFdbJvn4Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fPKCp4hrNz4wCW; Mon, 02 Mar 2026 11:13:42 +1100 (AEDT) Date: Mon, 2 Mar 2026 11:13:36 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 06/12] udp: Pass iov_tail to udp_update_hdr4()/udp_update_hdr6() Message-ID: References: <20260227140330.2216753-1-lvivier@redhat.com> <20260227140330.2216753-7-lvivier@redhat.com> MIME-Version: 1.0 In-Reply-To: <20260227140330.2216753-7-lvivier@redhat.com> 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 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="QjfP8a4MVKHJe22s" Content-Disposition: inline Message-ID-Hash: A2CFU3IQ7X3BMS4T5NNQ3H6HH33WUPSO X-Message-ID-Hash: A2CFU3IQ7X3BMS4T5NNQ3H6HH33WUPSO 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: --QjfP8a4MVKHJe22s Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 27, 2026 at 03:03:24PM +0100, Laurent Vivier wrote: > Change udp_update_hdr4() and udp_update_hdr6() to take a separate > struct udphdr pointer and an iov_tail for the payload, instead of a > struct udp_payload_t pointer and an explicit data length. >=20 > This decouples the header update functions from the udp_payload_t memory > layout, which assumes all headers and data sit in a single contiguous > buffer. The vhost-user path uses virtqueue-provided scatter-gather > buffers where this assumption does not hold; passing an iov_tail lets > both the tap path and the vhost-user path share the same functions > without casting through layout-specific helpers. >=20 > Signed-off-by: Laurent Vivier Concept looks good, a couple of nits below. > --- > udp.c | 65 ++++++++++++++++++++++---------------------------- > udp_internal.h | 10 ++++---- > udp_vu.c | 14 +++++++++-- > 3 files changed, 47 insertions(+), 42 deletions(-) >=20 > diff --git a/udp.c b/udp.c > index 19adda065f44..52e93e357a94 100644 > --- a/udp.c > +++ b/udp.c > @@ -257,18 +257,17 @@ static void udp_iov_init(const struct ctx *c) > * @ip4h:=09=09Pre-filled IPv4 header (except for tot_len and saddr) > * @bp:=09=09=09Pointer to udp_payload_t to update Needs to be replaced with @payload description. > * @toside:=09=09Flowside for destination side > - * @dlen:=09=09Length of UDP payload > * @no_udp_csum:=09Do not set UDP checksum > * > * Return: size of IPv4 payload (UDP header + data) > */ > -size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *bp, > -=09=09 const struct flowside *toside, size_t dlen, > -=09=09 bool no_udp_csum) > +size_t udp_update_hdr4(struct iphdr *ip4h, struct udphdr *uh, > +=09=09 struct iov_tail *payload, > +=09=09 const struct flowside *toside, bool no_udp_csum) > { > =09const struct in_addr *src =3D inany_v4(&toside->oaddr); > =09const struct in_addr *dst =3D inany_v4(&toside->eaddr); > -=09size_t l4len =3D dlen + sizeof(bp->uh); > +=09size_t l4len =3D iov_tail_size(payload) + sizeof(*uh); > =09size_t l3len =3D l4len + sizeof(*ip4h); > =20 > =09ASSERT(src && dst); > @@ -278,19 +277,13 @@ size_t udp_update_hdr4(struct iphdr *ip4h, struct u= dp_payload_t *bp, > =09ip4h->saddr =3D src->s_addr; > =09ip4h->check =3D csum_ip4_header(l3len, IPPROTO_UDP, *src, *dst); > =20 > -=09bp->uh.source =3D htons(toside->oport); > -=09bp->uh.dest =3D htons(toside->eport); > -=09bp->uh.len =3D htons(l4len); > -=09if (no_udp_csum) { > -=09=09bp->uh.check =3D 0; > -=09} else { > -=09=09const struct iovec iov =3D { > -=09=09=09.iov_base =3D bp->data, > -=09=09=09.iov_len =3D dlen > -=09=09}; > -=09=09struct iov_tail data =3D IOV_TAIL(&iov, 1, 0); > -=09=09csum_udp4(&bp->uh, *src, *dst, &data); > -=09} > +=09uh->source =3D htons(toside->oport); > +=09uh->dest =3D htons(toside->eport); > +=09uh->len =3D htons(l4len); > +=09if (no_udp_csum) > +=09=09uh->check =3D 0; > +=09else > +=09=09csum_udp4(uh, *src, *dst, payload); > =20 > =09return l4len; > } > @@ -306,11 +299,11 @@ size_t udp_update_hdr4(struct iphdr *ip4h, struct u= dp_payload_t *bp, > * This comment also needs updates for the changed parameters. > * Return: size of IPv6 payload (UDP header + data) > */ > -size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp, > -=09=09 const struct flowside *toside, size_t dlen, > -=09=09 bool no_udp_csum) > +size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udphdr *uh, > +=09=09 struct iov_tail *payload, > +=09=09 const struct flowside *toside, bool no_udp_csum) > { > -=09uint16_t l4len =3D dlen + sizeof(bp->uh); > +=09uint16_t l4len =3D iov_tail_size(payload) + sizeof(*uh); > =20 > =09ip6h->payload_len =3D htons(l4len); > =09ip6h->daddr =3D toside->eaddr.a6; > @@ -319,22 +312,17 @@ size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct= udp_payload_t *bp, > =09ip6h->nexthdr =3D IPPROTO_UDP; > =09ip6h->hop_limit =3D 255; > =20 > -=09bp->uh.source =3D htons(toside->oport); > -=09bp->uh.dest =3D htons(toside->eport); > -=09bp->uh.len =3D ip6h->payload_len; > +=09uh->source =3D htons(toside->oport); > +=09uh->dest =3D htons(toside->eport); > +=09uh->len =3D ip6h->payload_len; > =09if (no_udp_csum) { > =09=09/* 0 is an invalid checksum for UDP IPv6 and dropped by > =09=09 * the kernel stack, even if the checksum is disabled by virtio > =09=09 * flags. We need to put any non-zero value here. > =09=09 */ > -=09=09bp->uh.check =3D 0xffff; > +=09=09uh->check =3D 0xffff; > =09} else { > -=09=09const struct iovec iov =3D { > -=09=09=09.iov_base =3D bp->data, > -=09=09=09.iov_len =3D dlen > -=09=09}; > -=09=09struct iov_tail data =3D IOV_TAIL(&iov, 1, 0); > -=09=09csum_udp6(&bp->uh, &toside->oaddr.a6, &toside->eaddr.a6, &data); > +=09=09csum_udp6(uh, &toside->oaddr.a6, &toside->eaddr.a6, payload); > =09} > =20 > =09return l4len; > @@ -374,12 +362,17 @@ static void udp_tap_prepare(const struct mmsghdr *m= mh, > =09struct ethhdr *eh =3D (*tap_iov)[UDP_IOV_ETH].iov_base; > =09struct udp_payload_t *bp =3D &udp_payload[idx]; > =09struct udp_meta_t *bm =3D &udp_meta[idx]; > +=09const struct iovec iov =3D { > +=09=09.iov_base =3D bp->data, > +=09=09.iov_len =3D mmh[idx].msg_len, > +=09}; > +=09struct iov_tail payload =3D IOV_TAIL(&iov, 1, 0); > =09size_t l4len, l2len; > =20 > =09eth_update_mac(eh, NULL, tap_omac); > =09if (!inany_v4(&toside->eaddr) || !inany_v4(&toside->oaddr)) { > -=09=09l4len =3D udp_update_hdr6(&bm->ip6h, bp, toside, > -=09=09=09=09=09mmh[idx].msg_len, no_udp_csum); > +=09=09l4len =3D udp_update_hdr6(&bm->ip6h, &bp->uh, &payload, toside, > +=09=09=09=09=09no_udp_csum); > =20 > =09=09l2len =3D MAX(l4len + sizeof(bm->ip6h) + ETH_HLEN, ETH_ZLEN); > =09=09tap_hdr_update(&bm->taph, l2len); > @@ -387,8 +380,8 @@ static void udp_tap_prepare(const struct mmsghdr *mmh= , > =09=09eh->h_proto =3D htons_constant(ETH_P_IPV6); > =09=09(*tap_iov)[UDP_IOV_IP] =3D IOV_OF_LVALUE(bm->ip6h); > =09} else { > -=09=09l4len =3D udp_update_hdr4(&bm->ip4h, bp, toside, > -=09=09=09=09=09mmh[idx].msg_len, no_udp_csum); > +=09=09l4len =3D udp_update_hdr4(&bm->ip4h, &bp->uh, &payload, toside, > +=09=09=09=09=09no_udp_csum); > =20 > =09=09l2len =3D MAX(l4len + sizeof(bm->ip4h) + ETH_HLEN, ETH_ZLEN); > =09=09tap_hdr_update(&bm->taph, l2len); > diff --git a/udp_internal.h b/udp_internal.h > index 0a8fe490b07e..aca831808ab4 100644 > --- a/udp_internal.h > +++ b/udp_internal.h > @@ -22,11 +22,13 @@ struct udp_payload_t { > } __attribute__ ((packed, aligned(__alignof__(unsigned int)))); > #endif > =20 > -size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *bp, > -=09=09 const struct flowside *toside, size_t dlen, > +size_t udp_update_hdr4(struct iphdr *ip4h, struct udphdr *uh, > +=09=09 struct iov_tail *payload, > +=09=09 const struct flowside *toside, > =09=09 bool no_udp_csum); > -size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp, > -=09=09 const struct flowside *toside, size_t dlen, > +size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udphdr *uh, > +=09=09 struct iov_tail *payload, > +=09=09 const struct flowside *toside, > =09=09 bool no_udp_csum); > void udp_sock_fwd(const struct ctx *c, int s, int rule_hint, > =09=09 uint8_t frompif, in_port_t port, const struct timespec *now); > diff --git a/udp_vu.c b/udp_vu.c > index aefcab0b86c2..dd8904d65a38 100644 > --- a/udp_vu.c > +++ b/udp_vu.c > @@ -122,21 +122,31 @@ static size_t udp_vu_prepare(const struct ctx *c, c= onst struct iov_tail *data, > =09if (inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)) { > =09=09struct iphdr *iph =3D vu_ip(iov[0].iov_base); > =09=09struct udp_payload_t *bp =3D vu_payloadv4(iov[0].iov_base); > +=09=09const struct iovec payload_iov =3D { > +=09=09=09.iov_base =3D bp->data, > +=09=09=09.iov_len =3D dlen, > +=09=09}; > +=09=09struct iov_tail payload =3D IOV_TAIL(&payload_iov, 1, 0); > =20 > =09=09eh->h_proto =3D htons(ETH_P_IP); > =20 > =09=09*iph =3D (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_UDP); > =20 > -=09=09l4len =3D udp_update_hdr4(iph, bp, toside, dlen, true); > +=09=09l4len =3D udp_update_hdr4(iph, &bp->uh, &payload, toside, true); > =09} else { > =09=09struct ipv6hdr *ip6h =3D vu_ip(iov[0].iov_base); > =09=09struct udp_payload_t *bp =3D vu_payloadv6(iov[0].iov_base); > +=09=09const struct iovec payload_iov =3D { > +=09=09=09.iov_base =3D bp->data, > +=09=09=09.iov_len =3D dlen, > +=09=09}; > +=09=09struct iov_tail payload =3D IOV_TAIL(&payload_iov, 1, 0); > =20 > =09=09eh->h_proto =3D htons(ETH_P_IPV6); > =20 > =09=09*ip6h =3D (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_UDP); > =20 > -=09=09l4len =3D udp_update_hdr6(ip6h, bp, toside, dlen, true); > +=09=09l4len =3D udp_update_hdr6(ip6h, &bp->uh, &payload, toside, true); > =09} > =20 > =09return l4len; > --=20 > 2.53.0 >=20 --=20 David Gibson (he or they)=09| I'll have my music baroque, and my code david AT gibson.dropbear.id.au=09| minimalist, thank you, not the other way =09=09=09=09| around. http://www.ozlabs.org/~dgibson --QjfP8a4MVKHJe22s Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmk1i8ACgkQzQJF27ox 2GdG9g//U6bMfOgKaGca5SmJB0Wcp5ho33SCiLxj9aayIItAMzKoVAiQuejvwCDK wdHqrl5i+k46hOCl8nt6ehY/pEdc4nAoJTyzpL7tqyx9OXVJgjNf8C9Rtg/0VtKD sdCouXbqAEbPcIaN8VoB7dRZC7A9J8vY7/u8Chm+WibEvWRB3h2R2MGdoFVMY1qO yy38FaE4heJefQZZzI+E6o2Icu5XhLd3zeIJXpsa6+e/X9ujjuMXSCKb/ZV8RXzz L2Dv39M6FjSr2W75HTX655W5MicN6e3KnzD+AU/AiVQrCrEpcjEKwumMllJ1IgJ7 aF3S9mIjd516d4rmA3ZQLv4VtEV4da+YxkiLPcHpBv05P9qCUcl6UGm4CbGKfNCx rEzXFTvty4fhq4p10ewdVSBOUXibESxLLmHhfEdqDXBYJ9ojfO5Ct/CESOabWlpG Hf7BwNgCFuIf0fu0X4ssFH41phCldMbC1Z8pucCIh2L8fj5P5mnVshAlgxZ3c30V jmB+YbM+UowgC5eJjloOJ8dctUzag/A1INUiYE1AqMaYKEVZUJ5lulCE8faB8KxN tZ9BUu0F6y+qTpU8fnOoyIlY+OeqsYVcM9dRpfL+FrsOAmx+RM6MtzomTMU2vEDx t/3DjzWIjX8IjorNlchHt9bDV+3qiIpHek8n8ejYTAYN+oiYwXQ= =VxIs -----END PGP SIGNATURE----- --QjfP8a4MVKHJe22s--