mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 02:50:43 +00:00
tcp_metrics: annotate data-races around tm->tcpm_stamp
[ Upstream commit949ad62a5d
] tm->tcpm_stamp can be read or written locklessly. Add needed READ_ONCE()/WRITE_ONCE() to document this. Also constify tcpm_check_stamp() dst argument. Fixes:51c5d0c4b1
("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-3-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
71f891a254
commit
4a77a0f752
1 changed files with 13 additions and 6 deletions
|
@ -97,7 +97,7 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm,
|
||||||
u32 msval;
|
u32 msval;
|
||||||
u32 val;
|
u32 val;
|
||||||
|
|
||||||
tm->tcpm_stamp = jiffies;
|
WRITE_ONCE(tm->tcpm_stamp, jiffies);
|
||||||
|
|
||||||
val = 0;
|
val = 0;
|
||||||
if (dst_metric_locked(dst, RTAX_RTT))
|
if (dst_metric_locked(dst, RTAX_RTT))
|
||||||
|
@ -131,9 +131,15 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm,
|
||||||
|
|
||||||
#define TCP_METRICS_TIMEOUT (60 * 60 * HZ)
|
#define TCP_METRICS_TIMEOUT (60 * 60 * HZ)
|
||||||
|
|
||||||
static void tcpm_check_stamp(struct tcp_metrics_block *tm, struct dst_entry *dst)
|
static void tcpm_check_stamp(struct tcp_metrics_block *tm,
|
||||||
|
const struct dst_entry *dst)
|
||||||
{
|
{
|
||||||
if (tm && unlikely(time_after(jiffies, tm->tcpm_stamp + TCP_METRICS_TIMEOUT)))
|
unsigned long limit;
|
||||||
|
|
||||||
|
if (!tm)
|
||||||
|
return;
|
||||||
|
limit = READ_ONCE(tm->tcpm_stamp) + TCP_METRICS_TIMEOUT;
|
||||||
|
if (unlikely(time_after(jiffies, limit)))
|
||||||
tcpm_suck_dst(tm, dst, false);
|
tcpm_suck_dst(tm, dst, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +180,8 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
|
||||||
oldest = deref_locked(tcp_metrics_hash[hash].chain);
|
oldest = deref_locked(tcp_metrics_hash[hash].chain);
|
||||||
for (tm = deref_locked(oldest->tcpm_next); tm;
|
for (tm = deref_locked(oldest->tcpm_next); tm;
|
||||||
tm = deref_locked(tm->tcpm_next)) {
|
tm = deref_locked(tm->tcpm_next)) {
|
||||||
if (time_before(tm->tcpm_stamp, oldest->tcpm_stamp))
|
if (time_before(READ_ONCE(tm->tcpm_stamp),
|
||||||
|
READ_ONCE(oldest->tcpm_stamp)))
|
||||||
oldest = tm;
|
oldest = tm;
|
||||||
}
|
}
|
||||||
tm = oldest;
|
tm = oldest;
|
||||||
|
@ -434,7 +441,7 @@ void tcp_update_metrics(struct sock *sk)
|
||||||
tp->reordering);
|
tp->reordering);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tm->tcpm_stamp = jiffies;
|
WRITE_ONCE(tm->tcpm_stamp, jiffies);
|
||||||
out_unlock:
|
out_unlock:
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
}
|
}
|
||||||
|
@ -647,7 +654,7 @@ static int tcp_metrics_fill_info(struct sk_buff *msg,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nla_put_msecs(msg, TCP_METRICS_ATTR_AGE,
|
if (nla_put_msecs(msg, TCP_METRICS_ATTR_AGE,
|
||||||
jiffies - tm->tcpm_stamp,
|
jiffies - READ_ONCE(tm->tcpm_stamp),
|
||||||
TCP_METRICS_ATTR_PAD) < 0)
|
TCP_METRICS_ATTR_PAD) < 0)
|
||||||
goto nla_put_failure;
|
goto nla_put_failure;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue