Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock
@ 2011-12-27 17:28 Gustavo F. Padovan
  2011-12-27 17:28 ` [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty Gustavo F. Padovan
  2012-01-02 22:18 ` [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock Marcel Holtmann
  0 siblings, 2 replies; 10+ messages in thread
From: Gustavo F. Padovan @ 2011-12-27 17:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo F. Padovan

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

Code now run in process context, does not need to disable interrupt
anymore.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/rfcomm/sock.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index aea2bdd..f066678 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -370,7 +370,7 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
 		goto done;
 	}
 
-	write_lock_bh(&rfcomm_sk_list.lock);
+	write_lock(&rfcomm_sk_list.lock);
 
 	if (sa->rc_channel && __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr)) {
 		err = -EADDRINUSE;
@@ -381,7 +381,7 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
 		sk->sk_state = BT_BOUND;
 	}
 
-	write_unlock_bh(&rfcomm_sk_list.lock);
+	write_unlock(&rfcomm_sk_list.lock);
 
 done:
 	release_sock(sk);
@@ -455,7 +455,7 @@ static int rfcomm_sock_listen(struct socket *sock, int backlog)
 
 		err = -EINVAL;
 
-		write_lock_bh(&rfcomm_sk_list.lock);
+		write_lock(&rfcomm_sk_list.lock);
 
 		for (channel = 1; channel < 31; channel++)
 			if (!__rfcomm_get_sock_by_addr(channel, src)) {
@@ -464,7 +464,7 @@ static int rfcomm_sock_listen(struct socket *sock, int backlog)
 				break;
 			}
 
-		write_unlock_bh(&rfcomm_sk_list.lock);
+		write_unlock(&rfcomm_sk_list.lock);
 
 		if (err < 0)
 			goto done;
@@ -982,7 +982,7 @@ static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p)
 	struct sock *sk;
 	struct hlist_node *node;
 
-	read_lock_bh(&rfcomm_sk_list.lock);
+	read_lock(&rfcomm_sk_list.lock);
 
 	sk_for_each(sk, node, &rfcomm_sk_list.head) {
 		seq_printf(f, "%s %s %d %d\n",
@@ -991,7 +991,7 @@ static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p)
 				sk->sk_state, rfcomm_pi(sk)->channel);
 	}
 
-	read_unlock_bh(&rfcomm_sk_list.lock);
+	read_unlock(&rfcomm_sk_list.lock);
 
 	return 0;
 }
-- 
1.7.7.5


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

* [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty
  2011-12-27 17:28 [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock Gustavo F. Padovan
@ 2011-12-27 17:28 ` Gustavo F. Padovan
  2011-12-27 17:28   ` [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO Gustavo F. Padovan
  2012-01-02 22:19   ` [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty Marcel Holtmann
  2012-01-02 22:18 ` [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock Marcel Holtmann
  1 sibling, 2 replies; 10+ messages in thread
From: Gustavo F. Padovan @ 2011-12-27 17:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo F. Padovan

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

We now run in process context, no need to disable interrupts.
Calls from the tty layer also run in process context.

rw_lock was converted to spinlock, we have more writers than readers in
this case.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/rfcomm/tty.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index fa8f4de5..a2d4f51 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -76,7 +76,7 @@ struct rfcomm_dev {
 };
 
 static LIST_HEAD(rfcomm_dev_list);
-static DEFINE_RWLOCK(rfcomm_dev_lock);
+static DEFINE_SPINLOCK(rfcomm_dev_lock);
 
 static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb);
 static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err);
@@ -146,7 +146,7 @@ static inline struct rfcomm_dev *rfcomm_dev_get(int id)
 {
 	struct rfcomm_dev *dev;
 
-	read_lock(&rfcomm_dev_lock);
+	spin_lock(&rfcomm_dev_lock);
 
 	dev = __rfcomm_dev_get(id);
 
@@ -157,7 +157,7 @@ static inline struct rfcomm_dev *rfcomm_dev_get(int id)
 			rfcomm_dev_hold(dev);
 	}
 
-	read_unlock(&rfcomm_dev_lock);
+	spin_unlock(&rfcomm_dev_lock);
 
 	return dev;
 }
@@ -205,7 +205,7 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
 	if (!dev)
 		return -ENOMEM;
 
-	write_lock_bh(&rfcomm_dev_lock);
+	spin_lock(&rfcomm_dev_lock);
 
 	if (req->dev_id < 0) {
 		dev->id = 0;
@@ -290,7 +290,7 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
 	__module_get(THIS_MODULE);
 
 out:
-	write_unlock_bh(&rfcomm_dev_lock);
+	spin_unlock(&rfcomm_dev_lock);
 
 	if (err < 0)
 		goto free;
@@ -327,9 +327,9 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
 	if (atomic_read(&dev->opened) > 0)
 		return;
 
-	write_lock_bh(&rfcomm_dev_lock);
+	spin_lock(&rfcomm_dev_lock);
 	list_del_init(&dev->list);
-	write_unlock_bh(&rfcomm_dev_lock);
+	spin_unlock(&rfcomm_dev_lock);
 
 	rfcomm_dev_put(dev);
 }
@@ -473,7 +473,7 @@ static int rfcomm_get_dev_list(void __user *arg)
 
 	di = dl->dev_info;
 
-	read_lock_bh(&rfcomm_dev_lock);
+	spin_lock(&rfcomm_dev_lock);
 
 	list_for_each_entry(dev, &rfcomm_dev_list, list) {
 		if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags))
