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=YUQeXvYL; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 0243C5A0265 for ; Wed, 25 Mar 2026 00:56:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774396606; bh=MLtAYBtZJoQtW4myAF8BCq9wP6y8udx+Rfi0yM1BFis=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YUQeXvYLQpyohn1t2F+XxEokttJBqgr8wFkBwO0mB60cNwTHyADqsgSMSa5Zv2IwV 1nuD7eKumzUkAGSng8G4pCBelkoWJK1mArpKcgZfSH1P8aP0V3TSQ1FdYmvtDmRZHF GFwZ1XDnTuMHnZGmWY5wplRpiQcvr+haskTcjR19RSbBhzIgQD/xWAnwrjLBHSuntF 0eAD+JksVVNZvKERtIEead4f3XP89uO+DRiwDbteKWosb+5n6xKkAd5tj4Nx1CkMwy 5uMlR02Do/OloyXjCkEfzQJ8OWtLh7ui3nGh0x+g/FZXWoPK0L9FWtYsrmOlWcXM6j hqIb4k8ceN5kA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fgRlf2CTfz4wHX; Wed, 25 Mar 2026 10:56:46 +1100 (AEDT) Date: Wed, 25 Mar 2026 10:49:08 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 1/7] tcp: pass ipv4h checksum, not a pointer to the checksum Message-ID: References: <20260323165259.1253482-1-lvivier@redhat.com> <20260323165259.1253482-2-lvivier@redhat.com> <18349a03-5325-4c47-92e0-054f354f0a49@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="roMYtZwRdhfIcc/H" Content-Disposition: inline In-Reply-To: <18349a03-5325-4c47-92e0-054f354f0a49@redhat.com> Message-ID-Hash: VLQ6R6LJRB5YW5QQT2OOCI7WOTSAPHYR X-Message-ID-Hash: VLQ6R6LJRB5YW5QQT2OOCI7WOTSAPHYR 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: --roMYtZwRdhfIcc/H Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 24, 2026 at 08:56:48AM +0100, Laurent Vivier wrote: > On 3/24/26 04:53, David Gibson wrote: > > On Mon, Mar 23, 2026 at 05:52:53PM +0100, Laurent Vivier wrote: > > > tcp_fill_headers() takes a pointer to a previously computed IPv4 head= er > > > checksum to avoid recalculating it when the payload length doesn't > > > change. A subsequent patch makes tcp_fill_headers() access ip4h via > > > with_header() which scopes it to a temporary variable, so a pointer to > > > ip4h->check would become dangling after the with_header() block. > >=20 > > Oof, that kind of indicates the dangers with the with_header() > > structure. Is that change merged already? If not we should probably > > fix it before merge rather than after the fact. >=20 > The problem appears in the subsequent patches of the series. > So at this point we prevent the problem, don't fix it. Oh, sorry, I misread your comment which already said that. > > > Pass the checksum by value as an int instead, using -1 as the sentinel > > > to indicate that the checksum should be computed from scratch (replac= ing > > > the NULL pointer sentinel). As the checksum is a uint16_t, -1 cannot = be > > > a valid checksum value in an int. > >=20 > > That said, passing this by value I think is cleaner than the pointer, > > regardless of other reasons. Would it also make sense to flag > > no_tcp_csum with an additional special value (a #define to -2, or > > whatever) instead of using an extra parameter? Logically the checksum > > parameter would be: > > CALCULATE | UNNEEDED | specific value >=20 > I can extract the patch from this series to make this improvement on the = current code. >=20 > Thanks, > Laurent >=20 > >=20 > > Reviewed-by: David Gibson > >=20 > > > Signed-off-by: Laurent Vivier > > > --- > > > tcp.c | 7 +++---- > > > tcp_buf.c | 10 +++++----- > > > tcp_internal.h | 3 +-- > > > tcp_vu.c | 12 ++++++------ > > > 4 files changed, 15 insertions(+), 17 deletions(-) > > >=20 > > > diff --git a/tcp.c b/tcp.c > > > index b14586249c4e..158a5be0327e 100644 > > > --- a/tcp.c > > > +++ b/tcp.c > > > @@ -953,8 +953,7 @@ size_t tcp_fill_headers(const struct ctx *c, stru= ct tcp_tap_conn *conn, > > > struct ethhdr *eh, > > > struct iphdr *ip4h, struct ipv6hdr *ip6h, > > > struct tcphdr *th, struct iov_tail *payload, > > > - const uint16_t *ip4_check, uint32_t seq, > > > - bool no_tcp_csum) > > > + int ip4_check, uint32_t seq, bool no_tcp_csum) > > > { > > > const struct flowside *tapside =3D TAPFLOW(conn); > > > size_t l4len =3D iov_tail_size(payload) + sizeof(*th); > > > @@ -974,8 +973,8 @@ size_t tcp_fill_headers(const struct ctx *c, stru= ct tcp_tap_conn *conn, > > > ip4h->saddr =3D src4->s_addr; > > > ip4h->daddr =3D dst4->s_addr; > > > - if (ip4_check) > > > - ip4h->check =3D *ip4_check; > > > + if (ip4_check !=3D -1) > > > + ip4h->check =3D ip4_check; > > > else > > > ip4h->check =3D csum_ip4_header(l3len, IPPROTO_TCP, > > > *src4, *dst4); > > > diff --git a/tcp_buf.c b/tcp_buf.c > > > index 41965b107567..bc0f58dd7a5e 100644 > > > --- a/tcp_buf.c > > > +++ b/tcp_buf.c > > > @@ -172,7 +172,7 @@ static void tcp_l2_buf_pad(struct iovec *iov) > > > */ > > > static void tcp_l2_buf_fill_headers(const struct ctx *c, > > > struct tcp_tap_conn *conn, > > > - struct iovec *iov, const uint16_t *check, > > > + struct iovec *iov, int check, > > > uint32_t seq, bool no_tcp_csum) > > > { > > > struct iov_tail tail =3D IOV_TAIL(&iov[TCP_IOV_PAYLOAD], 1, 0); > > > @@ -233,7 +233,7 @@ int tcp_buf_send_flag(const struct ctx *c, struct= tcp_tap_conn *conn, int flags) > > > if (flags & KEEPALIVE) > > > seq--; > > > - tcp_l2_buf_fill_headers(c, conn, iov, NULL, seq, false); > > > + tcp_l2_buf_fill_headers(c, conn, iov, -1, seq, false); > > > tcp_l2_buf_pad(iov); > > > @@ -270,7 +270,7 @@ static void tcp_data_to_tap(const struct ctx *c, = struct tcp_tap_conn *conn, > > > ssize_t dlen, int no_csum, uint32_t seq, bool push) > > > { > > > struct tcp_payload_t *payload; > > > - const uint16_t *check =3D NULL; > > > + int check =3D -1; > > > struct iovec *iov; > > > conn->seq_to_tap =3D seq + dlen; > > > @@ -279,9 +279,9 @@ static void tcp_data_to_tap(const struct ctx *c, = struct tcp_tap_conn *conn, > > > if (CONN_V4(conn)) { > > > if (no_csum) { > > > struct iovec *iov_prev =3D tcp_l2_iov[tcp_payload_used - 1]; > > > - struct iphdr *iph =3D iov_prev[TCP_IOV_IP].iov_base; > > > + const struct iphdr *iph =3D iov_prev[TCP_IOV_IP].iov_base; > > > - check =3D &iph->check; > > > + check =3D iph->check; > > > } > > > iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(tcp4_payload_ip[tcp_payload_use= d]); > > > } else if (CONN_V6(conn)) { > > > diff --git a/tcp_internal.h b/tcp_internal.h > > > index d9408852571f..bb7a6629839c 100644 > > > --- a/tcp_internal.h > > > +++ b/tcp_internal.h > > > @@ -187,8 +187,7 @@ size_t tcp_fill_headers(const struct ctx *c, stru= ct tcp_tap_conn *conn, > > > struct ethhdr *eh, > > > struct iphdr *ip4h, struct ipv6hdr *ip6h, > > > struct tcphdr *th, struct iov_tail *payload, > > > - const uint16_t *ip4_check, uint32_t seq, > > > - bool no_tcp_csum); > > > + int ip4_check, uint32_t seq, bool no_tcp_csum); > > > int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn = *conn, > > > bool force_seq, struct tcp_info_linux *tinfo); > > > diff --git a/tcp_vu.c b/tcp_vu.c > > > index 3001defb5467..a21ee3499aed 100644 > > > --- a/tcp_vu.c > > > +++ b/tcp_vu.c > > > @@ -138,7 +138,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct = tcp_tap_conn *conn, int flags) > > > seq--; > > > tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload, > > > - NULL, seq, !*c->pcap); > > > + -1, seq, !*c->pcap); > > > if (*c->pcap) > > > pcap_iov(&flags_elem[0].in_sg[0], 1, VNET_HLEN); > > > @@ -283,7 +283,7 @@ static ssize_t tcp_vu_sock_recv(const struct ctx = *c, struct vu_virtq *vq, > > > */ > > > static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn= *conn, > > > struct iovec *iov, size_t iov_cnt, > > > - const uint16_t **check, bool no_tcp_csum, bool push) > > > + 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)= ); > > > @@ -329,7 +329,7 @@ static void tcp_vu_prepare(const struct ctx *c, s= truct tcp_tap_conn *conn, > > > tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload, > > > *check, conn->seq_to_tap, no_tcp_csum); > > > if (ip4h) > > > - *check =3D &ip4h->check; > > > + *check =3D ip4h->check; > > > } > > > /** > > > @@ -350,7 +350,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, st= ruct tcp_tap_conn *conn) > > > size_t hdrlen, fillsize; > > > int v6 =3D CONN_V6(conn); > > > uint32_t already_sent; > > > - const uint16_t *check; > > > + int check; > > > if (!vu_queue_enabled(vq) || !vu_queue_started(vq)) { > > > debug("Got packet, but RX virtqueue not usable yet"); > > > @@ -437,7 +437,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, st= ruct tcp_tap_conn *conn) > > > */ > > > hdrlen =3D tcp_vu_hdrlen(v6); > > > - for (i =3D 0, previous_dlen =3D -1, check =3D NULL; i < head_cnt; i= ++) { > > > + for (i =3D 0, previous_dlen =3D -1, check =3D -1; i < head_cnt; i++= ) { > > > struct iovec *iov =3D &elem[head[i]].in_sg[0]; > > > int buf_cnt =3D head[i + 1] - head[i]; > > > size_t frame_size =3D iov_size(iov, buf_cnt); > > > @@ -451,7 +451,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, st= ruct tcp_tap_conn *conn) > > > /* The IPv4 header checksum varies only with dlen */ > > > if (previous_dlen !=3D dlen) > > > - check =3D NULL; > > > + check =3D -1; > > > previous_dlen =3D dlen; > > > tcp_vu_prepare(c, conn, iov, buf_cnt, &check, !*c->pcap, push); > > > --=20 > > > 2.53.0 > > >=20 > >=20 >=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 --roMYtZwRdhfIcc/H Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnDIvMACgkQzQJF27ox 2GcpQxAAlKjklWqNPLV5vToWvOW4lnnJB/62QXw8/KOpu/Q0i0oFb1j9L3BGBRLY S77BtyVTrsIOylXvyR1gFHyhwZgcSoUJfntaguanzWyrFd5ZAk0oduFETaCtninc oUObEUJ3XmNdX29td25bWoHVE+vQkSQUkwjkgYFtDmxgypExMri2LfxipRA3CeDl TIVmsMK8YrkBiu5iJ5mXXMLbp3LTnvpkjWnEkoDmwenhPaaAZ8+FNR0CT1r4OGcy 81qal7USZUvLyLhAKoHet8F6wgYte4+7hfA25g2OFmU7/UxMwo1bqT+MLcdGKejE mbfzoTYfII6Rxr1diic8/u+N8oBiyTX90jyWSwVwz4RYfRyvY9lcoA5b+IoYSxnG MywmTaFEv7WYuLSuMhhtxN1u2rceYSzM3miy9XKBwihHo1kLr6Ymhe9fhCrdC3YK NC3aFQ98KNS9D4EuVI52vSf7wrJrshU0uv244INxrcGEltF/j9hn2vFsNTp2KaRE IYec2b2JKwiQ+m0k7omGMKZV6qGH0Hdw9/rztuuLznuJx+1ZvZyko6rWgskvtQJh 0cn6DP+QPTHPgTvqDzIsMIQCQaVruSEh8pkpFNf1VK8+fxlmVu2HPeJ3VSp0KNOv x2OlR87uV+Fg5/7k0DhLw9zCnLgZ72Au5IdCAI+xEn1PM4Ni4/4= =Pdoc -----END PGP SIGNATURE----- --roMYtZwRdhfIcc/H--