Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/include/linux/nmi.h |
| 3 | */ |
| 4 | #ifndef LINUX_NMI_H |
| 5 | #define LINUX_NMI_H |
| 6 | |
Michal Schmidt | 9938406 | 2006-09-29 01:59:03 -0700 | [diff] [blame] | 7 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <asm/irq.h> |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 9 | #if defined(CONFIG_HAVE_NMI_WATCHDOG) |
| 10 | #include <asm/nmi.h> |
| 11 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 13 | #ifdef CONFIG_LOCKUP_DETECTOR |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 14 | void lockup_detector_init(void); |
Thomas Gleixner | 6554fd8 | 2017-09-12 21:36:57 +0200 | [diff] [blame] | 15 | void lockup_detector_soft_poweroff(void); |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 16 | void lockup_detector_cleanup(void); |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame^] | 17 | bool is_hardlockup(void); |
| 18 | |
| 19 | extern int watchdog_user_enabled; |
| 20 | extern int nmi_watchdog_enabled; |
| 21 | extern int soft_watchdog_enabled; |
| 22 | extern int watchdog_thresh; |
| 23 | extern unsigned long watchdog_enabled; |
| 24 | |
| 25 | extern struct cpumask watchdog_cpumask; |
| 26 | extern unsigned long *watchdog_cpumask_bits; |
| 27 | #ifdef CONFIG_SMP |
| 28 | extern int sysctl_softlockup_all_cpu_backtrace; |
| 29 | extern int sysctl_hardlockup_all_cpu_backtrace; |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 30 | #else |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame^] | 31 | #define sysctl_softlockup_all_cpu_backtrace 0 |
| 32 | #define sysctl_hardlockup_all_cpu_backtrace 0 |
| 33 | #endif /* !CONFIG_SMP */ |
| 34 | |
| 35 | #else /* CONFIG_LOCKUP_DETECTOR */ |
Thomas Gleixner | 6554fd8 | 2017-09-12 21:36:57 +0200 | [diff] [blame] | 36 | static inline void lockup_detector_init(void) { } |
| 37 | static inline void lockup_detector_soft_poweroff(void) { } |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 38 | static inline void lockup_detector_cleanup(void) { } |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame^] | 39 | #endif /* !CONFIG_LOCKUP_DETECTOR */ |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 40 | |
| 41 | #ifdef CONFIG_SOFTLOCKUP_DETECTOR |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 42 | extern void touch_softlockup_watchdog_sched(void); |
| 43 | extern void touch_softlockup_watchdog(void); |
| 44 | extern void touch_softlockup_watchdog_sync(void); |
| 45 | extern void touch_all_softlockup_watchdogs(void); |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 46 | extern unsigned int softlockup_panic; |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 47 | #else |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame^] | 48 | static inline void touch_softlockup_watchdog_sched(void) { } |
| 49 | static inline void touch_softlockup_watchdog(void) { } |
| 50 | static inline void touch_softlockup_watchdog_sync(void) { } |
| 51 | static inline void touch_all_softlockup_watchdogs(void) { } |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 52 | #endif |
| 53 | |
| 54 | #ifdef CONFIG_DETECT_HUNG_TASK |
| 55 | void reset_hung_task_detector(void); |
| 56 | #else |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame^] | 57 | static inline void reset_hung_task_detector(void) { } |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 58 | #endif |
| 59 | |
Babu Moger | 249e52e | 2016-12-14 15:06:21 -0800 | [diff] [blame] | 60 | /* |
| 61 | * The run state of the lockup detectors is controlled by the content of the |
| 62 | * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit - |
| 63 | * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector. |
| 64 | * |
| 65 | * 'watchdog_user_enabled', 'nmi_watchdog_enabled' and 'soft_watchdog_enabled' |
| 66 | * are variables that are only used as an 'interface' between the parameters |
| 67 | * in /proc/sys/kernel and the internal state bits in 'watchdog_enabled'. The |
| 68 | * 'watchdog_thresh' variable is handled differently because its value is not |
| 69 | * boolean, and the lockup detectors are 'suspended' while 'watchdog_thresh' |
| 70 | * is equal zero. |
| 71 | */ |
| 72 | #define NMI_WATCHDOG_ENABLED_BIT 0 |
| 73 | #define SOFT_WATCHDOG_ENABLED_BIT 1 |
| 74 | #define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT) |
| 75 | #define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT) |
| 76 | |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 77 | #if defined(CONFIG_HARDLOCKUP_DETECTOR) |
| 78 | extern void hardlockup_detector_disable(void); |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 79 | extern unsigned int hardlockup_panic; |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 80 | #else |
| 81 | static inline void hardlockup_detector_disable(void) {} |
| 82 | #endif |
| 83 | |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 84 | #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF) |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 85 | extern void arch_touch_nmi_watchdog(void); |
Peter Zijlstra | d0b6e0a | 2017-09-12 21:36:55 +0200 | [diff] [blame] | 86 | extern void hardlockup_detector_perf_stop(void); |
| 87 | extern void hardlockup_detector_perf_restart(void); |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 88 | extern void hardlockup_detector_perf_disable(void); |
| 89 | extern void hardlockup_detector_perf_cleanup(void); |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 90 | #else |
Peter Zijlstra | d0b6e0a | 2017-09-12 21:36:55 +0200 | [diff] [blame] | 91 | static inline void hardlockup_detector_perf_stop(void) { } |
| 92 | static inline void hardlockup_detector_perf_restart(void) { } |
Thomas Gleixner | 941154b | 2017-09-12 21:37:04 +0200 | [diff] [blame] | 93 | static inline void hardlockup_detector_perf_disable(void) { } |
| 94 | static inline void hardlockup_detector_perf_cleanup(void) { } |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 95 | #if !defined(CONFIG_HAVE_NMI_WATCHDOG) |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 96 | static inline void arch_touch_nmi_watchdog(void) {} |
| 97 | #endif |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 98 | #endif |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /** |
| 101 | * touch_nmi_watchdog - restart NMI watchdog timeout. |
Thomas Gleixner | 3b371b5 | 2017-09-12 21:37:13 +0200 | [diff] [blame^] | 102 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | * If the architecture supports the NMI watchdog, touch_nmi_watchdog() |
| 104 | * may be used to reset the timeout - for code which intentionally |
| 105 | * disables interrupts for a long time. This call is stateless. |
| 106 | */ |
Ingo Molnar | 5d0e600 | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 107 | static inline void touch_nmi_watchdog(void) |
| 108 | { |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 109 | arch_touch_nmi_watchdog(); |
Ingo Molnar | 5d0e600 | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 110 | touch_softlockup_watchdog(); |
| 111 | } |
Ulrich Obergfell | 6e7458a | 2014-10-13 15:55:35 -0700 | [diff] [blame] | 112 | |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 113 | /* |
| 114 | * Create trigger_all_cpu_backtrace() out of the arch-provided |
| 115 | * base function. Return whether such support was available, |
| 116 | * to allow calling code to fall back to some other mechanism: |
| 117 | */ |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 118 | #ifdef arch_trigger_cpumask_backtrace |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 119 | static inline bool trigger_all_cpu_backtrace(void) |
| 120 | { |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 121 | arch_trigger_cpumask_backtrace(cpu_online_mask, false); |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 122 | return true; |
| 123 | } |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 124 | |
Aaron Tomlin | f3aca3d0 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 125 | static inline bool trigger_allbutself_cpu_backtrace(void) |
| 126 | { |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 127 | arch_trigger_cpumask_backtrace(cpu_online_mask, true); |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) |
| 132 | { |
| 133 | arch_trigger_cpumask_backtrace(mask, false); |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | static inline bool trigger_single_cpu_backtrace(int cpu) |
| 138 | { |
| 139 | arch_trigger_cpumask_backtrace(cpumask_of(cpu), false); |
Aaron Tomlin | f3aca3d0 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 140 | return true; |
| 141 | } |
Russell King | b2c0b2c | 2014-09-03 23:57:13 +0100 | [diff] [blame] | 142 | |
| 143 | /* generic implementation */ |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 144 | void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, |
| 145 | bool exclude_self, |
Russell King | b2c0b2c | 2014-09-03 23:57:13 +0100 | [diff] [blame] | 146 | void (*raise)(cpumask_t *mask)); |
| 147 | bool nmi_cpu_backtrace(struct pt_regs *regs); |
| 148 | |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 149 | #else |
| 150 | static inline bool trigger_all_cpu_backtrace(void) |
| 151 | { |
| 152 | return false; |
| 153 | } |
Aaron Tomlin | f3aca3d0 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 154 | static inline bool trigger_allbutself_cpu_backtrace(void) |
| 155 | { |
| 156 | return false; |
| 157 | } |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 158 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) |
| 159 | { |
| 160 | return false; |
| 161 | } |
| 162 | static inline bool trigger_single_cpu_backtrace(int cpu) |
| 163 | { |
| 164 | return false; |
| 165 | } |
Andrew Morton | bb81a09 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 166 | #endif |
| 167 | |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 168 | #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF |
Mandeep Singh Baines | 4eec42f | 2011-05-22 22:10:23 -0700 | [diff] [blame] | 169 | u64 hw_nmi_get_sample_period(int watchdog_thresh); |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 170 | #endif |
| 171 | |
Thomas Gleixner | 7edaeb6 | 2017-08-15 09:50:13 +0200 | [diff] [blame] | 172 | #if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \ |
| 173 | defined(CONFIG_HARDLOCKUP_DETECTOR) |
| 174 | void watchdog_update_hrtimer_threshold(u64 period); |
| 175 | #else |
| 176 | static inline void watchdog_update_hrtimer_threshold(u64 period) { } |
| 177 | #endif |
| 178 | |
Don Zickus | 504d7cf | 2010-02-12 17:19:19 -0500 | [diff] [blame] | 179 | struct ctl_table; |
Ulrich Obergfell | 83a80a3 | 2015-04-14 15:44:08 -0700 | [diff] [blame] | 180 | extern int proc_watchdog(struct ctl_table *, int , |
| 181 | void __user *, size_t *, loff_t *); |
| 182 | extern int proc_nmi_watchdog(struct ctl_table *, int , |
| 183 | void __user *, size_t *, loff_t *); |
| 184 | extern int proc_soft_watchdog(struct ctl_table *, int , |
| 185 | void __user *, size_t *, loff_t *); |
| 186 | extern int proc_watchdog_thresh(struct ctl_table *, int , |
| 187 | void __user *, size_t *, loff_t *); |
Chris Metcalf | fe4ba3c | 2015-06-24 16:55:45 -0700 | [diff] [blame] | 188 | extern int proc_watchdog_cpumask(struct ctl_table *, int, |
| 189 | void __user *, size_t *, loff_t *); |
Don Zickus | 84e478c | 2010-02-05 21:47:05 -0500 | [diff] [blame] | 190 | |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 191 | #ifdef CONFIG_HAVE_ACPI_APEI_NMI |
| 192 | #include <asm/nmi.h> |
| 193 | #endif |
| 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | #endif |