History

locking/lockdep: Mark local_lock_t

The local_lock_t's are special, because they cannot form IRQ inversions, make sure we can tell them apart from the rest of the locks.

Peter Zijlstra committed 5 years ago

Commit dfd5e3f1 parent 5831c0f4 files · +39 −15Browse files

Unified · Split

4 files
  1. include/linux/local_lock_internal.h +4 −1
  2. include/linux/lockdep.h +12 −3
  3. include/linux/lockdep_types.h +14 −4
  4. kernel/locking/lockdep.c +9 −7
include/linux/local_lock_internal.h+4−1
@@ -18,6 +18,7 @@ typedef struct { · 17 unmodified lines
1818 .dep_map = { \
1919 .name = #lockname, \
2020 .wait_type_inner = LD_WAIT_CONFIG, \
21+ .lock_type = LD_LOCK_PERCPU, \
2122 }
2223 #else
2324 # define LL_DEP_MAP_INIT(lockname)
@@ -30,7 +31,9 @@ do { \ · 6 unmodified lines
3031 static struct lock_class_key __key; \
3132 \
3233 debug_check_no_locks_freed((void *)lock, sizeof(*lock));\
33− lockdep_init_map_wait(&(lock)->dep_map, #lock, &__key, 0, LD_WAIT_CONFIG);\
34+ lockdep_init_map_type(&(lock)->dep_map, #lock, &__key, 0, \
35+ LD_WAIT_CONFIG, LD_WAIT_INV, \
36+ LD_LOCK_PERCPU); \
3437 } while (0)
3538
3639 #ifdef CONFIG_DEBUG_LOCK_ALLOC
include/linux/lockdep.h+12−3
@@ -185,12 +185,19 @@ extern void lockdep_unregister_key(struct lock_class_key *key); · 184 unmodified lines
185185 * to lockdep:
186186 */
187187
188−extern void lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
189− struct lock_class_key *key, int subclass, short inner, short outer);
188+extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
189+ struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
190+
191+static inline void
192+lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
193+ struct lock_class_key *key, int subclass, u8 inner, u8 outer)
194+{
195+ lockdep_init_map_type(lock, name, key, subclass, inner, LD_WAIT_INV, LD_LOCK_NORMAL);
196+}
190197
191198 static inline void
192199 lockdep_init_map_wait(struct lockdep_map *lock, const char *name,
193− struct lock_class_key *key, int subclass, short inner)
200+ struct lock_class_key *key, int subclass, u8 inner)
194201 {
195202 lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV);
196203 }
@@ -340,6 +347,8 @@ static inline void lockdep_set_selftest_task(struct task_struct *task) · 143 unmodified lines
340347 # define lock_set_class(l, n, k, s, i) do { } while (0)
341348 # define lock_set_subclass(l, s, i) do { } while (0)
342349 # define lockdep_init() do { } while (0)
350+# define lockdep_init_map_type(lock, name, key, sub, inner, outer, type) \
351+ do { (void)(name); (void)(key); } while (0)
343352 # define lockdep_init_map_waits(lock, name, key, sub, inner, outer) \
344353 do { (void)(name); (void)(key); } while (0)
345354 # define lockdep_init_map_wait(lock, name, key, sub, inner) \
include/linux/lockdep_types.h+14−4
@@ -30,6 +30,12 @@ enum lockdep_wait_type { · 29 unmodified lines
3030 LD_WAIT_MAX, /* must be last */
3131 };
3232
33+enum lockdep_lock_type {
34+ LD_LOCK_NORMAL = 0, /* normal, catch all */
35+ LD_LOCK_PERCPU, /* percpu */
36+ LD_LOCK_MAX,
37+};
38+
3339 #ifdef CONFIG_LOCKDEP
3440
3541 /*
@@ -119,8 +125,10 @@ struct lock_class { · 83 unmodified lines
119125 int name_version;
120126 const char *name;
121127
122− short wait_type_inner;
123− short wait_type_outer;
128+ u8 wait_type_inner;
129+ u8 wait_type_outer;
130+ u8 lock_type;
131+ /* u8 hole; */
124132
125133 #ifdef CONFIG_LOCK_STAT
126134 unsigned long contention_point[LOCKSTAT_POINTS];
@@ -169,8 +177,10 @@ struct lockdep_map { · 42 unmodified lines
169177 struct lock_class_key *key;
170178 struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
171179 const char *name;
172− short wait_type_outer; /* can be taken in this context */
173− short wait_type_inner; /* presents this context */
180+ u8 wait_type_outer; /* can be taken in this context */
181+ u8 wait_type_inner; /* presents this context */
182+ u8 lock_type;
183+ /* u8 hole; */
174184 #ifdef CONFIG_LOCK_STAT
175185 int cpu;
176186 unsigned long ip;
kernel/locking/lockdep.c+9−7
@@ -1290,6 +1290,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force) · 1289 unmodified lines
12901290 class->name_version = count_matching_names(class);
12911291 class->wait_type_inner = lock->wait_type_inner;
12921292 class->wait_type_outer = lock->wait_type_outer;
1293+ class->lock_type = lock->lock_type;
12931294 /*
12941295 * We use RCU's safe list-add method to make
12951296 * parallel walking of the hash-list safe:
@@ -4503,9 +4504,9 @@ print_lock_invalid_wait_context(struct task_struct *curr, · 3207 unmodified lines
45034504 */
45044505 static int check_wait_context(struct task_struct *curr, struct held_lock *next)
45054506 {
4506− short next_inner = hlock_class(next)->wait_type_inner;
4507− short next_outer = hlock_class(next)->wait_type_outer;
4508− short curr_inner;
4507+ u8 next_inner = hlock_class(next)->wait_type_inner;
4508+ u8 next_outer = hlock_class(next)->wait_type_outer;
4509+ u8 curr_inner;
45094510 int depth;
45104511
45114512 if (!curr->lockdep_depth || !next_inner || next->trylock)
@@ -4528,7 +4529,7 @@ static int check_wait_context(struct task_struct *curr, struct held_lock *next) · 16 unmodified lines
45284529
45294530 for (; depth < curr->lockdep_depth; depth++) {
45304531 struct held_lock *prev = curr->held_locks + depth;
4531− short prev_inner = hlock_class(prev)->wait_type_inner;
4532+ u8 prev_inner = hlock_class(prev)->wait_type_inner;
45324533
45334534 if (prev_inner) {
45344535 /*
@@ -4577,9 +4578,9 @@ static inline int check_wait_context(struct task_struct *curr, · 42 unmodified lines
45774578 /*
45784579 * Initialize a lock instance's lock-class mapping info:
45794580 */
4580−void lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
4581+void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
45814582 struct lock_class_key *key, int subclass,
4582− short inner, short outer)
4583+ u8 inner, u8 outer, u8 lock_type)
45834584 {
45844585 int i;
45854586
@@ -4602,6 +4603,7 @@ void lockdep_init_map_waits(struct lockdep_map *lock, const char *name, · 16 unmodified lines
46024603
46034604 lock->wait_type_outer = outer;
46044605 lock->wait_type_inner = inner;
4606+ lock->lock_type = lock_type;
46054607
46064608 /*
46074609 * No key, no joy, we need to hash something.
@@ -4636,7 +4638,7 @@ void lockdep_init_map_waits(struct lockdep_map *lock, const char *name, · 28 unmodified lines
46364638 raw_local_irq_restore(flags);
46374639 }
46384640 }
4639−EXPORT_SYMBOL_GPL(lockdep_init_map_waits);
4641+EXPORT_SYMBOL_GPL(lockdep_init_map_type);
46404642
46414643 struct lock_class_key __lockdep_no_validate__;
46424644 EXPORT_SYMBOL_GPL(__lockdep_no_validate__);