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