All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH driver-core-linus] kernfs: make kernfs_deactivate() honor KERNFS_LOCKDEP flag
       [not found] ` <Pine.LNX.4.44L0.1401291134070.11997-100000@netrider.rowland.org>
@ 2014-01-29 17:04   ` Tejun Heo
  2014-01-29 17:19     ` Fabio Estevam
  2014-01-30 10:42     ` Jiri Kosina
  0 siblings, 2 replies; 4+ messages in thread
From: Tejun Heo @ 2014-01-29 17:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Fabio Estevam, Alan Stern
  Cc: Denis Kirjanov, linux-kernel, USB list

kernfs_deactivate() forgot to check whether KERNFS_LOCKDEP is set
before performing lockdep annotations and ends up feeding
uninitialized lockdep_map to lockdep triggering warning like the
following on USB stick hotunplug.

 usb 1-2: USB disconnect, device number 2
 INFO: trying to register non-static key.
 the code is fine but needs lockdep annotation.
 turning off the locking correctness validator.
 CPU: 1 PID: 62 Comm: khubd Not tainted 3.13.0-work+ #82
 Hardware name: empty empty/S3992, BIOS 080011  10/26/2007
  ffff880065ca7f60 ffff88013a4ffa08 ffffffff81cfb6bd 0000000000000002
  ffff88013a4ffac8 ffffffff810f8530 ffff88013a4fc710 0000000000000002
  ffff880100000000 ffffffff82a3db50 0000000000000001 ffff88013a4fc710
 Call Trace:
  [<ffffffff81cfb6bd>] dump_stack+0x4e/0x7a
  [<ffffffff810f8530>] __lock_acquire+0x1910/0x1e70
  [<ffffffff810f931a>] lock_acquire+0x9a/0x1d0
  [<ffffffff8127c75e>] kernfs_deactivate+0xee/0x130
  [<ffffffff8127d4c8>] kernfs_addrm_finish+0x38/0x60
  [<ffffffff8127d701>] kernfs_remove_by_name_ns+0x51/0xa0
  [<ffffffff8127b4f1>] remove_files.isra.1+0x41/0x80
  [<ffffffff8127b7e7>] sysfs_remove_group+0x47/0xa0
  [<ffffffff8127b873>] sysfs_remove_groups+0x33/0x50
  [<ffffffff8177d66d>] device_remove_attrs+0x4d/0x80
  [<ffffffff8177e25e>] device_del+0x12e/0x1d0
  [<ffffffff819722c2>] usb_disconnect+0x122/0x1a0
  [<ffffffff819749b5>] hub_thread+0x3c5/0x1290
  [<ffffffff810c6a6d>] kthread+0xed/0x110
  [<ffffffff81d0a56c>] ret_from_fork+0x7c/0xb0

Fix it by making kernfs_deactivate() perform lockdep annotations only
if KERNFS_LOCKDEP is set.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Fabio Estevam <festevam@gmail.com>
Reported-by: Alan Stern <stern@rowland.harvard.edu>
---
 fs/kernfs/dir.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 5104cf5..bd6e18b 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -187,19 +187,23 @@ static void kernfs_deactivate(struct kernfs_node *kn)
 
 	kn->u.completion = (void *)&wait;
 
-	rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_);
+	if (kn->flags & KERNFS_LOCKDEP)
+		rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_);
 	/* atomic_add_return() is a mb(), put_active() will always see
 	 * the updated kn->u.completion.
 	 */
 	v = atomic_add_return(KN_DEACTIVATED_BIAS, &kn->active);
 
 	if (v != KN_DEACTIVATED_BIAS) {
-		lock_contended(&kn->dep_map, _RET_IP_);
+		if (kn->flags & KERNFS_LOCKDEP)
+			lock_contended(&kn->dep_map, _RET_IP_);
 		wait_for_completion(&wait);
 	}
 
