Skip to content

Commit 6f008e7

Browse files
Peter Zijlstraingomolnar
authored andcommitted
locking/mutex: Fix debug checks
OK, so commit: 1d8fe7d ("locking/mutexes: Unlock the mutex without the wait_lock") generates this boot warning when CONFIG_DEBUG_MUTEXES=y: WARNING: CPU: 0 PID: 139 at /usr/src/linux-2.6/kernel/locking/mutex-debug.c:82 debug_mutex_unlock+0x155/0x180() DEBUG_LOCKS_WARN_ON(lock->owner != current) And that makes sense, because as soon as we release the lock a new owner can come in... One would think that !__mutex_slowpath_needs_to_unlock() implementations suffer the same, but for DEBUG we fall back to mutex-null.h which has an unconditional 1 for that. The mutex debug code requires the mutex to be unlocked after doing the debug checks, otherwise it can find inconsistent state. Reported-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: jason.low2@hp.com Link: http://lkml.kernel.org/r/20140312122442.GB27965@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 34c6bc2 commit 6f008e7

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎kernel/locking/mutex-debug.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ void debug_mutex_unlock(struct mutex *lock)
8383

8484
DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
8585
mutex_clear_owner(lock);
86+
87+
/*
88+
* __mutex_slowpath_needs_to_unlock() is explicitly 0 for debug
89+
* mutexes so that we can do it here after we've verified state.
90+
*/
91+
atomic_set(&lock->count, 1);
8692
}
8793

8894
void debug_mutex_init(struct mutex *lock, const char *name,

‎kernel/locking/mutex.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
#ifdef CONFIG_DEBUG_MUTEXES
3535
# include "mutex-debug.h"
3636
# include <asm-generic/mutex-null.h>
37+
/*
38+
* Must be 0 for the debug case so we do not do the unlock outside of the
39+
* wait_lock region. debug_mutex_unlock() will do the actual unlock in this
40+
* case.
41+
*/
42+
# undef __mutex_slowpath_needs_to_unlock
43+
# define __mutex_slowpath_needs_to_unlock() 0
3744
#else
3845
# include "mutex.h"
3946
# include <asm/mutex.h>

0 commit comments

Comments
 (0)