* [PATCH] locking/lockdep: Zap lock classes even with lock debugging disabled
@ 2019-03-26 19:59 Bart Van Assche
2019-04-03 12:44 ` Will Deacon
0 siblings, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2019-03-26 19:59 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Thomas Gleixner, linux-kernel, Bart Van Assche,
Will Deacon, Waiman Long, shenghui
Commit a0b0fd53e1e6 ("locking/lockdep: Free lock classes that are no longer
in use") changed the behavior of lockdep_free_key_range() from
unconditionally zapping lock classes into only zapping lock classes if
debug_lock == true. Since the new behavior can cause cat /proc/lockdep to
crash due to a NULL pointer dereference, restore the pre-v5.1 behavior.
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 | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 34cdcbedda49..70480e4f8f5d 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -4689,8 +4689,7 @@ static void free_zapped_rcu(struct rcu_head *ch)
return;
raw_local_irq_save(flags);
- if (!graph_lock())
- goto out_irq;
+ arch_spin_lock(&lockdep_lock);
/* closed head */
pf = delayed_free.pf + (delayed_free.index ^ 1);
@@ -4702,8 +4701,7 @@ static void free_zapped_rcu(struct rcu_head *ch)
*/
call_rcu_zapped(delayed_free.pf + delayed_free.index);
- graph_unlock();
-out_irq:
+ arch_spin_unlock(&lockdep_lock);
raw_local_irq_restore(flags);
}
@@ -4744,21 +4742,15 @@ static void lockdep_free_key_range_reg(void *start, unsigned long size)
{
struct pending_free *pf;
unsigned long flags;
- int locked;
init_data_structures_once();
raw_local_irq_save(flags);
- locked = graph_lock();
- if (!locked)
- goto out_irq;
-
+ arch_spin_lock(&lockdep_lock);
pf = get_pending_free();
__lockdep_free_key_range(pf, start, size);
call_rcu_zapped(pf);
-
- graph_unlock();
-out_irq:
+ arch_spin_unlock(&lockdep_lock);
raw_local_irq_restore(flags);
/*
@@ -4911,9 +4903,7 @@ void lockdep_unregister_key(struct lock_class_key *key)
return;
raw_local_irq_save(flags);
- if (!graph_lock())
- goto out_irq;
-
+ arch_spin_lock(&lockdep_lock);
pf = get_pending_free();
hlist_for_each_entry_rcu(k, hash_head, hash_entry) {
if (k == key) {
@@ -4925,8 +4915,7 @@ void lockdep_unregister_key(struct lock_class_key *key)
WARN_ON_ONCE(!found);
__lockdep_free_key_range(pf, key, 1);
call_rcu_zapped(pf);
- graph_unlock();
-out_irq:
+ arch_spin_unlock(&lockdep_lock);
raw_local_irq_restore(flags);
/* Wait until is_dynamic_key() has finished accessing k->hash_entry. */
--
2.21.0.196.g041f5ea1cf98
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] locking/lockdep: Zap lock classes even with lock debugging disabled
2019-03-26 19:59 [PATCH] locking/lockdep: Zap lock classes even with lock debugging disabled Bart Van Assche
@ 2019-04-03 12:44 ` Will Deacon
2019-04-03 15:48 ` Bart Van Assche
2019-04-03 21:15 ` Bart Van Assche
0 siblings, 2 replies; 5+ messages in thread
From: Will Deacon @ 2019-04-03 12:44 UTC (permalink / raw)
To: Bart Van Assche
Cc: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, linux-kernel,
Waiman Long, shenghui
On Tue, Mar 26, 2019 at 12:59:12PM -0700, Bart Van Assche wrote:
> Commit a0b0fd53e1e6 ("locking/lockdep: Free lock classes that are no longer
> in use") changed the behavior of lockdep_free_key_range() from
> unconditionally zapping lock classes into only zapping lock classes if
> debug_lock == true. Since the new behavior can cause cat /proc/lockdep to
> crash due to a NULL pointer dereference, restore the pre-v5.1 behavior.
Can you elaborate on this NULL dereference please, and why this patch fixes
it?
> 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 | 23 ++++++-----------------
> 1 file changed, 6 insertions(+), 17 deletions(-)
>
> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> index 34cdcbedda49..70480e4f8f5d 100644
> --- a/kernel/locking/lockdep.c
> +++ b/kernel/locking/lockdep.c
> @@ -4689,8 +4689,7 @@ static void free_zapped_rcu(struct rcu_head *ch)
> return;
>
> raw_local_irq_save(flags);
> - if (!graph_lock())
> - goto out_irq;
> + arch_spin_lock(&lockdep_lock);
This also throws out the recursion counting. Is that ok?
Will
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] locking/lockdep: Zap lock classes even with lock debugging disabled
2019-04-03 12:44 ` Will Deacon
@ 2019-04-03 15:48 ` Bart Van Assche
2019-04-03 17:33 ` Will Deacon
2019-04-03 21:15 ` Bart Van Assche
1 sibling, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2019-04-03 15:48 UTC (permalink / raw)
To: Will Deacon
Cc: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, linux-kernel,
Waiman Long, shenghui
On Wed, 2019-04-03 at 13:44 +0100, Will Deacon wrote:
> On Tue, Mar 26, 2019 at 12:59:12PM -0700, Bart Van Assche wrote:
> > Commit a0b0fd53e1e6 ("locking/lockdep: Free lock classes that are no longer
> > in use") changed the behavior of lockdep_free_key_range() from
> > unconditionally zapping lock classes into only zapping lock classes if
> > debug_lock == true. Since the new behavior can cause cat /proc/lockdep to
> > crash due to a NULL pointer dereference, restore the pre-v5.1 behavior.
>
> Can you elaborate on this NULL dereference please, and why this patch fixes
> it?
Hi Will,
Not zapping lock classes if debug_lock == false leaves dangling pointers in
several lockdep datastructures, e.g. lock_class::name in the all_lock_classes
list. The shell command "cat /proc/lockdep" causes the kernel to iterate the
all_lock_classes list. Hence the "unable to handle kernel paging request"
issue that Shenghui encountered by running cat /proc/lockdep. Please let me
know if you would like me to repost this patch with a more detailed
description.
> > 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 | 23 ++++++-----------------
> > 1 file changed, 6 insertions(+), 17 deletions(-)
> >
> > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> > index 34cdcbedda49..70480e4f8f5d 100644
> > --- a/kernel/locking/lockdep.c
> > +++ b/kernel/locking/lockdep.c
> > @@ -4689,8 +4689,7 @@ static void free_zapped_rcu(struct rcu_head *ch)
> > return;
> >
> > raw_local_irq_save(flags);
> > - if (!graph_lock())
> > - goto out_irq;
> > + arch_spin_lock(&lockdep_lock);
>
> This also throws out the recursion counting. Is that ok?
I think that that's OK. My understanding is that lockdep keeps track of
recursion to avoid that lockdep_lock is locked recursively. However, none
of the functions modified by this patch are called with that lock held.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] locking/lockdep: Zap lock classes even with lock debugging disabled
2019-04-03 15:48 ` Bart Van Assche
@ 2019-04-03 17:33 ` Will Deacon
0 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2019-04-03 17:33 UTC (permalink / raw)
To: Bart Van Assche
Cc: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, linux-kernel,
Waiman Long, shenghui
On Wed, Apr 03, 2019 at 08:48:02AM -0700, Bart Van Assche wrote:
> On Wed, 2019-04-03 at 13:44 +0100, Will Deacon wrote:
> > On Tue, Mar 26, 2019 at 12:59:12PM -0700, Bart Van Assche wrote:
> > > Commit a0b0fd53e1e6 ("locking/lockdep: Free lock classes that are no longer
> > > in use") changed the behavior of lockdep_free_key_range() from
> > > unconditionally zapping lock classes into only zapping lock classes if
> > > debug_lock == true. Since the new behavior can cause cat /proc/lockdep to
> > > crash due to a NULL pointer dereference, restore the pre-v5.1 behavior.
> >
> > Can you elaborate on this NULL dereference please, and why this patch fixes
> > it?
>
> Not zapping lock classes if debug_lock == false leaves dangling pointers in
> several lockdep datastructures, e.g. lock_class::name in the all_lock_classes
> list. The shell command "cat /proc/lockdep" causes the kernel to iterate the
> all_lock_classes list. Hence the "unable to handle kernel paging request"
> issue that Shenghui encountered by running cat /proc/lockdep. Please let me
> know if you would like me to repost this patch with a more detailed
> description.
That would help me, at least (maybe with the crash log). Thanks.
> > > 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 | 23 ++++++-----------------
> > > 1 file changed, 6 insertions(+), 17 deletions(-)
> > >
> > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> > > index 34cdcbedda49..70480e4f8f5d 100644
> > > --- a/kernel/locking/lockdep.c
> > > +++ b/kernel/locking/lockdep.c
> > > @@ -4689,8 +4689,7 @@ static void free_zapped_rcu(struct rcu_head *ch)
> > > return;
> > >
> > > raw_local_irq_save(flags);
> > > - if (!graph_lock())
> > > - goto out_irq;
> > > + arch_spin_lock(&lockdep_lock);
> >
> > This also throws out the recursion counting. Is that ok?
>
> I think that that's OK. My understanding is that lockdep keeps track of
> recursion to avoid that lockdep_lock is locked recursively. However, none
> of the functions modified by this patch are called with that lock held.
Might be worth adding a comment to that effect, so people don't change that
in future.
Will
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] locking/lockdep: Zap lock classes even with lock debugging disabled
2019-04-03 12:44 ` Will Deacon
2019-04-03 15:48 ` Bart Van Assche
@ 2019-04-03 21:15 ` Bart Van Assche
1 sibling, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2019-04-03 21:15 UTC (permalink / raw)
To: Will Deacon
Cc: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, linux-kernel,
Waiman Long, shenghui
On Wed, 2019-04-03 at 13:44 +0100, Will Deacon wrote:
> > --- a/kernel/locking/lockdep.c
> > +++ b/kernel/locking/lockdep.c
> > @@ -4689,8 +4689,7 @@ static void free_zapped_rcu(struct rcu_head *ch)
> > return;
> >
> > raw_local_irq_save(flags);
> > - if (!graph_lock())
> > - goto out_irq;
> > + arch_spin_lock(&lockdep_lock);
>
> This also throws out the recursion counting. Is that ok?
Apparently not, as the build bot just figured out. I will restore recursion
counting. See also
https://lore.kernel.org/lkml/5ca4ea66.eVtXtf5CmqRjP7xF%25lkp@intel.com/.
Bart.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-04-03 21:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-26 19:59 [PATCH] locking/lockdep: Zap lock classes even with lock debugging disabled Bart Van Assche
2019-04-03 12:44 ` Will Deacon
2019-04-03 15:48 ` Bart Van Assche
2019-04-03 17:33 ` Will Deacon
2019-04-03 21:15 ` Bart Van Assche
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.