summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2023-08-02 13:14:57 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-08-11 11:33:55 +0200
commita5a6fe8d122b87c98bd066f370b853a8d2a6fbd0 (patch)
treea11c0592ec9b7217bdb8c1e4c723c225e91d1fb8
parent005f68d6b3da8dd41b885550e0dfb46783d4bfb2 (diff)
downloadlinux-a5a6fe8d122b87c98bd066f370b853a8d2a6fbd0.tar.gz
linux-a5a6fe8d122b87c98bd066f370b853a8d2a6fbd0.tar.bz2
linux-a5a6fe8d122b87c98bd066f370b853a8d2a6fbd0.zip
tcp_metrics: annotate data-races around tm->tcpm_lock
[ Upstream commit 285ce119a3c6c4502585936650143e54c8692788 ] tm->tcpm_lock can be read or written locklessly. Add needed READ_ONCE()/WRITE_ONCE() to document this. Fixes: 51c5d0c4b169 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--net/ipv4/tcp_metrics.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index a283b0710a7e..2f0e7c38e634 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -61,7 +61,8 @@ static inline struct net *tm_net(struct tcp_metrics_block *tm)
static bool tcp_metric_locked(struct tcp_metrics_block *tm,
enum tcp_metric_index idx)
{
- return tm->tcpm_lock & (1 << idx);
+ /* Paired with WRITE_ONCE() in tcpm_suck_dst() */
+ return READ_ONCE(tm->tcpm_lock) & (1 << idx);
}
static u32 tcp_metric_get(struct tcp_metrics_block *tm,
@@ -112,7 +113,8 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm,
val |= 1 << TCP_METRIC_CWND;
if (dst_metric_locked(dst, RTAX_REORDERING))
val |= 1 << TCP_METRIC_REORDERING;
- tm->tcpm_lock = val;
+ /* Paired with READ_ONCE() in tcp_metric_locked() */
+ WRITE_ONCE(tm->tcpm_lock, val);
msval = dst_metric_raw(dst, RTAX_RTT);
tm->tcpm_vals[TCP_METRIC_RTT] = msval * USEC_PER_MSEC;