Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/include/linux/nmi.h |
| 4 | */ |
| 5 | #ifndef LINUX_NMI_H |
| 6 | #define LINUX_NMI_H |
| 7 | |
Michal Schmidt | 9938406 | 2006-09-29 01:59:03 -0700 | [diff] [blame] | 8 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <asm/irq.h> |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 10 | #if defined(CONFIG_HAVE_NMI_WATCHDOG) |
| 11 | #include <asm/nmi.h> |
| 12 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 14 | #ifdef CONFIG_LOCKUP_DETECTOR |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 15 | void lockup_detector_init(void); |
Thomas Gleixner | 6554fd8 | 2017-09-12 21:36:57 +0200 | [diff] [blame] | 16 | void lockup_detector_soft_poweroff(void); |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 17 | void lockup_detector_cleanup(void); |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame] | 18 | bool is_hardlockup(void); |
| 19 | |
| 20 | extern int watchdog_user_enabled; |
Thomas Gleixner | 7feeb9c | 2017-09-12 21:37:15 +0200 | [diff] [blame] | 21 | extern int nmi_watchdog_user_enabled; |
| 22 | extern int soft_watchdog_user_enabled; |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame] | 23 | extern int watchdog_thresh; |
| 24 | extern unsigned long watchdog_enabled; |
| 25 | |
| 26 | extern struct cpumask watchdog_cpumask; |
| 27 | extern unsigned long *watchdog_cpumask_bits; |
| 28 | #ifdef CONFIG_SMP |
| 29 | extern int sysctl_softlockup_all_cpu_backtrace; |
| 30 | extern int sysctl_hardlockup_all_cpu_backtrace; |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 31 | #else |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame] | 32 | #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 Gleixner | 6554fd8 | 2017-09-12 21:36:57 +0200 | [diff] [blame] | 37 | static inline void lockup_detector_init(void) { } |
| 38 | static inline void lockup_detector_soft_poweroff(void) { } |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 39 | static inline void lockup_detector_cleanup(void) { } |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame] | 40 | #endif /* !CONFIG_LOCKUP_DETECTOR */ |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 41 | |
| 42 | #ifdef CONFIG_SOFTLOCKUP_DETECTOR |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 43 | extern void touch_softlockup_watchdog_sched(void); |
| 44 | extern void touch_softlockup_watchdog(void); |
| 45 | extern void touch_softlockup_watchdog_sync(void); |
| 46 | extern void touch_all_softlockup_watchdogs(void); |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 47 | extern unsigned int softlockup_panic; |
Peter Zijlstra | aef92a8 | 2018-07-10 13:42:10 +0200 | [diff] [blame] | 48 | |
| 49 | extern int lockup_detector_online_cpu(unsigned int cpu); |
| 50 | extern int lockup_detector_offline_cpu(unsigned int cpu); |
| 51 | #else /* CONFIG_SOFTLOCKUP_DETECTOR */ |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame] | 52 | static inline void touch_softlockup_watchdog_sched(void) { } |
| 53 | static inline void touch_softlockup_watchdog(void) { } |
| 54 | static inline void touch_softlockup_watchdog_sync(void) { } |
| 55 | static inline void touch_all_softlockup_watchdogs(void) { } |
Peter Zijlstra | aef92a8 | 2018-07-10 13:42:10 +0200 | [diff] [blame] | 56 | |
| 57 | #define lockup_detector_online_cpu NULL |
| 58 | #define lockup_detector_offline_cpu NULL |
| 59 | #endif /* CONFIG_SOFTLOCKUP_DETECTOR */ |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 60 | |
| 61 | #ifdef CONFIG_DETECT_HUNG_TASK |
| 62 | void reset_hung_task_detector(void); |
| 63 | #else |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame] | 64 | static inline void reset_hung_task_detector(void) { } |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 65 | #endif |
| 66 | |
Babu Moger | 249e52e | 2016-12-14 15:06:21 -0800 | [diff] [blame] | 67 | /* |
| 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 Gleixner | 7feeb9c | 2017-09-12 21:37:15 +0200 | [diff] [blame] | 72 | * '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 Moger | 249e52e | 2016-12-14 15:06:21 -0800 | [diff] [blame] | 78 | */ |
| 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 Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 84 | #if defined(CONFIG_HARDLOCKUP_DETECTOR) |
| 85 | extern void hardlockup_detector_disable(void); |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 86 | extern unsigned int hardlockup_panic; |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 87 | #else |
| 88 | static inline void hardlockup_detector_disable(void) {} |
| 89 | #endif |
| 90 | |
Thomas Gleixner | 51d4052 | 2017-09-12 21:37:14 +0200 | [diff] [blame] | 91 | #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 Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 97 | #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF) |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 98 | extern void arch_touch_nmi_watchdog(void); |
Peter Zijlstra | d0b6e0a | 2017-09-12 21:36:55 +0200 | [diff] [blame] | 99 | extern void hardlockup_detector_perf_stop(void); |
| 100 | extern void hardlockup_detector_perf_restart(void); |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 101 | extern void hardlockup_detector_perf_disable(void); |
Thomas Gleixner | 2a1b8ee | 2017-09-12 21:37:20 +0200 | [diff] [blame] | 102 | extern void hardlockup_detector_perf_enable(void); |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 103 | extern void hardlockup_detector_perf_cleanup(void); |
Thomas Gleixner | 178b9f7 | 2017-09-12 21:37:18 +0200 | [diff] [blame] | 104 | extern int hardlockup_detector_perf_init(void); |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 105 | #else |
Peter Zijlstra | d0b6e0a | 2017-09-12 21:36:55 +0200 | [diff] [blame] | 106 | static inline void hardlockup_detector_perf_stop(void) { } |
| 107 | static inline void hardlockup_detector_perf_restart(void) { } |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 108 | static inline void hardlockup_detector_perf_disable(void) { } |
Thomas Gleixner | 2a1b8ee | 2017-09-12 21:37:20 +0200 | [diff] [blame] | 109 | static inline void hardlockup_detector_perf_enable(void) { } |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 110 | static inline void hardlockup_detector_perf_cleanup(void) { } |
Thomas Gleixner | 178b9f7 | 2017-09-12 21:37:18 +0200 | [diff] [blame] | 111 | # if !defined(CONFIG_HAVE_NMI_WATCHDOG) |
| 112 | static inline int hardlockup_detector_perf_init(void) { return -ENODEV; } |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 113 | static inline void arch_touch_nmi_watchdog(void) {} |
Thomas Gleixner | 178b9f7 | 2017-09-12 21:37:18 +0200 | [diff] [blame] | 114 | # else |
| 115 | static inline int hardlockup_detector_perf_init(void) { return 0; } |
| 116 | # endif |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 117 | #endif |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 118 | |
Thomas Gleixner | 6b9dc48 | 2017-10-02 12:34:50 +0200 | [diff] [blame] | 119 | void watchdog_nmi_stop(void); |
| 120 | void watchdog_nmi_start(void); |
Thomas Gleixner | 34ddaa3 | 2017-10-03 16:39:02 +0200 | [diff] [blame] | 121 | int watchdog_nmi_probe(void); |
Mathieu Malaterre | 81bd415 | 2018-06-06 21:42:32 +0200 | [diff] [blame] | 122 | int watchdog_nmi_enable(unsigned int cpu); |
| 123 | void watchdog_nmi_disable(unsigned int cpu); |
Thomas Gleixner | 6592ad2 | 2017-09-12 21:37:16 +0200 | [diff] [blame] | 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | /** |
| 126 | * touch_nmi_watchdog - restart NMI watchdog timeout. |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame] | 127 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | * If the architecture supports the NMI watchdog, touch_nmi_watchdog() |
| 129 | * may be used to reset the timeout - for code which intentionally |
| 130 | * disables interrupts for a long time. This call is stateless. |
| 131 | */ |
Ingo Molnar | 5d0e600 | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 132 | static inline void touch_nmi_watchdog(void) |
| 133 | { |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 134 | arch_touch_nmi_watchdog(); |
Ingo Molnar | 5d0e600 | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 135 | touch_softlockup_watchdog(); |
| 136 | } |
Ulrich Obergfell | 6e7458a | 2014-10-13 15:55:35 -0700 | [diff] [blame] | 137 | |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 138 | /* |
| 139 | * Create trigger_all_cpu_backtrace() out of the arch-provided |
| 140 | * base function. Return whether such support was available, |
| 141 | * to allow calling code to fall back to some other mechanism: |
| 142 | */ |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 143 | #ifdef arch_trigger_cpumask_backtrace |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 144 | static inline bool trigger_all_cpu_backtrace(void) |
| 145 | { |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 146 | arch_trigger_cpumask_backtrace(cpu_online_mask, false); |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 147 | return true; |
| 148 | } |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 149 | |
Aaron Tomlin | f3aca3d0 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 150 | static inline bool trigger_allbutself_cpu_backtrace(void) |
| 151 | { |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 152 | arch_trigger_cpumask_backtrace(cpu_online_mask, true); |
| 153 | return true; |
| 154 | } |
| 155 | |
| 156 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) |
| 157 | { |
| 158 | arch_trigger_cpumask_backtrace(mask, false); |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | static inline bool trigger_single_cpu_backtrace(int cpu) |
| 163 | { |
| 164 | arch_trigger_cpumask_backtrace(cpumask_of(cpu), false); |
Aaron Tomlin | f3aca3d0 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 165 | return true; |
| 166 | } |
Russell King | b2c0b2c | 2014-09-03 23:57:13 +0100 | [diff] [blame] | 167 | |
| 168 | /* generic implementation */ |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 169 | void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, |
| 170 | bool exclude_self, |
Russell King | b2c0b2c | 2014-09-03 23:57:13 +0100 | [diff] [blame] | 171 | void (*raise)(cpumask_t *mask)); |
| 172 | bool nmi_cpu_backtrace(struct pt_regs *regs); |
| 173 | |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 174 | #else |
| 175 | static inline bool trigger_all_cpu_backtrace(void) |
| 176 | { |
| 177 | return false; |
| 178 | } |
Aaron Tomlin | f3aca3d0 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 179 | static inline bool trigger_allbutself_cpu_backtrace(void) |
| 180 | { |
| 181 | return false; |
| 182 | } |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 183 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) |
| 184 | { |
| 185 | return false; |
| 186 | } |
| 187 | static inline bool trigger_single_cpu_backtrace(int cpu) |
| 188 | { |
| 189 | return false; |
| 190 | } |
Andrew Morton | bb81a09 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 191 | #endif |
| 192 | |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 193 | #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF |
Mandeep Singh Baines | 4eec42f | 2011-05-22 22:10:23 -0700 | [diff] [blame] | 194 | u64 hw_nmi_get_sample_period(int watchdog_thresh); |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 195 | #endif |
| 196 | |
Thomas Gleixner | 7edaeb6 | 2017-08-15 09:50:13 +0200 | [diff] [blame] | 197 | #if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \ |
| 198 | defined(CONFIG_HARDLOCKUP_DETECTOR) |
| 199 | void watchdog_update_hrtimer_threshold(u64 period); |
| 200 | #else |
| 201 | static inline void watchdog_update_hrtimer_threshold(u64 period) { } |
| 202 | #endif |
| 203 | |
Don Zickus | 504d7cf | 2010-02-12 17:19:19 -0500 | [diff] [blame] | 204 | struct ctl_table; |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 205 | int proc_watchdog(struct ctl_table *, int, void *, size_t *, loff_t *); |
| 206 | int proc_nmi_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *); |
| 207 | int proc_soft_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *); |
| 208 | int proc_watchdog_thresh(struct ctl_table *, int , void *, size_t *, loff_t *); |
| 209 | int proc_watchdog_cpumask(struct ctl_table *, int, void *, size_t *, loff_t *); |
Don Zickus | 84e478c | 2010-02-05 21:47:05 -0500 | [diff] [blame] | 210 | |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 211 | #ifdef CONFIG_HAVE_ACPI_APEI_NMI |
| 212 | #include <asm/nmi.h> |
| 213 | #endif |
| 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | #endif |