debug_locks.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_DEBUG_LOCKING_H
  3. #define __LINUX_DEBUG_LOCKING_H
  4. #include <linux/kernel.h>
  5. #include <linux/atomic.h>
  6. #include <linux/bug.h>
  7. struct task_struct;
  8. extern int debug_locks;
  9. extern int debug_locks_silent;
  10. static 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. if (debug_locks_off() && !debug_locks_silent) \
  24. WARN(1, "DEBUG_LOCKS_WARN_ON(%s)", #c); \
  25. __ret = 1; \
  26. } \
  27. __ret; \
  28. })
  29. #ifdef CONFIG_SMP
  30. # define SMP_DEBUG_LOCKS_WARN_ON(c) DEBUG_LOCKS_WARN_ON(c)
  31. #else
  32. # define SMP_DEBUG_LOCKS_WARN_ON(c) do { } while (0)
  33. #endif
  34. #ifdef CONFIG_DEBUG_LOCKING_API_SELFTESTS
  35. extern void locking_selftest(void);
  36. #else
  37. # define locking_selftest() do { } while (0)
  38. #endif
  39. struct task_struct;
  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