linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] locking/lockdep: Make lockdep_register_key() ignore 'debug_locks'
@ 2019-04-11 17:26 Bart Van Assche
  2019-04-12  5:47 ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Van Assche @ 2019-04-11 17:26 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, Thomas Gleixner, linux-kernel, Bart Van Assche,
	Will Deacon, Waiman Long, shenghui

If lockdep_register_key() and lockdep_unregister_key() are called with
debug_locks == false then the following warning is reported:

WARNING: CPU: 2 PID: 15145 at kernel/locking/lockdep.c:4920 lockdep_unregister_key+0x1ad/0x240

That warning is reported because lockdep_unregister_key() ignores the
value of 'debug_locks' and because the behavior of lockdep_register_key()
depends on whether or not 'debug_locks' is set. Fix this inconsistency
by making lockdep_register_key() unconditionally register lock keys.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Waiman Long <longman@redhat.com>
Cc: shenghui <shhuiw@foxmail.com>
Reported-by: shenghui <shhuiw@foxmail.com>
Fixes: a0b0fd53e1e6 ("locking/lockdep: Free lock classes that are no longer in use") # v5.1-rc1.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 kernel/locking/lockdep.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index d2d65bbfae01..a228509b62f1 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -1027,15 +1027,16 @@ void lockdep_register_key(struct lock_class_key *key)
 	hash_head = keyhashentry(key);
 
 	raw_local_irq_save(flags);
-	if (!graph_lock())
-		goto restore_irqs;
+	arch_spin_lock(&lockdep_lock);
+	current->lockdep_recursion = 1;
 	hlist_for_each_entry_rcu(k, hash_head, hash_entry) {
 		if (WARN_ON_ONCE(k == key))
 			goto out_unlock;
 	}
 	hlist_add_head_rcu(&key->hash_entry, hash_head);
 out_unlock:
-	graph_unlock();
+	current->lockdep_recursion = 0;
+	arch_spin_unlock(&lockdep_lock);
 restore_irqs:
 	raw_local_irq_restore(flags);
 }
-- 
2.21.0.196.g041f5ea1cf98


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

* Re: [PATCH] locking/lockdep: Make lockdep_register_key() ignore 'debug_locks'
  2019-04-11 17:26 [PATCH] locking/lockdep: Make lockdep_register_key() ignore 'debug_locks' Bart Van Assche
@ 2019-04-12  5:47 ` Ingo Molnar
  2019-04-12 15:32   ` Bart Van Assche
  0 siblings, 1 reply; 4+ messages in thread
From: Ingo Molnar @ 2019-04-12  5:47 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, linux-kernel,
	Will Deacon, Waiman Long, shenghui


* Bart Van Assche <bvanassche@acm.org> wrote:

> If lockdep_register_key() and lockdep_unregister_key() are called with
> debug_locks == false then the following warning is reported:
> 
> WARNING: CPU: 2 PID: 15145 at kernel/locking/lockdep.c:4920 lockdep_unregister_key+0x1ad/0x240
> 
> That warning is reported because lockdep_unregister_key() ignores the
> value of 'debug_locks' and because the behavior of lockdep_register_key()
> depends on whether or not 'debug_locks' is set. Fix this inconsistency
> by making lockdep_register_key() unconditionally register lock keys.
> 
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Waiman Long <longman@redhat.com>
> Cc: shenghui <shhuiw@foxmail.com>
> Reported-by: shenghui <shhuiw@foxmail.com>
> Fixes: a0b0fd53e1e6 ("locking/lockdep: Free lock classes that are no longer in use") # v5.1-rc1.
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  kernel/locking/lockdep.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> index d2d65bbfae01..a228509b62f1 100644
> --- a/kernel/locking/lockdep.c
> +++ b/kernel/locking/lockdep.c
> @@ -1027,15 +1027,16 @@ void lockdep_register_key(struct lock_class_key *key)
>  	hash_head = keyhashentry(key);
>  
>  	raw_local_irq_save(flags);
> -	if (!graph_lock())
> -		goto restore_irqs;
> +	arch_spin_lock(&lockdep_lock);
> +	current->lockdep_recursion = 1;
>  	hlist_for_each_entry_rcu(k, hash_head, hash_entry) {
>  		if (WARN_ON_ONCE(k == key))
>  			goto out_unlock;
>  	}
>  	hlist_add_head_rcu(&key->hash_entry, hash_head);
>  out_unlock:
> -	graph_unlock();
> +	current->lockdep_recursion = 0;
> +	arch_spin_unlock(&lockdep_lock);
>  restore_irqs:
>  	raw_local_irq_restore(flags);
>  }

So why don't we add a debug_locks test to lockdep_unregister_key() 
instead? The general principle to bring lockdep to a screeching halt when 
bugs are detected, ASAP.

Thanks,

	Ingo

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

* Re: [PATCH] locking/lockdep: Make lockdep_register_key() ignore 'debug_locks'
  2019-04-12  5:47 ` Ingo Molnar
@ 2019-04-12 15:32   ` Bart Van Assche
  2019-04-13  8:29     ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Van Assche @ 2019-04-12 15:32 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, linux-kernel,
	Will Deacon, Waiman Long, shenghui

On Fri, 2019-04-12 at 07:47 +0200, Ingo Molnar wrote:
> So why don't we add a debug_locks test to lockdep_unregister_key() 
> instead? The general principle to bring lockdep to a screeching halt when 
> bugs are detected, ASAP.

Hi Ingo,

Since this issue was introduced by patch "locking/lockdep: Zap lock classes
even with lock debugging disabled" and since that patch is in the tip tree
but not yet upstream: do you prefer that I post a version 3 of that patch or
do you rather prefer that I post a follow-up patch?

Thanks,

Bart.

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

* Re: [PATCH] locking/lockdep: Make lockdep_register_key() ignore 'debug_locks'
  2019-04-12 15:32   ` Bart Van Assche
@ 2019-04-13  8:29     ` Ingo Molnar
  0 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2019-04-13  8:29 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, linux-kernel,
	Will Deacon, Waiman Long, shenghui


* Bart Van Assche <bvanassche@acm.org> wrote:

> On Fri, 2019-04-12 at 07:47 +0200, Ingo Molnar wrote:
> > So why don't we add a debug_locks test to lockdep_unregister_key() 
> > instead? The general principle to bring lockdep to a screeching halt when 
> > bugs are detected, ASAP.
> 
> Hi Ingo,
> 
> Since this issue was introduced by patch "locking/lockdep: Zap lock classes
> even with lock debugging disabled" and since that patch is in the tip tree
> but not yet upstream: do you prefer that I post a version 3 of that patch or
> do you rather prefer that I post a follow-up patch?

The crash fix is now upstream, mind sending a followup patch for the 
warning fix?

Thanks,

	Ingo

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

end of thread, other threads:[~2019-04-13  8:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-11 17:26 [PATCH] locking/lockdep: Make lockdep_register_key() ignore 'debug_locks' Bart Van Assche
2019-04-12  5:47 ` Ingo Molnar
2019-04-12 15:32   ` Bart Van Assche
2019-04-13  8:29     ` Ingo Molnar

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).