]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tcp: annotate data-races around tp->srtt_us
authorEric Dumazet <edumazet@google.com>
Thu, 16 Apr 2026 20:03:16 +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: e8bd8fca6773 ("tcp: add SRTT to SCM_TIMESTAMPING_OPT_STATS")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260416200319.3608680-12-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/tcp.c
net/ipv4/tcp_input.c

index 39a4b06e36bbc63b8bc334c8f568c5a2046573b6..541bd0d2d8c4ed24934fd047dd46e532b30021be 100644 (file)
@@ -3623,7 +3623,8 @@ static void tcp_enable_tx_delay(struct sock *sk, int val)
        if (delta && sk->sk_state == TCP_ESTABLISHED) {
                s64 srtt = (s64)tp->srtt_us + delta;
 
-               tp->srtt_us = clamp_t(s64, srtt, 1, ~0U);
+               WRITE_ONCE(tp->srtt_us,
+                          clamp_t(s64, srtt, 1, ~0U));
 
                /* Note: does not deal with non zero icsk_backoff */
                tcp_set_rto(sk);
@@ -4467,7 +4468,7 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,
                          READ_ONCE(tp->bytes_retrans), TCP_NLA_PAD);
        nla_put_u32(stats, TCP_NLA_DSACK_DUPS, READ_ONCE(tp->dsack_dups));
        nla_put_u32(stats, TCP_NLA_REORD_SEEN, READ_ONCE(tp->reord_seen));
-       nla_put_u32(stats, TCP_NLA_SRTT, tp->srtt_us >> 3);
+       nla_put_u32(stats, TCP_NLA_SRTT, READ_ONCE(tp->srtt_us) >> 3);
        nla_put_u16(stats, TCP_NLA_TIMEOUT_REHASH, tp->timeout_rehash);
        nla_put_u32(stats, TCP_NLA_BYTES_NOTSENT,
                    max_t(int, 0, tp->write_seq - tp->snd_nxt));
index 896a5a5a6b1a9a678e5321dd802554ab343f7835..e04ae105893c2bf234e593b1529748283bb2176c 100644 (file)
@@ -1132,7 +1132,7 @@ static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
 
                tcp_bpf_rtt(sk, mrtt_us, srtt);
        }
-       tp->srtt_us = max(1U, srtt);
+       WRITE_ONCE(tp->srtt_us, max(1U, srtt));
 }
 
 void tcp_update_pacing_rate(struct sock *sk)