-	lock_acquired(&kn->dep_map, _RET_IP_);
-	rwsem_release(&kn->dep_map, 1, _RET_IP_);
+	if (kn->flags & KERNFS_LOCKDEP) {
+		lock_acquired(&kn->dep_map, _RET_IP_);
+		rwsem_release(&kn->dep_map, 1, _RET_IP_);
+	}
 }
 
 /**

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

* Re: [PATCH driver-core-linus] kernfs: make kernfs_deactivate() honor KERNFS_LOCKDEP flag
  2014-01-29 17:04   ` [PATCH driver-core-linus] kernfs: make kernfs_deactivate() honor KERNFS_LOCKDEP flag Tejun Heo
@ 2014-01-29 17:19     ` Fabio Estevam
  2014-01-29 21:21       ` Greg Kroah-Hartman
  2014-01-30 10:42     ` Jiri Kosina
  1 sibling, 1 reply; 4+ messages in thread
From: Fabio Estevam @ 2014-01-29 17:19 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Greg Kroah-Hartman, Alan Stern, Denis Kirjanov, linux-kernel,
	USB list

On Wed, Jan 29, 2014 at 3:04 PM, Tejun Heo <tj@kernel.org> wrote:
> kernfs_deactivate() forgot to check whether KERNFS_LOCKDEP is set
> before performing lockdep annotations and ends up feeding
> uninitialized lockdep_map to lockdep triggering warning like the
> following on USB stick hotunplug.
>
>  usb 1-2: USB disconnect, device number 2
>  INFO: trying to register non-static key.
>  the code is fine but needs lockdep annotation.
>  turning off the locking correctness validator.
>  CPU: 1 PID: 62 Comm: khubd Not tainted 3.13.0-work+ #82
>  Hardware name: empty empty/S3992, BIOS 080011  10/26/2007
>   ffff880065ca7f60 ffff88013a4ffa08 ffffffff81cfb6bd 0000000000000002
>   ffff88013a4ffac8 ffffffff810f8530 ffff88013a4fc710 0000000000000002
>   ffff880100000000 ffffffff82a3db50 0000000000000001 ffff88013a4fc710
>  Call Trace:
>   [<ffffffff81cfb6bd>] dump_stack+0x4e/0x7a
>   [<ffffffff810f8530>] __lock_acquire+0x1910/0x1e70
>   [<ffffffff810f931a>] lock_acquire+0x9a/0x1d0
>   [<ffffffff8127c75e>] kernfs_deactivate+0xee/0x130
>   [<ffffffff8127d4c8>] kernfs_addrm_finish+0x38/0x60
>   [<ffffffff8127d701>] kernfs_remove_by_name_ns+0x51/0xa0
>   [<ffffffff8127b4f1>] remove_files.isra.1+0x41/0x80
>   [<ffffffff8127b7e7>] sysfs_remove_group+0x47/0xa0
>   [<ffffffff8127b873>] sysfs_remove_groups+0x33/0x50
>   [<ffffffff8177d66d>] device_remove_attrs+0x4d/0x80
>   [<ffffffff8177e25e>] device_del+0x12e/0x1d0
>   [<ffffffff819722c2>] usb_disconnect+0x122/0x1a0
>   [<ffffffff819749b5>] hub_thread+0x3c5/0x1290
>   [<ffffffff810c6a6d>] kthread+0xed/0x110
>   [<ffffffff81d0a56c>] ret_from_fork+0x7c/0xb0
>
> Fix it by making kernfs_deactivate() perform lockdep annotations only
> if KERNFS_LOCKDEP is set.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Reported-by: Fabio Estevam <festevam@gmail.com>
> Reported-by: Alan Stern <stern@rowland.harvard.edu>

Thanks, Tejun. I don't get the warning after removing the USB stick
after applying this patch:

Tested-by: Fabio Estevam <fabio.estevam@freescale.com>

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

* Re: [PATCH driver-core-linus] kernfs: make kernfs_deactivate() honor KERNFS_LOCKDEP flag
  2014-01-29 17:19     ` Fabio Estevam
@ 2014-01-29 21:21       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2014-01-29 21:21 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Tejun Heo, Alan Stern, Denis Kirjanov, linux-kernel, USB list

On Wed, Jan 29, 2014 at 03:19:51PM -0200, Fabio Estevam wrote:
> On Wed, Jan 29, 2014 at 3:04 PM, Tejun Heo <tj@kernel.org> wrote:
> > kernfs_deactivate() forgot to check whether KERNFS_LOCKDEP is set
> > before performing lockdep annotations and ends up feeding
> > uninitialized lockdep_map to lockdep triggering warning like the
> > following on USB stick hotunplug.
> >
> >  usb 1-2: USB disconnect, device number 2
> >  INFO: trying to register non-static key.
> >  the code is fine but needs lockdep annotation.
> >  turning off the locking correctness validator.
> >  CPU: 1 PID: 62 Comm: khubd Not tainted 3.13.0-work+ #82
> >  Hardware name: empty empty/S3992, BIOS 080011  10/26/2007
> >   ffff880065ca7f60 ffff88013a4ffa08 ffffffff81cfb6bd 0000000000000002
> >   ffff88013a4ffac8 ffffffff810f8530 ffff88013a4fc710 0000000000000002
> >   ffff880100000000 ffffffff82a3db50 0000000000000001 ffff88013a4fc710
> >  Call Trace:
> >   [<ffffffff81cfb6bd>] dump_stack+0x4e/0x7a
> >   [<ffffffff810f8530>] __lock_acquire+0x1910/0x1e70
> >   [<ffffffff810f931a>] lock_acquire+0x9a/0x1d0
> >   [<ffffffff8127c75e>] kernfs_deactivate+0xee/0x130
> >   [<ffffffff8127d4c8>] kernfs_addrm_finish+0x38/0x60
> >   [<ffffffff8127d701>] kernfs_remove_by_name_ns+0x51/0xa0
> >   [<ffffffff8127b4f1>] remove_files.isra.1+0x41/0x80
> >   [<ffffffff8127b7e7>] sysfs_remove_group+0x47/0xa0
> >   [<ffffffff8127b873>] sysfs_remove_groups+0x33/0x50
> >   [<ffffffff8177d66d>] device_remove_attrs+0x4d/0x80
> >   [<ffffffff8177e25e>] device_del+0x12e/0x1d0
> >   [<ffffffff819722c2>] usb_disconnect+0x122/0x1a0
> >   [<ffffffff819749b5>] hub_thread+0x3c5/0x1290
> >   [<ffffffff810c6a6d>] kthread+0xed/0x110
> >   [<ffffffff81d0a56c>] ret_from_fork+0x7c/0xb0
> >
> > Fix it by making kernfs_deactivate() perform lockdep annotations only
> > if KERNFS_LOCKDEP is set.
> >
> > Signed-off-by: Tejun Heo <tj@kernel.org>
> > Reported-by: Fabio Estevam <festevam@gmail.com>
> > Reported-by: Alan Stern <stern@rowland.harvard.edu>
> 
> Thanks, Tejun. I don't get the warning after removing the USB stick
> after applying this patch:
> 
> Tested-by: Fabio Estevam <fabio.estevam@freescale.com>

Great, I'll queue this up and get it to Linus after 3.14-rc1 is out.

thanks,

greg k-h

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

* Re: [PATCH driver-core-linus] kernfs: make kernfs_deactivate() honor KERNFS_LOCKDEP flag
  2014-01-29 17:04   ` [PATCH driver-core-linus] kernfs: make kernfs_deactivate() honor KERNFS_LOCKDEP flag Tejun Heo
  2014-01-29 17:19     ` Fabio Estevam
@ 2014-01-30 10:42     ` Jiri Kosina
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2014-01-30 10:42 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Greg Kroah-Hartman, Fabio Estevam, Alan Stern, Denis Kirjanov,
	linux-kernel, USB list

On Wed, 29 Jan 2014, Tejun Heo wrote:

> kernfs_deactivate() forgot to check whether KERNFS_LOCKDEP is set
> before performing lockdep annotations and ends up feeding
> uninitialized lockdep_map to lockdep triggering warning like the
> following on USB stick hotunplug.
> 
>  usb 1-2: USB disconnect, device number 2
>  INFO: trying to register non-static key.
>  the code is fine but needs lockdep annotation.
>  turning off the locking correctness validator.
>  CPU: 1 PID: 62 Comm: khubd Not tainted 3.13.0-work+ #82
>  Hardware name: empty empty/S3992, BIOS 080011  10/26/2007
>   ffff880065ca7f60 ffff88013a4ffa08 ffffffff81cfb6bd 0000000000000002
>   ffff88013a4ffac8 ffffffff810f8530 ffff88013a4fc710 0000000000000002
>   ffff880100000000 ffffffff82a3db50 0000000000000001 ffff88013a4fc710
>  Call Trace:
>   [<ffffffff81cfb6bd>] dump_stack+0x4e/0x7a
>   [<ffffffff810f8530>] __lock_acquire+0x1910/0x1e70
>   [<ffffffff810f931a>] lock_acquire+0x9a/0x1d0
>   [<ffffffff8127c75e>] kernfs_deactivate+0xee/0x130
>   [<ffffffff8127d4c8>] kernfs_addrm_finish+0x38/0x60
>   [<ffffffff8127d701>] kernfs_remove_by_name_ns+0x51/0xa0
>   [<ffffffff8127b4f1>] remove_files.isra.1+0x41/0x80
>   [<ffffffff8127b7e7>] sysfs_remove_group+0x47/0xa0
>   [<ffffffff8127b873>] sysfs_remove_groups+0x33/0x50
>   [<ffffffff8177d66d>] device_remove_attrs+0x4d/0x80
>   [<ffffffff8177e25e>] device_del+0x12e/0x1d0
>   [<ffffffff819722c2>] usb_disconnect+0x122/0x1a0
>   [<ffffffff819749b5>] hub_thread+0x3c5/0x1290
>   [<ffffffff810c6a6d>] kthread+0xed/0x110
>   [<ffffffff81d0a56c>] ret_from_fork+0x7c/0xb0
> 
> Fix it by making kernfs_deactivate() perform lockdep annotations only
> if KERNFS_LOCKDEP is set.
> 
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Reported-by: Fabio Estevam <festevam@gmail.com>
> Reported-by: Alan Stern <stern@rowland.harvard.edu>

I reported it here:

	https://lkml.org/lkml/2014/1/22/217

The patch fixes it for me as well.

Reported-and-tested-by: Jiri Kosina <jkosina@suse.cz>

Thanks,

-- 
Jiri Kosina
SUSE Labs

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

end of thread, other threads:[~2014-01-30 10:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAOJe8K20xx3o7HXH3E4pE3=G4pQ-nUf4LYF6sEwy5wYQE23+AA@mail.gmail.com>
     [not found] ` <Pine.LNX.4.44L0.1401291134070.11997-100000@netrider.rowland.org>
2014-01-29 17:04   ` [PATCH driver-core-linus] kernfs: make kernfs_deactivate() honor KERNFS_LOCKDEP flag Tejun Heo
2014-01-29 17:19     ` Fabio Estevam
2014-01-29 21:21       ` Greg Kroah-Hartman
2014-01-30 10:42     ` Jiri Kosina

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.