Skip to content

Commit

Permalink
locking/lockdep: Add module_param to enable consistency checks
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Feb 28, 2019
1 parent f214737 commit 72dcd50
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions kernel/locking/lockdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ module_param(lock_stat, int, 0644);
#define lock_stat 0
#endif

static bool check_data_structure_consistency;

/*
* lockdep_lock: protects the lockdep graph, the hashes and the
* class/list/hash allocators.
Expand Down Expand Up @@ -791,6 +789,8 @@ static bool assign_lock_key(struct lockdep_map *lock)
return true;
}

#ifdef CONFIG_DEBUG_LOCKDEP

/* Check whether element @e occurs in list @h */
static bool in_list(struct list_head *e, struct list_head *h)
{
Expand Down Expand Up @@ -855,31 +855,31 @@ static bool check_lock_chain_key(struct lock_chain *chain)
* The 'unsigned long long' casts avoid that a compiler warning
* 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",
(unsigned long long)(chain - lock_chains),
(unsigned long long)chain->chain_key,
(unsigned long long)chain_key);
return chain->chain_key == chain_key;
#else
return true;
return false;
}
#endif
return true;
}

static bool in_any_zapped_class_list(struct lock_class *class)
{
struct pending_free *pf;
int i;

for (i = 0, pf = delayed_free.pf; i < ARRAY_SIZE(delayed_free.pf);
i++, pf++)
for (i = 0, pf = delayed_free.pf; i < ARRAY_SIZE(delayed_free.pf); i++, pf++) {
if (in_list(&class->lock_entry, &pf->zapped))
return true;
}

return false;
}

static bool check_data_structures(void)
static bool __check_data_structures(void)
{
struct lock_class *class;
struct lock_chain *chain;
Expand All @@ -896,7 +896,6 @@ static bool check_data_structures(void)
printk(KERN_INFO "class %px/%s is not in any class list\n",
class, class->name ? : "(?)");
return false;
return false;
}
}

Expand Down Expand Up @@ -953,6 +952,27 @@ static bool check_data_structures(void)
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
* and also the delayed_free structure.
Expand Down Expand Up @@ -4474,10 +4494,11 @@ static void remove_class_from_lock_chain(struct pending_free *pf,
if (chain_hlocks[i] != class - lock_classes)
continue;
/* The code below leaks one chain_hlock[] entry. */
if (--chain->depth > 0)
if (--chain->depth > 0) {
memmove(&chain_hlocks[i], &chain_hlocks[i + 1],
(chain->base + chain->depth - i) *
sizeof(chain_hlocks[0]));
}
/*
* Each lock class occurs at most once in a lock chain so once
* we found a match we can break out of this loop.
Expand Down Expand Up @@ -4631,8 +4652,7 @@ static void __free_zapped_classes(struct pending_free *pf)
{
struct lock_class *class;

if (check_data_structure_consistency)
WARN_ON_ONCE(!check_data_structures());
check_data_structures();

list_for_each_entry(class, &pf->zapped, lock_entry)
reinit_class(class);
Expand Down

0 comments on commit 72dcd50

Please sign in to comment.