lockdep.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Runtime locking correctness validator
  4. *
  5. * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  6. * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
  7. *
  8. * see Documentation/locking/lockdep-design.txt for more details.
  9. */
  10. #ifndef __LINUX_LOCKDEP_H
  11. #define __LINUX_LOCKDEP_H
  12. struct task_struct;
  13. struct lockdep_map;
  14. /* for sysctl */
  15. extern int prove_locking;
  16. extern int lock_stat;
  17. #define MAX_LOCKDEP_SUBCLASSES 8UL
  18. #include <linux/types.h>
  19. #ifdef CONFIG_LOCKDEP
  20. #include <linux/linkage.h>
  21. #include <linux/list.h>
  22. #include <linux/debug_locks.h>
  23. #include <linux/stacktrace.h>
  24. /*
  25. * We'd rather not expose kernel/lockdep_states.h this wide, but we do need
  26. * the total number of states... :-(
  27. */
  28. #define XXX_LOCK_USAGE_STATES (1+2*4)
  29. /*
  30. * NR_LOCKDEP_CACHING_CLASSES ... Number of classes
  31. * cached in the instance of lockdep_map
  32. *
  33. * Currently main class (subclass == 0) and signle depth subclass
  34. * are cached in lockdep_map. This optimization is mainly targeting
  35. * on rq->lock. double_rq_lock() acquires this highly competitive with
  36. * single depth.
  37. */
  38. #define NR_LOCKDEP_CACHING_CLASSES 2
  39. /*
  40. * Lock-classes are keyed via unique addresses, by embedding the
  41. * lockclass-key into the kernel (or module) .data section. (For
  42. * static locks we use the lock address itself as the key.)
  43. */
  44. struct lockdep_subclass_key {
  45. char __one_byte;
  46. } __attribute__ ((__packed__));
  47. struct lock_class_key {
  48. struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES];
  49. };
  50. extern struct lock_class_key __lockdep_no_validate__;
  51. #define LOCKSTAT_POINTS 4
  52. /*
  53. * The lock-class itself:
  54. */
  55. struct lock_class {
  56. /*
  57. * class-hash:
  58. */
  59. struct hlist_node hash_entry;
  60. /*
  61. * global list of all lock-classes:
  62. */
  63. struct list_head lock_entry;
  64. struct lockdep_subclass_key *key;
  65. unsigned int subclass;
  66. unsigned int dep_gen_id;
  67. /*
  68. * IRQ/softirq usage tracking bits:
  69. */
  70. unsigned long usage_mask;
  71. struct stack_trace usage_traces[XXX_LOCK_USAGE_STATES];
  72. /*
  73. * These fields represent a directed graph of lock dependencies,
  74. * to every node we attach a list of "forward" and a list of
  75. * "backward" graph nodes.
  76. */
  77. struct list_head locks_after, locks_before;
  78. /*
  79. * Generation counter, when doing certain classes of graph walking,
  80. * to ensure that we check one node only once:
  81. */
  82. unsigned int version;
  83. /*
  84. * Statistics counter:
  85. */
  86. unsigned long ops;
  87. const char *name;
  88. int name_version;
  89. #ifdef CONFIG_LOCK_STAT
  90. unsigned long contention_point[LOCKSTAT_POINTS];
  91. unsigned long contending_point[LOCKSTAT_POINTS];
  92. #endif
  93. };
  94. #ifdef CONFIG_LOCK_STAT
  95. struct lock_time {
  96. s64 min;
  97. s64 max;
  98. s64 total;
  99. unsigned long nr;
  100. };
  101. enum bounce_type {
  102. bounce_acquired_write,
  103. bounce_acquired_read,
  104. bounce_contended_write,
  105. bounce_contended_read,
  106. nr_bounce_types,
  107. bounce_acquired = bounce_acquired_write,
  108. bounce_contended = bounce_contended_write,
  109. };
  110. struct lock_class_stats {
  111. unsigned long contention_point[LOCKSTAT_POINTS];
  112. unsigned long contending_point[LOCKSTAT_POINTS];
  113. struct lock_time read_waittime;
  114. struct lock_time write_waittime;
  115. struct lock_time read_holdtime;
  116. struct lock_time write_holdtime;
  117. unsigned long bounces[nr_bounce_types];
  118. };
  119. struct lock_class_stats lock_stats(struct lock_class *class);
  120. void clear_lock_stats(struct lock_class *class);
  121. #endif
  122. /*
  123. * Map the lock object (the lock instance) to the lock-class object.
  124. * This is embedded into specific lock instances:
  125. */
  126. struct lockdep_map {
  127. struct lock_class_key *key;
  128. struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
  129. const char *name;
  130. #ifdef CONFIG_LOCK_STAT
  131. int cpu;
  132. unsigned long ip;
  133. #endif
  134. };
  135. static inline void lockdep_copy_map(struct lockdep_map *to,
  136. struct lockdep_map *from)
  137. {
  138. int i;
  139. *to = *from;
  140. /*
  141. * Since the class cache can be modified concurrently we could observe
  142. * half pointers (64bit arch using 32bit copy insns). Therefore clear
  143. * the caches and take the performance hit.
  144. *
  145. * XXX it doesn't work well with lockdep_set_class_and_subclass(), since
  146. * that relies on cache abuse.
  147. */
  148. for (i = 0; i < NR_LOCKDEP_CACHING_CLASSES; i++)
  149. to->class_cache[i] = NULL;
  150. }
  151. /*
  152. * Every lock has a list of other locks that were taken after it.
  153. * We only grow the list, never remove from it:
  154. */
  155. struct lock_list {
  156. struct list_head entry;
  157. struct lock_class *class;
  158. struct stack_trace trace;
  159. int distance;
  160. /*
  161. * The parent field is used to implement breadth-first search, and the
  162. * bit 0 is reused to indicate if the lock has been accessed in BFS.
  163. */
  164. struct lock_list *parent;
  165. };
  166. /*
  167. * We record lock dependency chains, so that we can cache them:
  168. */
  169. struct lock_chain {
  170. /* see BUILD_BUG_ON()s in lookup_chain_cache() */
  171. unsigned int irq_context : 2,
  172. depth : 6,
  173. base : 24;
  174. /* 4 byte hole */
  175. struct hlist_node entry;
  176. u64 chain_key;
  177. };
  178. #define MAX_LOCKDEP_KEYS_BITS 13
  179. /*
  180. * Subtract one because we offset hlock->class_idx by 1 in order
  181. * to make 0 mean no class. This avoids overflowing the class_idx
  182. * bitfield and hitting the BUG in hlock_class().
  183. */
  184. #define MAX_LOCKDEP_KEYS ((1UL << MAX_LOCKDEP_KEYS_BITS) - 1)
  185. struct held_lock {
  186. /*
  187. * One-way hash of the dependency chain up to this point. We
  188. * hash the hashes step by step as the dependency chain grows.
  189. *
  190. * We use it for dependency-caching and we skip detection
  191. * passes and dependency-updates if there is a cache-hit, so
  192. * it is absolutely critical for 100% coverage of the validator
  193. * to have a unique key value for every unique dependency path
  194. * that can occur in the system, to make a unique hash value
  195. * as likely as possible - hence the 64-bit width.
  196. *
  197. * The task struct holds the current hash value (initialized
  198. * with zero), here we store the previous hash value:
  199. */
  200. u64 prev_chain_key;
  201. unsigned long acquire_ip;
  202. struct lockdep_map *instance;
  203. struct lockdep_map *nest_lock;
  204. #ifdef CONFIG_LOCK_STAT
  205. u64 waittime_stamp;
  206. u64 holdtime_stamp;
  207. #endif
  208. unsigned int class_idx:MAX_LOCKDEP_KEYS_BITS;
  209. /*
  210. * The lock-stack is unified in that the lock chains of interrupt
  211. * contexts nest ontop of process context chains, but we 'separate'
  212. * the hashes by starting with 0 if we cross into an interrupt
  213. * context, and we also keep do not add cross-context lock
  214. * dependencies - the lock usage graph walking covers that area
  215. * anyway, and we'd just unnecessarily increase the number of
  216. * dependencies otherwise. [Note: hardirq and softirq contexts
  217. * are separated from each other too.]
  218. *
  219. * The following field is used to detect when we cross into an
  220. * interrupt context:
  221. */
  222. unsigned int irq_context:2; /* bit 0 - soft, bit 1 - hard */
  223. unsigned int trylock:1; /* 16 bits */
  224. unsigned int read:2; /* see lock_acquire() comment */
  225. unsigned int check:1; /* see lock_acquire() comment */
  226. unsigned int hardirqs_off:1;
  227. unsigned int references:12; /* 32 bits */
  228. unsigned int pin_count;
  229. };
  230. /*
  231. * Initialization, self-test and debugging-output methods:
  232. */
  233. extern void lockdep_init(void);
  234. extern void lockdep_reset(void);
  235. extern void lockdep_reset_lock(struct lockdep_map *lock);
  236. extern void lockdep_free_key_range(void *start, unsigned long size);
  237. extern asmlinkage void lockdep_sys_exit(void);
  238. extern void lockdep_off(void);
  239. extern void lockdep_on(void);
  240. /*
  241. * These methods are used by specific locking variants (spinlocks,
  242. * rwlocks, mutexes and rwsems) to pass init/acquire/release events
  243. * to lockdep:
  244. */
  245. extern void lockdep_init_map(struct lockdep_map *lock, const char *name,
  246. struct lock_class_key *key, int subclass);
  247. /*
  248. * Reinitialize a lock key - for cases where there is special locking or
  249. * special initialization of locks so that the validator gets the scope
  250. * of dependencies wrong: they are either too broad (they need a class-split)
  251. * or they are too narrow (they suffer from a false class-split):
  252. */
  253. #define lockdep_set_class(lock, key) \
  254. lockdep_init_map(&(lock)->dep_map, #key, key, 0)
  255. #define lockdep_set_class_and_name(lock, key, name) \
  256. lockdep_init_map(&(lock)->dep_map, name, key, 0)
  257. #define lockdep_set_class_and_subclass(lock, key, sub) \
  258. lockdep_init_map(&(lock)->dep_map, #key, key, sub)
  259. #define lockdep_set_subclass(lock, sub) \
  260. lockdep_init_map(&(lock)->dep_map, #lock, \
  261. (lock)->dep_map.key, sub)
  262. #define lockdep_set_novalidate_class(lock) \
  263. lockdep_set_class_and_name(lock, &__lockdep_no_validate__, #lock)
  264. /*
  265. * Compare locking classes
  266. */
  267. #define lockdep_match_class(lock, key) lockdep_match_key(&(lock)->dep_map, key)
  268. static inline int lockdep_match_key(struct lockdep_map *lock,
  269. struct lock_class_key *key)
  270. {
  271. return lock->key == key;
  272. }
  273. struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
  274. /*
  275. * Acquire a lock.
  276. *
  277. * Values for "read":
  278. *
  279. * 0: exclusive (write) acquire
  280. * 1: read-acquire (no recursion allowed)
  281. * 2: read-acquire with same-instance recursion allowed
  282. *
  283. * Values for check:
  284. *
  285. * 0: simple checks (freeing, held-at-exit-time, etc.)
  286. * 1: full validation
  287. */
  288. extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
  289. int trylock, int read, int check,
  290. struct lockdep_map *nest_lock, unsigned long ip);
  291. extern void lock_release(struct lockdep_map *lock, int nested,
  292. unsigned long ip);
  293. /*
  294. * Same "read" as for lock_acquire(), except -1 means any.
  295. */
  296. extern int lock_is_held_type(const struct lockdep_map *lock, int read);
  297. static inline int lock_is_held(const struct lockdep_map *lock)
  298. {
  299. return lock_is_held_type(lock, -1);
  300. }
  301. #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
  302. #define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
  303. extern void lock_set_class(struct lockdep_map *lock, const char *name,
  304. struct lock_class_key *key, unsigned int subclass,
  305. unsigned long ip);
  306. static inline void lock_set_subclass(struct lockdep_map *lock,
  307. unsigned int subclass, unsigned long ip)
  308. {
  309. lock_set_class(lock, lock->name, lock->key, subclass, ip);
  310. }
  311. extern void lock_downgrade(struct lockdep_map *lock, unsigned long ip);
  312. struct pin_cookie { unsigned int val; };
  313. #define NIL_COOKIE (struct pin_cookie){ .val = 0U, }
  314. extern struct pin_cookie lock_pin_lock(struct lockdep_map *lock);
  315. extern void lock_repin_lock(struct lockdep_map *lock, struct pin_cookie);
  316. extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie);
  317. #define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0)
  318. #define lockdep_assert_held(l) do { \
  319. WARN_ON(debug_locks && !lockdep_is_held(l)); \
  320. } while (0)
  321. #define lockdep_assert_held_exclusive(l) do { \
  322. WARN_ON(debug_locks && !lockdep_is_held_type(l, 0)); \
  323. } while (0)
  324. #define lockdep_assert_held_read(l) do { \
  325. WARN_ON(debug_locks && !lockdep_is_held_type(l, 1)); \
  326. } while (0)
  327. #define lockdep_assert_held_once(l) do { \
  328. WARN_ON_ONCE(debug_locks && !lockdep_is_held(l)); \
  329. } while (0)
  330. #define lockdep_recursing(tsk) ((tsk)->lockdep_recursion)
  331. #define lockdep_pin_lock(l) lock_pin_lock(&(l)->dep_map)
  332. #define lockdep_repin_lock(l,c) lock_repin_lock(&(l)->dep_map, (c))
  333. #define lockdep_unpin_lock(l,c) lock_unpin_lock(&(l)->dep_map, (c))
  334. #else /* !CONFIG_LOCKDEP */
  335. static inline void lockdep_off(void)
  336. {
  337. }
  338. static inline void lockdep_on(void)
  339. {
  340. }
  341. # define lock_acquire(l, s, t, r, c, n, i) do { } while (0)
  342. # define lock_release(l, n, i) do { } while (0)
  343. # define lock_downgrade(l, i) do { } while (0)
  344. # define lock_set_class(l, n, k, s, i) do { } while (0)
  345. # define lock_set_subclass(l, s, i) do { } while (0)
  346. # define lockdep_init() do { } while (0)
  347. # define lockdep_init_map(lock, name, key, sub) \
  348. do { (void)(name); (void)(key); } while (0)
  349. # define lockdep_set_class(lock, key) do { (void)(key); } while (0)
  350. # define lockdep_set_class_and_name(lock, key, name) \
  351. do { (void)(key); (void)(name); } while (0)
  352. #define lockdep_set_class_and_subclass(lock, key, sub) \
  353. do { (void)(key); } while (0)
  354. #define lockdep_set_subclass(lock, sub) do { } while (0)
  355. #define lockdep_set_novalidate_class(lock) do { } while (0)
  356. /*
  357. * We don't define lockdep_match_class() and lockdep_match_key() for !LOCKDEP
  358. * case since the result is not well defined and the caller should rather
  359. * #ifdef the call himself.
  360. */
  361. # define lockdep_reset() do { debug_locks = 1; } while (0)
  362. # define lockdep_free_key_range(start, size) do { } while (0)
  363. # define lockdep_sys_exit() do { } while (0)
  364. /*
  365. * The class key takes no space if lockdep is disabled:
  366. */
  367. struct lock_class_key { };
  368. /*
  369. * The lockdep_map takes no space if lockdep is disabled:
  370. */
  371. struct lockdep_map { };
  372. #define lockdep_depth(tsk) (0)
  373. #define lockdep_is_held(lock) (1)
  374. #define lockdep_is_held_type(l, r) (1)
  375. #define lockdep_assert_held(l) do { (void)(l); } while (0)
  376. #define lockdep_assert_held_exclusive(l) do { (void)(l); } while (0)
  377. #define lockdep_assert_held_read(l) do { (void)(l); } while (0)
  378. #define lockdep_assert_held_once(l) do { (void)(l); } while (0)
  379. #define lockdep_recursing(tsk) (0)
  380. struct pin_cookie { };
  381. #define NIL_COOKIE (struct pin_cookie){ }
  382. #define lockdep_pin_lock(l) ({ struct pin_cookie cookie; cookie; })
  383. #define lockdep_repin_lock(l, c) do { (void)(l); (void)(c); } while (0)
  384. #define lockdep_unpin_lock(l, c) do { (void)(l); (void)(c); } while (0)
  385. #endif /* !LOCKDEP */
  386. enum xhlock_context_t {
  387. XHLOCK_HARD,
  388. XHLOCK_SOFT,
  389. XHLOCK_CTX_NR,
  390. };
  391. #define lockdep_init_map_crosslock(m, n, k, s) do {} while (0)
  392. /*
  393. * To initialize a lockdep_map statically use this macro.
  394. * Note that _name must not be NULL.
  395. */
  396. #define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
  397. { .name = (_name), .key = (void *)(_key), }
  398. static inline void lockdep_invariant_state(bool force) {}
  399. static inline void lockdep_init_task(struct task_struct *task) {}
  400. static inline void lockdep_free_task(struct task_struct *task) {}
  401. #ifdef CONFIG_LOCK_STAT
  402. extern void lock_contended(struct lockdep_map *lock, unsigned long ip);
  403. extern void lock_acquired(struct lockdep_map *lock, unsigned long ip);
  404. #define LOCK_CONTENDED(_lock, try, lock) \
  405. do { \
  406. if (!try(_lock)) { \
  407. lock_contended(&(_lock)->dep_map, _RET_IP_); \
  408. lock(_lock); \
  409. } \
  410. lock_acquired(&(_lock)->dep_map, _RET_IP_); \
  411. } while (0)
  412. #define LOCK_CONTENDED_RETURN(_lock, try, lock) \
  413. ({ \
  414. int ____err = 0; \
  415. if (!try(_lock)) { \
  416. lock_contended(&(_lock)->dep_map, _RET_IP_); \
  417. ____err = lock(_lock); \
  418. } \
  419. if (!____err) \
  420. lock_acquired(&(_lock)->dep_map, _RET_IP_); \
  421. ____err; \
  422. })
  423. #else /* CONFIG_LOCK_STAT */
  424. #define lock_contended(lockdep_map, ip) do {} while (0)
  425. #define lock_acquired(lockdep_map, ip) do {} while (0)
  426. #define LOCK_CONTENDED(_lock, try, lock) \
  427. lock(_lock)
  428. #define LOCK_CONTENDED_RETURN(_lock, try, lock) \
  429. lock(_lock)
  430. #endif /* CONFIG_LOCK_STAT */
  431. #ifdef CONFIG_LOCKDEP
  432. /*
  433. * On lockdep we dont want the hand-coded irq-enable of
  434. * _raw_*_lock_flags() code, because lockdep assumes
  435. * that interrupts are not re-enabled during lock-acquire:
  436. */
  437. #define LOCK_CONTENDED_FLAGS(_lock, try, lock, lockfl, flags) \
  438. LOCK_CONTENDED((_lock), (try), (lock))
  439. #else /* CONFIG_LOCKDEP */
  440. #define LOCK_CONTENDED_FLAGS(_lock, try, lock, lockfl, flags) \
  441. lockfl((_lock), (flags))
  442. #endif /* CONFIG_LOCKDEP */
  443. #ifdef CONFIG_PROVE_LOCKING
  444. extern void print_irqtrace_events(struct task_struct *curr);
  445. #else
  446. static inline void print_irqtrace_events(struct task_struct *curr)
  447. {
  448. }
  449. #endif
  450. /*
  451. * For trivial one-depth nesting of a lock-class, the following
  452. * global define can be used. (Subsystems with multiple levels
  453. * of nesting should define their own lock-nesting subclasses.)
  454. */
  455. #define SINGLE_DEPTH_NESTING 1
  456. /*
  457. * Map the dependency ops to NOP or to real lockdep ops, depending
  458. * on the per lock-class debug mode:
  459. */
  460. #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i)
  461. #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i)
  462. #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i)
  463. #define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
  464. #define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
  465. #define spin_release(l, n, i) lock_release(l, n, i)
  466. #define rwlock_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
  467. #define rwlock_acquire_read(l, s, t, i) lock_acquire_shared_recursive(l, s, t, NULL, i)
  468. #define rwlock_release(l, n, i) lock_release(l, n, i)
  469. #define seqcount_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
  470. #define seqcount_acquire_read(l, s, t, i) lock_acquire_shared_recursive(l, s, t, NULL, i)
  471. #define seqcount_release(l, n, i) lock_release(l, n, i)
  472. #define mutex_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
  473. #define mutex_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
  474. #define mutex_release(l, n, i) lock_release(l, n, i)
  475. #define rwsem_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
  476. #define rwsem_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
  477. #define rwsem_acquire_read(l, s, t, i) lock_acquire_shared(l, s, t, NULL, i)
  478. #define rwsem_release(l, n, i) lock_release(l, n, i)
  479. #define lock_map_acquire(l) lock_acquire_exclusive(l, 0, 0, NULL, _THIS_IP_)
  480. #define lock_map_acquire_read(l) lock_acquire_shared_recursive(l, 0, 0, NULL, _THIS_IP_)
  481. #define lock_map_acquire_tryread(l) lock_acquire_shared_recursive(l, 0, 1, NULL, _THIS_IP_)
  482. #define lock_map_release(l) lock_release(l, 1, _THIS_IP_)
  483. #ifdef CONFIG_PROVE_LOCKING
  484. # define might_lock(lock) \
  485. do { \
  486. typecheck(struct lockdep_map *, &(lock)->dep_map); \
  487. lock_acquire(&(lock)->dep_map, 0, 0, 0, 1, NULL, _THIS_IP_); \
  488. lock_release(&(lock)->dep_map, 0, _THIS_IP_); \
  489. } while (0)
  490. # define might_lock_read(lock) \
  491. do { \
  492. typecheck(struct lockdep_map *, &(lock)->dep_map); \
  493. lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_); \
  494. lock_release(&(lock)->dep_map, 0, _THIS_IP_); \
  495. } while (0)
  496. #define lockdep_assert_irqs_enabled() do { \
  497. WARN_ONCE(debug_locks && !current->lockdep_recursion && \
  498. !current->hardirqs_enabled, \
  499. "IRQs not enabled as expected\n"); \
  500. } while (0)
  501. #define lockdep_assert_irqs_disabled() do { \
  502. WARN_ONCE(debug_locks && !current->lockdep_recursion && \
  503. current->hardirqs_enabled, \
  504. "IRQs not disabled as expected\n"); \
  505. } while (0)
  506. #else
  507. # define might_lock(lock) do { } while (0)
  508. # define might_lock_read(lock) do { } while (0)
  509. # define lockdep_assert_irqs_enabled() do { } while (0)
  510. # define lockdep_assert_irqs_disabled() do { } while (0)
  511. #endif
  512. #ifdef CONFIG_LOCKDEP
  513. void lockdep_rcu_suspicious(const char *file, const int line, const char *s);
  514. #else
  515. static inline void
  516. lockdep_rcu_suspicious(const char *file, const int line, const char *s)
  517. {
  518. }
  519. #endif
  520. #endif /* __LINUX_LOCKDEP_H */