* [PATCH net] sock: annotate data-races around prot->memory_pressure
@ 2023-08-18 1:51 Eric Dumazet
2023-08-18 19:14 ` Shakeel Butt
2023-08-19 2:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2023-08-18 1:51 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, eric.dumazet, Eric Dumazet, Abel Wu, Shakeel Butt
*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: 2d0c88e84e48 ("sock: Fix misuse of sk_under_memory_pressure()")
Fixes: 4d93df0abd50 ("[SCTP]: Rewrite of sctp buffer management code")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Abel Wu <wuyun.abel@bytedance.com>
Cc: Shakeel Butt <shakeelb@google.com>
---
include/net/sock.h | 7 ++++---
net/sctp/socket.c | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index e3d987b2ef124024110a0c67c4c4775742d3eb2d..690e22139543fb6eaf3ccd08475d2c6934231dbf 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1323,6 +1323,7 @@ struct proto {
/*
* Pressure flag: try to collapse.
* 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
* is strict, actions are advisory and have some latency.
*/
@@ -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)
{
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)
@@ -1435,7 +1436,7 @@ static inline bool sk_under_memory_pressure(const struct sock *sk)
mem_cgroup_under_socket_pressure(sk->sk_memcg))
return true;
- return !!*sk->sk_prot->memory_pressure;
+ return !!READ_ONCE(*sk->sk_prot->memory_pressure);
}
static inline long
@@ -1512,7 +1513,7 @@ proto_memory_pressure(struct proto *prot)
{
if (!prot->memory_pressure)
return false;
- return !!*prot->memory_pressure;
+ return !!READ_ONCE(*prot->memory_pressure);
}
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 9388d98aebc033f195e56d5295fd998996d41f7e..6da738f60f4b534d12245455c39bf4db18d8cb5a 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -99,7 +99,7 @@ struct percpu_counter sctp_sockets_allocated;
static void sctp_enter_memory_pressure(struct sock *sk)
{
- sctp_memory_pressure = 1;
+ WRITE_ONCE(sctp_memory_pressure, 1);
}
--
2.42.0.rc1.204.g551eb34607-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] sock: annotate data-races around prot->memory_pressure
2023-08-18 1:51 [PATCH net] sock: annotate data-races around prot->memory_pressure Eric Dumazet
@ 2023-08-18 19:14 ` Shakeel Butt
2023-08-19 2:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Shakeel Butt @ 2023-08-18 19:14 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
eric.dumazet, Abel Wu
On Thu, Aug 17, 2023 at 6:51 PM Eric Dumazet <edumazet@google.com> wrote:
>
> *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: 2d0c88e84e48 ("sock: Fix misuse of sk_under_memory_pressure()")
> Fixes: 4d93df0abd50 ("[SCTP]: Rewrite of sctp buffer management code")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Abel Wu <wuyun.abel@bytedance.com>
> Cc: Shakeel Butt <shakeelb@google.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] sock: annotate data-races around prot->memory_pressure
2023-08-18 1:51 [PATCH net] sock: annotate data-races around prot->memory_pressure Eric Dumazet
2023-08-18 19:14 ` Shakeel Butt
@ 2023-08-19 2:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-19 2:40 UTC (permalink / raw)
To: Eric Dumazet
Cc: davem, kuba, pabeni, netdev, eric.dumazet, wuyun.abel, shakeelb
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 18 Aug 2023 01:51:32 +0000 you wrote:
> *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: 2d0c88e84e48 ("sock: Fix misuse of sk_under_memory_pressure()")
> Fixes: 4d93df0abd50 ("[SCTP]: Rewrite of sctp buffer management code")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Abel Wu <wuyun.abel@bytedance.com>
> Cc: Shakeel Butt <shakeelb@google.com>
>
> [...]
Here is the summary with links:
- [net] sock: annotate data-races around prot->memory_pressure
https://git.kernel.org/netdev/net/c/76f33296d2e0
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-19 2:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-18 1:51 [PATCH net] sock: annotate data-races around prot->memory_pressure Eric Dumazet
2023-08-18 19:14 ` Shakeel Butt
2023-08-19 2:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).