sock_map: move cancel_work_sync() out of sock lock
Subsystems (5)
PATCH v2 1/1 sock_map: move cancel_work_sync() out of sock lock
From: Cong Wang <[email protected]>
Stanislav reported a lockdep warning, which is caused by the cancel_work_sync() called inside sock_map_close(), as analyzed below by Jakub:
psock->work.func = sk_psock_backlog()
ACQUIRE psock->work_mutex
sk_psock_handle_skb()
skb_send_sock()
__skb_send_sock()
sendpage_unlocked()
kernel_sendpage()
sock->ops->sendpage = inet_sendpage()
sk->sk_prot->sendpage = tcp_sendpage()
ACQUIRE sk->sk_lock
tcp_sendpage_locked()
RELEASE sk->sk_lock RELEASE psock->work_mutex
sock_map_close()
ACQUIRE sk->sk_lock
sk_psock_stop()
sk_psock_clear_state(psock, SK_PSOCK_TX_ENABLED)
cancel_work_sync()
__cancel_work_timer()
__flush_work()
// wait for psock->work to finish RELEASE sk->sk_lock
We can move the cancel_work_sync() out of the sock lock protection, but still before saved_close() was called.
--- include/linux/skmsg.h | 2 +- net/core/skmsg.c | 7 ++----- net/core/sock_map.c | 7 ++++--- 3 files changed, 7 insertions(+), 9 deletions(-)
include/linux/skmsg.h +1 -1
@@ -376,7 +376,7 @@ static inline void sk_psock_report_error(struct sk_psock *psock, int err) }struct sk_psock *sk_psock_init (struct sock *sk,int node); -void sk_psock_stop (struct sk_psock *psock,bool wait); +void sk_psock_stop (struct sk_psock *psock);#if IS_ENABLED (CONFIG_BPF_STREAM_PARSER )int sk_psock_init_strp (struct sock *sk,struct sk_psock *psock);
net/core/skmsg.c +2 -5
@@ -803,16 +803,13 @@ static void sk_psock_link_destroy(struct sk_psock *psock) } } -void sk_psock_stop (struct sk_psock *psock,bool wait) +void sk_psock_stop (struct sk_psock *psock) {spin_lock_bh (&psock->ingress_lock);sk_psock_clear_state (psock,SK_PSOCK_TX_ENABLED );sk_psock_cork_free (psock);__sk_psock_zap_ingress (psock);spin_unlock_bh (&psock->ingress_lock); - -if (wait) -cancel_work_sync (&psock->work); }static void sk_psock_done_strp (struct sk_psock *psock);
@@ -850,7 +847,7 @@ void sk_psock_drop(struct sock *sk, struct sk_psock *psock)sk_psock_stop_verdict (sk, psock);write_unlock_bh (&sk->sk_callback_lock); -sk_psock_stop (psock, false); +sk_psock_stop (psock);INIT_RCU_WORK (&psock->rwork, sk_psock_destroy);queue_rcu_work (system_wq, &psock->rwork);
net/core/sock_map.c +4 -3
@@ -1596,7 +1596,7 @@ void sock_map_destroy(struct sock *sk) saved_destroy = psock->saved_destroy;sock_map_remove_links (sk, psock);rcu_read_unlock (); -sk_psock_stop (psock, false); +sk_psock_stop (psock);sk_psock_put (sk, psock);saved_destroy (sk); }
@@ -1619,9 +1619,10 @@ void sock_map_close(struct sock *sk, long timeout) saved_close = psock->saved_close;sock_map_remove_links (sk, psock);rcu_read_unlock (); -sk_psock_stop (psock, true); -sk_psock_put (sk, psock); +sk_psock_stop (psock);release_sock (sk); +cancel_work_sync (&psock->work); +sk_psock_put (sk, psock);saved_close (sk, timeout); }EXPORT_SYMBOL_GPL (sock_map_close);
Signature · 1 line
2.34.1
Quoted 33 lines · Cong Wang
From: Cong Wang <[email protected]>
Stanislav reported a lockdep warning, which is caused by the
cancel_work_sync()called insidesock_map_close(), as analyzed below by Jakub:
psock->work.func=sk_psock_backlog()
ACQUIREpsock->work_mutexsk_psock_handle_skb() skb_send_sock() __skb_send_sock() sendpage_unlocked() kernel_sendpage() sock->ops->sendpage = inet_sendpage() sk->sk_prot->sendpage = tcp_sendpage() ACQUIRE sk->sk_lock tcp_sendpage_locked() RELEASE sk->sk_lockRELEASE
psock->work_mutex
sock_map_close()
ACQUIREsk->sk_lock
sk_psock_stop()sk_psock_clear_state(psock, SK_PSOCK_TX_ENABLED) cancel_work_sync() __cancel_work_timer() __flush_work() // wait for psock->work to finishRELEASE
sk->sk_lockWe can move the
cancel_work_sync()out of the sock lock protection, but still beforesaved_close()was called.
Quoted 6 lines
Fixes 799aa7f98d53 ("skmsg: Avoid lock_sock() in sk_psock_backlog()")Reported-by Stanislav Fomichev <[email protected]>Cc John Fastabend <[email protected]>Cc Jakub Sitnicki <[email protected]>Signed-off-by Cong Wang <[email protected]>---
LGTM. Thanks.
Quoted 33 lines · Cong Wang
From: Cong Wang <[email protected]>
Stanislav reported a lockdep warning, which is caused by the
cancel_work_sync()called insidesock_map_close(), as analyzed below by Jakub:
psock->work.func=sk_psock_backlog()
ACQUIREpsock->work_mutexsk_psock_handle_skb() skb_send_sock() __skb_send_sock() sendpage_unlocked() kernel_sendpage() sock->ops->sendpage = inet_sendpage() sk->sk_prot->sendpage = tcp_sendpage() ACQUIRE sk->sk_lock tcp_sendpage_locked() RELEASE sk->sk_lockRELEASE
psock->work_mutex
sock_map_close()
ACQUIREsk->sk_lock
sk_psock_stop()sk_psock_clear_state(psock, SK_PSOCK_TX_ENABLED) cancel_work_sync() __cancel_work_timer() __flush_work() // wait for psock->work to finishRELEASE
sk->sk_lockWe can move the
cancel_work_sync()out of the sock lock protection, but still beforesaved_close()was called.
Quoted 6 lines
Fixes 799aa7f98d53 ("skmsg: Avoid lock_sock() in sk_psock_backlog()")Reported-by Stanislav Fomichev <[email protected]>Cc John Fastabend <[email protected]>Cc Jakub Sitnicki <[email protected]>Signed-off-by Cong Wang <[email protected]>---
[...]
Thanks!
This patch was applied to bpf/bpf.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Daniel Borkmann <[email protected]>:
Quoted 18 lines · On Tue, 1 Nov 2022 21:34:17 -0700 you wrote:
From: Cong Wang <[email protected]>
Stanislav reported a lockdep warning, which is caused by the
cancel_work_sync()called insidesock_map_close(), as analyzed below by Jakub:
psock->work.func=sk_psock_backlog()
ACQUIREpsock->work_mutexsk_psock_handle_skb() skb_send_sock() __skb_send_sock() sendpage_unlocked() kernel_sendpage() sock->ops->sendpage = inet_sendpage() sk->sk_prot->sendpage = tcp_sendpage() ACQUIRE sk->sk_lock tcp_sendpage_locked() RELEASE sk->sk_lock
Quoted 3 lines
RELEASE
psock->work_mutex[...]
Here is the summary with links:
- [bpf,v2] sock_map: move cancel_work_sync() out of sock lock
https://git.kernel.org/bpf/bpf/c/8bbabb3fddcd
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html