2011-12-27 17:28:44

by Gustavo Padovan

[permalink] [raw]
Subject: [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock

From: "Gustavo F. Padovan" <[email protected]>

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

Signed-off-by: Gustavo F. Padovan <[email protected]>
---
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



2011-12-27 17:28:48

by Gustavo Padovan

[permalink] [raw]
Subject: [PATCH 5/5] Bluetooth: Remove *_bh from socket list lock.

From: "Gustavo F. Padovan" <[email protected]>

We don't need it anymore.

Signed-off-by: Gustavo F. Padovan <[email protected]>
---
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


2011-12-27 17:28:47

by Gustavo Padovan

[permalink] [raw]
Subject: [PATCH 4/5] Bluetooth: Remove local_bh_disable() from hci_sock.c

From: "Gustavo F. Padovan" <[email protected]>

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

Acked-by: Marcel Holtmann <[email protected]>
Signed-off-by: Gustavo F. Padovan <[email protected]>
---
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


2011-12-27 17:28:46

by Gustavo Padovan

[permalink] [raw]
Subject: [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO

From: "Gustavo F. Padovan" <[email protected]>

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 <[email protected]>
---
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


2011-12-27 17:28:45

by Gustavo Padovan

[permalink] [raw]
Subject: [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty

From: "Gustavo F. Padovan" <[email protected]>

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 <[email protected]>
---
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


2012-01-03 00:18:27

by Gustavo Padovan

[permalink] [raw]
Subject: Re: [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock

Hi Marcel,

* Marcel Holtmann <[email protected]> [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 <[email protected]>
> > ---
> > net/bluetooth/rfcomm/sock.c | 12 ++++++------
> > 1 files changed, 6 insertions(+), 6 deletions(-)
>
> Acked-by: Marcel Holtmann <[email protected]>
>
> 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

2012-01-02 22:21:21

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 5/5] Bluetooth: Remove *_bh from socket list lock.

Hi Gustavo,

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

Acked-by: Marcel Holtmann <[email protected]>

Regards

Marcel



2012-01-02 22:20:17

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 3/5] Bluetooth: Remove *_bh locks from SCO

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 <[email protected]>
> ---
> net/bluetooth/sco.c | 8 ++++----
> 1 files changed, 4 insertions(+), 4 deletions(-)

Acked-by: Marcel Holtmann <[email protected]>

Same socket list lock situation. RCU?

Regards

Marcel



2012-01-02 22:19:29

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 2/5] Bluetooth: Fix context in RFCOMM tty

On Tue, 2011-12-27 at 15:28 -0200, Gustavo F. Padovan wrote:
> From: "Gustavo F. Padovan" <[email protected]>
>
> 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 <[email protected]>
> ---
> net/bluetooth/rfcomm/tty.c | 22 +++++++++++-----------
> 1 files changed, 11 insertions(+), 11 deletions(-)

Acked-by: Marcel Holtmann <[email protected]>

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

Regards

Marcel



2012-01-02 22:18:04

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 1/5] Bluetooth: Fix context in rfcomm_sock_lock

Hi Gustavo,

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

Acked-by: Marcel Holtmann <[email protected]>

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

Regards

Marcel