linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Bluetooth: bnep: Fix deadlock in session deletion
@ 2011-08-05 14:41 Peter Hurley
  2011-08-11 21:05 ` Gustavo Padovan
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Hurley @ 2011-08-05 14:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jaikumar Ganesh

Commit f4d7cd4a4c 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 bnep_del_connection()
which is waiting for the thread to exit -- deadlock.

Use atomic_t/wake_up_process instead to signal to the thread to exit.

Signed-off-by: Jaikumar Ganesh <jaikumar@google.com>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
---
 net/bluetooth/bnep/bnep.h |    1 +
 net/bluetooth/bnep/core.c |    9 +++++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/bnep/bnep.h b/net/bluetooth/bnep/bnep.h
index 8e6c061..e7ee531 100644
--- a/net/bluetooth/bnep/bnep.h
+++ b/net/bluetooth/bnep/bnep.h
@@ -155,6 +155,7 @@ struct bnep_session {
 	unsigned int  role;
 	unsigned long state;
 	unsigned long flags;
+	atomic_t      terminate;
 	struct task_struct *task;
 
 	struct ethhdr eh;
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index 7e8ff3c..d9edfe8 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -487,7 +487,7 @@ static int bnep_session(void *arg)
 	while (1) {
 		set_current_state(TASK_INTERRUPTIBLE);
 
-		if (kthread_should_stop())
+		if (atomic_read(&s->terminate))
 			break;
 		/* RX */
 		while ((skb = skb_dequeue(&sk->sk_receive_queue))) {
@@ -642,9 +642,10 @@ int bnep_del_connection(struct bnep_conndel_req *req)
 	down_read(&bnep_session_sem);
 
 	s = __bnep_get_session(req->dst);
-	if (s)
-		kthread_stop(s->task);
-	else
+	if (s) {
+		atomic_inc(&s->terminate);
+		wake_up_process(s->task);
+	} else
 		err = -ENOENT;
 
 	up_read(&bnep_session_sem);
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] Bluetooth: bnep: Fix deadlock in session deletion
  2011-08-05 14:41 [PATCH v2] Bluetooth: bnep: Fix deadlock in session deletion Peter Hurley
@ 2011-08-11 21:05 ` Gustavo Padovan
  0 siblings, 0 replies; 2+ messages in thread
From: Gustavo Padovan @ 2011-08-11 21:05 UTC (permalink / raw)
  To: Peter Hurley; +Cc: linux-bluetooth, Jaikumar Ganesh

Hi Peter,

* Peter Hurley <peter@hurleysoftware.com> [2011-08-05 10:41:35 -0400]:

> Commit f4d7cd4a4c 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 bnep_del_connection()
> which is waiting for the thread to exit -- deadlock.
> 
> Use atomic_t/wake_up_process instead to signal to the thread to exit.
> 
> Signed-off-by: Jaikumar Ganesh <jaikumar@google.com>
> Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
> ---
>  net/bluetooth/bnep/bnep.h |    1 +
>  net/bluetooth/bnep/core.c |    9 +++++----
>  2 files changed, 6 insertions(+), 4 deletions(-)

Applied, thanks.

	Gustavo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-11 21:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-05 14:41 [PATCH v2] Bluetooth: bnep: Fix deadlock in session deletion Peter Hurley
2011-08-11 21:05 ` Gustavo Padovan

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).