Skip to content

Commit fec3adf

Browse files
Paolo Abenikuba-moo
authored andcommitted
mptcp: fix lockdep false positive
MattB reported a lockdep splat in the mptcp listener code cleanup: WARNING: possible circular locking dependency detected packetdrill/14278 is trying to acquire lock: ffff888017d868f0 ((work_completion)(&msk->work)){+.+.}-{0:0}, at: __flush_work (kernel/workqueue.c:3069) but task is already holding lock: ffff888017d84130 (sk_lock-AF_INET){+.+.}-{0:0}, at: mptcp_close (net/mptcp/protocol.c:2973) which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (sk_lock-AF_INET){+.+.}-{0:0}: __lock_acquire (kernel/locking/lockdep.c:5055) lock_acquire (kernel/locking/lockdep.c:466) lock_sock_nested (net/core/sock.c:3463) mptcp_worker (net/mptcp/protocol.c:2614) process_one_work (kernel/workqueue.c:2294) worker_thread (include/linux/list.h:292) kthread (kernel/kthread.c:376) ret_from_fork (arch/x86/entry/entry_64.S:312) -> #0 ((work_completion)(&msk->work)){+.+.}-{0:0}: check_prev_add (kernel/locking/lockdep.c:3098) validate_chain (kernel/locking/lockdep.c:3217) __lock_acquire (kernel/locking/lockdep.c:5055) lock_acquire (kernel/locking/lockdep.c:466) __flush_work (kernel/workqueue.c:3070) __cancel_work_timer (kernel/workqueue.c:3160) mptcp_cancel_work (net/mptcp/protocol.c:2758) mptcp_subflow_queue_clean (net/mptcp/subflow.c:1817) __mptcp_close_ssk (net/mptcp/protocol.c:2363) mptcp_destroy_common (net/mptcp/protocol.c:3170) mptcp_destroy (include/net/sock.h:1495) __mptcp_destroy_sock (net/mptcp/protocol.c:2886) __mptcp_close (net/mptcp/protocol.c:2959) mptcp_close (net/mptcp/protocol.c:2974) inet_release (net/ipv4/af_inet.c:432) __sock_release (net/socket.c:651) sock_close (net/socket.c:1367) __fput (fs/file_table.c:320) task_work_run (kernel/task_work.c:181 (discriminator 1)) exit_to_user_mode_prepare (include/linux/resume_user_mode.h:49) syscall_exit_to_user_mode (kernel/entry/common.c:130) do_syscall_64 (arch/x86/entry/common.c:87) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120) other info that might help us debug this: Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(sk_lock-AF_INET); lock((work_completion)(&msk->work)); lock(sk_lock-AF_INET); lock((work_completion)(&msk->work)); *** DEADLOCK *** The report is actually a false positive, since the only existing lock nesting is the msk socket lock acquired by the mptcp work. cancel_work_sync() is invoked without the relevant socket lock being held, but under a different (the msk listener) socket lock. We could silence the splat adding a per workqueue dynamic lockdep key, but that looks overkill. Instead just tell lockdep the msk socket lock is not held around cancel_work_sync(). Closes: multipath-tcp/mptcp_net-next#322 Fixes: 30e51b9 ("mptcp: fix unreleased socket in accept queue") Reported-by: Matthieu Baerts <matthieu.baerts@tessares.net> Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7d80334 commit fec3adf

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

net/mptcp/protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
23572357
/* otherwise tcp will dispose of the ssk and subflow ctx */
23582358
if (ssk->sk_state == TCP_LISTEN) {
23592359
tcp_set_state(ssk, TCP_CLOSE);
2360-
mptcp_subflow_queue_clean(ssk);
2360+
mptcp_subflow_queue_clean(sk, ssk);
23612361
inet_csk_listen_stop(ssk);
23622362
mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CLOSED);
23632363
}

net/mptcp/protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
628628
struct mptcp_subflow_context *subflow);
629629
void __mptcp_subflow_send_ack(struct sock *ssk);
630630
void mptcp_subflow_reset(struct sock *ssk);
631-
void mptcp_subflow_queue_clean(struct sock *ssk);
631+
void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk);
632632
void mptcp_sock_graft(struct sock *sk, struct socket *parent);
633633
struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk);
634634
bool __mptcp_close(struct sock *sk, long timeout);

net/mptcp/subflow.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,7 @@ static void subflow_state_change(struct sock *sk)
17911791
}
17921792
}
17931793

1794-
void mptcp_subflow_queue_clean(struct sock *listener_ssk)
1794+
void mptcp_subflow_queue_clean(struct sock *listener_sk, struct sock *listener_ssk)
17951795
{
17961796
struct request_sock_queue *queue = &inet_csk(listener_ssk)->icsk_accept_queue;
17971797
struct mptcp_sock *msk, *next, *head = NULL;
@@ -1840,8 +1840,23 @@ void mptcp_subflow_queue_clean(struct sock *listener_ssk)
18401840

18411841
do_cancel_work = __mptcp_close(sk, 0);
18421842
release_sock(sk);
1843-
if (do_cancel_work)
1843+
if (do_cancel_work) {
1844+
/* lockdep will report a false positive ABBA deadlock
1845+
* between cancel_work_sync and the listener socket.
1846+
* The involved locks belong to different sockets WRT
1847+
* the existing AB chain.
1848+
* Using a per socket key is problematic as key
1849+
* deregistration requires process context and must be
1850+
* performed at socket disposal time, in atomic
1851+
* context.
1852+
* Just tell lockdep to consider the listener socket
1853+
* released here.
1854+
*/
1855+
mutex_release(&listener_sk->sk_lock.dep_map, _RET_IP_);
18441856
mptcp_cancel_work(sk);
1857+
mutex_acquire(&listener_sk->sk_lock.dep_map,
1858+
SINGLE_DEPTH_NESTING, 0, _RET_IP_);
1859+
}
18451860
sock_put(sk);
18461861
}
18471862

0 commit comments

Comments
 (0)