From: Ulisses Furquim <ulisses@profusion.mobi>
To: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCHv1 08/14] Bluetooth: Use chan lock in L2CAP sig commands
Date: Tue, 21 Feb 2012 15:18:45 -0200 [thread overview]
Message-ID: <CAA37ikbY4GGGgBeT8XfYzozOFTevfAhr-oJ4zaS_XT0Hzv-EjA@mail.gmail.com> (raw)
In-Reply-To: <1329821707-11817-9-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Tue, Feb 21, 2012 at 8:55 AM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Convert sk lock to chan lock for L2CAP signalling commands.
>
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
> net/bluetooth/l2cap_core.c | 61 +++++++++++++++++++++++++------------------
> net/bluetooth/l2cap_sock.c | 7 +++-
> 2 files changed, 40 insertions(+), 28 deletions(-)
>
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index c008608..ab6bede 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -377,6 +377,8 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
> hci_conn_put(conn->hcon);
> }
>
> + lock_sock(sk);
> +
> __l2cap_state_change(chan, BT_CLOSED);
> sock_set_flag(sk, SOCK_ZAPPED);
>
> @@ -389,6 +391,8 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
> } else
> sk->sk_state_change(sk);
>
> + release_sock(sk);
> +
> if (!(test_bit(CONF_OUTPUT_DONE, &chan->conf_state) &&
> test_bit(CONF_INPUT_DONE, &chan->conf_state)))
> return;
You're making l2cap_chan_del() deal with sock lock so please remove
the comment above the function signature. It doesn't make sense to
leave old comments around.
> @@ -421,10 +425,10 @@ static void l2cap_chan_cleanup_listen(struct sock *parent)
> while ((sk = bt_accept_dequeue(parent, NULL))) {
> struct l2cap_chan *chan = l2cap_pi(sk)->chan;
>
> + l2cap_chan_lock(chan);
> __clear_chan_timer(chan);
> - lock_sock(sk);
> l2cap_chan_close(chan, ECONNRESET);
> - release_sock(sk);
> + l2cap_chan_unlock(chan);
>
> chan->ops->close(chan->data);
> }
Ok.
> @@ -440,10 +444,12 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
>
> switch (chan->state) {
> case BT_LISTEN:
> + lock_sock(sk);
> l2cap_chan_cleanup_listen(sk);
>
> __l2cap_state_change(chan, BT_CLOSED);
> sock_set_flag(sk, SOCK_ZAPPED);
> + release_sock(sk);
> break;
>
> case BT_CONNECTED:
Do we need to lock sock around l2cap_chan_cleanup_listen() as well?
l2cap_chan_close() will call l2cap_chan_del() which now does
lock_sock/release_sock, right?
> @@ -486,7 +492,9 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
> break;
>
> default:
> + lock_sock(sk);
> sock_set_flag(sk, SOCK_ZAPPED);
> + release_sock(sk);
> break;
> }
> }
Hmm, this indeed looks correct. However, it'd be good to later revisit
this as we want core without any sock handling, right?
> @@ -714,6 +722,7 @@ static inline int l2cap_mode_supported(__u8 mode, __u32 feat_mask)
>
> static void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *chan, int err)
> {
> + struct sock *sk = chan->sk;
> struct l2cap_disconn_req req;
>
> if (!conn)
> @@ -730,8 +739,10 @@ static void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *c
> l2cap_send_cmd(conn, l2cap_get_ident(conn),
> L2CAP_DISCONN_REQ, sizeof(req), &req);
>
> + lock_sock(sk);
> __l2cap_state_change(chan, BT_DISCONN);
> __l2cap_chan_set_err(chan, err);
> + release_sock(sk);
> }
>
> /* ---- L2CAP connections ---- */
It seems we didn't have any locking around these before. Why? Do we
really need it now?
<snip>
Regards,
--
Ulisses Furquim
ProFUSION embedded systems
http://profusion.mobi
Mobile: +55 19 9250 0942
Skype: ulissesffs
next prev parent reply other threads:[~2012-02-21 17:18 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-21 10:54 [PATCHv1 00/14] Bluetooth: Change socket lock to l2cap_chan lock Andrei Emeltchenko
2012-02-21 10:54 ` [PATCHv1 01/14] Bluetooth: trivial: Fix long line Andrei Emeltchenko
2012-02-21 10:54 ` [PATCHv1 02/14] Bluetooth: Revert to mutexes from RCU list Andrei Emeltchenko
2012-02-21 10:54 ` [PATCHv1 03/14] Bluetooth: Add l2cap_chan_lock Andrei Emeltchenko
2012-02-21 16:51 ` Ulisses Furquim
2012-02-21 17:25 ` Gustavo Padovan
2012-02-21 10:54 ` [PATCHv1 04/14] Bluetooth: Add locked and unlocked state_change Andrei Emeltchenko
2012-02-21 16:52 ` Ulisses Furquim
2012-02-21 17:26 ` Gustavo Padovan
2012-02-21 10:54 ` [PATCHv1 05/14] Bluetooth: Add socket error function Andrei Emeltchenko
2012-02-21 16:57 ` Ulisses Furquim
2012-02-21 17:27 ` Gustavo Padovan
2012-02-21 10:54 ` [PATCHv1 06/14] Bluetooth: Add unlocked __l2cap_chan_add function Andrei Emeltchenko
2012-02-21 17:01 ` Ulisses Furquim
2012-02-22 9:25 ` Andrei Emeltchenko
2012-02-21 17:28 ` Gustavo Padovan
2012-02-21 10:55 ` [PATCHv1 07/14] Bluetooth: Use chan lock in timers Andrei Emeltchenko
2012-02-21 17:06 ` Ulisses Furquim
2012-02-21 10:55 ` [PATCHv1 08/14] Bluetooth: Use chan lock in L2CAP sig commands Andrei Emeltchenko
2012-02-21 17:18 ` Ulisses Furquim [this message]
2012-02-21 17:57 ` Gustavo Padovan
2012-02-21 10:55 ` [PATCHv1 09/14] Bluetooth: Use chan lock in L2CAP conn start Andrei Emeltchenko
2012-02-21 17:20 ` Ulisses Furquim
2012-02-21 10:55 ` [PATCHv1 10/14] Bluetooth: Use chan lock in receiving data Andrei Emeltchenko
2012-02-21 20:28 ` Ulisses Furquim
2012-02-21 10:55 ` [PATCHv1 11/14] Bluetooth: Change locking logic for conn/chan ready Andrei Emeltchenko
2012-02-21 17:31 ` Ulisses Furquim
2012-02-21 10:55 ` [PATCHv1 12/14] Bluetooth: Change locking logic in security_cfm Andrei Emeltchenko
2012-02-21 17:32 ` Ulisses Furquim
2012-02-21 17:56 ` Gustavo Padovan
2012-02-21 20:44 ` Andrei Emeltchenko
2012-02-21 21:18 ` Ulisses Furquim
2012-02-21 10:55 ` [PATCHv1 13/14] Bluetooth: Use l2cap chan lock in socket connect Andrei Emeltchenko
2012-02-21 17:36 ` Ulisses Furquim
2012-02-21 17:46 ` Gustavo Padovan
2012-02-22 9:53 ` Andrei Emeltchenko
2012-02-21 10:55 ` [PATCHv1 14/14] Bluetooth: Remove socket lock check Andrei Emeltchenko
2012-02-21 17:37 ` Ulisses Furquim
2012-02-22 9:59 ` Andrei Emeltchenko
2012-02-21 17:51 ` Gustavo Padovan
2012-02-21 19:24 ` [PATCHv1 00/14] Bluetooth: Change socket lock to l2cap_chan lock Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAA37ikbY4GGGgBeT8XfYzozOFTevfAhr-oJ4zaS_XT0Hzv-EjA@mail.gmail.com \
--to=ulisses@profusion.mobi \
--cc=Andrei.Emeltchenko.news@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).