xref: /linux-6.15/include/linux/lockdep.h (revision 4de87f45)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Runtime locking correctness validator
4  *
5  *  Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <[email protected]>
6  *  Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
7  *
8  * see Documentation/locking/lockdep-design.rst for more details.
9  */
10 #ifndef __LINUX_LOCKDEP_H
11 #define __LINUX_LOCKDEP_H
12 
13 struct task_struct;
14 struct lockdep_map;
15 
16 /* for sysctl */
17 extern int prove_locking;
18 extern int lock_stat;
19 
20 #define MAX_LOCKDEP_SUBCLASSES		8UL
21 
22 #include <linux/types.h>
23 
24 enum lockdep_wait_type {
25 	LD_WAIT_INV = 0,	/* not checked, catch all */
26 
27 	LD_WAIT_FREE,		/* wait free, rcu etc.. */
28 	LD_WAIT_SPIN,		/* spin loops, raw_spinlock_t etc.. */
29 
30 #ifdef CONFIG_PROVE_RAW_LOCK_NESTING
31 	LD_WAIT_CONFIG,		/* CONFIG_PREEMPT_LOCK, spinlock_t etc.. */
32 #else
33 	LD_WAIT_CONFIG = LD_WAIT_SPIN,
34 #endif
35 	LD_WAIT_SLEEP,		/* sleeping locks, mutex_t etc.. */
36 
37 	LD_WAIT_MAX,		/* must be last */
38 };
39 
40 #ifdef CONFIG_LOCKDEP
41 
42 #include <linux/linkage.h>
43 #include <linux/list.h>
44 #include <linux/debug_locks.h>
45 #include <linux/stacktrace.h>
46 
47 /*
48  * We'd rather not expose kernel/lockdep_states.h this wide, but we do need
49  * the total number of states... :-(
50  */
51 #define XXX_LOCK_USAGE_STATES		(1+2*4)
52 
53 /*
54  * NR_LOCKDEP_CACHING_CLASSES ... Number of classes
55  * cached in the instance of lockdep_map
56  *
57  * Currently main class (subclass == 0) and signle depth subclass
58  * are cached in lockdep_map. This optimization is mainly targeting
59  * on rq->lock. double_rq_lock() acquires this highly competitive with
60  * single depth.
61  */
62 #define NR_LOCKDEP_CACHING_CLASSES	2
63 
64 /*
65  * A lockdep key is associated with each lock object. For static locks we use
66  * the lock address itself as the key. Dynamically allocated lock objects can
67  * have a statically or dynamically allocated key. Dynamically allocated lock
68  * keys must be registered before being used and must be unregistered before
69  * the key memory is freed.
70  */
71 struct lockdep_subclass_key {
72 	char __one_byte;
73 } __attribute__ ((__packed__));
74 
75 /* hash_entry is used to keep track of dynamically allocated keys. */
76 struct lock_class_key {
77 	union {
78 		struct hlist_node		hash_entry;
79 		struct lockdep_subclass_key	subkeys[MAX_LOCKDEP_SUBCLASSES];
80 	};
81 };
82 
83 extern struct lock_class_key __lockdep_no_validate__;
84 
85 struct lock_trace;
86 
87 #define LOCKSTAT_POINTS		4
88 
89 /*
90  * The lock-class itself. The order of the structure members matters.
91  * reinit_class() zeroes the key member and all subsequent members.
92  */
93 struct lock_class {
94 	/*
95 	 * class-hash:
96 	 */
97 	struct hlist_node		hash_entry;
98 
99 	/*
100 	 * Entry in all_lock_classes when in use. Entry in free_lock_classes
101 	 * when not in use. Instances that are being freed are on one of the
102 	 * zapped_classes lists.
103 	 */
104 	struct list_head		lock_entry;
105 
106 	/*
107 	 * These fields represent a directed graph of lock dependencies,
108 	 * to every node we attach a list of "forward" and a list of
109 	 * "backward" graph nodes.
110 	 */
111 	struct list_head		locks_after, locks_before;
112 
113 	const struct lockdep_subclass_key *key;
114 	unsigned int			subclass;
115 	unsigned int			dep_gen_id;
116 
117 	/*
118 	 * IRQ/softirq usage tracking bits:
119 	 */
120 	unsigned long			usage_mask;
121 	const struct lock_trace		*usage_traces[XXX_LOCK_USAGE_STATES];
122 
123 	/*
124 	 * Generation counter, when doing certain classes of graph walking,
125 	 * to ensure that we check one node only once:
126 	 */
127 	int				name_version;
128 	const char			*name;
129 
130 	short				wait_type_inner;
131 	short				wait_type_outer;
132 
133 #ifdef CONFIG_LOCK_STAT
134 	unsigned long			contention_point[LOCKSTAT_POINTS];
135 	unsigned long			contending_point[LOCKSTAT_POINTS];
136 #endif
137 } __no_randomize_layout;
138 
139 #ifdef CONFIG_LOCK_STAT
140 struct lock_time {
141 	s64				min;
142 	s64				max;
143 	s64				total;
144 	unsigned long			nr;
145 };
146 
147 enum bounce_type {
148 	bounce_acquired_write,
149 	bounce_acquired_read,
150 	bounce_contended_write,
151 	bounce_contended_read,
152 	nr_bounce_types,
153 
154 	bounce_acquired = bounce_acquired_write,
155 	bounce_contended = bounce_contended_write,
156 };
157 
158 struct lock_class_stats {
159 	unsigned long			contention_point[LOCKSTAT_POINTS];
160 	unsigned long			contending_point[LOCKSTAT_POINTS];
161 	struct lock_time		read_waittime;
162 	struct lock_time		write_waittime;
163 	struct lock_time		read_holdtime;
164 	struct lock_time		write_holdtime;
165 	unsigned long			bounces[nr_bounce_types];
166 };
167 
168 struct lock_class_stats lock_stats(struct lock_class *class);
169 void clear_lock_stats(struct lock_class *class);
170 #endif
171 
172 /*
173  * Map the lock object (the lock instance) to the lock-class object.
174  * This is embedded into specific lock instances:
175  */
176 struct lockdep_map {
177 	struct lock_class_key		*key;
178 	struct lock_class		*class_cache[NR_LOCKDEP_CACHING_CLASSES];
179 	const char			*name;
180 	short				wait_type_outer; /* can be taken in this context */
181 	short				wait_type_inner; /* presents this context */
182 #ifdef CONFIG_LOCK_STAT
183 	int				cpu;
184 	unsigned long			ip;
185 #endif
186 };
187 
188 static inline void lockdep_copy_map(struct lockdep_map *to,
189 				    struct lockdep_map *from)
190 {
191 	int i;
192 
193 	*to = *from;
194 	/*
195 	 * Since the class cache can be modified concurrently we could observe
196 	 * half pointers (64bit arch using 32bit copy insns). Therefore clear
197 	 * the caches and take the performance hit.
198 	 *
199 	 * XXX it doesn't work well with lockdep_set_class_and_subclass(), since
200 	 *     that relies on cache abuse.
201 	 */
202 	for (i = 0; i < NR_LOCKDEP_CACHING_CLASSES; i++)
203 		to->class_cache[i] = NULL;
204 }
205 
206 /*
207  * Every lock has a list of other locks that were taken after it.
208  * We only grow the list, never remove from it:
209  */
210 struct lock_list {
211 	struct list_head		entry;
212 	struct lock_class		*class;
213 	struct lock_class		*links_to;
214 	const struct lock_trace		*trace;
215 	int				distance;
216 
217 	/*
218 	 * The parent field is used to implement breadth-first search, and the
219 	 * bit 0 is reused to indicate if the lock has been accessed in BFS.
220 	 */
221 	struct lock_list		*parent;
222 };
223 
224 /**
225  * struct lock_chain - lock dependency chain record
226  *
227  * @irq_context: the same as irq_context in held_lock below
228  * @depth:       the number of held locks in this chain
229  * @base:        the index in chain_hlocks for this chain
230  * @entry:       the collided lock chains in lock_chain hash list
231  * @chain_key:   the hash key of this lock_chain
232  */
233 struct lock_chain {
234 	/* see BUILD_BUG_ON()s in add_chain_cache() */
235 	unsigned int			irq_context :  2,
236 					depth       :  6,
237 					base	    : 24;
238 	/* 4 byte hole */
239 	struct hlist_node		entry;
240 	u64				chain_key;
241 };
242 
243 #define MAX_LOCKDEP_KEYS_BITS		13
244 #define MAX_LOCKDEP_KEYS		(1UL << MAX_LOCKDEP_KEYS_BITS)
245 #define INITIAL_CHAIN_KEY		-1
246 
247 struct held_lock {
248 	/*
249 	 * One-way hash of the dependency chain up to this point. We
250 	 * hash the hashes step by step as the dependency chain grows.
251 	 *
252 	 * We use it for dependency-caching and we skip detection
253 	 * passes and dependency-updates if there is a cache-hit, so
254 	 * it is absolutely critical for 100% coverage of the validator
255 	 * to have a unique key value for every unique dependency path
256 	 * that can occur in the system, to make a unique hash value
257 	 * as likely as possible - hence the 64-bit width.
258 	 *
259 	 * The task struct holds the current hash value (initialized
260 	 * with zero), here we store the previous hash value:
261 	 */
262 	u64				prev_chain_key;
263 	unsigned long			acquire_ip;
264 	struct lockdep_map		*instance;
265 	struct lockdep_map		*nest_lock;
266 #ifdef CONFIG_LOCK_STAT
267 	u64 				waittime_stamp;
268 	u64				holdtime_stamp;
269 #endif
270 	/*
271 	 * class_idx is zero-indexed; it points to the element in
272 	 * lock_classes this held lock instance belongs to. class_idx is in
273 	 * the range from 0 to (MAX_LOCKDEP_KEYS-1) inclusive.
274 	 */
275 	unsigned int			class_idx:MAX_LOCKDEP_KEYS_BITS;
276 	/*
277 	 * The lock-stack is unified in that the lock chains of interrupt
278 	 * contexts nest ontop of process context chains, but we 'separate'
279 	 * the hashes by starting with 0 if we cross into an interrupt
280 	 * context, and we also keep do not add cross-context lock
281 	 * dependencies - the lock usage graph walking covers that area
282 	 * anyway, and we'd just unnecessarily increase the number of
283 	 * dependencies otherwise. [Note: hardirq and softirq contexts
284 	 * are separated from each other too.]
285 	 *
286 	 * The following field is used to detect when we cross into an
287 	 * interrupt context:
288 	 */
289 	unsigned int irq_context:2; /* bit 0 - soft, bit 1 - hard */
290 	unsigned int trylock:1;						/* 16 bits */
291 
292 	unsigned int read:2;        /* see lock_acquire() comment */
293 	unsigned int check:1;       /* see lock_acquire() comment */
294 	unsigned int hardirqs_off:1;
295 	unsigned int references:12;					/* 32 bits */
296 	unsigned int pin_count;
297 };
298 
299 /*
300  * Initialization, self-test and debugging-output methods:
301  */
302 extern void lockdep_init(void);
303 extern void lockdep_reset(void);
304 extern void lockdep_reset_lock(struct lockdep_map *lock);
305 extern void lockdep_free_key_range(void *start, unsigned long size);
306 extern asmlinkage void lockdep_sys_exit(void);
307 extern void lockdep_set_selftest_task(struct task_struct *task);
308 
309 extern void lockdep_init_task(struct task_struct *task);
310 
311 /*
312  * Split the recrursion counter in two to readily detect 'off' vs recursion.
313  */
314 #define LOCKDEP_RECURSION_BITS	16
315 #define LOCKDEP_OFF		(1U << LOCKDEP_RECURSION_BITS)
316 #define LOCKDEP_RECURSION_MASK	(LOCKDEP_OFF - 1)
317 
318 /*
319  * lockdep_{off,on}() are macros to avoid tracing and kprobes; not inlines due
320  * to header dependencies.
321  */
322 
323 #define lockdep_off()					\
324 do {							\
325 	current->lockdep_recursion += LOCKDEP_OFF;	\
326 } while (0)
327 
328 #define lockdep_on()					\
329 do {							\
330 	current->lockdep_recursion -= LOCKDEP_OFF;	\
331 } while (0)
332 
333 extern void lockdep_register_key(struct lock_class_key *key);
334 extern void lockdep_unregister_key(struct lock_class_key *key);
335 
336 /*
337  * These methods are used by specific locking variants (spinlocks,
338  * rwlocks, mutexes and rwsems) to pass init/acquire/release events
339  * to lockdep:
340  */
341 
342 extern void lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
343 	struct lock_class_key *key, int subclass, short inner, short outer);
344 
345 static inline void
346 lockdep_init_map_wait(struct lockdep_map *lock, const char *name,
347 		      struct lock_class_key *key, int subclass, short inner)
348 {
349 	lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV);
350 }
351 
352 static inline void lockdep_init_map(struct lockdep_map *lock, const char *name,
353 			     struct lock_class_key *key, int subclass)
354 {
355 	lockdep_init_map_wait(lock, name, key, subclass, LD_WAIT_INV);
356 }
357 
358 /*
359  * Reinitialize a lock key - for cases where there is special locking or
360  * special initialization of locks so that the validator gets the scope
361  * of dependencies wrong: they are either too broad (they need a class-split)
362  * or they are too narrow (they suffer from a false class-split):
363  */
364 #define lockdep_set_class(lock, key)				\
365 	lockdep_init_map_waits(&(lock)->dep_map, #key, key, 0,	\
366 			       (lock)->dep_map.wait_type_inner,	\
367 			       (lock)->dep_map.wait_type_outer)
368 
369 #define lockdep_set_class_and_name(lock, key, name)		\
370 	lockdep_init_map_waits(&(lock)->dep_map, name, key, 0,	\
371 			       (lock)->dep_map.wait_type_inner,	\
372 			       (lock)->dep_map.wait_type_outer)
373 
374 #define lockdep_set_class_and_subclass(lock, key, sub)		\
375 	lockdep_init_map_waits(&(lock)->dep_map, #key, key, sub,\
376 			       (lock)->dep_map.wait_type_inner,	\
377 			       (lock)->dep_map.wait_type_outer)
378 
379 #define lockdep_set_subclass(lock, sub)					\
380 	lockdep_init_map_waits(&(lock)->dep_map, #lock, (lock)->dep_map.key, sub,\
381 			       (lock)->dep_map.wait_type_inner,		\
382 			       (lock)->dep_map.wait_type_outer)
383 
384 #define lockdep_set_novalidate_class(lock) \
385 	lockdep_set_class_and_name(lock, &__lockdep_no_validate__, #lock)
386 
387 /*
388  * Compare locking classes
389  */
390 #define lockdep_match_class(lock, key) lockdep_match_key(&(lock)->dep_map, key)
391 
392 static inline int lockdep_match_key(struct lockdep_map *lock,
393 				    struct lock_class_key *key)
394 {
395 	return lock->key == key;
396 }
397 
398 /*
399  * Acquire a lock.
400  *
401  * Values for "read":
402  *
403  *   0: exclusive (write) acquire
404  *   1: read-acquire (no recursion allowed)
405  *   2: read-acquire with same-instance recursion allowed
406  *
407  * Values for check:
408  *
409  *   0: simple checks (freeing, held-at-exit-time, etc.)
410  *   1: full validation
411  */
412 extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
413 			 int trylock, int read, int check,
414 			 struct lockdep_map *nest_lock, unsigned long ip);
415 
416 extern void lock_release(struct lockdep_map *lock, unsigned long ip);
417 
418 /*
419  * Same "read" as for lock_acquire(), except -1 means any.
420  */
421 extern int lock_is_held_type(const struct lockdep_map *lock, int read);
422 
423 static inline int lock_is_held(const struct lockdep_map *lock)
424 {
425 	return lock_is_held_type(lock, -1);
426 }
427 
428 #define lockdep_is_held(lock)		lock_is_held(&(lock)->dep_map)
429 #define lockdep_is_held_type(lock, r)	lock_is_held_type(&(lock)->dep_map, (r))
430 
431 extern void lock_set_class(struct lockdep_map *lock, const char *name,
432 			   struct lock_class_key *key, unsigned int subclass,
433 			   unsigned long ip);
434 
435 static inline void lock_set_subclass(struct lockdep_map *lock,
436 		unsigned int subclass, unsigned long ip)
437 {
438 	lock_set_class(lock, lock->name, lock->key, subclass, ip);
439 }
440 
441 extern void lock_downgrade(struct lockdep_map *lock, unsigned long ip);
442 
443 struct pin_cookie { unsigned int val; };
444 
445 #define NIL_COOKIE (struct pin_cookie){ .val = 0U, }
446 
447 extern struct pin_cookie lock_pin_lock(struct lockdep_map *lock);
448 extern void lock_repin_lock(struct lockdep_map *lock, struct pin_cookie);
449 extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie);
450 
451 #define lockdep_depth(tsk)	(debug_locks ? (tsk)->lockdep_depth : 0)
452 
453 #define lockdep_assert_held(l)	do {				\
454 		WARN_ON(debug_locks && !lockdep_is_held(l));	\
455 	} while (0)
456 
457 #define lockdep_assert_held_write(l)	do {			\
458 		WARN_ON(debug_locks && !lockdep_is_held_type(l, 0));	\
459 	} while (0)
460 
461 #define lockdep_assert_held_read(l)	do {				\
462 		WARN_ON(debug_locks && !lockdep_is_held_type(l, 1));	\
463 	} while (0)
464 
465 #define lockdep_assert_held_once(l)	do {				\
466 		WARN_ON_ONCE(debug_locks && !lockdep_is_held(l));	\
467 	} while (0)
468 
469 #define lockdep_recursing(tsk)	((tsk)->lockdep_recursion)
470 
471 #define lockdep_pin_lock(l)	lock_pin_lock(&(l)->dep_map)
472 #define lockdep_repin_lock(l,c)	lock_repin_lock(&(l)->dep_map, (c))
473 #define lockdep_unpin_lock(l,c)	lock_unpin_lock(&(l)->dep_map, (c))
474 
475 #else /* !CONFIG_LOCKDEP */
476 
477 static inline void lockdep_init_task(struct task_struct *task)
478 {
479 }
480 
481 static inline void lockdep_off(void)
482 {
483 }
484 
485 static inline void lockdep_on(void)
486 {
487 }
488 
489 static inline void lockdep_set_selftest_task(struct task_struct *task)
490 {
491 }
492 
493 # define lock_acquire(l, s, t, r, c, n, i)	do { } while (0)
494 # define lock_release(l, i)			do { } while (0)
495 # define lock_downgrade(l, i)			do { } while (0)
496 # define lock_set_class(l, n, k, s, i)		do { } while (0)
497 # define lock_set_subclass(l, s, i)		do { } while (0)
498 # define lockdep_init()				do { } while (0)
499 # define lockdep_init_map_waits(lock, name, key, sub, inner, outer) \
500 		do { (void)(name); (void)(key); } while (0)
501 # define lockdep_init_map_wait(lock, name, key, sub, inner) \
502 		do { (void)(name); (void)(key); } while (0)
503 # define lockdep_init_map(lock, name, key, sub) \
504 		do { (void)(name); (void)(key); } while (0)
505 # define lockdep_set_class(lock, key)		do { (void)(key); } while (0)
506 # define lockdep_set_class_and_name(lock, key, name) \
507 		do { (void)(key); (void)(name); } while (0)
508 #define lockdep_set_class_and_subclass(lock, key, sub) \
509 		do { (void)(key); } while (0)
510 #define lockdep_set_subclass(lock, sub)		do { } while (0)
511 
512 #define lockdep_set_novalidate_class(lock) do { } while (0)
513 
514 /*
515  * We don't define lockdep_match_class() and lockdep_match_key() for !LOCKDEP
516  * case since the result is not well defined and the caller should rather
517  * #ifdef the call himself.
518  */
519 
520 # define lockdep_reset()		do { debug_locks = 1; } while (0)
521 # define lockdep_free_key_range(start, size)	do { } while (0)
522 # define lockdep_sys_exit() 			do { } while (0)
523 /*
524  * The class key takes no space if lockdep is disabled:
525  */
526 struct lock_class_key { };
527 
528 static inline void lockdep_register_key(struct lock_class_key *key)
529 {
530 }
531 
532 static inline void lockdep_unregister_key(struct lock_class_key *key)
533 {
534 }
535 
536 /*
537  * The lockdep_map takes no space if lockdep is disabled:
538  */
539 struct lockdep_map { };
540 
541 #define lockdep_depth(tsk)	(0)
542 
543 #define lockdep_is_held_type(l, r)		(1)
544 
545 #define lockdep_assert_held(l)			do { (void)(l); } while (0)
546 #define lockdep_assert_held_write(l)	do { (void)(l); } while (0)
547 #define lockdep_assert_held_read(l)		do { (void)(l); } while (0)
548 #define lockdep_assert_held_once(l)		do { (void)(l); } while (0)
549 
550 #define lockdep_recursing(tsk)			(0)
551 
552 struct pin_cookie { };
553 
554 #define NIL_COOKIE (struct pin_cookie){ }
555 
556 #define lockdep_pin_lock(l)			({ struct pin_cookie cookie = { }; cookie; })
557 #define lockdep_repin_lock(l, c)		do { (void)(l); (void)(c); } while (0)
558 #define lockdep_unpin_lock(l, c)		do { (void)(l); (void)(c); } while (0)
559 
560 #endif /* !LOCKDEP */
561 
562 enum xhlock_context_t {
563 	XHLOCK_HARD,
564 	XHLOCK_SOFT,
565 	XHLOCK_CTX_NR,
566 };
567 
568 #define lockdep_init_map_crosslock(m, n, k, s) do {} while (0)
569 /*
570  * To initialize a lockdep_map statically use this macro.
571  * Note that _name must not be NULL.
572  */
573 #define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
574 	{ .name = (_name), .key = (void *)(_key), }
575 
576 static inline void lockdep_invariant_state(bool force) {}
577 static inline void lockdep_free_task(struct task_struct *task) {}
578 
579 #ifdef CONFIG_LOCK_STAT
580 
581 extern void lock_contended(struct lockdep_map *lock, unsigned long ip);
582 extern void lock_acquired(struct lockdep_map *lock, unsigned long ip);
583 
584 #define LOCK_CONTENDED(_lock, try, lock)			\
585 do {								\
586 	if (!try(_lock)) {					\
587 		lock_contended(&(_lock)->dep_map, _RET_IP_);	\
588 		lock(_lock);					\
589 	}							\
590 	lock_acquired(&(_lock)->dep_map, _RET_IP_);			\
591 } while (0)
592 
593 #define LOCK_CONTENDED_RETURN(_lock, try, lock)			\
594 ({								\
595 	int ____err = 0;					\
596 	if (!try(_lock)) {					\
597 		lock_contended(&(_lock)->dep_map, _RET_IP_);	\
598 		____err = lock(_lock);				\
599 	}							\
600 	if (!____err)						\
601 		lock_acquired(&(_lock)->dep_map, _RET_IP_);	\
602 	____err;						\
603 })
604 
605 #else /* CONFIG_LOCK_STAT */
606 
607 #define lock_contended(lockdep_map, ip) do {} while (0)
608 #define lock_acquired(lockdep_map, ip) do {} while (0)
609 
610 #define LOCK_CONTENDED(_lock, try, lock) \
611 	lock(_lock)
612 
613 #define LOCK_CONTENDED_RETURN(_lock, try, lock) \
614 	lock(_lock)
615 
616 #endif /* CONFIG_LOCK_STAT */
617 
618 #ifdef CONFIG_LOCKDEP
619 
620 /*
621  * On lockdep we dont want the hand-coded irq-enable of
622  * _raw_*_lock_flags() code, because lockdep assumes
623  * that interrupts are not re-enabled during lock-acquire:
624  */
625 #define LOCK_CONTENDED_FLAGS(_lock, try, lock, lockfl, flags) \
626 	LOCK_CONTENDED((_lock), (try), (lock))
627 
628 #else /* CONFIG_LOCKDEP */
629 
630 #define LOCK_CONTENDED_FLAGS(_lock, try, lock, lockfl, flags) \
631 	lockfl((_lock), (flags))
632 
633 #endif /* CONFIG_LOCKDEP */
634 
635 #ifdef CONFIG_PROVE_LOCKING
636 extern void print_irqtrace_events(struct task_struct *curr);
637 #else
638 static inline void print_irqtrace_events(struct task_struct *curr)
639 {
640 }
641 #endif
642 
643 /*
644  * For trivial one-depth nesting of a lock-class, the following
645  * global define can be used. (Subsystems with multiple levels
646  * of nesting should define their own lock-nesting subclasses.)
647  */
648 #define SINGLE_DEPTH_NESTING			1
649 
650 /*
651  * Map the dependency ops to NOP or to real lockdep ops, depending
652  * on the per lock-class debug mode:
653  */
654 
655 #define lock_acquire_exclusive(l, s, t, n, i)		lock_acquire(l, s, t, 0, 1, n, i)
656 #define lock_acquire_shared(l, s, t, n, i)		lock_acquire(l, s, t, 1, 1, n, i)
657 #define lock_acquire_shared_recursive(l, s, t, n, i)	lock_acquire(l, s, t, 2, 1, n, i)
658 
659 #define spin_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
660 #define spin_acquire_nest(l, s, t, n, i)	lock_acquire_exclusive(l, s, t, n, i)
661 #define spin_release(l, i)			lock_release(l, i)
662 
663 #define rwlock_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
664 #define rwlock_acquire_read(l, s, t, i)		lock_acquire_shared_recursive(l, s, t, NULL, i)
665 #define rwlock_release(l, i)			lock_release(l, i)
666 
667 #define seqcount_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
668 #define seqcount_acquire_read(l, s, t, i)	lock_acquire_shared_recursive(l, s, t, NULL, i)
669 #define seqcount_release(l, i)			lock_release(l, i)
670 
671 #define mutex_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
672 #define mutex_acquire_nest(l, s, t, n, i)	lock_acquire_exclusive(l, s, t, n, i)
673 #define mutex_release(l, i)			lock_release(l, i)
674 
675 #define rwsem_acquire(l, s, t, i)		lock_acquire_exclusive(l, s, t, NULL, i)
676 #define rwsem_acquire_nest(l, s, t, n, i)	lock_acquire_exclusive(l, s, t, n, i)
677 #define rwsem_acquire_read(l, s, t, i)		lock_acquire_shared(l, s, t, NULL, i)
678 #define rwsem_release(l, i)			lock_release(l, i)
679 
680 #define lock_map_acquire(l)			lock_acquire_exclusive(l, 0, 0, NULL, _THIS_IP_)
681 #define lock_map_acquire_read(l)		lock_acquire_shared_recursive(l, 0, 0, NULL, _THIS_IP_)
682 #define lock_map_acquire_tryread(l)		lock_acquire_shared_recursive(l, 0, 1, NULL, _THIS_IP_)
683 #define lock_map_release(l)			lock_release(l, _THIS_IP_)
684 
685 #ifdef CONFIG_PROVE_LOCKING
686 # define might_lock(lock) 						\
687 do {									\
688 	typecheck(struct lockdep_map *, &(lock)->dep_map);		\
689 	lock_acquire(&(lock)->dep_map, 0, 0, 0, 1, NULL, _THIS_IP_);	\
690 	lock_release(&(lock)->dep_map, _THIS_IP_);			\
691 } while (0)
692 # define might_lock_read(lock) 						\
693 do {									\
694 	typecheck(struct lockdep_map *, &(lock)->dep_map);		\
695 	lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_);	\
696 	lock_release(&(lock)->dep_map, _THIS_IP_);			\
697 } while (0)
698 # define might_lock_nested(lock, subclass) 				\
699 do {									\
700 	typecheck(struct lockdep_map *, &(lock)->dep_map);		\
701 	lock_acquire(&(lock)->dep_map, subclass, 0, 1, 1, NULL,		\
702 		     _THIS_IP_);					\
703 	lock_release(&(lock)->dep_map, _THIS_IP_);			\
704 } while (0)
705 
706 #define lockdep_assert_irqs_enabled()	do {				\
707 		WARN_ONCE(debug_locks && !current->lockdep_recursion &&	\
708 			  !current->hardirqs_enabled,			\
709 			  "IRQs not enabled as expected\n");		\
710 	} while (0)
711 
712 #define lockdep_assert_irqs_disabled()	do {				\
713 		WARN_ONCE(debug_locks && !current->lockdep_recursion &&	\
714 			  current->hardirqs_enabled,			\
715 			  "IRQs not disabled as expected\n");		\
716 	} while (0)
717 
718 #define lockdep_assert_in_irq() do {					\
719 		WARN_ONCE(debug_locks && !current->lockdep_recursion &&	\
720 			  !current->hardirq_context,			\
721 			  "Not in hardirq as expected\n");		\
722 	} while (0)
723 
724 #else
725 # define might_lock(lock) do { } while (0)
726 # define might_lock_read(lock) do { } while (0)
727 # define might_lock_nested(lock, subclass) do { } while (0)
728 # define lockdep_assert_irqs_enabled() do { } while (0)
729 # define lockdep_assert_irqs_disabled() do { } while (0)
730 # define lockdep_assert_in_irq() do { } while (0)
731 #endif
732 
733 #ifdef CONFIG_PROVE_RAW_LOCK_NESTING
734 
735 # define lockdep_assert_RT_in_threaded_ctx() do {			\
736 		WARN_ONCE(debug_locks && !current->lockdep_recursion &&	\
737 			  current->hardirq_context &&			\
738 			  !(current->hardirq_threaded || current->irq_config),	\
739 			  "Not in threaded context on PREEMPT_RT as expected\n");	\
740 } while (0)
741 
742 #else
743 
744 # define lockdep_assert_RT_in_threaded_ctx() do { } while (0)
745 
746 #endif
747 
748 #ifdef CONFIG_LOCKDEP
749 void lockdep_rcu_suspicious(const char *file, const int line, const char *s);
750 #else
751 static inline void
752 lockdep_rcu_suspicious(const char *file, const int line, const char *s)
753 {
754 }
755 #endif
756 
757 #endif /* __LINUX_LOCKDEP_H */
758