Skip to content

Commit 285ce11

Browse files
edumazetkuba-moo
authored andcommitted
tcp_metrics: annotate data-races around tm->tcpm_lock
tm->tcpm_lock can be read or written locklessly. Add needed READ_ONCE()/WRITE_ONCE() to document this. Fixes: 51c5d0c ("tcp: Maintain dynamic metrics in local cache.") Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: David Ahern <dsahern@kernel.org> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://lore.kernel.org/r/20230802131500.1478140-4-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 949ad62 commit 285ce11

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/ipv4/tcp_metrics.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ static inline struct net *tm_net(struct tcp_metrics_block *tm)
5959
static bool tcp_metric_locked(struct tcp_metrics_block *tm,
6060
enum tcp_metric_index idx)
6161
{
62-
return tm->tcpm_lock & (1 << idx);
62+
/* Paired with WRITE_ONCE() in tcpm_suck_dst() */
63+
return READ_ONCE(tm->tcpm_lock) & (1 << idx);
6364
}
6465

6566
static u32 tcp_metric_get(struct tcp_metrics_block *tm,
@@ -110,7 +111,8 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm,
110111
val |= 1 << TCP_METRIC_CWND;
111112
if (dst_metric_locked(dst, RTAX_REORDERING))
112113
val |= 1 << TCP_METRIC_REORDERING;
113-
tm->tcpm_lock = val;
114+
/* Paired with READ_ONCE() in tcp_metric_locked() */
115+
WRITE_ONCE(tm->tcpm_lock, val);
114116

115117
msval = dst_metric_raw(dst, RTAX_RTT);
116118
tm->tcpm_vals[TCP_METRIC_RTT] = msval * USEC_PER_MSEC;

0 commit comments

Comments
 (0)