@@ -488,7 +488,7 @@ static int rfcomm_get_dev_list(void __user *arg)
 			break;
 	}
 
-	read_unlock_bh(&rfcomm_dev_lock);
+	spin_unlock(&rfcomm_dev_lock);
 
 	dl->dev_num = n;
 	size = sizeof(*dl) + n * sizeof(*di);
@@ -766,9 +766,9 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
 		rfcomm_dlc_unlock(dev->dlc);
 
 		if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) {
-			write_lock_bh(&rfcomm_dev_lock);
+			spin_lock(&rfcomm_dev_lock);
 			list_del_init(&dev->list);
-			write_unlock_bh(&rfcomm_dev_lock);
+			spin_unlock(&rfcomm_dev_lock);
 
 			rfcomm_dev_put(dev);
 		}
-- 
1.7.7.5


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

* [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO
  2011-12-27 17:28 ` [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty Gustavo F. Padovan
@ 2011-12-27 17:28   ` Gustavo F. Padovan
  2011-12-27 17:28     ` [PATCH 4/5] Bluetooth: Remove local_bh_disable() from hci_sock.c Gustavo F. Padovan
  2012-01-02 22:20     ` [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO Marcel Holtmann
  2012-01-02 22:19   ` [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty Marcel Holtmann
  1 sibling, 2 replies; 10+ messages in thread
From: Gustavo F. Padovan @ 2011-12-27 17:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo F. Padovan

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

Those locks are not shared between interrupt and process context anymore,
so remove the part that disable interrupts. We are still safe because
preemption is disabled.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/sco.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 0d59e61..471283e 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -482,7 +482,7 @@ static int sco_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_le
 		goto done;
 	}
 
-	write_lock_bh(&sco_sk_list.lock);
+	write_lock(&sco_sk_list.lock);
 
 	if (bacmp(src, BDADDR_ANY) && __sco_get_sock_by_addr(src)) {
 		err = -EADDRINUSE;
@@ -492,7 +492,7 @@ static int sco_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_le
 		sk->sk_state = BT_BOUND;
 	}
 
-	write_unlock_bh(&sco_sk_list.lock);
+	write_unlock(&sco_sk_list.lock);
 
 done:
 	release_sock(sk);
@@ -965,14 +965,14 @@ static int sco_debugfs_show(struct seq_file *f, void *p)
 	struct sock *sk;
 	struct hlist_node *node;
 
-	read_lock_bh(&sco_sk_list.lock);
+	read_lock(&sco_sk_list.lock);
 
 	sk_for_each(sk, node, &sco_sk_list.head) {
 		seq_printf(f, "%s %s %d\n", batostr(&bt_sk(sk)->src),
 				batostr(&bt_sk(sk)->dst), sk->sk_state);
 	}
 
-	read_unlock_bh(&sco_sk_list.lock);
+	read_unlock(&sco_sk_list.lock);
 
 	return 0;
 }
-- 
1.7.7.5


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

* [PATCH 4/5] Bluetooth: Remove local_bh_disable() from hci_sock.c
  2011-12-27 17:28   ` [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO Gustavo F. Padovan
@ 2011-12-27 17:28     ` Gustavo F. Padovan
  2011-12-27 17:28       ` [PATCH 5/5] Bluetooth: Remove *_bh from socket list lock Gustavo F. Padovan
  2012-01-02 22:20     ` [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO Marcel Holtmann
  1 sibling, 1 reply; 10+ messages in thread
From: Gustavo F. Padovan @ 2011-12-27 17:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo F. Padovan

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

Everything is in process context now, we do not need such a call.

Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/hci_sock.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 189a667..896a72f 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -767,7 +767,6 @@ static int hci_sock_dev_event(struct notifier_block *this, unsigned long event,
 		/* Detach sockets from device */
 		read_lock(&hci_sk_list.lock);
 		sk_for_each(sk, node, &hci_sk_list.head) {
-			local_bh_disable();
 			bh_lock_sock_nested(sk);
 			if (hci_pi(sk)->hdev == hdev) {
 				hci_pi(sk)->hdev = NULL;
@@ -778,7 +777,6 @@ static int hci_sock_dev_event(struct notifier_block *this, unsigned long event,
 				hci_dev_put(hdev);
 			}
 			bh_unlock_sock(sk);
-			local_bh_enable();
 		}
 		read_unlock(&hci_sk_list.lock);
 	}
-- 
1.7.7.5


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

* [PATCH 5/5] Bluetooth: Remove *_bh from socket list lock.
  2011-12-27 17:28     ` [PATCH 4/5] Bluetooth: Remove local_bh_disable() from hci_sock.c Gustavo F. Padovan
@ 2011-12-27 17:28       ` Gustavo F. Padovan
  2012-01-02 22:21         ` Marcel Holtmann
  0 siblings, 1 reply; 10+ messages in thread
From: Gustavo F. Padovan @ 2011-12-27 17:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo F. Padovan

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

We don't need it anymore.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/af_bluetooth.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index cdcfcab..ef92864 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -156,17 +156,17 @@ static int bt_sock_create(struct net *net, struct socket *sock, int proto,
 
 void bt_sock_link(struct bt_sock_list *l, struct sock *sk)
 {
-	write_lock_bh(&l->lock);
+	write_lock(&l->lock);
 	sk_add_node(sk, &l->head);
-	write_unlock_bh(&l->lock);
+	write_unlock(&l->lock);
 }
 EXPORT_SYMBOL(bt_sock_link);
 
 void bt_sock_unlink(struct bt_sock_list *l, struct sock *sk)
 {
-	write_lock_bh(&l->lock);
+	write_lock(&l->lock);
 	sk_del_node_init(sk);
-	write_unlock_bh(&l->lock);
+	write_unlock(&l->lock);
 }
 EXPORT_SYMBOL(bt_sock_unlink);
 
-- 
1.7.7.5


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

* Re: [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock
  2011-12-27 17:28 [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock Gustavo F. Padovan
  2011-12-27 17:28 ` [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty Gustavo F. Padovan
@ 2012-01-02 22:18 ` Marcel Holtmann
  2012-01-03  0:18   ` Gustavo Padovan
  1 sibling, 1 reply; 10+ messages in thread
From: Marcel Holtmann @ 2012-01-02 22:18 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth

Hi Gustavo,

> Code now run in process context, does not need to disable interrupt
> anymore.
> 
> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
> ---
>  net/bluetooth/rfcomm/sock.c |   12 ++++++------
>  1 files changed, 6 insertions(+), 6 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

However I get the feeling that we might should mover all the Bluetooth
specific socket list locking to RCU.

Regards

Marcel



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

* Re: [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty
  2011-12-27 17:28 ` [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty Gustavo F. Padovan
  2011-12-27 17:28   ` [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO Gustavo F. Padovan
@ 2012-01-02 22:19   ` Marcel Holtmann
  1 sibling, 0 replies; 10+ messages in thread
From: Marcel Holtmann @ 2012-01-02 22:19 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth

On Tue, 2011-12-27 at 15:28 -0200, Gustavo F. Padovan wrote:
> From: "Gustavo F. Padovan" <padovan@profusion.mobi>
> 
> We now run in process context, no need to disable interrupts.
> Calls from the tty layer also run in process context.
> 
> rw_lock was converted to spinlock, we have more writers than readers in
> this case.
> 
> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
> ---
>  net/bluetooth/rfcomm/tty.c |   22 +++++++++++-----------
>  1 files changed, 11 insertions(+), 11 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

And here also, any reason this can not be RCU?

Regards

Marcel



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

* Re: [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO
  2011-12-27 17:28   ` [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO Gustavo F. Padovan
  2011-12-27 17:28     ` [PATCH 4/5] Bluetooth: Remove local_bh_disable() from hci_sock.c Gustavo F. Padovan
@ 2012-01-02 22:20     ` Marcel Holtmann
  1 sibling, 0 replies; 10+ messages in thread
From: Marcel Holtmann @ 2012-01-02 22:20 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth

Hi Gustavo,

> Those locks are not shared between interrupt and process context anymore,
> so remove the part that disable interrupts. We are still safe because
> preemption is disabled.
> 
> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
> ---
>  net/bluetooth/sco.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Same socket list lock situation. RCU?

Regards

Marcel



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

* Re: [PATCH 5/5] Bluetooth: Remove *_bh from socket list lock.
  2011-12-27 17:28       ` [PATCH 5/5] Bluetooth: Remove *_bh from socket list lock Gustavo F. Padovan
@ 2012-01-02 22:21         ` Marcel Holtmann
  0 siblings, 0 replies; 10+ messages in thread
From: Marcel Holtmann @ 2012-01-02 22:21 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth

Hi Gustavo,

> We don't need it anymore.
> 
> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
> ---
>  net/bluetooth/af_bluetooth.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



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

* Re: [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock
  2012-01-02 22:18 ` [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock Marcel Holtmann
@ 2012-01-03  0:18   ` Gustavo Padovan
  0 siblings, 0 replies; 10+ messages in thread
From: Gustavo Padovan @ 2012-01-03  0:18 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

Hi Marcel,

* Marcel Holtmann <marcel@holtmann.org> [2012-01-02 14:18:04 -0800]:

> Hi Gustavo,
> 
> > Code now run in process context, does not need to disable interrupt
> > anymore.
> > 
> > Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
> > ---
> >  net/bluetooth/rfcomm/sock.c |   12 ++++++------
> >  1 files changed, 6 insertions(+), 6 deletions(-)
> 
> Acked-by: Marcel Holtmann <marcel@holtmann.org>
> 
> However I get the feeling that we might should mover all the Bluetooth
> specific socket list locking to RCU.

I agree, but I can't go ahead with such a change now, the merge windows is
around the corner.

	Gustavo

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

end of thread, other threads:[~2012-01-03  0:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-27 17:28 [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock Gustavo F. Padovan
2011-12-27 17:28 ` [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty Gustavo F. Padovan
2011-12-27 17:28   ` [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO Gustavo F. Padovan
2011-12-27 17:28     ` [PATCH 4/5] Bluetooth: Remove local_bh_disable() from hci_sock.c Gustavo F. Padovan
2011-12-27 17:28       ` [PATCH 5/5] Bluetooth: Remove *_bh from socket list lock Gustavo F. Padovan
2012-01-02 22:21         ` Marcel Holtmann
2012-01-02 22:20     ` [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO Marcel Holtmann
2012-01-02 22:19   ` [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty Marcel Holtmann
2012-01-02 22:18 ` [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock Marcel Holtmann
2012-01-03  0:18   ` Gustavo Padovan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox