public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernfs: skip lockdep annotation always if ignore_lockdep is set
@ 2014-02-07 19:47 Imre Deak
  2014-02-07 19:53 ` Tejun Heo
  0 siblings, 1 reply; 3+ messages in thread
From: Imre Deak @ 2014-02-07 19:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Tejun Heo; +Cc: Borislav Petkov, linux-kernel

We skip lockdep annotations for sysfs attributes with ignore_lockdep
set. An exception is kernfs_deactivate where we annotate even in this
case. Since the lockdep map key needed for the annotation is not
initialized whenever ignore_lockdep is set, we'll get a warning for
the uninitialized key.

Note that this happens since,

commit 517e64f57883bd63c5a4ab8b3d0d3ed68c55d0cf
Author: Tejun Heo <tj@kernel.org>
Date:   Thu Nov 28 14:54:29 2013 -0500

Before this change we had a valid key even in case of ignore_lockdep, so
the annotation in kernfs_deactivate worked, or at least didn't produce
the above warning. Fix this by skipping the annotation whenever
ignore_lockdep is set.

The actual attribute triggering the bug was 'delete_device' in
drivers/i2c/i2c-core.c, for the backtrace see the reference below.

Reported-by: Borislav Petkov <bp@alien8.de>
Reference: http://lists.freedesktop.org/archives/intel-gfx/2014-February/039663.html
Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 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_);
+	}
 }
 
 /**
-- 
1.8.1.2


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

* Re: [PATCH] kernfs: skip lockdep annotation always if ignore_lockdep is set
  2014-02-07 19:47 [PATCH] kernfs: skip lockdep annotation always if ignore_lockdep is set Imre Deak
@ 2014-02-07 19:53 ` Tejun Heo
  2014-02-07 22:17   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Tejun Heo @ 2014-02-07 19:53 UTC (permalink / raw)
  To: Imre Deak; +Cc: Greg Kroah-Hartman, Borislav Petkov, linux-kernel

On Fri, Feb 07, 2014 at 09:47:01PM +0200, Imre Deak wrote:
> We skip lockdep annotations for sysfs attributes with ignore_lockdep
> set. An exception is kernfs_deactivate where we annotate even in this
> case. Since the lockdep map key needed for the annotation is not
> initialized whenever ignore_lockdep is set, we'll get a warning for
> the uninitialized key.
> 
> Note that this happens since,
> 
> commit 517e64f57883bd63c5a4ab8b3d0d3ed68c55d0cf
> Author: Tejun Heo <tj@kernel.org>
> Date:   Thu Nov 28 14:54:29 2013 -0500
> 
> Before this change we had a valid key even in case of ignore_lockdep, so
> the annotation in kernfs_deactivate worked, or at least didn't produce
> the above warning. Fix this by skipping the annotation whenever
> ignore_lockdep is set.
> 
> The actual attribute triggering the bug was 'delete_device' in
> drivers/i2c/i2c-core.c, for the backtrace see the reference below.

I think Greg already has about the same patch queued.

  http://lkml.kernel.org/g/20140129170403.GJ30842@htj.dyndns.org

Thanks.

-- 
tejun

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

* Re: [PATCH] kernfs: skip lockdep annotation always if ignore_lockdep is set
  2014-02-07 19:53 ` Tejun Heo
@ 2014-02-07 22:17   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2014-02-07 22:17 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Imre Deak, Borislav Petkov, linux-kernel

On Fri, Feb 07, 2014 at 02:53:13PM -0500, Tejun Heo wrote:
> On Fri, Feb 07, 2014 at 09:47:01PM +0200, Imre Deak wrote:
> > We skip lockdep annotations for sysfs attributes with ignore_lockdep
> > set. An exception is kernfs_deactivate where we annotate even in this
> > case. Since the lockdep map key needed for the annotation is not
> > initialized whenever ignore_lockdep is set, we'll get a warning for
> > the uninitialized key.
> > 
> > Note that this happens since,
> > 
> > commit 517e64f57883bd63c5a4ab8b3d0d3ed68c55d0cf
> > Author: Tejun Heo <tj@kernel.org>
> > Date:   Thu Nov 28 14:54:29 2013 -0500
> > 
> > Before this change we had a valid key even in case of ignore_lockdep, so
> > the annotation in kernfs_deactivate worked, or at least didn't produce
> > the above warning. Fix this by skipping the annotation whenever
> > ignore_lockdep is set.
> > 
> > The actual attribute triggering the bug was 'delete_device' in
> > drivers/i2c/i2c-core.c, for the backtrace see the reference below.
> 
> I think Greg already has about the same patch queued.
> 
>   http://lkml.kernel.org/g/20140129170403.GJ30842@htj.dyndns.org

Yes, I just sent it to Linus a few minutes ago.

thanks,

greg k-h

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

end of thread, other threads:[~2014-02-07 22:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-07 19:47 [PATCH] kernfs: skip lockdep annotation always if ignore_lockdep is set Imre Deak
2014-02-07 19:53 ` Tejun Heo
2014-02-07 22:17   ` Greg Kroah-Hartman

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