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=CtMoKHrT; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 9AD205A026D for ; Thu, 12 Mar 2026 05:30:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1773289822; bh=UTSItdsfoBIRhSGD/ZnHLaCZ9zlBQAhBzbdRW/6Y95A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CtMoKHrT8m1mjq+2z98lOPNsfRraVgJ/vso4wyxxJsv96UU6X2pQkN5JMArtuwfd2 G0FY6VHmc3wpBddVR3ZA9zpAAWGIChrZwcrsHATdJPus66px9qB09e8yqtzhRDZdsY Z4OIhn9ISWh7D348KgK9+NXk2siKVqJFD7AphQDBcqPObBvdJH9ITWaYEO/excnr+A 83BTkv49jgGDLDELaE5e7dxIWhAgxH9qsrML+SDavh5619CH+AelcqKrZn2LUEVCnc DtaMji3YSTqGxwElkkpYo3Z+hCDvHTJVUmjefl6/eX2C0LgBYfYvzYHyTFDBAyLr7u Hy28jNtR+NlIA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fWZRL0plDz4wD4; Thu, 12 Mar 2026 15:30:22 +1100 (AEDT) Date: Thu, 12 Mar 2026 15:16:39 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 07/13] udp: Pass iov_tail to udp_update_hdr4()/udp_update_hdr6() Message-ID: References: <20260309094744.1907754-1-lvivier@redhat.com> <20260309094744.1907754-8-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="DS2u4j0irbHOuDut" Content-Disposition: inline In-Reply-To: <20260309094744.1907754-8-lvivier@redhat.com> Message-ID-Hash: TWF2J4FJZMABCY6LCJF5DXP4IDWXNKJX X-Message-ID-Hash: TWF2J4FJZMABCY6LCJF5DXP4IDWXNKJX 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: --DS2u4j0irbHOuDut Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 09, 2026 at 10:47:38AM +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 Reviewed-by: David Gibson > --- > udp.c | 72 +++++++++++++++++++++++--------------------------- > udp_internal.h | 10 ++++--- > udp_vu.c | 14 ++++++++-- > 3 files changed, 51 insertions(+), 45 deletions(-) >=20 > diff --git a/udp.c b/udp.c > index 464aa09365cc..6840e8843e68 100644 > --- a/udp.c > +++ b/udp.c > @@ -255,20 +255,20 @@ static void udp_iov_init(const struct ctx *c) > /** > * udp_update_hdr4() - Update headers for one IPv4 datagram > * @ip4h: Pre-filled IPv4 header (except for tot_len and saddr) > - * @bp: Pointer to udp_payload_t to update > + * @uh: UDP header to update > + * @payload: UDP payload > * @toside: Flowside for destination side > - * @dlen: Length of UDP payload > * @no_udp_csum: Do 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, > - const struct flowside *toside, size_t dlen, > - bool no_udp_csum) > +size_t udp_update_hdr4(struct iphdr *ip4h, struct udphdr *uh, > + struct iov_tail *payload, > + const struct flowside *toside, bool no_udp_csum) > { > const struct in_addr *src =3D inany_v4(&toside->oaddr); > const struct in_addr *dst =3D inany_v4(&toside->eaddr); > - size_t l4len =3D dlen + sizeof(bp->uh); > + size_t l4len =3D iov_tail_size(payload) + sizeof(*uh); > size_t l3len =3D l4len + sizeof(*ip4h); > =20 > ASSERT(src && dst); > @@ -278,19 +278,13 @@ size_t udp_update_hdr4(struct iphdr *ip4h, struct u= dp_payload_t *bp, > ip4h->saddr =3D src->s_addr; > ip4h->check =3D csum_ip4_header(l3len, IPPROTO_UDP, *src, *dst); > =20 > - bp->uh.source =3D htons(toside->oport); > - bp->uh.dest =3D htons(toside->eport); > - bp->uh.len =3D htons(l4len); > - if (no_udp_csum) { > - bp->uh.check =3D 0; > - } else { > - const struct iovec iov =3D { > - .iov_base =3D bp->data, > - .iov_len =3D dlen > - }; > - struct iov_tail data =3D IOV_TAIL(&iov, 1, 0); > - csum_udp4(&bp->uh, *src, *dst, &data); > - } > + uh->source =3D htons(toside->oport); > + uh->dest =3D htons(toside->eport); > + uh->len =3D htons(l4len); > + if (no_udp_csum) > + uh->check =3D 0; > + else > + csum_udp4(uh, *src, *dst, payload); > =20 > return l4len; > } > @@ -299,18 +293,18 @@ size_t udp_update_hdr4(struct iphdr *ip4h, struct u= dp_payload_t *bp, > * udp_update_hdr6() - Update headers for one IPv6 datagram > * @ip6h: Pre-filled IPv6 header (except for payload_len and > * addresses) > - * @bp: Pointer to udp_payload_t to update > + * @uh: UDP header to update > + * @payload: UDP payload > * @toside: Flowside for destination side > - * @dlen: Length of UDP payload > * @no_udp_csum: Do not set UDP checksum > * > * Return: size of IPv6 payload (UDP header + data) > */ > -size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp, > - const struct flowside *toside, size_t dlen, > - bool no_udp_csum) > +size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udphdr *uh, > + struct iov_tail *payload, > + const struct flowside *toside, bool no_udp_csum) > { > - uint16_t l4len =3D dlen + sizeof(bp->uh); > + uint16_t l4len =3D iov_tail_size(payload) + sizeof(*uh); > =20 > ip6h->payload_len =3D htons(l4len); > ip6h->daddr =3D toside->eaddr.a6; > @@ -319,22 +313,17 @@ size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct= udp_payload_t *bp, > ip6h->nexthdr =3D IPPROTO_UDP; > ip6h->hop_limit =3D 255; > =20 > - bp->uh.source =3D htons(toside->oport); > - bp->uh.dest =3D htons(toside->eport); > - bp->uh.len =3D ip6h->payload_len; > + uh->source =3D htons(toside->oport); > + uh->dest =3D htons(toside->eport); > + uh->len =3D ip6h->payload_len; > if (no_udp_csum) { > /* 0 is an invalid checksum for UDP IPv6 and dropped by > * the kernel stack, even if the checksum is disabled by virtio > * flags. We need to put any non-zero value here. > */ > - bp->uh.check =3D 0xffff; > + uh->check =3D 0xffff; > } else { > - const struct iovec iov =3D { > - .iov_base =3D bp->data, > - .iov_len =3D dlen > - }; > - struct iov_tail data =3D IOV_TAIL(&iov, 1, 0); > - csum_udp6(&bp->uh, &toside->oaddr.a6, &toside->eaddr.a6, &data); > + csum_udp6(uh, &toside->oaddr.a6, &toside->eaddr.a6, payload); > } > =20 > return l4len; > @@ -374,12 +363,17 @@ 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]; > + const struct iovec iov =3D { > + .iov_base =3D bp->data, > + .iov_len =3D mmh[idx].msg_len, > + }; > + struct iov_tail payload =3D IOV_TAIL(&iov, 1, 0); > 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); > + l4len =3D udp_update_hdr6(&bm->ip6h, &bp->uh, &payload, toside, > + no_udp_csum); > =20 > l2len =3D MAX(l4len + sizeof(bm->ip6h) + ETH_HLEN, ETH_ZLEN); > tap_hdr_update(&bm->taph, l2len); > @@ -387,8 +381,8 @@ static void udp_tap_prepare(const struct mmsghdr *mmh, > 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); > + l4len =3D udp_update_hdr4(&bm->ip4h, &bp->uh, &payload, toside, > + no_udp_csum); > =20 > l2len =3D MAX(l4len + sizeof(bm->ip4h) + ETH_HLEN, ETH_ZLEN); > tap_hdr_update(&bm->taph, l2len); > diff --git a/udp_internal.h b/udp_internal.h > index 64e457748324..fba5ef33cf99 100644 > --- a/udp_internal.h > +++ b/udp_internal.h > @@ -25,11 +25,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, > - const struct flowside *toside, size_t dlen, > +size_t udp_update_hdr4(struct iphdr *ip4h, struct udphdr *uh, > + struct iov_tail *payload, > + const struct flowside *toside, > bool no_udp_csum); > -size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp, > - const struct flowside *toside, size_t dlen, > +size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udphdr *uh, > + struct iov_tail *payload, > + const struct flowside *toside, > bool no_udp_csum); > void udp_sock_fwd(const struct ctx *c, int s, int rule_hint, > uint8_t frompif, in_port_t port, const struct timespec *now); > diff --git a/udp_vu.c b/udp_vu.c > index 27ae93de4420..2a5d3f822bf6 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, > if (inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)) { > struct iphdr *iph =3D vu_ip(iov[0].iov_base); > struct udp_payload_t *bp =3D vu_payloadv4(iov[0].iov_base); > + const struct iovec payload_iov =3D { > + .iov_base =3D bp->data, > + .iov_len =3D dlen, > + }; > + struct iov_tail payload =3D IOV_TAIL(&payload_iov, 1, 0); > =20 > eh->h_proto =3D htons(ETH_P_IP); > =20 > *iph =3D (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_UDP); > =20 > - l4len =3D udp_update_hdr4(iph, bp, toside, dlen, true); > + l4len =3D udp_update_hdr4(iph, &bp->uh, &payload, toside, true); > } else { > struct ipv6hdr *ip6h =3D vu_ip(iov[0].iov_base); > struct udp_payload_t *bp =3D vu_payloadv6(iov[0].iov_base); > + const struct iovec payload_iov =3D { > + .iov_base =3D bp->data, > + .iov_len =3D dlen, > + }; > + struct iov_tail payload =3D IOV_TAIL(&payload_iov, 1, 0); > =20 > eh->h_proto =3D htons(ETH_P_IPV6); > =20 > *ip6h =3D (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_UDP); > =20 > - l4len =3D udp_update_hdr6(ip6h, bp, toside, dlen, true); > + l4len =3D udp_update_hdr6(ip6h, &bp->uh, &payload, toside, true); > } > =20 > return l4len; > --=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 --DS2u4j0irbHOuDut Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmyPiYACgkQzQJF27ox 2GcYMA/9Hdn8ylcDIpDjpSY22KtAhtQaACfzHK/xP2JpUX2TxB1Luty3geJtsAF6 lomuTKMbQS3vG23JhE8M5ty0QGhFsstQWSE9s45FTteD5sl7CN7WYM8zhT4EXjw1 7vTHfqiqUucaCaAEMD+8sjeFFEBC4d7zZN08Vu0aHS5TVuIOJfCFcjSTgIQW3Uw+ gGguhrT5d9YMilJZV/3A0UQjO925FzW1+IXCySfP/QaRaqdCuQwJF4veh519rqPP jOXSYcwX0mRqE6E7BXcm8NGhoTvBwL8CjwyEEUw337HqXmgwUs2RH+1OodI38clK 0juUiG16NoE5wv62OpjNDzevFLHjU7YNTWw/BVYC8JvLhiz2SDEoUiShFqtsBwSL FRbtENhMFQm2ob5DQd+dkKJL1mVqCbXG4a2MWTvExtdXaR4dKX7WU9P8u7Tcshmb QdcaGpsW5NYSCT7kmOt2OywT7OdxTSkvl/0zM24X7ygDOnP9UMVsgJuKiTL2Vkzj QxFl3WuhVYDZBLhmGvsD21mkaMsd3wWrfZWmC3SeDCgH/+jXAycOzooZZ3bP/1Gr kyRWNRDGQHuabl9SL3soMIBSdrkiAzxFoRSmv9g3TRctkYEXs0r0fjeCQd0p/MAr B9SjO2WX6Y3e32dUGosCGbRpcOZ5Rqu7ofV3dbOuEUxvvoSi3U4= =3DWG -----END PGP SIGNATURE----- --DS2u4j0irbHOuDut--