Skip to content

Commit 76f3329

Browse files
edumazetkuba-moo
authored andcommitted
sock: annotate data-races around prot->memory_pressure
*prot->memory_pressure is read/writen locklessly, we need to add proper annotations. A recent commit added a new race, it is time to audit all accesses. Fixes: 2d0c88e ("sock: Fix misuse of sk_under_memory_pressure()") Fixes: 4d93df0 ("[SCTP]: Rewrite of sctp buffer management code") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Abel Wu <wuyun.abel@bytedance.com> Reviewed-by: Shakeel Butt <shakeelb@google.com> Link: https://lore.kernel.org/r/20230818015132.2699348-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d44036c commit 76f3329

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

include/net/sock.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,7 @@ struct proto {
13231323
/*
13241324
* Pressure flag: try to collapse.
13251325
* Technical note: it is used by multiple contexts non atomically.
1326+
* Make sure to use READ_ONCE()/WRITE_ONCE() for all reads/writes.
13261327
* All the __sk_mem_schedule() is of this nature: accounting
13271328
* is strict, actions are advisory and have some latency.
13281329
*/
@@ -1423,7 +1424,7 @@ static inline bool sk_has_memory_pressure(const struct sock *sk)
14231424
static inline bool sk_under_global_memory_pressure(const struct sock *sk)
14241425
{
14251426
return sk->sk_prot->memory_pressure &&
1426-
!!*sk->sk_prot->memory_pressure;
1427+
!!READ_ONCE(*sk->sk_prot->memory_pressure);
14271428
}
14281429

14291430
static inline bool sk_under_memory_pressure(const struct sock *sk)
@@ -1435,7 +1436,7 @@ static inline bool sk_under_memory_pressure(const struct sock *sk)
14351436
mem_cgroup_under_socket_pressure(sk->sk_memcg))
14361437
return true;
14371438

1438-
return !!*sk->sk_prot->memory_pressure;
1439+
return !!READ_ONCE(*sk->sk_prot->memory_pressure);
14391440
}
14401441

14411442
static inline long
@@ -1512,7 +1513,7 @@ proto_memory_pressure(struct proto *prot)
15121513
{
15131514
if (!prot->memory_pressure)
15141515
return false;
1515-
return !!*prot->memory_pressure;
1516+
return !!READ_ONCE(*prot->memory_pressure);
15161517
}
15171518

15181519

net/sctp/socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct percpu_counter sctp_sockets_allocated;
9999

100100
static void sctp_enter_memory_pressure(struct sock *sk)
101101
{
102-
sctp_memory_pressure = 1;
102+
WRITE_ONCE(sctp_memory_pressure, 1);
103103
}
104104

105105

0 commit comments

Comments
 (0)