blob: 11f9130ac513e732fb6f9832d3af32c07bd4bd05 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * NMI watchdog support on APIC systems
3 *
4 * Started by Ingo Molnar <mingo@redhat.com>
5 *
6 * Fixes:
7 * Mikael Pettersson : AMD K7 support for local APIC NMI watchdog.
8 * Mikael Pettersson : Power Management for local APIC NMI watchdog.
9 * Pavel Machek and
10 * Mikael Pettersson : PM converted to driver model. Disable/enable API.
11 */
12
Andrew Mortonbb81a092006-12-07 02:14:01 +010013#include <linux/nmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/module.h>
18#include <linux/sysdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/sysctl.h>
Andi Kleeneddb6fb2006-02-03 21:50:41 +010020#include <linux/kprobes.h>
Andrew Mortonbb81a092006-12-07 02:14:01 +010021#include <linux/cpumask.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070022#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/nmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/proto.h>
Andi Kleen553f2652006-04-07 19:49:57 +020027#include <asm/mce.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Glauber de Oliveira Costae32ede12008-03-19 14:25:35 -030029#include <mach_traps.h>
30
Andi Kleen29cbc782006-09-30 01:47:55 +020031int unknown_nmi_panic;
32int nmi_watchdog_enabled;
33int panic_on_unrecovered_nmi;
34
Andi Kleen1714f9b2007-04-16 10:30:27 +020035static cpumask_t backtrace_mask = CPU_MASK_NONE;
Don Zickus828f0af2006-09-26 10:52:26 +020036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/* nmi_active:
Don Zickusf2802e72006-09-26 10:52:26 +020038 * >0: the lapic NMI watchdog is active, but can be disabled
39 * <0: the lapic NMI watchdog has not been set up, and cannot
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 * be enabled
Don Zickusf2802e72006-09-26 10:52:26 +020041 * 0: the lapic NMI watchdog is disabled, but can be enabled
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 */
Don Zickusf2802e72006-09-26 10:52:26 +020043atomic_t nmi_active = ATOMIC_INIT(0); /* oprofile uses this */
Adrian Bunk867ab542008-01-30 13:30:31 +010044static int panic_on_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46unsigned int nmi_watchdog = NMI_DEFAULT;
47static unsigned int nmi_hz = HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Andi Kleen05cb0072007-05-02 19:27:20 +020049static DEFINE_PER_CPU(short, wd_enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/* Run after command line and cpu_init init, but before all other checks */
Don Zickuse33e89a2006-09-26 10:52:27 +020052void nmi_watchdog_default(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 if (nmi_watchdog != NMI_DEFAULT)
55 return;
Linus Torvalds8ce5e3e2007-03-14 17:50:48 -070056 nmi_watchdog = NMI_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Ravikiran G Thirumalai92715e22006-12-09 21:33:35 +010059static int endflag __initdata = 0;
60
Andi Kleen75152112005-05-16 21:53:34 -070061#ifdef CONFIG_SMP
62/* The performance counters used by NMI_LOCAL_APIC don't trigger when
63 * the CPU is idle. To make sure the NMI watchdog really ticks on all
64 * CPUs during the test make them busy.
65 */
66static __init void nmi_cpu_busy(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Ingo Molnar366c7f52006-07-03 00:25:25 -070068 local_irq_enable_in_hardirq();
Andi Kleen75152112005-05-16 21:53:34 -070069 /* Intentionally don't use cpu_relax here. This is
70 to make sure that the performance counter really ticks,
71 even if there is a simulator or similar that catches the
72 pause instruction. On a real HT machine this is fine because
73 all other CPUs are busy with "useless" delay loops and don't
74 care if they get somewhat less cycles. */
Ravikiran G Thirumalai92715e22006-12-09 21:33:35 +010075 while (endflag == 0)
76 mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
Andi Kleen75152112005-05-16 21:53:34 -070078#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +010080int __init check_nmi_watchdog(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +010082 int *prev_nmi_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 int cpu;
84
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +010085 if ((nmi_watchdog == NMI_NONE) || (nmi_watchdog == NMI_DISABLED))
Don Zickusf2802e72006-09-26 10:52:26 +020086 return 0;
87
88 if (!atomic_read(&nmi_active))
89 return 0;
90
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +010091 prev_nmi_count = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL);
92 if (!prev_nmi_count)
Andi Kleen75152112005-05-16 21:53:34 -070093 return -1;
Jack F Vogel67701ae92005-05-01 08:58:48 -070094
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +010095 printk(KERN_INFO "Testing NMI watchdog ... ");
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Andi Kleen7554c3f2006-01-11 22:45:45 +010097#ifdef CONFIG_SMP
Andi Kleen75152112005-05-16 21:53:34 -070098 if (nmi_watchdog == NMI_LOCAL_APIC)
99 smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
Andi Kleen7554c3f2006-01-11 22:45:45 +0100100#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 for (cpu = 0; cpu < NR_CPUS; cpu++)
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100103 prev_nmi_count[cpu] = cpu_pda(cpu)->__nmi_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 local_irq_enable();
Andi Kleen0fb2ebf2007-04-02 12:14:12 +0200105 mdelay((20*1000)/nmi_hz); // wait 20 ticks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Andrew Morton394e3902006-03-23 03:01:05 -0800107 for_each_online_cpu(cpu) {
Andi Kleen05cb0072007-05-02 19:27:20 +0200108 if (!per_cpu(wd_enabled, cpu))
Don Zickusf2802e72006-09-26 10:52:26 +0200109 continue;
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100110 if (cpu_pda(cpu)->__nmi_count - prev_nmi_count[cpu] <= 5) {
Don Zickus75bc1222007-12-04 17:19:07 +0100111 printk(KERN_WARNING "WARNING: CPU#%d: NMI "
112 "appears to be stuck (%d->%d)!\n",
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100113 cpu,
114 prev_nmi_count[cpu],
115 cpu_pda(cpu)->__nmi_count);
Andi Kleen05cb0072007-05-02 19:27:20 +0200116 per_cpu(wd_enabled, cpu) = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200117 atomic_dec(&nmi_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119 }
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100120 endflag = 1;
Don Zickusf2802e72006-09-26 10:52:26 +0200121 if (!atomic_read(&nmi_active)) {
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100122 kfree(prev_nmi_count);
Don Zickusf2802e72006-09-26 10:52:26 +0200123 atomic_set(&nmi_active, -1);
124 return -1;
125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 printk("OK.\n");
127
128 /* now that we know it works we can reduce NMI frequency to
129 something more reasonable; makes a difference in some configs */
Andi Kleen05cb0072007-05-02 19:27:20 +0200130 if (nmi_watchdog == NMI_LOCAL_APIC)
131 nmi_hz = lapic_adjust_nmi_hz(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100133 kfree(prev_nmi_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return 0;
135}
136
Adrian Bunk867ab542008-01-30 13:30:31 +0100137static int __init setup_nmi_watchdog(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 int nmi;
140
141 if (!strncmp(str,"panic",5)) {
142 panic_on_timeout = 1;
143 str = strchr(str, ',');
144 if (!str)
145 return 1;
146 ++str;
147 }
148
149 get_option(&str, &nmi);
150
Don Zickusf2802e72006-09-26 10:52:26 +0200151 if ((nmi >= NMI_INVALID) || (nmi < NMI_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 return 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200153
Andi Kleen75152112005-05-16 21:53:34 -0700154 nmi_watchdog = nmi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 return 1;
156}
157
158__setup("nmi_watchdog=", setup_nmi_watchdog);
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#ifdef CONFIG_PM
161
162static int nmi_pm_active; /* nmi_active before suspend */
163
Pavel Machek829ca9a2005-09-03 15:56:56 -0700164static int lapic_nmi_suspend(struct sys_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Shaohua Li4038f902006-09-26 10:52:27 +0200166 /* only CPU0 goes here, other CPUs should be offline */
Don Zickusf2802e72006-09-26 10:52:26 +0200167 nmi_pm_active = atomic_read(&nmi_active);
Shaohua Li4038f902006-09-26 10:52:27 +0200168 stop_apic_nmi_watchdog(NULL);
169 BUG_ON(atomic_read(&nmi_active) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return 0;
171}
172
173static int lapic_nmi_resume(struct sys_device *dev)
174{
Shaohua Li4038f902006-09-26 10:52:27 +0200175 /* only CPU0 goes here, other CPUs should be offline */
176 if (nmi_pm_active > 0) {
177 setup_apic_nmi_watchdog(NULL);
178 touch_nmi_watchdog();
179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 return 0;
181}
182
183static struct sysdev_class nmi_sysclass = {
Kay Sieversaf5ca3f42007-12-20 02:09:39 +0100184 .name = "lapic_nmi",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 .resume = lapic_nmi_resume,
186 .suspend = lapic_nmi_suspend,
187};
188
189static struct sys_device device_lapic_nmi = {
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100190 .id = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 .cls = &nmi_sysclass,
192};
193
194static int __init init_lapic_nmi_sysfs(void)
195{
196 int error;
197
Don Zickusf2802e72006-09-26 10:52:26 +0200198 /* should really be a BUG_ON but b/c this is an
199 * init call, it just doesn't work. -dcz
200 */
201 if (nmi_watchdog != NMI_LOCAL_APIC)
202 return 0;
203
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100204 if (atomic_read(&nmi_active) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return 0;
206
207 error = sysdev_class_register(&nmi_sysclass);
208 if (!error)
209 error = sysdev_register(&device_lapic_nmi);
210 return error;
211}
212/* must come after the local APIC's device_initcall() */
213late_initcall(init_lapic_nmi_sysfs);
214
215#endif /* CONFIG_PM */
216
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100217static void __acpi_nmi_enable(void *__unused)
218{
219 apic_write(APIC_LVT0, APIC_DM_NMI);
220}
221
222/*
223 * Enable timer based NMIs on all CPUs:
224 */
225void acpi_nmi_enable(void)
226{
227 if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
228 on_each_cpu(__acpi_nmi_enable, NULL, 0, 1);
229}
230
231static void __acpi_nmi_disable(void *__unused)
232{
233 apic_write(APIC_LVT0, APIC_DM_NMI | APIC_LVT_MASKED);
234}
235
236/*
237 * Disable timer based NMIs on all CPUs:
238 */
239void acpi_nmi_disable(void)
240{
241 if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
242 on_each_cpu(__acpi_nmi_disable, NULL, 0, 1);
243}
244
Don Zickusf2802e72006-09-26 10:52:26 +0200245void setup_apic_nmi_watchdog(void *unused)
246{
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100247 if (__get_cpu_var(wd_enabled))
Shaohua Li4038f902006-09-26 10:52:27 +0200248 return;
249
250 /* cheap hack to support suspend/resume */
251 /* if cpu0 is not active neither should the other cpus */
252 if ((smp_processor_id() != 0) && (atomic_read(&nmi_active) <= 0))
253 return;
254
Andi Kleen05cb0072007-05-02 19:27:20 +0200255 switch (nmi_watchdog) {
256 case NMI_LOCAL_APIC:
257 __get_cpu_var(wd_enabled) = 1;
258 if (lapic_watchdog_init(nmi_hz) < 0) {
259 __get_cpu_var(wd_enabled) = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200260 return;
261 }
Andi Kleen05cb0072007-05-02 19:27:20 +0200262 /* FALL THROUGH */
263 case NMI_IO_APIC:
264 __get_cpu_var(wd_enabled) = 1;
265 atomic_inc(&nmi_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
Don Zickusf2802e72006-09-26 10:52:26 +0200267}
268
Shaohua Li4038f902006-09-26 10:52:27 +0200269void stop_apic_nmi_watchdog(void *unused)
Don Zickusf2802e72006-09-26 10:52:26 +0200270{
271 /* only support LOCAL and IO APICs for now */
272 if ((nmi_watchdog != NMI_LOCAL_APIC) &&
273 (nmi_watchdog != NMI_IO_APIC))
274 return;
Andi Kleen05cb0072007-05-02 19:27:20 +0200275 if (__get_cpu_var(wd_enabled) == 0)
Shaohua Li4038f902006-09-26 10:52:27 +0200276 return;
Andi Kleen05cb0072007-05-02 19:27:20 +0200277 if (nmi_watchdog == NMI_LOCAL_APIC)
278 lapic_watchdog_stop();
279 __get_cpu_var(wd_enabled) = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200280 atomic_dec(&nmi_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
282
283/*
284 * the best way to detect whether a CPU has a 'hard lockup' problem
285 * is to check it's local APIC timer IRQ counts. If they are not
286 * changing then that CPU has some problem.
287 *
288 * as these watchdog NMI IRQs are generated on every CPU, we only
289 * have to check the current processor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 */
291
Andi Kleen75152112005-05-16 21:53:34 -0700292static DEFINE_PER_CPU(unsigned, last_irq_sum);
293static DEFINE_PER_CPU(local_t, alert_counter);
294static DEFINE_PER_CPU(int, nmi_touch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Andrew Morton567f3e42007-07-17 04:03:58 -0700296void touch_nmi_watchdog(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Jan Beulich99019e92006-02-16 23:41:55 +0100298 if (nmi_watchdog > 0) {
299 unsigned cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Jan Beulich99019e92006-02-16 23:41:55 +0100301 /*
302 * Tell other CPUs to reset their alert counters. We cannot
303 * do it ourselves because the alert count increase is not
304 * atomic.
305 */
Andrew Morton567f3e42007-07-17 04:03:58 -0700306 for_each_present_cpu(cpu) {
307 if (per_cpu(nmi_touch, cpu) != 1)
308 per_cpu(nmi_touch, cpu) = 1;
309 }
Jan Beulich99019e92006-02-16 23:41:55 +0100310 }
Ingo Molnar8446f1d2005-09-06 15:16:27 -0700311
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100312 touch_softlockup_watchdog();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
Hiroshi Shimamoto416b7212008-01-30 13:30:33 +0100314EXPORT_SYMBOL(touch_nmi_watchdog);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Don Zickus3adbbcc2006-09-26 10:52:26 +0200316int __kprobes nmi_watchdog_tick(struct pt_regs * regs, unsigned reason)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Andi Kleen75152112005-05-16 21:53:34 -0700318 int sum;
319 int touched = 0;
Andrew Mortonbb81a092006-12-07 02:14:01 +0100320 int cpu = smp_processor_id();
Andi Kleen05cb0072007-05-02 19:27:20 +0200321 int rc = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200322
323 /* check for other users first */
324 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
325 == NOTIFY_STOP) {
Don Zickus3adbbcc2006-09-26 10:52:26 +0200326 rc = 1;
Don Zickusf2802e72006-09-26 10:52:26 +0200327 touched = 1;
328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Thomas Gleixner4e77ae32007-10-12 23:04:07 +0200330 sum = read_pda(apic_timer_irqs) + read_pda(irq0_irqs);
Andi Kleen75152112005-05-16 21:53:34 -0700331 if (__get_cpu_var(nmi_touch)) {
332 __get_cpu_var(nmi_touch) = 0;
333 touched = 1;
334 }
Don Zickusf2802e72006-09-26 10:52:26 +0200335
Andrew Mortonbb81a092006-12-07 02:14:01 +0100336 if (cpu_isset(cpu, backtrace_mask)) {
337 static DEFINE_SPINLOCK(lock); /* Serialise the printks */
338
339 spin_lock(&lock);
340 printk("NMI backtrace for cpu %d\n", cpu);
341 dump_stack();
342 spin_unlock(&lock);
343 cpu_clear(cpu, backtrace_mask);
344 }
345
Andi Kleen553f2652006-04-07 19:49:57 +0200346#ifdef CONFIG_X86_MCE
347 /* Could check oops_in_progress here too, but it's safer
348 not too */
349 if (atomic_read(&mce_entry) > 0)
350 touched = 1;
351#endif
Don Zickusf2802e72006-09-26 10:52:26 +0200352 /* if the apic timer isn't firing, this cpu isn't doing much */
Andi Kleen75152112005-05-16 21:53:34 -0700353 if (!touched && __get_cpu_var(last_irq_sum) == sum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 /*
355 * Ayiee, looks like this CPU is stuck ...
356 * wait a few IRQs (5 seconds) before doing the oops ...
357 */
Andi Kleen75152112005-05-16 21:53:34 -0700358 local_inc(&__get_cpu_var(alert_counter));
Don Zickusf2802e72006-09-26 10:52:26 +0200359 if (local_read(&__get_cpu_var(alert_counter)) == 5*nmi_hz)
Andi Kleenfac58552006-09-26 10:52:27 +0200360 die_nmi("NMI Watchdog detected LOCKUP on CPU %d\n", regs,
361 panic_on_timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 } else {
Andi Kleen75152112005-05-16 21:53:34 -0700363 __get_cpu_var(last_irq_sum) = sum;
364 local_set(&__get_cpu_var(alert_counter), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
Don Zickusf2802e72006-09-26 10:52:26 +0200366
367 /* see if the nmi watchdog went off */
Andi Kleen05cb0072007-05-02 19:27:20 +0200368 if (!__get_cpu_var(wd_enabled))
369 return rc;
370 switch (nmi_watchdog) {
371 case NMI_LOCAL_APIC:
372 rc |= lapic_wd_event(nmi_hz);
373 break;
374 case NMI_IO_APIC:
375 /* don't know how to accurately check for this.
376 * just assume it was a watchdog timer interrupt
377 * This matches the old behaviour.
378 */
379 rc = 1;
380 break;
Andi Kleen75152112005-05-16 21:53:34 -0700381 }
Don Zickus3adbbcc2006-09-26 10:52:26 +0200382 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
384
Andi Kleen8f4e9562007-07-22 11:12:32 +0200385static unsigned ignore_nmis;
386
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100387asmlinkage __kprobes void do_nmi(struct pt_regs * regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 nmi_enter();
390 add_pda(__nmi_count,1);
Andi Kleen8f4e9562007-07-22 11:12:32 +0200391 if (!ignore_nmis)
392 default_do_nmi(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 nmi_exit();
394}
395
Andi Kleen8f4e9562007-07-22 11:12:32 +0200396void stop_nmi(void)
397{
398 acpi_nmi_disable();
399 ignore_nmis++;
400}
401
402void restart_nmi(void)
403{
404 ignore_nmis--;
405 acpi_nmi_enable();
406}
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408#ifdef CONFIG_SYSCTL
409
410static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
411{
412 unsigned char reason = get_nmi_reason();
413 char buf[64];
414
Don Zickus2fbe7b22006-09-26 10:52:27 +0200415 sprintf(buf, "NMI received for unknown reason %02x\n", reason);
Andi Kleenfac58552006-09-26 10:52:27 +0200416 die_nmi(buf, regs, 1); /* Always panic here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 return 0;
418}
419
Don Zickus407984f2006-09-26 10:52:27 +0200420/*
421 * proc handler for /proc/sys/kernel/nmi
422 */
423int proc_nmi_enabled(struct ctl_table *table, int write, struct file *file,
424 void __user *buffer, size_t *length, loff_t *ppos)
425{
426 int old_state;
427
428 nmi_watchdog_enabled = (atomic_read(&nmi_active) > 0) ? 1 : 0;
429 old_state = nmi_watchdog_enabled;
430 proc_dointvec(table, write, file, buffer, length, ppos);
431 if (!!old_state == !!nmi_watchdog_enabled)
432 return 0;
433
Daniel Gollub0328ece2007-08-15 02:40:35 +0200434 if (atomic_read(&nmi_active) < 0 || nmi_watchdog == NMI_DISABLED) {
Don Zickus407984f2006-09-26 10:52:27 +0200435 printk( KERN_WARNING "NMI watchdog is permanently disabled\n");
Don Zickuse33e89a2006-09-26 10:52:27 +0200436 return -EIO;
Don Zickus407984f2006-09-26 10:52:27 +0200437 }
438
439 /* if nmi_watchdog is not set yet, then set it */
440 nmi_watchdog_default();
441
Don Zickuse33e89a2006-09-26 10:52:27 +0200442 if (nmi_watchdog == NMI_LOCAL_APIC) {
Don Zickus407984f2006-09-26 10:52:27 +0200443 if (nmi_watchdog_enabled)
444 enable_lapic_nmi_watchdog();
445 else
446 disable_lapic_nmi_watchdog();
Don Zickus407984f2006-09-26 10:52:27 +0200447 } else {
Don Zickuse33e89a2006-09-26 10:52:27 +0200448 printk( KERN_WARNING
Don Zickus407984f2006-09-26 10:52:27 +0200449 "NMI watchdog doesn't know what hardware to touch\n");
450 return -EIO;
451 }
452 return 0;
453}
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#endif
456
Li Zefana062bae2008-02-03 15:40:30 +0800457int do_nmi_callback(struct pt_regs *regs, int cpu)
458{
459#ifdef CONFIG_SYSCTL
460 if (unknown_nmi_panic)
461 return unknown_nmi_panic_callback(regs, cpu);
462#endif
463 return 0;
464}
465
Andrew Mortonbb81a092006-12-07 02:14:01 +0100466void __trigger_all_cpu_backtrace(void)
467{
468 int i;
469
470 backtrace_mask = cpu_online_map;
471 /* Wait for up to 10 seconds for all CPUs to do the backtrace */
472 for (i = 0; i < 10 * 1000; i++) {
473 if (cpus_empty(backtrace_mask))
474 break;
475 mdelay(1);
476 }
477}
478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479EXPORT_SYMBOL(nmi_active);
480EXPORT_SYMBOL(nmi_watchdog);