* [PATCH 1/2] Bluetooth: Release chan lock upon sleeping
@ 2012-05-31 19:25 Gustavo Padovan
2012-05-31 19:25 ` [PATCH 2/2] Bluetooth: Release all locks before sleep Gustavo Padovan
0 siblings, 1 reply; 3+ messages in thread
From: Gustavo Padovan @ 2012-05-31 19:25 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Gustavo Padovan
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
The lock must be released otherwise we block any other piece of the code
trying to lock the chan lock.
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
net/bluetooth/l2cap_core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 9750204..1cb3ca0 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1569,7 +1569,9 @@ int __l2cap_wait_ack(struct sock *sk)
}
release_sock(sk);
+ l2cap_chan_unlock(chan);
timeo = schedule_timeout(timeo);
+ l2cap_chan_lock(chan);
lock_sock(sk);
set_current_state(TASK_INTERRUPTIBLE);
--
1.7.10.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] Bluetooth: Release all locks before sleep
2012-05-31 19:25 [PATCH 1/2] Bluetooth: Release chan lock upon sleeping Gustavo Padovan
@ 2012-05-31 19:25 ` Gustavo Padovan
2012-06-04 17:14 ` Mat Martineau
0 siblings, 1 reply; 3+ messages in thread
From: Gustavo Padovan @ 2012-05-31 19:25 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Gustavo Padovan
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
To avoid deadlock we need to release locks while waiting for a ack to
arrive.
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
net/bluetooth/l2cap_core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 1cb3ca0..94273dc 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1553,13 +1553,14 @@ done:
int __l2cap_wait_ack(struct sock *sk)
{
struct l2cap_chan *chan = l2cap_pi(sk)->chan;
+ struct l2cap_conn *conn = chan->conn;
DECLARE_WAITQUEUE(wait, current);
int err = 0;
int timeo = HZ/5;
add_wait_queue(sk_sleep(sk), &wait);
set_current_state(TASK_INTERRUPTIBLE);
- while (chan->unacked_frames > 0 && chan->conn) {
+ while (chan->unacked_frames > 0 && conn) {
if (!timeo)
timeo = HZ/5;
@@ -1570,7 +1571,9 @@ int __l2cap_wait_ack(struct sock *sk)
release_sock(sk);
l2cap_chan_unlock(chan);
+ mutex_unlock(&conn->chan_lock);
timeo = schedule_timeout(timeo);
+ mutex_lock(&conn->chan_lock);
l2cap_chan_lock(chan);
lock_sock(sk);
set_current_state(TASK_INTERRUPTIBLE);
--
1.7.10.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 2/2] Bluetooth: Release all locks before sleep
2012-05-31 19:25 ` [PATCH 2/2] Bluetooth: Release all locks before sleep Gustavo Padovan
@ 2012-06-04 17:14 ` Mat Martineau
0 siblings, 0 replies; 3+ messages in thread
From: Mat Martineau @ 2012-06-04 17:14 UTC (permalink / raw)
To: Gustavo Padovan; +Cc: linux-bluetooth
Hi Gustavo -
On Thu, 31 May 2012, Gustavo Padovan wrote:
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>
> To avoid deadlock we need to release locks while waiting for a ack to
> arrive.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> ---
> net/bluetooth/l2cap_core.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 1cb3ca0..94273dc 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -1553,13 +1553,14 @@ done:
> int __l2cap_wait_ack(struct sock *sk)
> {
> struct l2cap_chan *chan = l2cap_pi(sk)->chan;
> + struct l2cap_conn *conn = chan->conn;
I don't think you want to store the l2cap_conn pointer on the stack,
the structure can be freed when the locks are released.
> DECLARE_WAITQUEUE(wait, current);
> int err = 0;
> int timeo = HZ/5;
>
> add_wait_queue(sk_sleep(sk), &wait);
> set_current_state(TASK_INTERRUPTIBLE);
> - while (chan->unacked_frames > 0 && chan->conn) {
> + while (chan->unacked_frames > 0 && conn) {
> if (!timeo)
> timeo = HZ/5;
>
> @@ -1570,7 +1571,9 @@ int __l2cap_wait_ack(struct sock *sk)
>
> release_sock(sk);
> l2cap_chan_unlock(chan);
> + mutex_unlock(&conn->chan_lock);
> timeo = schedule_timeout(timeo);
> + mutex_lock(&conn->chan_lock);
> l2cap_chan_lock(chan);
> lock_sock(sk);
> set_current_state(TASK_INTERRUPTIBLE);
> --
> 1.7.10.2
I think it would be better to only acquire the chan_lock mutex when
calling l2cap_chan_close in l2cap_sock_shutdown. However, you will
have to be careful to avoid deadlocks. I think it's only safe to
acquire the conn->chan_lock when both the l2cap_chan and the socket
are unlocked. Can you collapse all the locking changes in to one
patch?
Since __l2cap_wait_ack is only called from l2cap_sock.c, would it
make sense to move the function to l2cap_sock.c?
--
Mat Martineau
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-06-04 17:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-31 19:25 [PATCH 1/2] Bluetooth: Release chan lock upon sleeping Gustavo Padovan
2012-05-31 19:25 ` [PATCH 2/2] Bluetooth: Release all locks before sleep Gustavo Padovan
2012-06-04 17:14 ` Mat Martineau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox