debug_locks.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_DEBUG_LOCKING_H
  3. #define __LINUX_DEBUG_LOCKING_H
  4. #include <linux/atomic.h>
  5. #include <linux/bug.h>
  6. #include <linux/printk.h>
  7. struct task_struct;
  8. extern int debug_locks __read_mostly;
  9. extern int debug_locks_silent __read_mostly;
  10. static __always_inline int __debug_locks_off(void)
  11. {
  12. return xchg(&debug_locks, 0);
  13. }
  14. /*
  15. * Generic 'turn off all lock debugging' function:
  16. */
  17. extern int debug_locks_off(void);
  18. #define DEBUG_LOCKS_WARN_ON(c) \
  19. ({ \
  20. int __ret = 0; \
  21. \
  22. if (!oops_in_progress && unlikely(c)) { \
  23. instrumentation_begin(); \
  24. if (debug_locks_off() && !debug_locks_silent) \
  25. WARN(1, "DEBUG_LOCKS_WARN_ON(%s)", #c); \
  26. instrumentation_end(); \
  27. __ret = 1; \
  28. } \
  29. __ret; \
  30. })
  31. #ifdef CONFIG_SMP
  32. # define SMP_DEBUG_LOCKS_WARN_ON(c) DEBUG_LOCKS_WARN_ON(c)
  33. #else
  34. # define SMP_DEBUG_LOCKS_WARN_ON(c) do { } while (0)
  35. #endif
  36. #ifdef CONFIG_DEBUG_LOCKING_API_SELFTESTS
  37. extern void locking_selftest(void);
  38. #else
  39. # define locking_selftest() do { } while (0)
  40. #endif
  41. struct task_struct;
  42. #ifdef CONFIG_LOCKDEP
  43. extern void debug_show_all_locks(void);
  44. extern void debug_show_held_locks(struct task_struct *task);
  45. extern void debug_check_no_locks_freed(const void *from, unsigned long len);
  46. extern void debug_check_no_locks_held(void);
  47. #else
  48. static inline void debug_show_all_locks(void)
  49. {
  50. }
  51. static inline void debug_show_held_locks(struct task_struct *task)
  52. {
  53. }
  54. static inline void
  55. debug_check_no_locks_freed(const void *from, unsigned long len)
  56. {
  57. }
  58. static inline void
  59. debug_check_no_locks_held(void)
  60. {
  61. }
  62. #endif
  63. #endif