blob: 257ab3c92cb8ad5b78f88f8eb81974f550c657c3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Ingo Molnar9a11b49a2006-07-03 00:24:33 -07002#ifndef __LINUX_DEBUG_LOCKING_H
3#define __LINUX_DEBUG_LOCKING_H
4
Eduard - Gabriel Munteanuca31e142008-07-05 12:14:23 +03005#include <linux/kernel.h>
Arun Sharma600634972011-07-26 16:09:06 -07006#include <linux/atomic.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -05007#include <linux/bug.h>
Eduard - Gabriel Munteanuca31e142008-07-05 12:14:23 +03008
Alexey Dobriyan9b7f7502006-08-05 12:14:27 -07009struct task_struct;
10
Waiman Long01a14bd2018-10-18 21:45:18 -040011extern int debug_locks __read_mostly;
12extern int debug_locks_silent __read_mostly;
Ingo Molnar9a11b49a2006-07-03 00:24:33 -070013
Frederic Weisbecker9eeba612009-04-11 03:17:17 +020014
15static inline int __debug_locks_off(void)
16{
17 return xchg(&debug_locks, 0);
18}
19
Ingo Molnar9a11b49a2006-07-03 00:24:33 -070020/*
21 * Generic 'turn off all lock debugging' function:
22 */
23extern int debug_locks_off(void);
24
Ingo Molnar9a11b49a2006-07-03 00:24:33 -070025#define DEBUG_LOCKS_WARN_ON(c) \
26({ \
27 int __ret = 0; \
28 \
Andrew Morton53b9d872008-09-11 17:02:58 -070029 if (!oops_in_progress && unlikely(c)) { \
Ingo Molnar9127d4b2006-12-22 01:08:52 -080030 if (debug_locks_off() && !debug_locks_silent) \
James Hogan2c2fea12013-04-29 15:06:06 -070031 WARN(1, "DEBUG_LOCKS_WARN_ON(%s)", #c); \
Ingo Molnar9a11b49a2006-07-03 00:24:33 -070032 __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 McMartinf86e4512006-08-13 21:09:31 -040049struct task_struct;
50
Ingo Molnar9a11b49a2006-07-03 00:24:33 -070051#ifdef CONFIG_LOCKDEP
52extern void debug_show_all_locks(void);
53extern void debug_show_held_locks(struct task_struct *task);
54extern void debug_check_no_locks_freed(const void *from, unsigned long len);
Colin Cross1b1d2fb2013-05-06 23:50:08 +000055extern void debug_check_no_locks_held(void);
Ingo Molnar9a11b49a2006-07-03 00:24:33 -070056#else
57static inline void debug_show_all_locks(void)
58{
59}
60
Ingo Molnar9a11b49a2006-07-03 00:24:33 -070061static inline void debug_show_held_locks(struct task_struct *task)
62{
63}
64
65static inline void
66debug_check_no_locks_freed(const void *from, unsigned long len)
67{
68}
69
70static inline void
Colin Cross1b1d2fb2013-05-06 23:50:08 +000071debug_check_no_locks_held(void)
Ingo Molnar9a11b49a2006-07-03 00:24:33 -070072{
73}
74#endif
75
76#endif