Commit 76f33296 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

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: 2d0c88e8 ("sock: Fix misuse of sk_under_memory_pressure()")
Fixes: 4d93df0a ("[SCTP]: Rewrite of sctp buffer management code")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Cc: Abel Wu <wuyun.abel@bytedance.com>
Reviewed-by: default avatarShakeel Butt <shakeelb@google.com>
Link: https://lore.kernel.org/r/20230818015132.2699348-1-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d44036ca
...@@ -1323,6 +1323,7 @@ struct proto { ...@@ -1323,6 +1323,7 @@ struct proto {
/* /*
* Pressure flag: try to collapse. * Pressure flag: try to collapse.
* Technical note: it is used by multiple contexts non atomically. * Technical note: it is used by multiple contexts non atomically.
* Make sure to use READ_ONCE()/WRITE_ONCE() for all reads/writes.
* All the __sk_mem_schedule() is of this nature: accounting * All the __sk_mem_schedule() is of this nature: accounting
* is strict, actions are advisory and have some latency. * is strict, actions are advisory and have some latency.
*/ */
...@@ -1423,7 +1424,7 @@ static inline bool sk_has_memory_pressure(const struct sock *sk) ...@@ -1423,7 +1424,7 @@ static inline bool sk_has_memory_pressure(const struct sock *sk)
static inline bool sk_under_global_memory_pressure(const struct sock *sk) static inline bool sk_under_global_memory_pressure(const struct sock *sk)
{ {
return sk->sk_prot->memory_pressure && return sk->sk_prot->memory_pressure &&
!!*sk->sk_prot->memory_pressure; !!READ_ONCE(*sk->sk_prot->memory_pressure);
} }
static inline bool sk_under_memory_pressure(const struct sock *sk) 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) ...@@ -1435,7 +1436,7 @@ static inline bool sk_under_memory_pressure(const struct sock *sk)
mem_cgroup_under_socket_pressure(sk->sk_memcg)) mem_cgroup_under_socket_pressure(sk->sk_memcg))
return true; return true;
return !!*sk->sk_prot->memory_pressure; return !!READ_ONCE(*sk->sk_prot->memory_pressure);
} }
static inline long static inline long
...@@ -1512,7 +1513,7 @@ proto_memory_pressure(struct proto *prot) ...@@ -1512,7 +1513,7 @@ proto_memory_pressure(struct proto *prot)
{ {
if (!prot->memory_pressure) if (!prot->memory_pressure)
return false; return false;
return !!*prot->memory_pressure; return !!READ_ONCE(*prot->memory_pressure);
} }
......
...@@ -99,7 +99,7 @@ struct percpu_counter sctp_sockets_allocated; ...@@ -99,7 +99,7 @@ struct percpu_counter sctp_sockets_allocated;
static void sctp_enter_memory_pressure(struct sock *sk) static void sctp_enter_memory_pressure(struct sock *sk)
{ {
sctp_memory_pressure = 1; WRITE_ONCE(sctp_memory_pressure, 1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment