]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/nmi.h
perf/x86/intel, watchdog/core: Sanitize PMU HT bug workaround
[mirror_ubuntu-bionic-kernel.git] / include / linux / nmi.h
CommitLineData
1da177e4
LT
1/*
2 * linux/include/linux/nmi.h
3 */
4#ifndef LINUX_NMI_H
5#define LINUX_NMI_H
6
9938406a 7#include <linux/sched.h>
1da177e4 8#include <asm/irq.h>
f2e0cff8
NP
9#if defined(CONFIG_HAVE_NMI_WATCHDOG)
10#include <asm/nmi.h>
11#endif
1da177e4 12
d151b27d 13#ifdef CONFIG_LOCKUP_DETECTOR
05a4a952
NP
14void lockup_detector_init(void);
15#else
16static inline void lockup_detector_init(void)
17{
18}
19#endif
20
21#ifdef CONFIG_SOFTLOCKUP_DETECTOR
d151b27d
IM
22extern void touch_softlockup_watchdog_sched(void);
23extern void touch_softlockup_watchdog(void);
24extern void touch_softlockup_watchdog_sync(void);
25extern void touch_all_softlockup_watchdogs(void);
d151b27d 26extern unsigned int softlockup_panic;
05a4a952
NP
27extern int soft_watchdog_enabled;
28extern atomic_t watchdog_park_in_progress;
d151b27d
IM
29#else
30static inline void touch_softlockup_watchdog_sched(void)
31{
32}
33static inline void touch_softlockup_watchdog(void)
34{
35}
36static inline void touch_softlockup_watchdog_sync(void)
37{
38}
39static inline void touch_all_softlockup_watchdogs(void)
40{
41}
d151b27d
IM
42#endif
43
44#ifdef CONFIG_DETECT_HUNG_TASK
45void reset_hung_task_detector(void);
46#else
47static inline void reset_hung_task_detector(void)
48{
49}
50#endif
51
249e52e3
BM
52/*
53 * The run state of the lockup detectors is controlled by the content of the
54 * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
55 * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
56 *
57 * 'watchdog_user_enabled', 'nmi_watchdog_enabled' and 'soft_watchdog_enabled'
58 * are variables that are only used as an 'interface' between the parameters
59 * in /proc/sys/kernel and the internal state bits in 'watchdog_enabled'. The
60 * 'watchdog_thresh' variable is handled differently because its value is not
61 * boolean, and the lockup detectors are 'suspended' while 'watchdog_thresh'
62 * is equal zero.
63 */
64#define NMI_WATCHDOG_ENABLED_BIT 0
65#define SOFT_WATCHDOG_ENABLED_BIT 1
66#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
67#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
68
f2e0cff8
NP
69#if defined(CONFIG_HARDLOCKUP_DETECTOR)
70extern void hardlockup_detector_disable(void);
05a4a952 71extern unsigned int hardlockup_panic;
f2e0cff8
NP
72#else
73static inline void hardlockup_detector_disable(void) {}
74#endif
75
05a4a952 76#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
f2e0cff8 77extern void arch_touch_nmi_watchdog(void);
d0b6e0a8
PZ
78extern void hardlockup_detector_perf_stop(void);
79extern void hardlockup_detector_perf_restart(void);
f2e0cff8 80#else
d0b6e0a8
PZ
81static inline void hardlockup_detector_perf_stop(void) { }
82static inline void hardlockup_detector_perf_restart(void) { }
05a4a952 83#if !defined(CONFIG_HAVE_NMI_WATCHDOG)
f2e0cff8
NP
84static inline void arch_touch_nmi_watchdog(void) {}
85#endif
05a4a952 86#endif
f2e0cff8 87
1da177e4
LT
88/**
89 * touch_nmi_watchdog - restart NMI watchdog timeout.
90 *
91 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
92 * may be used to reset the timeout - for code which intentionally
93 * disables interrupts for a long time. This call is stateless.
94 */
5d0e600d
IM
95static inline void touch_nmi_watchdog(void)
96{
f2e0cff8 97 arch_touch_nmi_watchdog();
5d0e600d
IM
98 touch_softlockup_watchdog();
99}
6e7458a6 100
47cab6a7
IM
101/*
102 * Create trigger_all_cpu_backtrace() out of the arch-provided
103 * base function. Return whether such support was available,
104 * to allow calling code to fall back to some other mechanism:
105 */
9a01c3ed 106#ifdef arch_trigger_cpumask_backtrace
47cab6a7
IM
107static inline bool trigger_all_cpu_backtrace(void)
108{
9a01c3ed 109 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
47cab6a7
IM
110 return true;
111}
9a01c3ed 112
f3aca3d0
AT
113static inline bool trigger_allbutself_cpu_backtrace(void)
114{
9a01c3ed
CM
115 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
116 return true;
117}
118
119static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
120{
121 arch_trigger_cpumask_backtrace(mask, false);
122 return true;
123}
124
125static inline bool trigger_single_cpu_backtrace(int cpu)
126{
127 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
f3aca3d0
AT
128 return true;
129}
b2c0b2cb
RK
130
131/* generic implementation */
9a01c3ed
CM
132void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
133 bool exclude_self,
b2c0b2cb
RK
134 void (*raise)(cpumask_t *mask));
135bool nmi_cpu_backtrace(struct pt_regs *regs);
136
47cab6a7
IM
137#else
138static inline bool trigger_all_cpu_backtrace(void)
139{
140 return false;
141}
f3aca3d0
AT
142static inline bool trigger_allbutself_cpu_backtrace(void)
143{
144 return false;
145}
9a01c3ed
CM
146static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
147{
148 return false;
149}
150static inline bool trigger_single_cpu_backtrace(int cpu)
151{
152 return false;
153}
bb81a09e
AM
154#endif
155
05a4a952 156#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
4eec42f3 157u64 hw_nmi_get_sample_period(int watchdog_thresh);
05a4a952
NP
158#endif
159
160#ifdef CONFIG_LOCKUP_DETECTOR
84d56e66 161extern int nmi_watchdog_enabled;
3c00ea82 162extern int watchdog_user_enabled;
586692a5 163extern int watchdog_thresh;
249e52e3 164extern unsigned long watchdog_enabled;
05a4a952 165extern struct cpumask watchdog_cpumask;
fe4ba3c3 166extern unsigned long *watchdog_cpumask_bits;
05a4a952 167extern int __read_mostly watchdog_suspended;
249e52e3 168#ifdef CONFIG_SMP
ed235875 169extern int sysctl_softlockup_all_cpu_backtrace;
55537871 170extern int sysctl_hardlockup_all_cpu_backtrace;
249e52e3
BM
171#else
172#define sysctl_softlockup_all_cpu_backtrace 0
173#define sysctl_hardlockup_all_cpu_backtrace 0
174#endif
7edaeb68
TG
175
176#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
177 defined(CONFIG_HARDLOCKUP_DETECTOR)
178void watchdog_update_hrtimer_threshold(u64 period);
179#else
180static inline void watchdog_update_hrtimer_threshold(u64 period) { }
181#endif
182
249e52e3 183extern bool is_hardlockup(void);
504d7cf1 184struct ctl_table;
83a80a39
UO
185extern int proc_watchdog(struct ctl_table *, int ,
186 void __user *, size_t *, loff_t *);
187extern int proc_nmi_watchdog(struct ctl_table *, int ,
188 void __user *, size_t *, loff_t *);
189extern int proc_soft_watchdog(struct ctl_table *, int ,
190 void __user *, size_t *, loff_t *);
191extern int proc_watchdog_thresh(struct ctl_table *, int ,
192 void __user *, size_t *, loff_t *);
fe4ba3c3
CM
193extern int proc_watchdog_cpumask(struct ctl_table *, int,
194 void __user *, size_t *, loff_t *);
ec6a9066
UO
195extern int lockup_detector_suspend(void);
196extern void lockup_detector_resume(void);
999bbe49 197#else
ec6a9066 198static inline int lockup_detector_suspend(void)
999bbe49
UO
199{
200 return 0;
201}
202
ec6a9066 203static inline void lockup_detector_resume(void)
999bbe49
UO
204{
205}
84e478c6
DZ
206#endif
207
44a69f61
TN
208#ifdef CONFIG_HAVE_ACPI_APEI_NMI
209#include <asm/nmi.h>
210#endif
211
1da177e4 212#endif