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=SyiF6nro; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 8E9895A0265 for ; Wed, 25 Mar 2026 05:46:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774413997; bh=N3RZsV0hOwmR2sTNUaoDMvgy+pdNmwzEzFjioS9+UVU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SyiF6nrom+NBNEuMaT3/izTUmu3RpVDm1ZPEosjq1JgpPN54+4pBXVwnmS6E4SWcN jKjbXkUps0go3rB6GcL/TISnzk15JlllCKEZ5EFzV3LFMwwANuKuavFaOJJj/98HkK /F4alNlJfn+90vZzDyjRv6HqQ2ukfiZnemHepuFcV76oX+FnU75GOrGbcNGz/RdI95 yFpfFrItXxFhMg447aY127T7rfPliTVzO6sP+68HWIFB7KkNYnR0fn4u0izRrKyi0J hmCddhANrk8ydAipczGMRQsVFcV+nOLSwgv3xlDFZ+D7dORQxM9ttcUhparx5RXatV flW+ySqUbZyUA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fgZB51Qqwz4wH2; Wed, 25 Mar 2026 15:46:37 +1100 (AEDT) Date: Wed, 25 Mar 2026 15:46:31 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 3/7] tcp_vu: Use iov_tail helpers to build headers in tcp_vu_prepare() Message-ID: References: <20260323165259.1253482-1-lvivier@redhat.com> <20260323165259.1253482-4-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="s3MLbTTifbKSNebG" Content-Disposition: inline In-Reply-To: <20260323165259.1253482-4-lvivier@redhat.com> Message-ID-Hash: BGRBQAOR4CZ4IRFXLJVUBFXHLDEQZM7Q X-Message-ID-Hash: BGRBQAOR4CZ4IRFXLJVUBFXHLDEQZM7Q 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: --s3MLbTTifbKSNebG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 23, 2026 at 05:52:55PM +0100, Laurent Vivier wrote: > Replace direct pointer arithmetic using vu_eth(), vu_ip(), > vu_payloadv4() and vu_payloadv6() with the iov_tail abstraction > to build Ethernet, IP and TCP headers in tcp_vu_prepare(). >=20 > This removes the assumption that all headers reside in a single > contiguous iov entry. >=20 > Signed-off-by: Laurent Vivier LGTM, with the exception of my general concerns about with_header(). > --- > tcp_vu.c | 61 ++++++++++++++++++++++++++------------------------------ > 1 file changed, 28 insertions(+), 33 deletions(-) >=20 > diff --git a/tcp_vu.c b/tcp_vu.c > index c6206b7a689c..a39f6ea018e9 100644 > --- a/tcp_vu.c > +++ b/tcp_vu.c > @@ -222,6 +222,7 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, = struct vu_virtq *vq, > /* reserve space for headers in iov */ > iov =3D &elem[elem_cnt].in_sg[0]; > assert(iov->iov_len >=3D hdrlen); > + Unrelated change (usually I don't mind if it's a reasonable change adjacent to what you're doing, but this is an entirely different function). > iov->iov_base =3D (char *)iov->iov_base + hdrlen; > iov->iov_len -=3D hdrlen; > head[(*head_cnt)++] =3D elem_cnt; > @@ -285,51 +286,45 @@ static void tcp_vu_prepare(const struct ctx *c, str= uct tcp_tap_conn *conn, > int *check, bool no_tcp_csum, bool push) > { > const struct flowside *toside =3D TAPFLOW(conn); > - bool v6 =3D !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); > - size_t hdrlen =3D tcp_vu_hdrlen(v6); > - char *base =3D iov[0].iov_base; > - struct ipv6hdr *ip6h =3D NULL; > - struct iphdr *ip4h =3D NULL; > + bool ipv4 =3D inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr); > struct iov_tail payload; > - struct tcphdr *th; > - struct ethhdr *eh; > - > - /* we guess the first iovec provided by the guest can embed > - * all the headers needed by L2 frame, including any padding > - */ > - assert(iov[0].iov_len >=3D hdrlen); > - > - eh =3D vu_eth(base); > =20 > - memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); > + payload =3D IOV_TAIL(iov, iov_cnt, VNET_HLEN); > + with_header(struct ethhdr, eh, &payload) > + memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); > + IOV_DROP_HEADER(&payload, struct ethhdr); > =20 > /* initialize header */ > =20 > - if (!v6) { > - eh->h_proto =3D htons(ETH_P_IP); > - > - ip4h =3D vu_ip(base); > - *ip4h =3D (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); > - th =3D vu_payloadv4(base); > + if (ipv4) { > + with_header(struct iphdr, ip4h, &payload) > + *ip4h =3D (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); > + IOV_DROP_HEADER(&payload, struct iphdr); > } else { > - eh->h_proto =3D htons(ETH_P_IPV6); > - > - ip6h =3D vu_ip(base); > - *ip6h =3D (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_TCP); > - > - th =3D vu_payloadv6(base); > + with_header(struct ipv6hdr, ip6h, &payload) > + *ip6h =3D (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_TCP); > + IOV_DROP_HEADER(&payload, struct ipv6hdr); > } > =20 > - memset(th, 0, sizeof(*th)); > - th->doff =3D sizeof(*th) / 4; > - th->ack =3D 1; > - th->psh =3D push; > + with_header(struct tcphdr, th, &payload) { > + memset(th, 0, sizeof(*th)); > + th->doff =3D sizeof(*th) / 4; > + th->ack =3D 1; > + th->psh =3D push; > + } > =20 > payload =3D IOV_TAIL(iov, iov_cnt, VNET_HLEN); > - tcp_fill_headers(c, conn, !v6, &payload, *check, conn->seq_to_tap, > + tcp_fill_headers(c, conn, ipv4, &payload, *check, conn->seq_to_tap, > no_tcp_csum); > - if (ip4h) > + if (ipv4) { > + struct iphdr ip4h_storage; > + const struct iphdr *ip4h; > + > + IOV_DROP_HEADER(&payload, struct ethhdr); > + ip4h =3D IOV_PEEK_HEADER(&payload, ip4h_storage); > + > *check =3D ip4h->check; > + } > } > =20 > /** > --=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 --s3MLbTTifbKSNebG Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnDaKYACgkQzQJF27ox 2GfHAw//UR3XNaDCMq1/cQFL+oH+MEkRLZHByW0kR2UNxGPbkOtbfJs4lkf6LMRL 8m0+dPq5j0zC6TxpPy9gqKPTBgF+rHbNAFZ7Co8qGnNzQ45+rcDGdFvVCQ4LTr2b TXLJ1oLYtsbQAZd1lkkucN7hBYKHAC7668RVJS56lJszQCgwgMCpgO7Ddkk9Lcnd hSjcmFUZKjbHiM352PgxM4KkuAsQc3HviDUyCN8r8igmvaVh3yOPv17sDuoY6tsg JFsxcFhDpJiRwPCQ+dYB8GAllWDfdOMKli52ehKu5gOIWXXbFt6Gef1WNsVnTY7x IKUY2g/QaM5UuTr+R6avogsRlDPy4PlwL0W/U9ZedBRVteoe5sPSpEblDpDt8gBA ELEwei3tXTwz9Duian/z/0NeKkadnF1N1ROxaiQqhJxcy4csemcjOme9Fwyr5AlX v4ZizVle8uNhnNPQ6yq2fVXrczYNgNqb55gxtXmjoE71LA7o8rblLGHc/mNatu53 hPbxXyzYOMbCXtRQb85hE1ZsO3xNqGDfIli9FNpzw/LIBQmN3FR1OIUgHWDU9t9D hFiqwPb3mrhYjmFbdNIChXCa6GTF3S9jnqs03Rwwk52fARTpwErl4Q69AIa1igzB +qjqTkr+zpBtFwzaFX7ZLYl8xg71jk5D4JOuL75N+2ySvaROCtI= =yFfU -----END PGP SIGNATURE----- --s3MLbTTifbKSNebG--