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

index 8c84639dc54bb8d8aa6f3eeb2b7c1fea16ebfcb5..57c4dcc8bfe948e895f713cadaad20409a9b8f14 100644 (file)
@@ -4465,7 +4465,7 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,
                          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_DSACK_DUPS, READ_ONCE(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);
        nla_put_u16(stats, TCP_NLA_TIMEOUT_REHASH, tp->timeout_rehash);
index edb5013873e0c4a9ba2f8a81a43eff5fb6e7a47b..65b3ecc6be4b57f97a62d0e5737a96ddb16dd14d 100644 (file)
@@ -1246,7 +1246,7 @@ static u32 tcp_dsack_seen(struct tcp_sock *tp, u32 start_seq,
        else if (tp->tlp_high_seq && tp->tlp_high_seq == end_seq)
                state->flag |= FLAG_DSACK_TLP;
 
-       tp->dsack_dups += dup_segs;
+       WRITE_ONCE(tp->dsack_dups, tp->dsack_dups + dup_segs);
        /* Skip the DSACK if dup segs weren't retransmitted by sender */
        if (tp->dsack_dups > tp->total_retrans)
                return 0;