Skip to content

Commit 1a39340

Browse files
author
Peter Zijlstra
committed
lockdep: Fix nr_unused_locks accounting
Chris reported that commit 24d5a3b ("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: 24d5a3b ("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
1 parent d48e385 commit 1a39340

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

kernel/locking/lockdep.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4396,26 +4396,20 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this,
43964396
if (unlikely(hlock_class(this)->usage_mask & new_mask))
43974397
goto unlock;
43984398

4399+
if (!hlock_class(this)->usage_mask)
4400+
debug_atomic_dec(nr_unused_locks);
4401+
43994402
hlock_class(this)->usage_mask |= new_mask;
44004403

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

4406-
switch (new_bit) {
4407-
case 0 ... LOCK_USED-1:
4409+
if (new_bit < LOCK_USED) {
44084410
ret = mark_lock_irq(curr, this, new_bit);
44094411
if (!ret)
44104412
return 0;
4411-
break;
4412-
4413-
case LOCK_USED:
4414-
debug_atomic_dec(nr_unused_locks);
4415-
break;
4416-
4417-
default:
4418-
break;
44194413
}
44204414

44214415
unlock:

0 commit comments

Comments
 (0)