debug_locks.h 1.6 KB

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