Merge tag 'rproc-v6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc...
[linux-2.6-block.git] / include / linux / lockdep.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
fbb9ce95
IM
2/*
3 * Runtime locking correctness validator
4 *
4b32d0a4 5 * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
90eec103 6 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
fbb9ce95 7 *
387b1468 8 * see Documentation/locking/lockdep-design.rst for more details.
fbb9ce95
IM
9 */
10#ifndef __LINUX_LOCKDEP_H
11#define __LINUX_LOCKDEP_H
12
c935cd62 13#include <linux/lockdep_types.h>
0cd39f46 14#include <linux/smp.h>
a21ee605 15#include <asm/percpu.h>
c935cd62 16
a1e96b03
HC
17struct task_struct;
18
db0b0ead
MT
19#ifdef CONFIG_LOCKDEP
20
fbb9ce95 21#include <linux/linkage.h>
5be542e9 22#include <linux/list.h>
fbb9ce95
IM
23#include <linux/debug_locks.h>
24#include <linux/stacktrace.h>
25
4d82a1de
PZ
26static inline void lockdep_copy_map(struct lockdep_map *to,
27 struct lockdep_map *from)
28{
29 int i;
30
31 *to = *from;
32 /*
33 * Since the class cache can be modified concurrently we could observe
34 * half pointers (64bit arch using 32bit copy insns). Therefore clear
35 * the caches and take the performance hit.
36 *
37 * XXX it doesn't work well with lockdep_set_class_and_subclass(), since
38 * that relies on cache abuse.
39 */
40 for (i = 0; i < NR_LOCKDEP_CACHING_CLASSES; i++)
41 to->class_cache[i] = NULL;
42}
43
fbb9ce95
IM
44/*
45 * Every lock has a list of other locks that were taken after it.
46 * We only grow the list, never remove from it:
47 */
48struct lock_list {
49 struct list_head entry;
50 struct lock_class *class;
86cffb80 51 struct lock_class *links_to;
12593b74 52 const struct lock_trace *trace;
bd76eca1 53 u16 distance;
3454a36d
BF
54 /* bitmap of different dependencies from head to this */
55 u8 dep;
6971c0f3
BF
56 /* used by BFS to record whether "prev -> this" only has -(*R)-> */
57 u8 only_xr;
c94aa5ca 58
af012961
PZ
59 /*
60 * The parent field is used to implement breadth-first search, and the
61 * bit 0 is reused to indicate if the lock has been accessed in BFS.
c94aa5ca
ML
62 */
63 struct lock_list *parent;
fbb9ce95
IM
64};
65
d16dbd1b
YD
66/**
67 * struct lock_chain - lock dependency chain record
68 *
69 * @irq_context: the same as irq_context in held_lock below
70 * @depth: the number of held locks in this chain
71 * @base: the index in chain_hlocks for this chain
72 * @entry: the collided lock chains in lock_chain hash list
73 * @chain_key: the hash key of this lock_chain
fbb9ce95
IM
74 */
75struct lock_chain {
d16dbd1b 76 /* see BUILD_BUG_ON()s in add_chain_cache() */
75dd602a
PZ
77 unsigned int irq_context : 2,
78 depth : 6,
79 base : 24;
80 /* 4 byte hole */
a63f38cc 81 struct hlist_node entry;
fbb9ce95
IM
82 u64 chain_key;
83};
84
fbb9ce95
IM
85/*
86 * Initialization, self-test and debugging-output methods:
87 */
c3bc8fd6 88extern void lockdep_init(void);
fbb9ce95
IM
89extern void lockdep_reset(void);
90extern void lockdep_reset_lock(struct lockdep_map *lock);
91extern void lockdep_free_key_range(void *start, unsigned long size);
63f9a7fd 92extern asmlinkage void lockdep_sys_exit(void);
cdc84d79 93extern void lockdep_set_selftest_task(struct task_struct *task);
fbb9ce95 94
e196e479
YD
95extern void lockdep_init_task(struct task_struct *task);
96
e616cb8d 97/*
e2db7592 98 * Split the recursion counter in two to readily detect 'off' vs recursion.
e616cb8d
PZ
99 */
100#define LOCKDEP_RECURSION_BITS 16
101#define LOCKDEP_OFF (1U << LOCKDEP_RECURSION_BITS)
102#define LOCKDEP_RECURSION_MASK (LOCKDEP_OFF - 1)
103
104/*
105 * lockdep_{off,on}() are macros to avoid tracing and kprobes; not inlines due
106 * to header dependencies.
107 */
108
109#define lockdep_off() \
110do { \
111 current->lockdep_recursion += LOCKDEP_OFF; \
112} while (0)
113
114#define lockdep_on() \
115do { \
116 current->lockdep_recursion -= LOCKDEP_OFF; \
117} while (0)
fbb9ce95 118
108c1485
BVA
119extern void lockdep_register_key(struct lock_class_key *key);
120extern void lockdep_unregister_key(struct lock_class_key *key);
121
fbb9ce95
IM
122/*
123 * These methods are used by specific locking variants (spinlocks,
124 * rwlocks, mutexes and rwsems) to pass init/acquire/release events
125 * to lockdep:
126 */
127
dfd5e3f5
PZ
128extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
129 struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
130
131static inline void
132lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
133 struct lock_class_key *key, int subclass, u8 inner, u8 outer)
134{
eae6d58d 135 lockdep_init_map_type(lock, name, key, subclass, inner, outer, LD_LOCK_NORMAL);
dfd5e3f5 136}
de8f5e4f
PZ
137
138static inline void
139lockdep_init_map_wait(struct lockdep_map *lock, const char *name,
dfd5e3f5 140 struct lock_class_key *key, int subclass, u8 inner)
de8f5e4f
PZ
141{
142 lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV);
143}
144
145static inline void lockdep_init_map(struct lockdep_map *lock, const char *name,
146 struct lock_class_key *key, int subclass)
147{
148 lockdep_init_map_wait(lock, name, key, subclass, LD_WAIT_INV);
149}
fbb9ce95
IM
150
151/*
152 * Reinitialize a lock key - for cases where there is special locking or
153 * special initialization of locks so that the validator gets the scope
154 * of dependencies wrong: they are either too broad (they need a class-split)
155 * or they are too narrow (they suffer from a false class-split):
156 */
de8f5e4f 157#define lockdep_set_class(lock, key) \
eae6d58d
PZ
158 lockdep_init_map_type(&(lock)->dep_map, #key, key, 0, \
159 (lock)->dep_map.wait_type_inner, \
160 (lock)->dep_map.wait_type_outer, \
161 (lock)->dep_map.lock_type)
de8f5e4f
PZ
162
163#define lockdep_set_class_and_name(lock, key, name) \
eae6d58d
PZ
164 lockdep_init_map_type(&(lock)->dep_map, name, key, 0, \
165 (lock)->dep_map.wait_type_inner, \
166 (lock)->dep_map.wait_type_outer, \
167 (lock)->dep_map.lock_type)
de8f5e4f
PZ
168
169#define lockdep_set_class_and_subclass(lock, key, sub) \
eae6d58d
PZ
170 lockdep_init_map_type(&(lock)->dep_map, #key, key, sub, \
171 (lock)->dep_map.wait_type_inner, \
172 (lock)->dep_map.wait_type_outer, \
173 (lock)->dep_map.lock_type)
de8f5e4f
PZ
174
175#define lockdep_set_subclass(lock, sub) \
eae6d58d
PZ
176 lockdep_init_map_type(&(lock)->dep_map, #lock, (lock)->dep_map.key, sub,\
177 (lock)->dep_map.wait_type_inner, \
178 (lock)->dep_map.wait_type_outer, \
179 (lock)->dep_map.lock_type)
1704f47b
PZ
180
181#define lockdep_set_novalidate_class(lock) \
47be1c1a 182 lockdep_set_class_and_name(lock, &__lockdep_no_validate__, #lock)
de8f5e4f 183
9a7aa12f
JK
184/*
185 * Compare locking classes
186 */
187#define lockdep_match_class(lock, key) lockdep_match_key(&(lock)->dep_map, key)
188
189static inline int lockdep_match_key(struct lockdep_map *lock,
190 struct lock_class_key *key)
191{
192 return lock->key == key;
193}
fbb9ce95
IM
194
195/*
196 * Acquire a lock.
197 *
198 * Values for "read":
199 *
200 * 0: exclusive (write) acquire
201 * 1: read-acquire (no recursion allowed)
202 * 2: read-acquire with same-instance recursion allowed
203 *
204 * Values for check:
205 *
fb9edbe9
ON
206 * 0: simple checks (freeing, held-at-exit-time, etc.)
207 * 1: full validation
fbb9ce95
IM
208 */
209extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
7531e2f3
PZ
210 int trylock, int read, int check,
211 struct lockdep_map *nest_lock, unsigned long ip);
fbb9ce95 212
5facae4f 213extern void lock_release(struct lockdep_map *lock, unsigned long ip);
fbb9ce95 214
2f1f043e
BF
215extern void lock_sync(struct lockdep_map *lock, unsigned int subclass,
216 int read, int check, struct lockdep_map *nest_lock,
217 unsigned long ip);
218
f8cfa466
SK
219/* lock_is_held_type() returns */
220#define LOCK_STATE_UNKNOWN -1
221#define LOCK_STATE_NOT_HELD 0
222#define LOCK_STATE_HELD 1
223
f8319483
PZ
224/*
225 * Same "read" as for lock_acquire(), except -1 means any.
226 */
08f36ff6 227extern int lock_is_held_type(const struct lockdep_map *lock, int read);
f8319483 228
08f36ff6 229static inline int lock_is_held(const struct lockdep_map *lock)
f8319483
PZ
230{
231 return lock_is_held_type(lock, -1);
232}
f607c668 233
f8319483
PZ
234#define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
235#define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
f607c668 236
00ef9f73
PZ
237extern void lock_set_class(struct lockdep_map *lock, const char *name,
238 struct lock_class_key *key, unsigned int subclass,
239 unsigned long ip);
240
d864b8ea
DW
241#define lock_set_novalidate_class(l, n, i) \
242 lock_set_class(l, n, &__lockdep_no_validate__, 0, i)
243
00ef9f73
PZ
244static inline void lock_set_subclass(struct lockdep_map *lock,
245 unsigned int subclass, unsigned long ip)
246{
247 lock_set_class(lock, lock->name, lock->key, subclass, ip);
248}
64aa348e 249
6419c4af
O
250extern void lock_downgrade(struct lockdep_map *lock, unsigned long ip);
251
e7904a28
PZ
252#define NIL_COOKIE (struct pin_cookie){ .val = 0U, }
253
254extern struct pin_cookie lock_pin_lock(struct lockdep_map *lock);
255extern void lock_repin_lock(struct lockdep_map *lock, struct pin_cookie);
256extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie);
a24fc60d 257
e3a55fd1 258#define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0)
d5abe669 259
d19c8137
PZ
260#define lockdep_assert(cond) \
261 do { WARN_ON(debug_locks && !(cond)); } while (0)
3e31f947 262
d19c8137
PZ
263#define lockdep_assert_once(cond) \
264 do { WARN_ON_ONCE(debug_locks && !(cond)); } while (0)
f607c668 265
d19c8137
PZ
266#define lockdep_assert_held(l) \
267 lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD)
f8319483 268
d19c8137
PZ
269#define lockdep_assert_not_held(l) \
270 lockdep_assert(lockdep_is_held(l) != LOCK_STATE_HELD)
f8319483 271
d19c8137
PZ
272#define lockdep_assert_held_write(l) \
273 lockdep_assert(lockdep_is_held_type(l, 0))
9a37110d 274
d19c8137
PZ
275#define lockdep_assert_held_read(l) \
276 lockdep_assert(lockdep_is_held_type(l, 1))
277
278#define lockdep_assert_held_once(l) \
279 lockdep_assert_once(lockdep_is_held(l) != LOCK_STATE_NOT_HELD)
280
281#define lockdep_assert_none_held_once() \
282 lockdep_assert_once(!current->lockdep_depth)
7621350c 283
94d24fc4
PZ
284#define lockdep_recursing(tsk) ((tsk)->lockdep_recursion)
285
e7904a28
PZ
286#define lockdep_pin_lock(l) lock_pin_lock(&(l)->dep_map)
287#define lockdep_repin_lock(l,c) lock_repin_lock(&(l)->dep_map, (c))
288#define lockdep_unpin_lock(l,c) lock_unpin_lock(&(l)->dep_map, (c))
a24fc60d 289
0cce06ba
PZ
290/*
291 * Must use lock_map_aquire_try() with override maps to avoid
292 * lockdep thinking they participate in the block chain.
293 */
294#define DEFINE_WAIT_OVERRIDE_MAP(_name, _wait_type) \
295 struct lockdep_map _name = { \
296 .name = #_name "-wait-type-override", \
297 .wait_type_inner = _wait_type, \
298 .lock_type = LD_LOCK_WAIT_OVERRIDE, }
299
a51805ef 300#else /* !CONFIG_LOCKDEP */
fbb9ce95 301
e196e479
YD
302static inline void lockdep_init_task(struct task_struct *task)
303{
304}
305
fbb9ce95
IM
306static inline void lockdep_off(void)
307{
308}
309
310static inline void lockdep_on(void)
311{
312}
313
cdc84d79
BVA
314static inline void lockdep_set_selftest_task(struct task_struct *task)
315{
316}
317
7531e2f3 318# define lock_acquire(l, s, t, r, c, n, i) do { } while (0)
5facae4f 319# define lock_release(l, i) do { } while (0)
6419c4af 320# define lock_downgrade(l, i) do { } while (0)
d864b8ea
DW
321# define lock_set_class(l, n, key, s, i) do { (void)(key); } while (0)
322# define lock_set_novalidate_class(l, n, i) do { } while (0)
64aa348e 323# define lock_set_subclass(l, s, i) do { } while (0)
c3bc8fd6 324# define lockdep_init() do { } while (0)
dfd5e3f5
PZ
325# define lockdep_init_map_type(lock, name, key, sub, inner, outer, type) \
326 do { (void)(name); (void)(key); } while (0)
de8f5e4f
PZ
327# define lockdep_init_map_waits(lock, name, key, sub, inner, outer) \
328 do { (void)(name); (void)(key); } while (0)
329# define lockdep_init_map_wait(lock, name, key, sub, inner) \
330 do { (void)(name); (void)(key); } while (0)
e25cf3db
IM
331# define lockdep_init_map(lock, name, key, sub) \
332 do { (void)(name); (void)(key); } while (0)
fbb9ce95
IM
333# define lockdep_set_class(lock, key) do { (void)(key); } while (0)
334# define lockdep_set_class_and_name(lock, key, name) \
e25cf3db 335 do { (void)(key); (void)(name); } while (0)
4dfbb9d8
PZ
336#define lockdep_set_class_and_subclass(lock, key, sub) \
337 do { (void)(key); } while (0)
07646e21 338#define lockdep_set_subclass(lock, sub) do { } while (0)
1704f47b
PZ
339
340#define lockdep_set_novalidate_class(lock) do { } while (0)
341
9a7aa12f
JK
342/*
343 * We don't define lockdep_match_class() and lockdep_match_key() for !LOCKDEP
344 * case since the result is not well defined and the caller should rather
345 * #ifdef the call himself.
346 */
07646e21 347
fbb9ce95
IM
348# define lockdep_reset() do { debug_locks = 1; } while (0)
349# define lockdep_free_key_range(start, size) do { } while (0)
b351d164 350# define lockdep_sys_exit() do { } while (0)
d5abe669 351
108c1485
BVA
352static inline void lockdep_register_key(struct lock_class_key *key)
353{
354}
355
356static inline void lockdep_unregister_key(struct lock_class_key *key)
357{
358}
359
d5abe669
PZ
360#define lockdep_depth(tsk) (0)
361
cd539cff
JK
362/*
363 * Dummy forward declarations, allow users to write less ifdef-y code
364 * and depend on dead code elimination.
365 */
366extern int lock_is_held(const void *);
367extern int lockdep_is_held(const void *);
f8319483
PZ
368#define lockdep_is_held_type(l, r) (1)
369
d19c8137
PZ
370#define lockdep_assert(c) do { } while (0)
371#define lockdep_assert_once(c) do { } while (0)
372
5cd3f5af 373#define lockdep_assert_held(l) do { (void)(l); } while (0)
3e31f947
SK
374#define lockdep_assert_not_held(l) do { (void)(l); } while (0)
375#define lockdep_assert_held_write(l) do { (void)(l); } while (0)
f8319483 376#define lockdep_assert_held_read(l) do { (void)(l); } while (0)
9a37110d 377#define lockdep_assert_held_once(l) do { (void)(l); } while (0)
7621350c 378#define lockdep_assert_none_held_once() do { } while (0)
f607c668 379
94d24fc4
PZ
380#define lockdep_recursing(tsk) (0)
381
e7904a28
PZ
382#define NIL_COOKIE (struct pin_cookie){ }
383
3771b0fe 384#define lockdep_pin_lock(l) ({ struct pin_cookie cookie = { }; cookie; })
e7904a28
PZ
385#define lockdep_repin_lock(l, c) do { (void)(l); (void)(c); } while (0)
386#define lockdep_unpin_lock(l, c) do { (void)(l); (void)(c); } while (0)
a24fc60d 387
0cce06ba
PZ
388#define DEFINE_WAIT_OVERRIDE_MAP(_name, _wait_type) \
389 struct lockdep_map __maybe_unused _name = {}
390
fbb9ce95
IM
391#endif /* !LOCKDEP */
392
eb1cfd09
KO
393#ifdef CONFIG_PROVE_LOCKING
394void lockdep_set_lock_cmp_fn(struct lockdep_map *, lock_cmp_fn, lock_print_fn);
395
396#define lock_set_cmp_fn(lock, ...) lockdep_set_lock_cmp_fn(&(lock)->dep_map, __VA_ARGS__)
397#else
398#define lock_set_cmp_fn(lock, ...) do { } while (0)
399#endif
400
b09be676
BP
401enum xhlock_context_t {
402 XHLOCK_HARD,
403 XHLOCK_SOFT,
b09be676
BP
404 XHLOCK_CTX_NR,
405};
406
b09be676
BP
407/*
408 * To initialize a lockdep_map statically use this macro.
409 * Note that _name must not be NULL.
410 */
411#define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
412 { .name = (_name), .key = (void *)(_key), }
413
f52be570 414static inline void lockdep_invariant_state(bool force) {}
b09be676 415static inline void lockdep_free_task(struct task_struct *task) {}
b09be676 416
f20786ff
PZ
417#ifdef CONFIG_LOCK_STAT
418
419extern void lock_contended(struct lockdep_map *lock, unsigned long ip);
c7e78cff 420extern void lock_acquired(struct lockdep_map *lock, unsigned long ip);
f20786ff
PZ
421
422#define LOCK_CONTENDED(_lock, try, lock) \
423do { \
424 if (!try(_lock)) { \
425 lock_contended(&(_lock)->dep_map, _RET_IP_); \
426 lock(_lock); \
f20786ff 427 } \
c7e78cff 428 lock_acquired(&(_lock)->dep_map, _RET_IP_); \
f20786ff
PZ
429} while (0)
430
916633a4
MH
431#define LOCK_CONTENDED_RETURN(_lock, try, lock) \
432({ \
433 int ____err = 0; \
434 if (!try(_lock)) { \
435 lock_contended(&(_lock)->dep_map, _RET_IP_); \
436 ____err = lock(_lock); \
437 } \
438 if (!____err) \
439 lock_acquired(&(_lock)->dep_map, _RET_IP_); \
440 ____err; \
441})
442
f20786ff
PZ
443#else /* CONFIG_LOCK_STAT */
444
445#define lock_contended(lockdep_map, ip) do {} while (0)
c7e78cff 446#define lock_acquired(lockdep_map, ip) do {} while (0)
f20786ff
PZ
447
448#define LOCK_CONTENDED(_lock, try, lock) \
449 lock(_lock)
450
916633a4
MH
451#define LOCK_CONTENDED_RETURN(_lock, try, lock) \
452 lock(_lock)
453
f20786ff
PZ
454#endif /* CONFIG_LOCK_STAT */
455
c3bc8fd6 456#ifdef CONFIG_PROVE_LOCKING
3117df04 457extern void print_irqtrace_events(struct task_struct *curr);
fbb9ce95 458#else
3117df04
IM
459static inline void print_irqtrace_events(struct task_struct *curr)
460{
461}
fbb9ce95
IM
462#endif
463
e9181886
BF
464/* Variable used to make lockdep treat read_lock() as recursive in selftests */
465#ifdef CONFIG_DEBUG_LOCKING_API_SELFTESTS
466extern unsigned int force_read_lock_recursive;
467#else /* CONFIG_DEBUG_LOCKING_API_SELFTESTS */
468#define force_read_lock_recursive 0
469#endif /* CONFIG_DEBUG_LOCKING_API_SELFTESTS */
470
471#ifdef CONFIG_LOCKDEP
472extern bool read_lock_is_recursive(void);
473#else /* CONFIG_LOCKDEP */
474/* If !LOCKDEP, the value is meaningless */
475#define read_lock_is_recursive() 0
476#endif
477
fbb9ce95
IM
478/*
479 * For trivial one-depth nesting of a lock-class, the following
480 * global define can be used. (Subsystems with multiple levels
481 * of nesting should define their own lock-nesting subclasses.)
482 */
483#define SINGLE_DEPTH_NESTING 1
484
485/*
486 * Map the dependency ops to NOP or to real lockdep ops, depending
487 * on the per lock-class debug mode:
488 */
489
fb9edbe9
ON
490#define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i)
491#define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i)
492#define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i)
fbb9ce95 493
a51805ef
ML
494#define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
495#define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
5facae4f 496#define spin_release(l, i) lock_release(l, i)
fbb9ce95 497
a51805ef 498#define rwlock_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
e9181886
BF
499#define rwlock_acquire_read(l, s, t, i) \
500do { \
501 if (read_lock_is_recursive()) \
502 lock_acquire_shared_recursive(l, s, t, NULL, i); \
503 else \
504 lock_acquire_shared(l, s, t, NULL, i); \
505} while (0)
506
5facae4f 507#define rwlock_release(l, i) lock_release(l, i)
fbb9ce95 508
1ca7d67c
JS
509#define seqcount_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
510#define seqcount_acquire_read(l, s, t, i) lock_acquire_shared_recursive(l, s, t, NULL, i)
5facae4f 511#define seqcount_release(l, i) lock_release(l, i)
1ca7d67c 512
a51805ef
ML
513#define mutex_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
514#define mutex_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
5facae4f 515#define mutex_release(l, i) lock_release(l, i)
a51805ef
ML
516
517#define rwsem_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
518#define rwsem_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
519#define rwsem_acquire_read(l, s, t, i) lock_acquire_shared(l, s, t, NULL, i)
5facae4f 520#define rwsem_release(l, i) lock_release(l, i)
fbb9ce95 521
a51805ef 522#define lock_map_acquire(l) lock_acquire_exclusive(l, 0, 0, NULL, _THIS_IP_)
0cce06ba 523#define lock_map_acquire_try(l) lock_acquire_exclusive(l, 0, 1, NULL, _THIS_IP_)
a51805ef 524#define lock_map_acquire_read(l) lock_acquire_shared_recursive(l, 0, 0, NULL, _THIS_IP_)
dd56af42 525#define lock_map_acquire_tryread(l) lock_acquire_shared_recursive(l, 0, 1, NULL, _THIS_IP_)
5facae4f 526#define lock_map_release(l) lock_release(l, _THIS_IP_)
2f1f043e 527#define lock_map_sync(l) lock_sync(l, 0, 0, 1, NULL, _THIS_IP_)
4f3e7524 528
76b189e9 529#ifdef CONFIG_PROVE_LOCKING
baffd723 530# define might_lock(lock) \
76b189e9
PZ
531do { \
532 typecheck(struct lockdep_map *, &(lock)->dep_map); \
fb9edbe9 533 lock_acquire(&(lock)->dep_map, 0, 0, 0, 1, NULL, _THIS_IP_); \
5facae4f 534 lock_release(&(lock)->dep_map, _THIS_IP_); \
76b189e9 535} while (0)
baffd723 536# define might_lock_read(lock) \
76b189e9
PZ
537do { \
538 typecheck(struct lockdep_map *, &(lock)->dep_map); \
fb9edbe9 539 lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_); \
5facae4f 540 lock_release(&(lock)->dep_map, _THIS_IP_); \
76b189e9 541} while (0)
baffd723 542# define might_lock_nested(lock, subclass) \
e692b402
DV
543do { \
544 typecheck(struct lockdep_map *, &(lock)->dep_map); \
545 lock_acquire(&(lock)->dep_map, subclass, 0, 1, 1, NULL, \
546 _THIS_IP_); \
023265ed 547 lock_release(&(lock)->dep_map, _THIS_IP_); \
e692b402 548} while (0)
f54bb2ec 549
a21ee605
PZ
550DECLARE_PER_CPU(int, hardirqs_enabled);
551DECLARE_PER_CPU(int, hardirq_context);
4d004099 552DECLARE_PER_CPU(unsigned int, lockdep_recursion);
f54bb2ec 553
baffd723 554#define __lockdep_enabled (debug_locks && !this_cpu_read(lockdep_recursion))
fddf9055 555
a21ee605
PZ
556#define lockdep_assert_irqs_enabled() \
557do { \
baffd723 558 WARN_ON_ONCE(__lockdep_enabled && !this_cpu_read(hardirqs_enabled)); \
a21ee605 559} while (0)
f54bb2ec 560
a21ee605
PZ
561#define lockdep_assert_irqs_disabled() \
562do { \
baffd723 563 WARN_ON_ONCE(__lockdep_enabled && this_cpu_read(hardirqs_enabled)); \
a21ee605
PZ
564} while (0)
565
566#define lockdep_assert_in_irq() \
567do { \
baffd723 568 WARN_ON_ONCE(__lockdep_enabled && !this_cpu_read(hardirq_context)); \
a21ee605 569} while (0)
71d8d153 570
ff4e538c
JK
571#define lockdep_assert_no_hardirq() \
572do { \
573 WARN_ON_ONCE(__lockdep_enabled && (this_cpu_read(hardirq_context) || \
574 !this_cpu_read(hardirqs_enabled))); \
575} while (0)
576
8fd8ad5c
AD
577#define lockdep_assert_preemption_enabled() \
578do { \
579 WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \
4d004099 580 __lockdep_enabled && \
8fd8ad5c 581 (preempt_count() != 0 || \
baffd723 582 !this_cpu_read(hardirqs_enabled))); \
8fd8ad5c
AD
583} while (0)
584
585#define lockdep_assert_preemption_disabled() \
586do { \
587 WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \
4d004099 588 __lockdep_enabled && \
8fd8ad5c 589 (preempt_count() == 0 && \
baffd723 590 this_cpu_read(hardirqs_enabled))); \
8fd8ad5c
AD
591} while (0)
592
8b5536ad
YL
593/*
594 * Acceptable for protecting per-CPU resources accessed from BH.
595 * Much like in_softirq() - semantics are ambiguous, use carefully.
596 */
597#define lockdep_assert_in_softirq() \
598do { \
599 WARN_ON_ONCE(__lockdep_enabled && \
600 (!in_softirq() || in_irq() || in_nmi())); \
601} while (0)
602
76b189e9
PZ
603#else
604# define might_lock(lock) do { } while (0)
605# define might_lock_read(lock) do { } while (0)
e692b402 606# define might_lock_nested(lock, subclass) do { } while (0)
a21ee605 607
f54bb2ec
FW
608# define lockdep_assert_irqs_enabled() do { } while (0)
609# define lockdep_assert_irqs_disabled() do { } while (0)
71d8d153 610# define lockdep_assert_in_irq() do { } while (0)
ff4e538c 611# define lockdep_assert_no_hardirq() do { } while (0)
8fd8ad5c
AD
612
613# define lockdep_assert_preemption_enabled() do { } while (0)
614# define lockdep_assert_preemption_disabled() do { } while (0)
8b5536ad 615# define lockdep_assert_in_softirq() do { } while (0)
76b189e9
PZ
616#endif
617
8bf6c677
SS
618#ifdef CONFIG_PROVE_RAW_LOCK_NESTING
619
620# define lockdep_assert_RT_in_threaded_ctx() do { \
621 WARN_ONCE(debug_locks && !current->lockdep_recursion && \
f9ad4a5f 622 lockdep_hardirq_context() && \
8bf6c677
SS
623 !(current->hardirq_threaded || current->irq_config), \
624 "Not in threaded context on PREEMPT_RT as expected\n"); \
625} while (0)
626
627#else
628
629# define lockdep_assert_RT_in_threaded_ctx() do { } while (0)
630
631#endif
632
d24209bb 633#ifdef CONFIG_LOCKDEP
b3fbab05 634void lockdep_rcu_suspicious(const char *file, const int line, const char *s);
d24209bb
PM
635#else
636static inline void
637lockdep_rcu_suspicious(const char *file, const int line, const char *s)
638{
639}
0632eb3d
PM
640#endif
641
fbb9ce95 642#endif /* __LINUX_LOCKDEP_H */