aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2017-03-01 10:23:30 -0500
committerIngo Molnar <mingo@kernel.org>2017-03-02 03:00:38 -0500
commit7fb4a2cea6b18dab56d609530d077f168169ed6b (patch)
tree4b0e6b73918486e175841c1deb6ff72811add002
parent2b232e0c3b3a09f3e33750aa20e314f1b80e5361 (diff)
locking/lockdep: Add nest_lock integrity test
Boqun reported that hlock->references can overflow. Add a debug test for that to generate a clear error when this happens. Without this, lockdep is likely to report a mysterious failure on unlock. Reported-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Nicolai Hähnle <Nicolai.Haehnle@amd.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--kernel/locking/lockdep.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 9812e5dd409e..c0ee8607c11e 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -3260,10 +3260,17 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
3260 if (depth) { 3260 if (depth) {
3261 hlock = curr->held_locks + depth - 1; 3261 hlock = curr->held_locks + depth - 1;
3262 if (hlock->class_idx == class_idx && nest_lock) { 3262 if (hlock->class_idx == class_idx && nest_lock) {
3263 if (hlock->references) 3263 if (hlock->references) {
3264 /*
3265 * Check: unsigned int references:12, overflow.
3266 */
3267 if (DEBUG_LOCKS_WARN_ON(hlock->references == (1 << 12)-1))
3268 return 0;
3269
3264 hlock->references++; 3270 hlock->references++;
3265 else 3271 } else {
3266 hlock->references = 2; 3272 hlock->references = 2;
3273 }
3267 3274
3268 return 1; 3275 return 1;
3269 } 3276 }