Bluetooth: cmtp: Fix deadlock in session deletion
Subsystems (2)
PATCH 1/1 Bluetooth: cmtp: Fix deadlock in session deletion
Commit fada4ac339 introduced the usage of kthread API. kthread_stop is a blocking function which returns only when the thread exits. In this case, the thread can't exit because it's waiting for the write lock, which is being held by cmtp_del_connection() which is waiting for the thread to exit -- deadlock.
Revert cmtp_reset_ctr to its original behavior: non-blocking signalling for the session to terminate.
--- net/bluetooth/cmtp/capi.c | 3 ++- net/bluetooth/cmtp/cmtp.h | 1 + net/bluetooth/cmtp/core.c | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-)
net/bluetooth/cmtp/capi.c +2 -1
@@ -387,7 +387,8 @@ static void cmtp_reset_ctr(struct capi_ctr *ctrl)capi_ctr_down (ctrl); -kthread_stop (session->task); +atomic_inc (&session->terminate); +wake_up_process (session->task); }static void cmtp_register_appl (struct capi_ctr *ctrl,__u16 appl,capi_register_params *rp)
net/bluetooth/cmtp/cmtp.h +1 -0
@@ -81,6 +81,7 @@ struct cmtp_session {char name[BTNAMSIZ ]; +atomic_t terminate;struct task_struct *task;wait_queue_head_t wait;
net/bluetooth/cmtp/core.c +3 -2
@@ -295,7 +295,7 @@ static int cmtp_session(void *arg)while (1 ) {set_current_state (TASK_INTERRUPTIBLE ); -if (kthread_should_stop ()) +if (atomic_read (&session->terminate))break ;if (sk->sk_state !=BT_CONNECTED )break ;
@@ -416,7 +416,8 @@ int cmtp_del_connection(struct cmtp_conndel_req *req)skb_queue_purge (&session->transmit);/* Stop session thread */ -kthread_stop (session->task); +atomic_inc (&session->terminate); +wake_up_process (session->task); }else err = -ENOENT ;
Signature · 1 line
1.7.4.1
Gustavo Padovan
AppliedHi Peter,
Quoted 9 lines · Peter Hurley
Commit
fada4ac339introduced the usage of kthread API.kthread_stopis a blocking function which returns only when the thread exits. In this case, the thread can't exit because it's waiting for the write lock, which is being held bycmtp_del_connection()which is waiting for the thread to exit -- deadlock.Revert
cmtp_reset_ctrto its original behavior: non-blocking signalling for the session to terminate.
Quoted 6 lines
Signed-off-by Peter Hurley <[email protected]>--- net/bluetooth/cmtp/capi.c | 3 ++- net/bluetooth/cmtp/cmtp.h | 1 + net/bluetooth/cmtp/core.c | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-)
Applied, thanks.
Gustavo