Skip to content

Commit fb9edbe

Browse files
oleg-nesterovingomolnar
authored andcommitted
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>
1 parent ddf1d16 commit fb9edbe

4 files changed

Lines changed: 18 additions & 35 deletions

File tree

‎drivers/tty/tty_ldsem.c‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,10 @@
3939
lock_acquire(&(l)->dep_map, s, t, r, c, n, i)
4040
# define __rel(l, n, i) \
4141
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)
5346
#else
5447
# define lockdep_acquire(l, s, t, i) do { } while (0)
5548
# define lockdep_acquire_nest(l, s, t, n, i) do { } while (0)

‎include/linux/lockdep.h‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ struct held_lock {
252252
unsigned int trylock:1; /* 16 bits */
253253

254254
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 */
256256
unsigned int hardirqs_off:1;
257-
unsigned int references:11; /* 32 bits */
257+
unsigned int references:12; /* 32 bits */
258258
};
259259

260260
/*
@@ -326,9 +326,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
326326
*
327327
* Values for check:
328328
*
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
332331
*/
333332
extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
334333
int trylock, int read, int check,
@@ -479,15 +478,9 @@ static inline void print_irqtrace_events(struct task_struct *curr)
479478
* on the per lock-class debug mode:
480479
*/
481480

482-
#ifdef CONFIG_PROVE_LOCKING
483-
#define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 2, n, i)
484-
#define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 2, 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
481+
#define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i)
482+
#define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i)
483+
#define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i)
491484

492485
#define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
493486
#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)
518511
# define might_lock(lock) \
519512
do { \
520513
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_); \
522515
lock_release(&(lock)->dep_map, 0, _THIS_IP_); \
523516
} while (0)
524517
# define might_lock_read(lock) \
525518
do { \
526519
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_); \
528521
lock_release(&(lock)->dep_map, 0, _THIS_IP_); \
529522
} while (0)
530523
#else

‎include/linux/rcupdate.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static inline bool rcu_lockdep_current_cpu_online(void)
314314

315315
static inline void rcu_lock_acquire(struct lockdep_map *map)
316316
{
317-
lock_acquire(map, 0, 0, 2, 1, NULL, _THIS_IP_);
317+
lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_);
318318
}
319319

320320
static inline void rcu_lock_release(struct lockdep_map *map)

‎kernel/locking/lockdep.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,7 @@ static int validate_chain(struct task_struct *curr, struct lockdep_map *lock,
20982098
* (If lookup_chain_cache() returns with 1 it acquires
20992099
* graph_lock for us)
21002100
*/
2101-
if (!hlock->trylock && (hlock->check == 2) &&
2101+
if (!hlock->trylock && hlock->check &&
21022102
lookup_chain_cache(curr, hlock, chain_key)) {
21032103
/*
21042104
* Check whether last held lock:
@@ -3055,9 +3055,6 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
30553055
int class_idx;
30563056
u64 chain_key;
30573057

3058-
if (!prove_locking)
3059-
check = 1;
3060-
30613058
if (unlikely(!debug_locks))
30623059
return 0;
30633060

@@ -3069,8 +3066,8 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
30693066
if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
30703067
return 0;
30713068

3072-
if (lock->key == &__lockdep_no_validate__)
3073-
check = 1;
3069+
if (!prove_locking || lock->key == &__lockdep_no_validate__)
3070+
check = 0;
30743071

30753072
if (subclass < NR_LOCKDEP_CACHING_CLASSES)
30763073
class = lock->class_cache[subclass];
@@ -3138,7 +3135,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
31383135
hlock->holdtime_stamp = lockstat_clock();
31393136
#endif
31403137

3141-
if (check == 2 && !mark_irqflags(curr, hlock))
3138+
if (check && !mark_irqflags(curr, hlock))
31423139
return 0;
31433140

31443141
/* mark it as used: */

0 commit comments

Comments
 (0)