Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: b8da51ebb1aa ("tcp: introduce tcp_under_memory_pressure()")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>

authored by

Eric Dumazet and committed by
Jakub Kicinski
1f142c17 60b173ca

+3 -3
+1 -1
include/net/tcp.h
··· 258 258 mem_cgroup_under_socket_pressure(sk->sk_memcg)) 259 259 return true; 260 260 261 - return tcp_memory_pressure; 261 + return READ_ONCE(tcp_memory_pressure); 262 262 } 263 263 /* 264 264 * The next routines deal with comparing 32 bit unsigned ints
+2 -2
net/ipv4/tcp.c
··· 326 326 { 327 327 unsigned long val; 328 328 329 - if (tcp_memory_pressure) 329 + if (READ_ONCE(tcp_memory_pressure)) 330 330 return; 331 331 val = jiffies; 332 332 ··· 341 341 { 342 342 unsigned long val; 343 343 344 - if (!tcp_memory_pressure) 344 + if (!READ_ONCE(tcp_memory_pressure)) 345 345 return; 346 346 val = xchg(&tcp_memory_pressure, 0); 347 347 if (val)