blob: 08f9247e9827e0056eb4d82c5c83a73a19cebd11 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/include/linux/nmi.h
4 */
5#ifndef LINUX_NMI_H
6#define LINUX_NMI_H
7
Michal Schmidt99384062006-09-29 01:59:03 -07008#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <asm/irq.h>
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070010#if defined(CONFIG_HAVE_NMI_WATCHDOG)
11#include <asm/nmi.h>
12#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Ingo Molnard151b272017-02-02 11:17:23 +010014#ifdef CONFIG_LOCKUP_DETECTOR
Nicholas Piggin05a4a952017-07-12 14:35:46 -070015void lockup_detector_init(void);
Thomas Gleixner6554fd82017-09-12 21:36:57 +020016void lockup_detector_soft_poweroff(void);
Thomas Gleixner941154b2017-09-12 21:37:04 +020017void lockup_detector_cleanup(void);
Thomas Gleixner3b371b52017-09-12 21:37:13 +020018bool is_hardlockup(void);
19
20extern int watchdog_user_enabled;
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +020021extern int nmi_watchdog_user_enabled;
22extern int soft_watchdog_user_enabled;
Thomas Gleixner3b371b52017-09-12 21:37:13 +020023extern int watchdog_thresh;
24extern unsigned long watchdog_enabled;
25
26extern struct cpumask watchdog_cpumask;
27extern unsigned long *watchdog_cpumask_bits;
28#ifdef CONFIG_SMP
29extern int sysctl_softlockup_all_cpu_backtrace;
30extern int sysctl_hardlockup_all_cpu_backtrace;
Nicholas Piggin05a4a952017-07-12 14:35:46 -070031#else
Thomas Gleixner3b371b52017-09-12 21:37:13 +020032#define sysctl_softlockup_all_cpu_backtrace 0
33#define sysctl_hardlockup_all_cpu_backtrace 0
34#endif /* !CONFIG_SMP */
35
36#else /* CONFIG_LOCKUP_DETECTOR */
Thomas Gleixner6554fd82017-09-12 21:36:57 +020037static inline void lockup_detector_init(void) { }
38static inline void lockup_detector_soft_poweroff(void) { }
Thomas Gleixner941154b2017-09-12 21:37:04 +020039static inline void lockup_detector_cleanup(void) { }
Thomas Gleixner3b371b52017-09-12 21:37:13 +020040#endif /* !CONFIG_LOCKUP_DETECTOR */
Nicholas Piggin05a4a952017-07-12 14:35:46 -070041
42#ifdef CONFIG_SOFTLOCKUP_DETECTOR
Ingo Molnard151b272017-02-02 11:17:23 +010043extern void touch_softlockup_watchdog_sched(void);
44extern void touch_softlockup_watchdog(void);
45extern void touch_softlockup_watchdog_sync(void);
46extern void touch_all_softlockup_watchdogs(void);
Ingo Molnard151b272017-02-02 11:17:23 +010047extern unsigned int softlockup_panic;
Peter Zijlstraaef92a82018-07-10 13:42:10 +020048
49extern int lockup_detector_online_cpu(unsigned int cpu);
50extern int lockup_detector_offline_cpu(unsigned int cpu);
51#else /* CONFIG_SOFTLOCKUP_DETECTOR */
Thomas Gleixner3b371b52017-09-12 21:37:13 +020052static inline void touch_softlockup_watchdog_sched(void) { }
53static inline void touch_softlockup_watchdog(void) { }
54static inline void touch_softlockup_watchdog_sync(void) { }
55static inline void touch_all_softlockup_watchdogs(void) { }
Peter Zijlstraaef92a82018-07-10 13:42:10 +020056
57#define lockup_detector_online_cpu NULL
58#define lockup_detector_offline_cpu NULL
59#endif /* CONFIG_SOFTLOCKUP_DETECTOR */
Ingo Molnard151b272017-02-02 11:17:23 +010060
61#ifdef CONFIG_DETECT_HUNG_TASK
62void reset_hung_task_detector(void);
63#else
Thomas Gleixner3b371b52017-09-12 21:37:13 +020064static inline void reset_hung_task_detector(void) { }
Ingo Molnard151b272017-02-02 11:17:23 +010065#endif
66
Babu Moger249e52e2016-12-14 15:06:21 -080067/*
68 * The run state of the lockup detectors is controlled by the content of the
69 * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
70 * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
71 *
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +020072 * 'watchdog_user_enabled', 'nmi_watchdog_user_enabled' and
73 * 'soft_watchdog_user_enabled' are variables that are only used as an
74 * 'interface' between the parameters in /proc/sys/kernel and the internal
75 * state bits in 'watchdog_enabled'. The 'watchdog_thresh' variable is
76 * handled differently because its value is not boolean, and the lockup
77 * detectors are 'suspended' while 'watchdog_thresh' is equal zero.
Babu Moger249e52e2016-12-14 15:06:21 -080078 */
79#define NMI_WATCHDOG_ENABLED_BIT 0
80#define SOFT_WATCHDOG_ENABLED_BIT 1
81#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
82#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
83
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070084#if defined(CONFIG_HARDLOCKUP_DETECTOR)
85extern void hardlockup_detector_disable(void);
Nicholas Piggin05a4a952017-07-12 14:35:46 -070086extern unsigned int hardlockup_panic;
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070087#else
88static inline void hardlockup_detector_disable(void) {}
89#endif
90
Thomas Gleixner51d40522017-09-12 21:37:14 +020091#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
92# define NMI_WATCHDOG_SYSCTL_PERM 0644
93#else
94# define NMI_WATCHDOG_SYSCTL_PERM 0444
95#endif
96
Nicholas Piggin05a4a952017-07-12 14:35:46 -070097#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070098extern void arch_touch_nmi_watchdog(void);
Peter Zijlstrad0b6e0a2017-09-12 21:36:55 +020099extern void hardlockup_detector_perf_stop(void);
100extern void hardlockup_detector_perf_restart(void);
Thomas Gleixner941154b2017-09-12 21:37:04 +0200101extern void hardlockup_detector_perf_disable(void);
Thomas Gleixner2a1b8ee2017-09-12 21:37:20 +0200102extern void hardlockup_detector_perf_enable(void);
Thomas Gleixner941154b2017-09-12 21:37:04 +0200103extern void hardlockup_detector_perf_cleanup(void);
Thomas Gleixner178b9f72017-09-12 21:37:18 +0200104extern int hardlockup_detector_perf_init(void);
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -0700105#else
Peter Zijlstrad0b6e0a2017-09-12 21:36:55 +0200106static inline void hardlockup_detector_perf_stop(void) { }
107static inline void hardlockup_detector_perf_restart(void) { }
Thomas Gleixner941154b2017-09-12 21:37:04 +0200108static inline void hardlockup_detector_perf_disable(void) { }
Thomas Gleixner2a1b8ee2017-09-12 21:37:20 +0200109static inline void hardlockup_detector_perf_enable(void) { }
Thomas Gleixner941154b2017-09-12 21:37:04 +0200110static inline void hardlockup_detector_perf_cleanup(void) { }
Thomas Gleixner178b9f72017-09-12 21:37:18 +0200111# if !defined(CONFIG_HAVE_NMI_WATCHDOG)
112static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -0700113static inline void arch_touch_nmi_watchdog(void) {}
Thomas Gleixner178b9f72017-09-12 21:37:18 +0200114# else
115static inline int hardlockup_detector_perf_init(void) { return 0; }
116# endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700117#endif
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -0700118
Thomas Gleixner6b9dc482017-10-02 12:34:50 +0200119void watchdog_nmi_stop(void);
120void watchdog_nmi_start(void);
Thomas Gleixner34ddaa32017-10-03 16:39:02 +0200121int watchdog_nmi_probe(void);
Thomas Gleixner6592ad22017-09-12 21:37:16 +0200122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123/**
124 * touch_nmi_watchdog - restart NMI watchdog timeout.
Thomas Gleixner3b371b52017-09-12 21:37:13 +0200125 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
127 * may be used to reset the timeout - for code which intentionally
128 * disables interrupts for a long time. This call is stateless.
129 */
Ingo Molnar5d0e6002007-02-13 13:26:24 +0100130static inline void touch_nmi_watchdog(void)
131{
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -0700132 arch_touch_nmi_watchdog();
Ingo Molnar5d0e6002007-02-13 13:26:24 +0100133 touch_softlockup_watchdog();
134}
Ulrich Obergfell6e7458a2014-10-13 15:55:35 -0700135
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200136/*
137 * Create trigger_all_cpu_backtrace() out of the arch-provided
138 * base function. Return whether such support was available,
139 * to allow calling code to fall back to some other mechanism:
140 */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700141#ifdef arch_trigger_cpumask_backtrace
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200142static inline bool trigger_all_cpu_backtrace(void)
143{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700144 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200145 return true;
146}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700147
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700148static inline bool trigger_allbutself_cpu_backtrace(void)
149{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700150 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
151 return true;
152}
153
154static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
155{
156 arch_trigger_cpumask_backtrace(mask, false);
157 return true;
158}
159
160static inline bool trigger_single_cpu_backtrace(int cpu)
161{
162 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700163 return true;
164}
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100165
166/* generic implementation */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700167void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
168 bool exclude_self,
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100169 void (*raise)(cpumask_t *mask));
170bool nmi_cpu_backtrace(struct pt_regs *regs);
171
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200172#else
173static inline bool trigger_all_cpu_backtrace(void)
174{
175 return false;
176}
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700177static inline bool trigger_allbutself_cpu_backtrace(void)
178{
179 return false;
180}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700181static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
182{
183 return false;
184}
185static inline bool trigger_single_cpu_backtrace(int cpu)
186{
187 return false;
188}
Andrew Mortonbb81a092006-12-07 02:14:01 +0100189#endif
190
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700191#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
Mandeep Singh Baines4eec42f2011-05-22 22:10:23 -0700192u64 hw_nmi_get_sample_period(int watchdog_thresh);
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700193#endif
194
Thomas Gleixner7edaeb62017-08-15 09:50:13 +0200195#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
196 defined(CONFIG_HARDLOCKUP_DETECTOR)
197void watchdog_update_hrtimer_threshold(u64 period);
198#else
199static inline void watchdog_update_hrtimer_threshold(u64 period) { }
200#endif
201
Don Zickus504d7cf2010-02-12 17:19:19 -0500202struct ctl_table;
Ulrich Obergfell83a80a32015-04-14 15:44:08 -0700203extern int proc_watchdog(struct ctl_table *, int ,
204 void __user *, size_t *, loff_t *);
205extern int proc_nmi_watchdog(struct ctl_table *, int ,
206 void __user *, size_t *, loff_t *);
207extern int proc_soft_watchdog(struct ctl_table *, int ,
208 void __user *, size_t *, loff_t *);
209extern int proc_watchdog_thresh(struct ctl_table *, int ,
210 void __user *, size_t *, loff_t *);
Chris Metcalffe4ba3c32015-06-24 16:55:45 -0700211extern int proc_watchdog_cpumask(struct ctl_table *, int,
212 void __user *, size_t *, loff_t *);
Don Zickus84e478c2010-02-05 21:47:05 -0500213
Tomasz Nowicki44a69f62014-07-22 11:20:12 +0200214#ifdef CONFIG_HAVE_ACPI_APEI_NMI
215#include <asm/nmi.h>
216#endif
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218#endif