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=GfIuArkV; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id C834C5A0265 for ; Mon, 11 May 2026 09:55:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1778486112; bh=yCVEhQyk5rDVr/qLMbf49vpBj92/jdT8LtSZakZP2dY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GfIuArkVG9h3ZsbMT8Awi1yo55ipqbeEQ48sHSSiE1N7nS60feaAQXLfuXjx/Ofcd AEec4Gtsb72sU625ei2yHE+C2pLbDDJT5rhPeHmPyUrpJQr4jktcFFWNYkWKmu4UCx R4dmDtGjZ6dQXXypuoBbTX1L3U8ENK7sYxH0AqheFuCRkHMgj0J718omq/3WNgSk5W y0YZswPXSGf9uLESatNq7kHaAuMQJXLNMfsY79fehUdG35mYq8mU+6vQpfsjB7TESR nCdFjnftqrEgvFcFNs68XBLVGBXm97dIGSohlqc6NEiEICCmcS2QCu694upo3ienyw iuLtD54LTk5ng== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gDX806RfWz4wJj; Mon, 11 May 2026 17:55:12 +1000 (AEST) Date: Mon, 11 May 2026 17:54:58 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v6 2/4] tcp_vu: Build headers on the stack and write them into the iovec Message-ID: References: <20260416161618.3826904-1-lvivier@redhat.com> <20260416161618.3826904-3-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="rzrbl1PYiSLUkB30" Content-Disposition: inline In-Reply-To: <20260416161618.3826904-3-lvivier@redhat.com> Message-ID-Hash: HIXWSWNR56KAPR66HTIIUOHUPS3OOMJL X-Message-ID-Hash: HIXWSWNR56KAPR66HTIIUOHUPS3OOMJL 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: --rzrbl1PYiSLUkB30 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 16, 2026 at 06:16:16PM +0200, Laurent Vivier wrote: > tcp_vu_prepare() currently assumes the first iovec element provided by > the guest is large enough to hold all L2-L4 headers, and builds them > in place via pointer casts into iov[0].iov_base. This assumption is > enforced by an assert(). >=20 > Since the headers in the buffer are uninitialized anyway, we can just > as well build the Ethernet, IP, and TCP headers on the stack instead, > and write them into the iovec with IOV_PUSH_HEADER(). This mirrors the > approach already used in udp_vu_prepare(), and prepares for support of > elements with multiple iovecs. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson Although one nit below. > --- > tcp_vu.c | 60 ++++++++++++++++++++++++-------------------------------- > 1 file changed, 26 insertions(+), 34 deletions(-) >=20 > diff --git a/tcp_vu.c b/tcp_vu.c > index 3e399c20f0d7..2017aec90342 100644 > --- a/tcp_vu.c > +++ b/tcp_vu.c > @@ -296,49 +296,41 @@ static void tcp_vu_prepare(const struct ctx *c, str= uct tcp_tap_conn *conn, > bool v6 =3D !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); > size_t hdrlen =3D tcp_vu_hdrlen(v6); > struct iov_tail payload =3D IOV_TAIL(iov, iov_cnt, hdrlen); > - char *base =3D iov[0].iov_base; > - struct ipv6hdr *ip6h =3D NULL; > - struct iphdr *ip4h =3D NULL; > - 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); > + struct ipv6hdr ip6h; > + struct iphdr ip4h; > + struct tcphdr th; > + struct ethhdr eh; > =20 > - eh =3D vu_eth(base); > - > - memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); > + memcpy(eh.h_dest, c->guest_mac, sizeof(eh.h_dest)); > =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); > - } else { > - eh->h_proto =3D htons(ETH_P_IPV6); > + if (!v6) > + ip4h =3D (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); > + else > + ip6h =3D (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_TCP); > =20 > - ip6h =3D vu_ip(base); > - *ip6h =3D (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_TCP); > + memset(&th, 0, sizeof(th)); > + th.doff =3D sizeof(th) / 4; > + th.ack =3D 1; > + th.psh =3D push; These 4 lines could now become an initialiser for th. > =20 > - th =3D vu_payloadv6(base); > - } > + tcp_fill_headers(c, conn, &eh, v6 ? NULL : &ip4h, v6 ? &ip6h : NULL, &t= h, > + &payload, dlen, *csum_flags, conn->seq_to_tap); > =20 > - memset(th, 0, sizeof(*th)); > - th->doff =3D sizeof(*th) / 4; > - th->ack =3D 1; > - th->psh =3D push; > + /* Preserve TCP_CSUM, overwrite IP4_CSUM as we set the checksum */ > + if (!v6) > + *csum_flags =3D (*csum_flags & TCP_CSUM) | ip4h.check; > =20 > - tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload, dlen, > - *csum_flags, conn->seq_to_tap); > + /* write headers */ > + payload =3D IOV_TAIL(iov, iov_cnt, VNET_HLEN); > =20 > - /* Preserve TCP_CSUM, overwrite IP4_CSUM as we set the checksum */ > - if (ip4h) > - *csum_flags =3D (*csum_flags & TCP_CSUM) | ip4h->check; > + IOV_PUSH_HEADER(&payload, eh); > + if (!v6) > + IOV_PUSH_HEADER(&payload, ip4h); > + else > + IOV_PUSH_HEADER(&payload, ip6h); > + IOV_PUSH_HEADER(&payload, th); > } > =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 --rzrbl1PYiSLUkB30 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoBi1EACgkQzQJF27ox 2GfQmxAAqjJlJHjWFSJdU/2/lpUDrs5bYaYqryDr/0GRi4x+lwyrgP3Ej2cqgWfz vBXJV3+giqHm1bBbPXu85lVGaZ9d076iv7uAWQZcJKukxOcEWSbg2AYlgJfperhF eKN05glPXGlnTCER2BUpaEmeZa2JfIhemsHfQGaF/SHW5+OECaxkKtCIbadDkBIW M4eTEzVedni7iU+7gRS0SrbsdXBh0en2NtPGtpMS/Xxd7K7MB5gOhnqYdQ9CxJaq O0mt3WXF0jHGH5EAZM2g2Gpbok5SVHfZEwGwgSney3YzfPTnAn/WVoNb+FaH+JBq To/Ud5UNa8ANpYrvXKly8NX4PQYcUgwPh2cc9hX/i7pHBgz63eHErxZxewXqZKBE ETQTw0t5Dif6dmPFuCrX2jR99hkBfezrZl0vgFTcY4ZBcpXTonOxvxioNzCT6f5P awwD44iVDrezEpbeI1Ggg3mQnfc3pJUJN7eWMg+8YPVQG5WCA2tkIdTED/RTF2KW LALbqh6mp+refHOo2V+9OjOlbQOEY2jdk9t1hrGFBnHPC4ywohgUXwdT1pPjfQRh N4y3pIDRzisBnez+ZT8Hmgjd2HBDg72W4zMd0fVPuYsKKDRj78LQI0YF5Zjdzxfh SUIBhzXruHirylCkHt/28xM3LhJVfSdnTPzZRLYPMxfXfkuqhr0= =zVID -----END PGP SIGNATURE----- --rzrbl1PYiSLUkB30--