All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: Satyam Sharma <satyam.sharma@gmail.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>,
	netdev@vger.kernel.org, Greg KH <gregkh@suse.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Jiri Kosina <jikos@jikos.cz>, Cedric Le Goater <clg@fr.ibm.com>,
	bluez-devel@lists.sourceforge.net, maxk@qualcomm.com
Subject: Re: [Bluez-devel] 2.6.21-rc7: BUG: sleeping function called from invalid context	at net/core/sock.c:1523
Date: Wed, 16 May 2007 14:16:15 +0200	[thread overview]
Message-ID: <1179317775.10069.77.camel@violet> (raw)
In-Reply-To: <a781481a0705160459p2d538d7fu8096bd594d6df2f9@mail.gmail.com>

Hi Satyam,

> > > > > > (later)
> > > > > > I Googled a bit to see if this problem was faced elsewhere in the kernel
> > > > > > too. Saw the following commit by Ingo Molnar
> > > > > > (9883a13c72dbf8c518814b6091019643cdb34429):
> > > > > > -     lock_sock(sock->sk);
> > > > > > +     local_bh_disable();
> > > > > > +     bh_lock_sock_nested(sock->sk);
> > > > > >       rc = selinux_netlbl_socket_setsid(sock, sksec->sid);
> > > > > > -     release_sock(sock->sk);
> > > > > > +     bh_unlock_sock(sock->sk);
> > > > > > +     local_bh_enable();
> > > > > > Is it _really_ *this* simple?
> > > > > [...]
> > > > > actually this *seems* to be proper solution also for our case, thanks for
> > > > > pointing this out. I will think about it once again, do some more tests
> > > > > with this locking scheme, and will let you know.
> > > >
> > > > Yes, I can almost confirm that this (open-coding of spin_lock_bh,
> > > > effectively) is the proper solution (Rusty's unreliable guide to
> > > > kernel-locking needs to be next to every developer's keyboard :-)
> > > > I also came across this idiom in other places in the networking code
> > > > so it seems to be pretty much the standard way. I wish I owned
> > > > bluetooth hardware, could've tested this for you myself.
> > >
> > > does this mean we should revert previous changes to the locking or only
> > > apply this on top of it?
> >
> > I've fixed a simple patch on top of 2.6.22-rc1 below.
> 
> Eek, please ignore previous one. This one's correct.
> 
> Signed-off-by: Satyam Sharma <ssatyam@cse.iitk.ac.in>
> 
> diff -ruNp a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
> --- a/net/bluetooth/hci_sock.c	2007-05-16 17:31:06.000000000 +0530
> +++ b/net/bluetooth/hci_sock.c	2007-05-16 17:38:35.000000000 +0530
> @@ -665,7 +665,8 @@ static int hci_sock_dev_event(struct not
>  		/* Detach sockets from device */
>  		read_lock(&hci_sk_list.lock);
>  		sk_for_each(sk, node, &hci_sk_list.head) {
> -			lock_sock(sk);
> +			local_bh_disable();
> +			bh_lock_sock_nested(sk);
>  			if (hci_pi(sk)->hdev == hdev) {
>  				hci_pi(sk)->hdev = NULL;
>  				sk->sk_err = EPIPE;
> @@ -674,7 +675,8 @@ static int hci_sock_dev_event(struct not
> 
>  				hci_dev_put(hdev);
>  			}
> -			release_sock(sk);
> +			bh_unlock_sock(sk);
> +			local_bh_enable();
>  		}
>  		read_unlock(&hci_sk_list.lock);
>  	}

since Jiri has a good test case for it, I leave it to him for testing.
If he confirms that this fixes the locking issues, then this is

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

Regards

Marcel



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

WARNING: multiple messages have this Message-ID (diff)
From: Marcel Holtmann <marcel@holtmann.org>
To: Satyam Sharma <satyam.sharma@gmail.com>
Cc: Jiri Kosina <jikos@jikos.cz>, Greg KH <gregkh@suse.de>,
	Jeremy Fitzhardinge <jeremy@goop.org>,
	maxk@qualcomm.com, bluez-devel@lists.sourceforge.net,
	Cedric Le Goater <clg@fr.ibm.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	netdev@vger.kernel.org
Subject: Re: 2.6.21-rc7: BUG: sleeping function called from invalid context at net/core/sock.c:1523
Date: Wed, 16 May 2007 14:16:15 +0200	[thread overview]
Message-ID: <1179317775.10069.77.camel@violet> (raw)
In-Reply-To: <a781481a0705160459p2d538d7fu8096bd594d6df2f9@mail.gmail.com>

Hi Satyam,

> > > > > > (later)
> > > > > > I Googled a bit to see if this problem was faced elsewhere in the kernel
> > > > > > too. Saw the following commit by Ingo Molnar
> > > > > > (9883a13c72dbf8c518814b6091019643cdb34429):
> > > > > > -     lock_sock(sock->sk);
> > > > > > +     local_bh_disable();
> > > > > > +     bh_lock_sock_nested(sock->sk);
> > > > > >       rc = selinux_netlbl_socket_setsid(sock, sksec->sid);
> > > > > > -     release_sock(sock->sk);
> > > > > > +     bh_unlock_sock(sock->sk);
> > > > > > +     local_bh_enable();
> > > > > > Is it _really_ *this* simple?
> > > > > [...]
> > > > > actually this *seems* to be proper solution also for our case, thanks for
> > > > > pointing this out. I will think about it once again, do some more tests
> > > > > with this locking scheme, and will let you know.
> > > >
> > > > Yes, I can almost confirm that this (open-coding of spin_lock_bh,
> > > > effectively) is the proper solution (Rusty's unreliable guide to
> > > > kernel-locking needs to be next to every developer's keyboard :-)
> > > > I also came across this idiom in other places in the networking code
> > > > so it seems to be pretty much the standard way. I wish I owned
> > > > bluetooth hardware, could've tested this for you myself.
> > >
> > > does this mean we should revert previous changes to the locking or only
> > > apply this on top of it?
> >
> > I've fixed a simple patch on top of 2.6.22-rc1 below.
> 
> Eek, please ignore previous one. This one's correct.
> 
> Signed-off-by: Satyam Sharma <ssatyam@cse.iitk.ac.in>
> 
> diff -ruNp a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
> --- a/net/bluetooth/hci_sock.c	2007-05-16 17:31:06.000000000 +0530
> +++ b/net/bluetooth/hci_sock.c	2007-05-16 17:38:35.000000000 +0530
> @@ -665,7 +665,8 @@ static int hci_sock_dev_event(struct not
>  		/* Detach sockets from device */
>  		read_lock(&hci_sk_list.lock);
>  		sk_for_each(sk, node, &hci_sk_list.head) {
> -			lock_sock(sk);
> +			local_bh_disable();
> +			bh_lock_sock_nested(sk);
>  			if (hci_pi(sk)->hdev == hdev) {
>  				hci_pi(sk)->hdev = NULL;
>  				sk->sk_err = EPIPE;
> @@ -674,7 +675,8 @@ static int hci_sock_dev_event(struct not
> 
>  				hci_dev_put(hdev);
>  			}
> -			release_sock(sk);
> +			bh_unlock_sock(sk);
> +			local_bh_enable();
>  		}
>  		read_unlock(&hci_sk_list.lock);
>  	}

since Jiri has a good test case for it, I leave it to him for testing.
If he confirms that this fixes the locking issues, then this is

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

Regards

Marcel



WARNING: multiple messages have this Message-ID (diff)
From: Marcel Holtmann <marcel@holtmann.org>
To: Satyam Sharma <satyam.sharma@gmail.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>,
	netdev@vger.kernel.org, Greg KH <gregkh@suse.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Jiri Kosina <jikos@jikos.cz>, Cedric Le Goater <clg@fr.ibm.com>,
	bluez-devel@lists.sourceforge.net, maxk@qualcomm.com
Subject: Re: 2.6.21-rc7: BUG: sleeping function called from invalid context	at net/core/sock.c:1523
Date: Wed, 16 May 2007 14:16:15 +0200	[thread overview]
Message-ID: <1179317775.10069.77.camel@violet> (raw)
In-Reply-To: <a781481a0705160459p2d538d7fu8096bd594d6df2f9@mail.gmail.com>

Hi Satyam,

> > > > > > (later)
> > > > > > I Googled a bit to see if this problem was faced elsewhere in the kernel
> > > > > > too. Saw the following commit by Ingo Molnar
> > > > > > (9883a13c72dbf8c518814b6091019643cdb34429):
> > > > > > -     lock_sock(sock->sk);
> > > > > > +     local_bh_disable();
> > > > > > +     bh_lock_sock_nested(sock->sk);
> > > > > >       rc = selinux_netlbl_socket_setsid(sock, sksec->sid);
> > > > > > -     release_sock(sock->sk);
> > > > > > +     bh_unlock_sock(sock->sk);
> > > > > > +     local_bh_enable();
> > > > > > Is it _really_ *this* simple?
> > > > > [...]
> > > > > actually this *seems* to be proper solution also for our case, thanks for
> > > > > pointing this out. I will think about it once again, do some more tests
> > > > > with this locking scheme, and will let you know.
> > > >
> > > > Yes, I can almost confirm that this (open-coding of spin_lock_bh,
> > > > effectively) is the proper solution (Rusty's unreliable guide to
> > > > kernel-locking needs to be next to every developer's keyboard :-)
> > > > I also came across this idiom in other places in the networking code
> > > > so it seems to be pretty much the standard way. I wish I owned
> > > > bluetooth hardware, could've tested this for you myself.
> > >
> > > does this mean we should revert previous changes to the locking or only
> > > apply this on top of it?
> >
> > I've fixed a simple patch on top of 2.6.22-rc1 below.
> 
> Eek, please ignore previous one. This one's correct.
> 
> Signed-off-by: Satyam Sharma <ssatyam@cse.iitk.ac.in>
> 
> diff -ruNp a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
> --- a/net/bluetooth/hci_sock.c	2007-05-16 17:31:06.000000000 +0530
> +++ b/net/bluetooth/hci_sock.c	2007-05-16 17:38:35.000000000 +0530
> @@ -665,7 +665,8 @@ static int hci_sock_dev_event(struct not
>  		/* Detach sockets from device */
>  		read_lock(&hci_sk_list.lock);
>  		sk_for_each(sk, node, &hci_sk_list.head) {
> -			lock_sock(sk);
> +			local_bh_disable();
> +			bh_lock_sock_nested(sk);
>  			if (hci_pi(sk)->hdev == hdev) {
>  				hci_pi(sk)->hdev = NULL;
>  				sk->sk_err = EPIPE;
> @@ -674,7 +675,8 @@ static int hci_sock_dev_event(struct not
> 
>  				hci_dev_put(hdev);
>  			}
> -			release_sock(sk);
> +			bh_unlock_sock(sk);
> +			local_bh_enable();
>  		}
>  		read_unlock(&hci_sk_list.lock);
>  	}

since Jiri has a good test case for it, I leave it to him for testing.
If he confirms that this fixes the locking issues, then this is

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

Regards

Marcel



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

  reply	other threads:[~2007-05-16 12:16 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-23 20:46 2.6.21-rc7: BUG: sleeping function called from invalid context at net/core/sock.c:1523 Jeremy Fitzhardinge
2007-04-23 21:56 ` Jiri Kosina
2007-04-24  3:30   ` Herbert Xu
2007-04-24  3:30     ` Herbert Xu
2007-04-24  7:59     ` Jiri Kosina
2007-04-24  7:59       ` Jiri Kosina
2007-04-26 14:31   ` Jiri Kosina
2007-05-11 13:29     ` [Bluez-devel] " Satyam Sharma
2007-05-11 13:29       ` Satyam Sharma
2007-05-11 13:29       ` Satyam Sharma
2007-05-13  9:20       ` Greg KH
2007-05-16  9:29       ` Jiri Kosina
2007-05-16  9:29         ` Jiri Kosina
2007-05-16 11:36         ` Satyam Sharma
2007-05-16 11:45           ` [Bluez-devel] " Marcel Holtmann
2007-05-16 11:45             ` Marcel Holtmann
2007-05-16 11:45             ` Marcel Holtmann
2007-05-16 11:56             ` Satyam Sharma
2007-05-16 11:56               ` Satyam Sharma
2007-05-16 11:59               ` Satyam Sharma
2007-05-16 11:59                 ` Satyam Sharma
2007-05-16 12:16                 ` Marcel Holtmann [this message]
2007-05-16 12:16                   ` Marcel Holtmann
2007-05-16 12:16                   ` Marcel Holtmann
2007-05-16 12:19                   ` Jiri Kosina
2007-05-16 12:19                     ` Jiri Kosina
2007-05-16 23:03                     ` Jiri Kosina
2007-05-16 23:03                       ` Jiri Kosina
2007-05-16 23:16                       ` David Miller
2007-05-16 23:20                         ` Jiri Kosina
2007-05-17  6:04                           ` Marcel Holtmann

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=1179317775.10069.77.camel@violet \
    --to=marcel@holtmann.org \
    --cc=bluez-devel@lists.sourceforge.net \
    --cc=clg@fr.ibm.com \
    --cc=gregkh@suse.de \
    --cc=jeremy@goop.org \
    --cc=jikos@jikos.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxk@qualcomm.com \
    --cc=netdev@vger.kernel.org \
    --cc=satyam.sharma@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.