]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tcp: annotate data-races around tp->plb_rehash
authorEric Dumazet <edumazet@google.com>
Thu, 16 Apr 2026 20:03:19 +0000 (20:03 +0000)
committerJakub Kicinski <kuba@kernel.org>
Sat, 18 Apr 2026 18:10:14 +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: 29c1c44646ae ("tcp: add u32 counter in tcp_sock and an SNMP counter for PLB")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260416200319.3608680-15-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/tcp.c
net/ipv4/tcp_plb.c

index 68894c03f2622d1a08fd747ff4c5e32be8579d2c..7fbf2fca5eb2c63763231d4d55b770b85a7cbdbf 100644 (file)
@@ -4480,7 +4480,8 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,
                nla_put_u8(stats, TCP_NLA_TTL,
                           tcp_skb_ttl_or_hop_limit(ack_skb));
 
-       nla_put_u32(stats, TCP_NLA_REHASH, tp->plb_rehash + tp->timeout_rehash);
+       nla_put_u32(stats, TCP_NLA_REHASH,
+                   READ_ONCE(tp->plb_rehash) + READ_ONCE(tp->timeout_rehash));
        return stats;
 }
 
index 68ccdb9a54127632b6b764b5cbb18e1589ab1aa7..c11a0cd3f8feb004150a4056f5ca57f90d2cb2b8 100644 (file)
@@ -80,7 +80,7 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
 
        sk_rethink_txhash(sk);
        plb->consec_cong_rounds = 0;
-       tcp_sk(sk)->plb_rehash++;
+       WRITE_ONCE(tcp_sk(sk)->plb_rehash, tcp_sk(sk)->plb_rehash + 1);
        NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
 }
 EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);