Skip to content

Commit 73f7c61

Browse files
edumazetgregkh
authored andcommitted
tcp: annotate data-races around tp->plb_rehash
[ Upstream commit 9e89b9d ] tcp_get_timestamping_opt_stats() intentionally runs lockless, we must add READ_ONCE() and WRITE_ONCE() annotations to keep KCSAN happy. Fixes: 29c1c44 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f597c36 commit 73f7c61

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

net/ipv4/tcp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4319,7 +4319,8 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,
43194319
nla_put_u8(stats, TCP_NLA_TTL,
43204320
tcp_skb_ttl_or_hop_limit(ack_skb));
43214321

4322-
nla_put_u32(stats, TCP_NLA_REHASH, tp->plb_rehash + tp->timeout_rehash);
4322+
nla_put_u32(stats, TCP_NLA_REHASH,
4323+
READ_ONCE(tp->plb_rehash) + READ_ONCE(tp->timeout_rehash));
43234324
return stats;
43244325
}
43254326

net/ipv4/tcp_plb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
7979

8080
sk_rethink_txhash(sk);
8181
plb->consec_cong_rounds = 0;
82-
tcp_sk(sk)->plb_rehash++;
82+
WRITE_ONCE(tcp_sk(sk)->plb_rehash, tcp_sk(sk)->plb_rehash + 1);
8383
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
8484
}
8585
EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);

0 commit comments

Comments
 (0)