]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tcp: annotate data-races around tp->bytes_retrans
authorEric Dumazet <edumazet@google.com>
Thu, 16 Apr 2026 20:03:13 +0000 (20:03 +0000)
committerJakub Kicinski <kuba@kernel.org>
Sat, 18 Apr 2026 18:10:13 +0000 (11:10 -0700)
tcp_get_timestamping_opt_stats() intentionally runs lockless, we must
add READ_ONCE() and WRITE_ONCE() annotations to keep KCSAN happy.

Fixes: fb31c9b9f6c8 ("tcp: add data bytes retransmitted stats")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260416200319.3608680-9-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/tcp.c
net/ipv4/tcp_output.c

index f999b86851cdcc2a9b9ce379397e55293871c00a..8c84639dc54bb8d8aa6f3eeb2b7c1fea16ebfcb5 100644 (file)
@@ -4463,8 +4463,8 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,
 
        nla_put_u64_64bit(stats, TCP_NLA_BYTES_SENT, READ_ONCE(tp->bytes_sent),
                          TCP_NLA_PAD);
-       nla_put_u64_64bit(stats, TCP_NLA_BYTES_RETRANS, tp->bytes_retrans,
-                         TCP_NLA_PAD);
+       nla_put_u64_64bit(stats, TCP_NLA_BYTES_RETRANS,
+                         READ_ONCE(tp->bytes_retrans), TCP_NLA_PAD);
        nla_put_u32(stats, TCP_NLA_DSACK_DUPS, tp->dsack_dups);
        nla_put_u32(stats, TCP_NLA_REORD_SEEN, tp->reord_seen);
        nla_put_u32(stats, TCP_NLA_SRTT, tp->srtt_us >> 3);
index 87af4731df87ea5f310d39b1392cb995d4fa8f78..f9d8755705f762fe4da3064d2b1bfce4828ec0c1 100644 (file)
@@ -3645,7 +3645,7 @@ start:
        if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)
                __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPSYNRETRANS);
        WRITE_ONCE(tp->total_retrans, tp->total_retrans + segs);
-       tp->bytes_retrans += skb->len;
+       WRITE_ONCE(tp->bytes_retrans, tp->bytes_retrans + skb->len);
 
        /* make sure skb->data is aligned on arches that require it
         * and check if ack-trimming & collapsing extended the headroom