Skip to content

Commit

Permalink
lockdep: Fix nr_unused_locks accounting
Browse files Browse the repository at this point in the history
Chris reported that commit 24d5a3bffef1 ("lockdep: Fix
usage_traceoverflow") breaks the nr_unused_locks validation code
triggered by /proc/lockdep_stats.

By fully splitting LOCK_USED and LOCK_USED_READ it becomes a bad
indicator for accounting nr_unused_locks; simplyfy by using any first
bit.

Fixes: 24d5a3bffef1 ("lockdep: Fix usage_traceoverflow")
Reported-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://lkml.kernel.org/r/20201027124834.GL2628@hirez.programming.kicks-ass.net
  • Loading branch information
Peter Zijlstra committed Oct 30, 2020
1 parent d48e385 commit 1a39340
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions kernel/locking/lockdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -4396,26 +4396,20 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this,
if (unlikely(hlock_class(this)->usage_mask & new_mask))
goto unlock;

if (!hlock_class(this)->usage_mask)
debug_atomic_dec(nr_unused_locks);

hlock_class(this)->usage_mask |= new_mask;

if (new_bit < LOCK_TRACE_STATES) {
if (!(hlock_class(this)->usage_traces[new_bit] = save_trace()))
return 0;
}

switch (new_bit) {
case 0 ... LOCK_USED-1:
if (new_bit < LOCK_USED) {
ret = mark_lock_irq(curr, this, new_bit);
if (!ret)
return 0;
break;

case LOCK_USED:
debug_atomic_dec(nr_unused_locks);
break;

default:
break;
}

unlock:
Expand Down

0 comments on commit 1a39340

Please sign in to comment.