locking/lockdep: Zap lock classes even with lock debugging disabled
PATCH 1/1 locking/lockdep: Zap lock classes even with lock debugging disabled
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.
--- kernel/locking/lockdep.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
kernel/locking/lockdep.c +6 -17
@@ -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. */
Signature · 1 line
2.21.0.196.g041f5ea1cf98
Quoted 5 lines · Bart Van Assche
Commit
a0b0fd53e1e6("locking/lockdep: Free lock classes that are no longer in use") changed the behavior oflockdep_free_key_range()from unconditionally zapping lock classes into only zapping lock classes ifdebug_lock== true. Since the new behavior can cause cat/proc/lockdepto 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?
Quoted 16 lines
Cc Thomas Gleixner <[email protected]>Cc Will Deacon <[email protected]>Cc Waiman Long <[email protected]>Cc shenghui <[email protected]>Reported-by shenghui <[email protected]>Fixes a0b0fd53e1e6 ("locking/lockdep: Free lock classes that are no longer in use") # v5.1-rc1.Signed-off-by Bart Van Assche <[email protected]>--- kernel/locking/lockdep.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)kernel/locking/lockdep.c +0
-0
kernel/locking/lockdep.c static void free_zapped_rcu(struct rcu_head *ch) · line 4692
Quoted 6 lines
kernel/locking/lockdep.c +1
-2@@ -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
Quoted 9 lines · Will Deacon
Quoted 5 lines · Bart Van Assche
Commit
a0b0fd53e1e6("locking/lockdep: Free lock classes that are no longer in use" changed the behavior oflockdep_free_key_range()from unconditionally zapping lock classes into only zapping lock classes ifdebug_lock==true. Since the new behavior can cause cat/proc/lockdepto 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 theall_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.
Quoted 5 lines
Quoted 5 lines
Cc Thomas Gleixner <[email protected]>>>Cc: Will Deacon <[email protected]>>>Cc: Waiman Long <[email protected]>>>Cc: shenghui <[email protected]>>>Reported-by: shenghui <[email protected]>>>Fixes: a0b0fd53e1e6 ("locking/lockdep: Free lock classes that are no longer in use" #v5.1-rc1.Signed-off-by Bart Van Assche <[email protected]>>>---
kernel/locking/lockdep.c|23 +-+-+-+-+-+------------------1 file changed, 6 insertions(+-), 17 deletions(-)
Quoted 9 lines
kernel/locking/lockdep.c
Quoted 8 lines
kernel/locking/lockdep.c +1
-1--- 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())kernel/locking/lockdep.c +0
-1- 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.
Quoted 11 lines · Bart Van Assche
Quoted 9 lines · Will Deacon
Quoted 5 lines · Bart Van Assche
Commit
a0b0fd53e1e6("locking/lockdep: Free lock classes that are no longer in use") changed the behavior oflockdep_free_key_range()from unconditionally zapping lock classes into only zapping lock classes ifdebug_lock== true. Since the new behavior can cause cat/proc/lockdepto 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?
Quoted 7 lines
Not zapping lock classes if
debug_lock== false leaves dangling pointers in several lockdep datastructures, e.g.lock_class::namein theall_lock_classeslist. The shell command "cat/proc/lockdep" causes the kernel to iterate theall_lock_classeslist. 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.
Quoted 25 lines
Quoted 18 lines
Quoted 18 lines
Cc Thomas Gleixner <[email protected]>Cc Will Deacon <[email protected]>Cc Waiman Long <[email protected]>Cc shenghui <[email protected]>Reported-by shenghui <[email protected]>Fixes a0b0fd53e1e6 ("locking/lockdep: Free lock classes that are no longer in use") # v5.1-rc1.Signed-off-by Bart Van Assche <[email protected]>--- kernel/locking/lockdep.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)kernel/locking/lockdep.c +0
-0@@ -4689,8 +4689,7 @@ static void free_zapped_rcu(struct rcu_head *ch)return ;Quoted 6 lines
kernel/locking/lockdep.c static void free_zapped_rcu(struct rcu_head *ch) · line 4692
Quoted 4 lines
kernel/locking/lockdep.c +1
-2raw_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?
Quoted 3 lines
I think that that's OK. My understanding is that lockdep keeps track of recursion to avoid that
lockdep_lockis 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
Quoted 7 lines · Will Deacon
Review
Quoted 6 lines
---
a/kernel/locking/lockdep.c
+-+-+-b/kernel/locking/lockdep.c
@@-4689,8 +-4689,7 @@static voidfree_zapped_rcu(struct rcu_head *ch)return;>> raw_local_irq_save(flags);>>- if (!graph_lock())(quoted diff) +0
-1- 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%[email protected]/.
Bart.