* [PATCH v1 net] net: Annotate sk->sk_write_space() for UDP SOCKMAP.
@ 2026-05-29 19:39 Kuniyuki Iwashima
2026-06-01 10:45 ` Jakub Sitnicki
2026-06-02 19:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Kuniyuki Iwashima @ 2026-05-29 19:39 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn
Cc: Simon Horman, Lorenz Bauer, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
UDP TX skb->destructor() is sock_wfree(), and UDP holds lock_sock()
only for UDP_CORK / MSG_MORE sendmsg().
Otherwise, sk->sk_write_space() may be read locklessly while SOCKMAP
rewrites sk->sk_write_space().
Let's use WRITE_ONCE() and READ_ONCE() for sk->sk_write_space().
Note that the write side is annotated by commit 2ef2b20cf4e0
("net: annotate data-races around sk->sk_{data_ready,write_space}").
Fixes: 7b98cd42b049 ("bpf: sockmap: Add UDP support")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
net/core/sock.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index b37b664b6eb9..d097025c116a 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2676,8 +2676,12 @@ void sock_wfree(struct sk_buff *skb)
int old;
if (!sock_flag(sk, SOCK_USE_WRITE_QUEUE)) {
+ void (*sk_write_space)(struct sock *sk);
+
+ sk_write_space = READ_ONCE(sk->sk_write_space);
+
if (sock_flag(sk, SOCK_RCU_FREE) &&
- sk->sk_write_space == sock_def_write_space) {
+ sk_write_space == sock_def_write_space) {
rcu_read_lock();
free = __refcount_sub_and_test(len, &sk->sk_wmem_alloc,
&old);
@@ -2693,7 +2697,7 @@ void sock_wfree(struct sk_buff *skb)
* after sk_write_space() call
*/
WARN_ON(refcount_sub_and_test(len - 1, &sk->sk_wmem_alloc));
- sk->sk_write_space(sk);
+ sk_write_space(sk);
len = 1;
}
/*
--
2.54.0.823.g6e5bcc1fc9-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v1 net] net: Annotate sk->sk_write_space() for UDP SOCKMAP.
2026-05-29 19:39 [PATCH v1 net] net: Annotate sk->sk_write_space() for UDP SOCKMAP Kuniyuki Iwashima
@ 2026-06-01 10:45 ` Jakub Sitnicki
2026-06-02 19:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jakub Sitnicki @ 2026-06-01 10:45 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Lorenz Bauer, Kuniyuki Iwashima,
netdev
On Fri, May 29, 2026 at 07:39 PM GMT, Kuniyuki Iwashima wrote:
> UDP TX skb->destructor() is sock_wfree(), and UDP holds lock_sock()
> only for UDP_CORK / MSG_MORE sendmsg().
Nit: lock_sock() serializes map updates via bpf() syscall. We also have
sockmap iterator programs which can insert UDP sockets into sockmap. On
this path, sock_map_update_elem, we grab only bh_lock_sock, so the race
against UDP_CORK / MSG_MORE sendmsg() path also exists.
> Otherwise, sk->sk_write_space() may be read locklessly while SOCKMAP
> rewrites sk->sk_write_space().
>
> Let's use WRITE_ONCE() and READ_ONCE() for sk->sk_write_space().
>
> Note that the write side is annotated by commit 2ef2b20cf4e0
> ("net: annotate data-races around sk->sk_{data_ready,write_space}").
>
> Fixes: 7b98cd42b049 ("bpf: sockmap: Add UDP support")
> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
> ---
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v1 net] net: Annotate sk->sk_write_space() for UDP SOCKMAP.
2026-05-29 19:39 [PATCH v1 net] net: Annotate sk->sk_write_space() for UDP SOCKMAP Kuniyuki Iwashima
2026-06-01 10:45 ` Jakub Sitnicki
@ 2026-06-02 19:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-06-02 19:00 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: davem, edumazet, kuba, pabeni, willemb, horms, lmb, kuni1840,
netdev
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 29 May 2026 19:39:23 +0000 you wrote:
> UDP TX skb->destructor() is sock_wfree(), and UDP holds lock_sock()
> only for UDP_CORK / MSG_MORE sendmsg().
>
> Otherwise, sk->sk_write_space() may be read locklessly while SOCKMAP
> rewrites sk->sk_write_space().
>
> Let's use WRITE_ONCE() and READ_ONCE() for sk->sk_write_space().
>
> [...]
Here is the summary with links:
- [v1,net] net: Annotate sk->sk_write_space() for UDP SOCKMAP.
https://git.kernel.org/netdev/net/c/b748765019fe
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:[~2026-06-02 19:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29 19:39 [PATCH v1 net] net: Annotate sk->sk_write_space() for UDP SOCKMAP Kuniyuki Iwashima
2026-06-01 10:45 ` Jakub Sitnicki
2026-06-02 19:00 ` 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