Skip to content

Commit 1f142c1

Browse files
edumazetJakub Kicinski
authored andcommitted
tcp: annotate lockless access to tcp_memory_pressure
tcp_memory_pressure is read without holding any lock, and its value could be changed on other cpus. Use READ_ONCE() to annotate these lockless reads. The write side is already using atomic ops. Fixes: b8da51e ("tcp: introduce tcp_under_memory_pressure()") Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 60b173c commit 1f142c1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

include/net/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static inline bool tcp_under_memory_pressure(const struct sock *sk)
258258
mem_cgroup_under_socket_pressure(sk->sk_memcg))
259259
return true;
260260

261-
return tcp_memory_pressure;
261+
return READ_ONCE(tcp_memory_pressure);
262262
}
263263
/*
264264
* The next routines deal with comparing 32 bit unsigned ints

net/ipv4/tcp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void tcp_enter_memory_pressure(struct sock *sk)
326326
{
327327
unsigned long val;
328328

329-
if (tcp_memory_pressure)
329+
if (READ_ONCE(tcp_memory_pressure))
330330
return;
331331
val = jiffies;
332332

@@ -341,7 +341,7 @@ void tcp_leave_memory_pressure(struct sock *sk)
341341
{
342342
unsigned long val;
343343

344-
if (!tcp_memory_pressure)
344+
if (!READ_ONCE(tcp_memory_pressure))
345345
return;
346346
val = xchg(&tcp_memory_pressure, 0);
347347
if (val)

0 commit comments

Comments
 (0)