diff options
| author | Oleg Nesterov <oleg@redhat.com> | 2014-01-20 13:20:06 -0500 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2014-02-09 15:18:54 -0500 |
| commit | fb9edbe98493fcd9df66de926ae9157cbe0e4dcd (patch) | |
| tree | 9fc6c5acfcd5c99bd9cf13a177ea3fd0b794cb3f | |
| parent | ddf1d169c0a489d498c1799a7043904a43b0c159 (diff) | |
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>
| -rw-r--r-- | drivers/tty/tty_ldsem.c | 15 | ||||
| -rw-r--r-- | include/linux/lockdep.h | 25 | ||||
| -rw-r--r-- | include/linux/rcupdate.h | 2 | ||||
| -rw-r--r-- | kernel/locking/lockdep.c | 11 |
4 files changed, 18 insertions, 35 deletions
diff --git a/drivers/tty/tty_ldsem.c b/drivers/tty/tty_ldsem.c index d8a55e87877f..0ffb0cbe2823 100644 --- a/drivers/tty/tty_ldsem.c +++ b/drivers/tty/tty_ldsem.c | |||
| @@ -39,17 +39,10 @@ | |||
| 39 | lock_acquire(&(l)->dep_map, s, t, r, c, n, i) | 39 | lock_acquire(&(l)->dep_map, s, t, r, c, n, i) |
| 40 | # define __rel(l, n, i) \ | 40 | # define __rel(l, n, i) \ |
| 41 | lock_release(&(l)->dep_map, n, i) | 41 | lock_release(&(l)->dep_map, n, i) |
| 42 | # ifdef CONFIG_PROVE_LOCKING | 42 | #define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 1, NULL, i) |
| 43 | # define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 2, NULL, i) | 43 | #define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 1, n, i) |
| 44 | # define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 2, n, i) | 44 | #define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 1, NULL, i) |
| 45 | # define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 2, NULL, i) | 45 | #define lockdep_release(l, n, i) __rel(l, n, 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 | ||
| 53 | #else | 46 | #else |
| 54 | # define lockdep_acquire(l, s, t, i) do { } while (0) | 47 | # define lockdep_acquire(l, s, t, i) do { } while (0) |
| 55 | # define lockdep_acquire_nest(l, s, t, n, i) do { } while (0) | 48 | # define lockdep_acquire_nest(l, s, t, n, i) do { } while (0) |
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 92b1bfc5da60..1626047c1f26 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h | |||
| @@ -252,9 +252,9 @@ struct held_lock { | |||
| 252 | unsigned int trylock:1; /* 16 bits */ | 252 | unsigned int trylock:1; /* 16 bits */ |
| 253 | 253 | ||
| 254 | unsigned int read:2; /* see lock_acquire() comment */ | 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 | unsigned int hardirqs_off:1; | 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,9 +326,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock, | |||
| 326 | * | 326 | * |
| 327 | * Values for check: | 327 | * Values for check: |
| 328 | * | 328 | * |
| 329 | * 0: disabled | 329 | * 0: simple checks (freeing, held-at-exit-time, etc.) |
| 330 | * 1: simple checks (freeing, held-at-exit-time, etc.) | 330 | * 1: full validation |
| 331 | * 2: full validation | ||
| 332 | */ | 331 | */ |
| 333 | extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass, | 332 | extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass, |
| 334 | int trylock, int read, int check, | 333 | int trylock, int read, int check, |
| @@ -479,15 +478,9 @@ static inline void print_irqtrace_events(struct task_struct *curr) | |||
| 479 | * on the per lock-class debug mode: | 478 | * on the per lock-class debug mode: |
| 480 | */ | 479 | */ |
| 481 | 480 | ||
| 482 | #ifdef CONFIG_PROVE_LOCKING | 481 | #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i) |
| 483 | #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 2, n, i) | 482 | #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i) |
| 484 | #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 2, n, i) | 483 | #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i) |
| 485 | #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 2, n, i) | ||
| 486 | #else | ||
| 487 | #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i) | ||
| 488 | #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i) | ||
| 489 | #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i) | ||
| 490 | #endif | ||
| 491 | 484 | ||
| 492 | #define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) | 485 | #define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) |
| 493 | #define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) | 486 | #define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) |
| @@ -518,13 +511,13 @@ static inline void print_irqtrace_events(struct task_struct *curr) | |||
| 518 | # define might_lock(lock) \ | 511 | # define might_lock(lock) \ |
| 519 | do { \ | 512 | do { \ |
| 520 | typecheck(struct lockdep_map *, &(lock)->dep_map); \ | 513 | typecheck(struct lockdep_map *, &(lock)->dep_map); \ |
| 521 | lock_acquire(&(lock)->dep_map, 0, 0, 0, 2, NULL, _THIS_IP_); \ | 514 | lock_acquire(&(lock)->dep_map, 0, 0, 0, 1, NULL, _THIS_IP_); \ |
| 522 | lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ | 515 | lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ |
| 523 | } while (0) | 516 | } while (0) |
| 524 | # define might_lock_read(lock) \ | 517 | # define might_lock_read(lock) \ |
| 525 | do { \ | 518 | do { \ |
| 526 | typecheck(struct lockdep_map *, &(lock)->dep_map); \ | 519 | typecheck(struct lockdep_map *, &(lock)->dep_map); \ |
| 527 | lock_acquire(&(lock)->dep_map, 0, 0, 1, 2, NULL, _THIS_IP_); \ | 520 | lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_); \ |
| 528 | lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ | 521 | lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ |
| 529 | } while (0) | 522 | } while (0) |
| 530 | #else | 523 | #else |
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 72bf3a01a4ee..adff3c99dcaa 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h | |||
| @@ -314,7 +314,7 @@ static inline bool rcu_lockdep_current_cpu_online(void) | |||
| 314 | 314 | ||
| 315 | static inline void rcu_lock_acquire(struct lockdep_map *map) | 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 | static inline void rcu_lock_release(struct lockdep_map *map) | 320 | static inline void rcu_lock_release(struct lockdep_map *map) |
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index eb8a54783fa0..8c85a0da5a38 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c | |||
| @@ -2098,7 +2098,7 @@ static int validate_chain(struct task_struct *curr, struct lockdep_map *lock, | |||
| 2098 | * (If lookup_chain_cache() returns with 1 it acquires | 2098 | * (If lookup_chain_cache() returns with 1 it acquires |
| 2099 | * graph_lock for us) | 2099 | * graph_lock for us) |
| 2100 | */ | 2100 | */ |
| 2101 | if (!hlock->trylock && (hlock->check == 2) && | 2101 | if (!hlock->trylock && hlock->check && |
| 2102 | lookup_chain_cache(curr, hlock, chain_key)) { | 2102 | lookup_chain_cache(curr, hlock, chain_key)) { |
| 2103 | /* | 2103 | /* |
| 2104 | * Check whether last held lock: | 2104 | * Check whether last held lock: |
| @@ -3055,9 +3055,6 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 3055 | int class_idx; | 3055 | int class_idx; |
| 3056 | u64 chain_key; | 3056 | u64 chain_key; |
| 3057 | 3057 | ||
| 3058 | if (!prove_locking) | ||
| 3059 | check = 1; | ||
| 3060 | |||
| 3061 | if (unlikely(!debug_locks)) | 3058 | if (unlikely(!debug_locks)) |
| 3062 | return 0; | 3059 | return 0; |
| 3063 | 3060 | ||
| @@ -3069,8 +3066,8 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 3069 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) | 3066 | if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) |
| 3070 | return 0; | 3067 | return 0; |
| 3071 | 3068 | ||
| 3072 | if (lock->key == &__lockdep_no_validate__) | 3069 | if (!prove_locking || lock->key == &__lockdep_no_validate__) |
| 3073 | check = 1; | 3070 | check = 0; |
| 3074 | 3071 | ||
| 3075 | if (subclass < NR_LOCKDEP_CACHING_CLASSES) | 3072 | if (subclass < NR_LOCKDEP_CACHING_CLASSES) |
| 3076 | class = lock->class_cache[subclass]; | 3073 | class = lock->class_cache[subclass]; |
| @@ -3138,7 +3135,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 3138 | hlock->holdtime_stamp = lockstat_clock(); | 3135 | hlock->holdtime_stamp = lockstat_clock(); |
| 3139 | #endif | 3136 | #endif |
| 3140 | 3137 | ||
| 3141 | if (check == 2 && !mark_irqflags(curr, hlock)) | 3138 | if (check && !mark_irqflags(curr, hlock)) |
| 3142 | return 0; | 3139 | return 0; |
| 3143 | 3140 | ||
| 3144 | /* mark it as used: */ | 3141 | /* mark it as used: */ |
