Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lockdep: Make held_lock->check and "int check" argument bool

The "int check" argument of lock_acquire() and held_lock->check are
misleading. This is actually a boolean: 2 means "true", everything
else is "false".

And there is no need to pass 1 or 0 to lock_acquire() depending on
CONFIG_PROVE_LOCKING, __lock_acquire() checks prove_locking at the
start and clears "check" if !CONFIG_PROVE_LOCKING.

Note: probably we can simply kill this member/arg. The only explicit
user of check => 0 is rcu_lock_acquire(), perhaps we can change it to
use lock_acquire(trylock =>, read => 2). __lockdep_no_validate means
check => 0 implicitly, but we can change validate_chain() to check
hlock->instance->key instead. Not to mention it would be nice to get
rid of lockdep_set_novalidate_class().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Dave Jones <davej@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20140120182006.GA26495@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Oleg Nesterov and committed by
Ingo Molnar
fb9edbe9 ddf1d169

+18 -35
+4 -11
drivers/tty/tty_ldsem.c
··· 39 39 lock_acquire(&(l)->dep_map, s, t, r, c, n, i) 40 40 # define __rel(l, n, i) \ 41 41 lock_release(&(l)->dep_map, n, i) 42 - # ifdef CONFIG_PROVE_LOCKING 43 - # define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 2, NULL, i) 44 - # define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 2, n, i) 45 - # define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 2, NULL, i) 46 - # define lockdep_release(l, n, i) __rel(l, n, i) 47 - # else 48 - # define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 1, NULL, i) 49 - # define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 1, n, i) 50 - # define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 1, NULL, i) 51 - # define lockdep_release(l, n, i) __rel(l, n, i) 52 - # endif 42 + #define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 1, NULL, i) 43 + #define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 1, n, i) 44 + #define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 1, NULL, i) 45 + #define lockdep_release(l, n, i) __rel(l, n, i) 53 46 #else 54 47 # define lockdep_acquire(l, s, t, i) do { } while (0) 55 48 # define lockdep_acquire_nest(l, s, t, n, i) do { } while (0)
+9 -16
include/linux/lockdep.h
··· 252 252 unsigned int trylock:1; /* 16 bits */ 253 253 254 254 unsigned int read:2; /* see lock_acquire() comment */ 255 - unsigned int check:2; /* see lock_acquire() comment */ 255 + unsigned int check:1; /* see lock_acquire() comment */ 256 256 unsigned int hardirqs_off:1; 257 - unsigned int references:11; /* 32 bits */ 257 + unsigned int references:12; /* 32 bits */ 258 258 }; 259 259 260 260 /* ··· 326 326 * 327 327 * Values for check: 328 328 * 329 - * 0: disabled 330 - * 1: simple checks (freeing, held-at-exit-time, etc.) 331 - * 2: full validation 329 + * 0: simple checks (freeing, held-at-exit-time, etc.) 330 + * 1: full validation 332 331 */ 333 332 extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass, 334 333 int trylock, int read, int check, ··· 478 479 * on the per lock-class debug mode: 479 480 */ 480 481 481 - #ifdef CONFIG_PROVE_LOCKING 482 - #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 2, n, i) 483 - #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 2, n, i) 484 - #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 2, n, i) 485 - #else 486 - #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i) 487 - #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i) 488 - #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i) 489 - #endif 482 + #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i) 483 + #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i) 484 + #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i) 490 485 491 486 #define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) 492 487 #define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) ··· 511 518 # define might_lock(lock) \ 512 519 do { \ 513 520 typecheck(struct lockdep_map *, &(lock)->dep_map); \ 514 - lock_acquire(&(lock)->dep_map, 0, 0, 0, 2, NULL, _THIS_IP_); \ 521 + lock_acquire(&(lock)->dep_map, 0, 0, 0, 1, NULL, _THIS_IP_); \ 515 522 lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ 516 523 } while (0) 517 524 # define might_lock_read(lock) \ 518 525 do { \ 519 526 typecheck(struct lockdep_map *, &(lock)->dep_map); \ 520 - lock_acquire(&(lock)->dep_map, 0, 0, 1, 2, NULL, _THIS_IP_); \ 527 + lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_); \ 521 528 lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ 522 529 } while (0) 523 530 #else
+1 -1
include/linux/rcupdate.h
··· 314 314 315 315 static inline void rcu_lock_acquire(struct lockdep_map *map) 316 316 { 317 - lock_acquire(map, 0, 0, 2, 1, NULL, _THIS_IP_); 317 + lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_); 318 318 } 319 319 320 320 static inline void rcu_lock_release(struct lockdep_map *map)
+4 -7
kernel/locking/lockdep.c
··· 2098 2098 * (If lookup_chain_cache() returns with 1 it acquires 2099 2099 * graph_lock for us) 2100 2100 */ 2101 - if (!hlock->trylock && (hlock->check == 2) && 2101 + if (!hlock->trylock && hlock->check && 2102 2102 lookup_chain_cache(curr, hlock, chain_key)) { 2103 2103 /* 2104 2104 * Check whether last held lock: ··· 3055 3055 int class_idx; 3056 3056 u64 chain_key; 3057 3057 3058 - if (!prove_locking) 3059 - check = 1; 3060 - 3061 3058 if (unlikely(!debug_locks)) 3062 3059 return 0; 3063 3060 ··· 3066 3069 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) 3067 3070 return 0; 3068 3071 3069 - if (lock->key == &__lockdep_no_validate__) 3070 - check = 1; 3072 + if (!prove_locking || lock->key == &__lockdep_no_validate__) 3073 + check = 0; 3071 3074 3072 3075 if (subclass < NR_LOCKDEP_CACHING_CLASSES) 3073 3076 class = lock->class_cache[subclass]; ··· 3135 3138 hlock->holdtime_stamp = lockstat_clock(); 3136 3139 #endif 3137 3140 3138 - if (check == 2 && !mark_irqflags(curr, hlock)) 3141 + if (check && !mark_irqflags(curr, hlock)) 3139 3142 return 0; 3140 3143 3141 3144 /* mark it as used: */