Skip to content

Commit

Permalink
lockdep: Fix wrong assumption in match_held_lock
Browse files Browse the repository at this point in the history
match_held_lock() was assuming it was being called on a lock class
that had already seen usage.

This condition was true for bug-free code using lockdep_assert_held(),
since you're in fact holding the lock when calling it. However the
assumption fails the moment you assume the assertion can fail, which
is the whole point of having the assertion in the first place.

Anyway, now that there's more lockdep_is_held() users, notably
__rcu_dereference_check(), its much easier to trigger this since we
test for a number of locks and we only need to hold any one of them to
be good.

Reported-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1312547787.28695.2.camel@twins
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Aug 9, 2011
1 parent 2f84dd7 commit 80e0401
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion kernel/lockdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3111,7 +3111,13 @@ static int match_held_lock(struct held_lock *hlock, struct lockdep_map *lock)
if (!class)
class = look_up_lock_class(lock, 0);

if (DEBUG_LOCKS_WARN_ON(!class))
/*
* If look_up_lock_class() failed to find a class, we're trying
* to test if we hold a lock that has never yet been acquired.
* Clearly if the lock hasn't been acquired _ever_, we're not
* holding it either, so report failure.
*/
if (!class)
return 0;

if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock))
Expand Down

0 comments on commit 80e0401

Please sign in to comment.