From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AFrfiqWl; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 78F855A0272 for ; Tue, 24 Mar 2026 08:56:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774339015; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=pTE2pkR16d3THsYPUTtJUJ4rkKQdQdWSeUI10mbuAII=; b=AFrfiqWlpaL+ykkJe1IGWeAZv/Z1iJRebH719O8HURsnxk9+kPE1Dz29dIa2XcQK+qwA4T twno3WjL7INna9OxcOKM+7DPv1OXV492CUdSLF6Emu7Dum8ROENS8PHLVd9zy95o8NqG+M OfYOnyw/FRSZVzU3My5j+y0QvpU1NhI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-329-2jT33gL4MQSP6rM0ekWZyQ-1; Tue, 24 Mar 2026 03:56:53 -0400 X-MC-Unique: 2jT33gL4MQSP6rM0ekWZyQ-1 X-Mimecast-MFC-AGG-ID: 2jT33gL4MQSP6rM0ekWZyQ_1774339012 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4853466655dso10628765e9.3 for ; Tue, 24 Mar 2026 00:56:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774339012; x=1774943812; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pTE2pkR16d3THsYPUTtJUJ4rkKQdQdWSeUI10mbuAII=; b=WMWzRnb6klR/c8xm4ES/UOcaR7Wvp3nICac9UPBYB7VH/O3psRT5G/VnuzDYfkjQRt clS8qoW8npS1eZmlR4wLBUkB8EhJSL0LN5dOYXfKYiCJDiaKhtCNLDmQXmyljkfIQgD4 WYagb2NfxSSTtBQOyy3W5b7DeYnRl/VW6ckjKoT0379D3ZSWoSYqwpWtBXLtXiCOIpta W/jiREd7mduLU/ce12J8ZUz5VR/H69qoT/iQnljdlsOg8MNEc5VTvaQtaAt8NaPsT786 6Dp+T8CoNr+EwoLhCXcUGeNgcAckvx+vGfVWY7XX7k7FudF4tlMmt615LIPExgq2G/PI 9/Kw== X-Gm-Message-State: AOJu0YwSGbe2LcBMg9lrUTbBrZP5IT3/DLjfPfNgsE6ICTdCYlRHbZPa IKAw8DxD7uD7Cv94VxjN4x9Xq9xSNfLMrS8YJy/hCuR551NKYt5ROiqWLi/jzkrEkr43EJ2QHBJ 1iaW4EulEs4lFShNgAIyQe5bcVxVqXPzWceRaIsVneNXtazCCocu7zg== X-Gm-Gg: ATEYQzwFtGB7G2ECYsfuuaoZpSErH86r7Q8ojETDTNmVR3b18RfMtFgTz4a5yEcfcOy af1uOS49vGFDbhFuIsGknLewCs+l/mBiXUUVDlLYltv1Ql45hvYbL85WKoezR1skBXsLnOLzf5p unhScrZZh5P918QdUgPwOCWTb5cGCZbklX2HJ0QGRoUn/FwuUXrTGMPDP0TVCmkPlCqp26hg/r+ UNQtG7BlGuqtx0RdpKLWbo8PvbB0OZH1LpcbltyFqfMZcACuM5x1+VZttCmnnOBhDm6+si9nfqR qNVblHV+xY19iQLChdf3ElWVeT5vh/KywBXklGLTSMnTQZHEnjqsWJu5tTkY+sHV98e/GKxcqH8 8rjaq576eycqYLV1002y01KMc238PIqUWgOgL0u8OyHK6nwXigBoiFzd1f+DRM9LNDQ== X-Received: by 2002:a05:600c:630d:b0:485:364e:934e with SMTP id 5b1f17b1804b1-486ff02c698mr227830645e9.21.1774339012122; Tue, 24 Mar 2026 00:56:52 -0700 (PDT) X-Received: by 2002:a05:600c:630d:b0:485:364e:934e with SMTP id 5b1f17b1804b1-486ff02c698mr227830235e9.21.1774339011589; Tue, 24 Mar 2026 00:56:51 -0700 (PDT) Received: from ?IPV6:2a01:e0a:e10:ef90:4326:a36e:a7cb:624b? ([2a01:e0a:e10:ef90:4326:a36e:a7cb:624b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-487113c4eb3sm35511645e9.0.2026.03.24.00.56.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Mar 2026 00:56:50 -0700 (PDT) Message-ID: <18349a03-5325-4c47-92e0-054f354f0a49@redhat.com> Date: Tue, 24 Mar 2026 08:56:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/7] tcp: pass ipv4h checksum, not a pointer to the checksum To: David Gibson References: <20260323165259.1253482-1-lvivier@redhat.com> <20260323165259.1253482-2-lvivier@redhat.com> From: Laurent Vivier Autocrypt: addr=lvivier@redhat.com; keydata= xsFNBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 WoeuLWDmXE7A3oJoIsRecD6BXHTb0OYS20lS608anr3B0xn5g0BX7es9Mw+hV/pL+63EOCVm SUVTEQwbGQN62guOKnJJJfphbbv82glIC/Ei4Ky8BwZkUuXd7d5NFJKC9/GDrbWdj75cDNQx UZ9XXbXEKY9MHX83Uy7JFoiFDMOVHn55HnncflUncO0zDzY7CxFeQFwYRbsCXOUL9yBtqLer Ky8/yjBskIlNrp0uQSt9LMoMsdSjYLYhvk1StsNPg74+s4u0Q6z45+l8RAsgLw5OLtTa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Bp P4W98bXCBIuQgs2m+OflERv5c3Ojldp04/S4NEjXEYRWdiCxN7ca5iPml5gLtuvhJMSy36gl U6IW9kn30IWuSoBpTkgV7rLUEhh9Ms82VWW/h2TxL8enfx40PrfbDtWwqRID3WY8jLrjKfTd R3LW8BnUDNkG+c4FzvvGUs8AvuqxxyHbXAfDx9o/jXfPHVRmJVhSmd+hC3mcQ+4iX5bBPBPM oDqSoLt5w9GoQQ6gDVP2ZjTWqwSRMLzNr37rJjZ1pt0DCMMTbiYIUcrhX8eveCJtY7NGWNyx FCRkhxRuGcpwPmRVDwOl39MB3iTsRighiMnijkbLXiKoJ5CDVvX5yicNqYJPKh5MFXN1bvsB kmYiStMRbrD0HoY1kx5/VozBtc70OU0EB8Wrv9hZD+Ofp0T3KOr1RUHvCZoLURfFhSQ= In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 4EYo-uMMqkzWHcAkqctjp1QR8Pqnz1xqWz5FbwKucTA_1774339012 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: NK2R3XZTNRFUF3RTNMNWTSZXZVPL7EZD X-Message-ID-Hash: NK2R3XZTNRFUF3RTNMNWTSZXZVPL7EZD X-MailFrom: lvivier@redhat.com 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: 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 header >> 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. > > 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. The problem appears in the subsequent patches of the series. So at this point we prevent the problem, don't fix it. > >> Pass the checksum by value as an int instead, using -1 as the sentinel >> to indicate that the checksum should be computed from scratch (replacing >> the NULL pointer sentinel). As the checksum is a uint16_t, -1 cannot be >> a valid checksum value in an int. > > 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 I can extract the patch from this series to make this improvement on the current code. Thanks, Laurent > > Reviewed-by: David Gibson > >> 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(-) >> >> 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, struct 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 = TAPFLOW(conn); >> size_t l4len = iov_tail_size(payload) + sizeof(*th); >> @@ -974,8 +973,8 @@ size_t tcp_fill_headers(const struct ctx *c, struct tcp_tap_conn *conn, >> ip4h->saddr = src4->s_addr; >> ip4h->daddr = dst4->s_addr; >> >> - if (ip4_check) >> - ip4h->check = *ip4_check; >> + if (ip4_check != -1) >> + ip4h->check = ip4_check; >> else >> ip4h->check = 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 = 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 = NULL; >> + int check = -1; >> struct iovec *iov; >> >> conn->seq_to_tap = 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 = tcp_l2_iov[tcp_payload_used - 1]; >> - struct iphdr *iph = iov_prev[TCP_IOV_IP].iov_base; >> + const struct iphdr *iph = iov_prev[TCP_IOV_IP].iov_base; >> >> - check = &iph->check; >> + check = iph->check; >> } >> iov[TCP_IOV_IP] = IOV_OF_LVALUE(tcp4_payload_ip[tcp_payload_used]); >> } 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, struct 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 = TAPFLOW(conn); >> bool v6 = !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); >> @@ -329,7 +329,7 @@ static void tcp_vu_prepare(const struct ctx *c, struct 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 = &ip4h->check; >> + *check = ip4h->check; >> } >> >> /** >> @@ -350,7 +350,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) >> size_t hdrlen, fillsize; >> int v6 = 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, struct tcp_tap_conn *conn) >> */ >> >> hdrlen = tcp_vu_hdrlen(v6); >> - for (i = 0, previous_dlen = -1, check = NULL; i < head_cnt; i++) { >> + for (i = 0, previous_dlen = -1, check = -1; i < head_cnt; i++) { >> struct iovec *iov = &elem[head[i]].in_sg[0]; >> int buf_cnt = head[i + 1] - head[i]; >> size_t frame_size = iov_size(iov, buf_cnt); >> @@ -451,7 +451,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) >> >> /* The IPv4 header checksum varies only with dlen */ >> if (previous_dlen != dlen) >> - check = NULL; >> + check = -1; >> previous_dlen = dlen; >> >> tcp_vu_prepare(c, conn, iov, buf_cnt, &check, !*c->pcap, push); >> -- >> 2.53.0 >> >