All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] tcp: Add READ_ONCE() to read tcp_orphan_count
@ 2022-05-12 10:33 Liu Jian
  2022-05-12 20:06 ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Liu Jian @ 2022-05-12 10:33 UTC (permalink / raw)
  To: edumazet, davem, yoshfuji, dsahern, kuba, pabeni, ncardwell, netdev
  Cc: liujian56

The tcp_orphan_count per-CPU variable is read locklessly, so this commit
add the READ_ONCE() to a load in order to avoid below KCSAN warnning:

BUG: KCSAN: data-race in tcp_orphan_count_sum net/ipv4/tcp.c:2476 [inline]
BUG: KCSAN: data-race in tcp_orphan_update+0x64/0x100 net/ipv4/tcp.c:2487

race at unknown origin, with read to 0xffff9c63bbdac7a8 of 4 bytes by interrupt on cpu 2:
 tcp_orphan_count_sum net/ipv4/tcp.c:2476 [inline]
 tcp_orphan_update+0x64/0x100 net/ipv4/tcp.c:2487
 call_timer_fn+0x33/0x210 kernel/time/timer.c:1414

Fixes: 19757cebf0c5 ("tcp: switch orphan_count to bare per-cpu counters")
Signed-off-by: Liu Jian <liujian56@huawei.com>
---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index cf18fbcbf123..7245609f41e6 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2718,7 +2718,7 @@ int tcp_orphan_count_sum(void)
 	int i, total = 0;
 
 	for_each_possible_cpu(i)
-		total += per_cpu(tcp_orphan_count, i);
+		total += READ_ONCE(per_cpu(tcp_orphan_count, i));
 
 	return max(total, 0);
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-17 20:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12 10:33 [PATCH net] tcp: Add READ_ONCE() to read tcp_orphan_count Liu Jian
2022-05-12 20:06 ` Eric Dumazet
2022-05-12 21:18   ` Marco Elver
2022-05-12 21:31     ` Eric Dumazet
2022-05-12 23:10       ` Paul E. McKenney
2022-05-12 23:43         ` Eric Dumazet
2022-05-13 11:08           ` David Laight
2022-05-17 20:28           ` Paul E. McKenney

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.