Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 2 | #ifndef __LINUX_DEBUG_LOCKING_H |
| 3 | #define __LINUX_DEBUG_LOCKING_H |
| 4 | |
Eduard - Gabriel Munteanu | ca31e14 | 2008-07-05 12:14:23 +0300 | [diff] [blame] | 5 | #include <linux/kernel.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 6 | #include <linux/atomic.h> |
Paul Gortmaker | 187f188 | 2011-11-23 20:12:59 -0500 | [diff] [blame] | 7 | #include <linux/bug.h> |
Eduard - Gabriel Munteanu | ca31e14 | 2008-07-05 12:14:23 +0300 | [diff] [blame] | 8 | |
Alexey Dobriyan | 9b7f750 | 2006-08-05 12:14:27 -0700 | [diff] [blame] | 9 | struct task_struct; |
| 10 | |
Waiman Long | 01a14bd | 2018-10-18 21:45:18 -0400 | [diff] [blame] | 11 | extern int debug_locks __read_mostly; |
| 12 | extern int debug_locks_silent __read_mostly; |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 13 | |
Frederic Weisbecker | 9eeba61 | 2009-04-11 03:17:17 +0200 | [diff] [blame] | 14 | |
| 15 | static inline int __debug_locks_off(void) |
| 16 | { |
| 17 | return xchg(&debug_locks, 0); |
| 18 | } |
| 19 | |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 20 | /* |
| 21 | * Generic 'turn off all lock debugging' function: |
| 22 | */ |
| 23 | extern int debug_locks_off(void); |
| 24 | |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 25 | #define DEBUG_LOCKS_WARN_ON(c) \ |
| 26 | ({ \ |
| 27 | int __ret = 0; \ |
| 28 | \ |
Andrew Morton | 53b9d87 | 2008-09-11 17:02:58 -0700 | [diff] [blame] | 29 | if (!oops_in_progress && unlikely(c)) { \ |
Ingo Molnar | 9127d4b | 2006-12-22 01:08:52 -0800 | [diff] [blame] | 30 | if (debug_locks_off() && !debug_locks_silent) \ |
James Hogan | 2c2fea1 | 2013-04-29 15:06:06 -0700 | [diff] [blame] | 31 | WARN(1, "DEBUG_LOCKS_WARN_ON(%s)", #c); \ |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 32 | __ret = 1; \ |
| 33 | } \ |
| 34 | __ret; \ |
| 35 | }) |
| 36 | |
| 37 | #ifdef CONFIG_SMP |
| 38 | # define SMP_DEBUG_LOCKS_WARN_ON(c) DEBUG_LOCKS_WARN_ON(c) |
| 39 | #else |
| 40 | # define SMP_DEBUG_LOCKS_WARN_ON(c) do { } while (0) |
| 41 | #endif |
| 42 | |
| 43 | #ifdef CONFIG_DEBUG_LOCKING_API_SELFTESTS |
| 44 | extern void locking_selftest(void); |
| 45 | #else |
| 46 | # define locking_selftest() do { } while (0) |
| 47 | #endif |
| 48 | |
Kyle McMartin | f86e451 | 2006-08-13 21:09:31 -0400 | [diff] [blame] | 49 | struct task_struct; |
| 50 | |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 51 | #ifdef CONFIG_LOCKDEP |
| 52 | extern void debug_show_all_locks(void); |
| 53 | extern void debug_show_held_locks(struct task_struct *task); |
| 54 | extern void debug_check_no_locks_freed(const void *from, unsigned long len); |
Colin Cross | 1b1d2fb | 2013-05-06 23:50:08 +0000 | [diff] [blame] | 55 | extern void debug_check_no_locks_held(void); |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 56 | #else |
| 57 | static inline void debug_show_all_locks(void) |
| 58 | { |
| 59 | } |
| 60 | |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 61 | static inline void debug_show_held_locks(struct task_struct *task) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | static inline void |
| 66 | debug_check_no_locks_freed(const void *from, unsigned long len) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | static inline void |
Colin Cross | 1b1d2fb | 2013-05-06 23:50:08 +0000 | [diff] [blame] | 71 | debug_check_no_locks_held(void) |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 72 | { |
| 73 | } |
| 74 | #endif |
| 75 | |
| 76 | #endif |