locking/lockdep: Add module_param to enable consistency checks
And move the whole lot under CONFIG_DEBUG_LOCKDEP. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>hifive-unleashed-5.1
parent
f214737b75
commit
72dcd505e8
|
@ -74,8 +74,6 @@ module_param(lock_stat, int, 0644);
|
||||||
#define lock_stat 0
|
#define lock_stat 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool check_data_structure_consistency;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* lockdep_lock: protects the lockdep graph, the hashes and the
|
* lockdep_lock: protects the lockdep graph, the hashes and the
|
||||||
* class/list/hash allocators.
|
* class/list/hash allocators.
|
||||||
|
@ -791,6 +789,8 @@ static bool assign_lock_key(struct lockdep_map *lock)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG_LOCKDEP
|
||||||
|
|
||||||
/* Check whether element @e occurs in list @h */
|
/* Check whether element @e occurs in list @h */
|
||||||
static bool in_list(struct list_head *e, struct list_head *h)
|
static bool in_list(struct list_head *e, struct list_head *h)
|
||||||
{
|
{
|
||||||
|
@ -855,15 +855,15 @@ static bool check_lock_chain_key(struct lock_chain *chain)
|
||||||
* The 'unsigned long long' casts avoid that a compiler warning
|
* The 'unsigned long long' casts avoid that a compiler warning
|
||||||
* is reported when building tools/lib/lockdep.
|
* is reported when building tools/lib/lockdep.
|
||||||
*/
|
*/
|
||||||
if (chain->chain_key != chain_key)
|
if (chain->chain_key != chain_key) {
|
||||||
printk(KERN_INFO "chain %lld: key %#llx <> %#llx\n",
|
printk(KERN_INFO "chain %lld: key %#llx <> %#llx\n",
|
||||||
(unsigned long long)(chain - lock_chains),
|
(unsigned long long)(chain - lock_chains),
|
||||||
(unsigned long long)chain->chain_key,
|
(unsigned long long)chain->chain_key,
|
||||||
(unsigned long long)chain_key);
|
(unsigned long long)chain_key);
|
||||||
return chain->chain_key == chain_key;
|
return false;
|
||||||
#else
|
}
|
||||||
return true;
|
|
||||||
#endif
|
#endif
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool in_any_zapped_class_list(struct lock_class *class)
|
static bool in_any_zapped_class_list(struct lock_class *class)
|
||||||
|
@ -871,15 +871,15 @@ static bool in_any_zapped_class_list(struct lock_class *class)
|
||||||
struct pending_free *pf;
|
struct pending_free *pf;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0, pf = delayed_free.pf; i < ARRAY_SIZE(delayed_free.pf);
|
for (i = 0, pf = delayed_free.pf; i < ARRAY_SIZE(delayed_free.pf); i++, pf++) {
|
||||||
i++, pf++)
|
|
||||||
if (in_list(&class->lock_entry, &pf->zapped))
|
if (in_list(&class->lock_entry, &pf->zapped))
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool check_data_structures(void)
|
static bool __check_data_structures(void)
|
||||||
{
|
{
|
||||||
struct lock_class *class;
|
struct lock_class *class;
|
||||||
struct lock_chain *chain;
|
struct lock_chain *chain;
|
||||||
|
@ -896,7 +896,6 @@ static bool check_data_structures(void)
|
||||||
printk(KERN_INFO "class %px/%s is not in any class list\n",
|
printk(KERN_INFO "class %px/%s is not in any class list\n",
|
||||||
class, class->name ? : "(?)");
|
class, class->name ? : "(?)");
|
||||||
return false;
|
return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -953,6 +952,27 @@ static bool check_data_structures(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int check_consistency = 0;
|
||||||
|
module_param(check_consistency, int, 0644);
|
||||||
|
|
||||||
|
static void check_data_structures(void)
|
||||||
|
{
|
||||||
|
static bool once = false;
|
||||||
|
|
||||||
|
if (check_consistency && !once) {
|
||||||
|
if (!__check_data_structures()) {
|
||||||
|
once = true;
|
||||||
|
WARN_ON(once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* CONFIG_DEBUG_LOCKDEP */
|
||||||
|
|
||||||
|
static inline void check_data_structures(void) { }
|
||||||
|
|
||||||
|
#endif /* CONFIG_DEBUG_LOCKDEP */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the lock_classes[] array elements, the free_lock_classes list
|
* Initialize the lock_classes[] array elements, the free_lock_classes list
|
||||||
* and also the delayed_free structure.
|
* and also the delayed_free structure.
|
||||||
|
@ -4474,10 +4494,11 @@ static void remove_class_from_lock_chain(struct pending_free *pf,
|
||||||
if (chain_hlocks[i] != class - lock_classes)
|
if (chain_hlocks[i] != class - lock_classes)
|
||||||
continue;
|
continue;
|
||||||
/* The code below leaks one chain_hlock[] entry. */
|
/* The code below leaks one chain_hlock[] entry. */
|
||||||
if (--chain->depth > 0)
|
if (--chain->depth > 0) {
|
||||||
memmove(&chain_hlocks[i], &chain_hlocks[i + 1],
|
memmove(&chain_hlocks[i], &chain_hlocks[i + 1],
|
||||||
(chain->base + chain->depth - i) *
|
(chain->base + chain->depth - i) *
|
||||||
sizeof(chain_hlocks[0]));
|
sizeof(chain_hlocks[0]));
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Each lock class occurs at most once in a lock chain so once
|
* Each lock class occurs at most once in a lock chain so once
|
||||||
* we found a match we can break out of this loop.
|
* we found a match we can break out of this loop.
|
||||||
|
@ -4631,8 +4652,7 @@ static void __free_zapped_classes(struct pending_free *pf)
|
||||||
{
|
{
|
||||||
struct lock_class *class;
|
struct lock_class *class;
|
||||||
|
|
||||||
if (check_data_structure_consistency)
|
check_data_structures();
|
||||||
WARN_ON_ONCE(!check_data_structures());
|
|
||||||
|
|
||||||
list_for_each_entry(class, &pf->zapped, lock_entry)
|
list_for_each_entry(class, &pf->zapped, lock_entry)
|
||||||
reinit_class(class);
|
reinit_class(class);
|
||||||
|
|
Loading…
Reference in New Issue