blob: cb8ee9d02f8682d4e52374aae1847a4daf03292a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/x86_64/nmi.c
3 *
4 * NMI watchdog support on APIC systems
5 *
6 * Started by Ingo Molnar <mingo@redhat.com>
7 *
8 * Fixes:
9 * Mikael Pettersson : AMD K7 support for local APIC NMI watchdog.
10 * Mikael Pettersson : Power Management for local APIC NMI watchdog.
11 * Pavel Machek and
12 * Mikael Pettersson : PM converted to driver model. Disable/enable API.
13 */
14
Andrew Mortonbb81a092006-12-07 02:14:01 +010015#include <linux/nmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/module.h>
20#include <linux/sysdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/sysctl.h>
Andi Kleeneddb6fb2006-02-03 21:50:41 +010022#include <linux/kprobes.h>
Andrew Mortonbb81a092006-12-07 02:14:01 +010023#include <linux/cpumask.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070024#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/nmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/proto.h>
Andi Kleen553f2652006-04-07 19:49:57 +020029#include <asm/mce.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044int panic_on_timeout;
45
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
Don Zickusf2802e72006-09-26 10:52:26 +020051/* local prototypes */
Don Zickusf2802e72006-09-26 10:52:26 +020052static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu);
Andi Kleen75152112005-05-16 21:53:34 -070053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/* Run after command line and cpu_init init, but before all other checks */
Don Zickuse33e89a2006-09-26 10:52:27 +020055void nmi_watchdog_default(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 if (nmi_watchdog != NMI_DEFAULT)
58 return;
Linus Torvalds8ce5e3e2007-03-14 17:50:48 -070059 nmi_watchdog = NMI_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Ravikiran G Thirumalai92715e22006-12-09 21:33:35 +010062static int endflag __initdata = 0;
63
Andi Kleen75152112005-05-16 21:53:34 -070064#ifdef CONFIG_SMP
65/* The performance counters used by NMI_LOCAL_APIC don't trigger when
66 * the CPU is idle. To make sure the NMI watchdog really ticks on all
67 * CPUs during the test make them busy.
68 */
69static __init void nmi_cpu_busy(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Ingo Molnar366c7f52006-07-03 00:25:25 -070071 local_irq_enable_in_hardirq();
Andi Kleen75152112005-05-16 21:53:34 -070072 /* Intentionally don't use cpu_relax here. This is
73 to make sure that the performance counter really ticks,
74 even if there is a simulator or similar that catches the
75 pause instruction. On a real HT machine this is fine because
76 all other CPUs are busy with "useless" delay loops and don't
77 care if they get somewhat less cycles. */
Ravikiran G Thirumalai92715e22006-12-09 21:33:35 +010078 while (endflag == 0)
79 mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
Andi Kleen75152112005-05-16 21:53:34 -070081#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Andi Kleen75152112005-05-16 21:53:34 -070083int __init check_nmi_watchdog (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Andi Kleenac6b9312005-05-16 21:53:19 -070085 int *counts;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 int cpu;
87
Don Zickusf2802e72006-09-26 10:52:26 +020088 if ((nmi_watchdog == NMI_NONE) || (nmi_watchdog == NMI_DEFAULT))
89 return 0;
90
91 if (!atomic_read(&nmi_active))
92 return 0;
93
Andi Kleen75152112005-05-16 21:53:34 -070094 counts = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL);
95 if (!counts)
96 return -1;
Jack F Vogel67701ae2005-05-01 08:58:48 -070097
Andi Kleen75152112005-05-16 21:53:34 -070098 printk(KERN_INFO "testing NMI watchdog ... ");
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Andi Kleen7554c3f2006-01-11 22:45:45 +0100100#ifdef CONFIG_SMP
Andi Kleen75152112005-05-16 21:53:34 -0700101 if (nmi_watchdog == NMI_LOCAL_APIC)
102 smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
Andi Kleen7554c3f2006-01-11 22:45:45 +0100103#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 for (cpu = 0; cpu < NR_CPUS; cpu++)
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100106 counts[cpu] = cpu_pda(cpu)->__nmi_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 local_irq_enable();
Andi Kleen0fb2ebf2007-04-02 12:14:12 +0200108 mdelay((20*1000)/nmi_hz); // wait 20 ticks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Andrew Morton394e3902006-03-23 03:01:05 -0800110 for_each_online_cpu(cpu) {
Andi Kleen05cb0072007-05-02 19:27:20 +0200111 if (!per_cpu(wd_enabled, cpu))
Don Zickusf2802e72006-09-26 10:52:26 +0200112 continue;
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100113 if (cpu_pda(cpu)->__nmi_count - counts[cpu] <= 5) {
Andi Kleen75152112005-05-16 21:53:34 -0700114 printk("CPU#%d: NMI appears to be stuck (%d->%d)!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 cpu,
Andi Kleen75152112005-05-16 21:53:34 -0700116 counts[cpu],
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100117 cpu_pda(cpu)->__nmi_count);
Andi Kleen05cb0072007-05-02 19:27:20 +0200118 per_cpu(wd_enabled, cpu) = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200119 atomic_dec(&nmi_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121 }
Don Zickusf2802e72006-09-26 10:52:26 +0200122 if (!atomic_read(&nmi_active)) {
123 kfree(counts);
124 atomic_set(&nmi_active, -1);
Ravikiran G Thirumalai92715e22006-12-09 21:33:35 +0100125 endflag = 1;
Don Zickusf2802e72006-09-26 10:52:26 +0200126 return -1;
127 }
Andi Kleen75152112005-05-16 21:53:34 -0700128 endflag = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 printk("OK.\n");
130
131 /* now that we know it works we can reduce NMI frequency to
132 something more reasonable; makes a difference in some configs */
Andi Kleen05cb0072007-05-02 19:27:20 +0200133 if (nmi_watchdog == NMI_LOCAL_APIC)
134 nmi_hz = lapic_adjust_nmi_hz(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Andi Kleenac6b9312005-05-16 21:53:19 -0700136 kfree(counts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return 0;
138}
139
140int __init setup_nmi_watchdog(char *str)
141{
142 int nmi;
143
144 if (!strncmp(str,"panic",5)) {
145 panic_on_timeout = 1;
146 str = strchr(str, ',');
147 if (!str)
148 return 1;
149 ++str;
150 }
151
152 get_option(&str, &nmi);
153
Don Zickusf2802e72006-09-26 10:52:26 +0200154 if ((nmi >= NMI_INVALID) || (nmi < NMI_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 return 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200156
Andi Kleen75152112005-05-16 21:53:34 -0700157 nmi_watchdog = nmi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return 1;
159}
160
161__setup("nmi_watchdog=", setup_nmi_watchdog);
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Ingo Molnar5d0e6002007-02-13 13:26:24 +0100164static void __acpi_nmi_disable(void *__unused)
165{
166 apic_write(APIC_LVT0, APIC_DM_NMI | APIC_LVT_MASKED);
167}
168
169/*
170 * Disable timer based NMIs on all CPUs:
171 */
172void acpi_nmi_disable(void)
173{
174 if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
175 on_each_cpu(__acpi_nmi_disable, NULL, 0, 1);
176}
177
178static void __acpi_nmi_enable(void *__unused)
179{
180 apic_write(APIC_LVT0, APIC_DM_NMI);
181}
182
183/*
184 * Enable timer based NMIs on all CPUs:
185 */
186void acpi_nmi_enable(void)
187{
188 if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
189 on_each_cpu(__acpi_nmi_enable, NULL, 0, 1);
190}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#ifdef CONFIG_PM
192
193static int nmi_pm_active; /* nmi_active before suspend */
194
Pavel Machek829ca9a2005-09-03 15:56:56 -0700195static int lapic_nmi_suspend(struct sys_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Shaohua Li4038f902006-09-26 10:52:27 +0200197 /* only CPU0 goes here, other CPUs should be offline */
Don Zickusf2802e72006-09-26 10:52:26 +0200198 nmi_pm_active = atomic_read(&nmi_active);
Shaohua Li4038f902006-09-26 10:52:27 +0200199 stop_apic_nmi_watchdog(NULL);
200 BUG_ON(atomic_read(&nmi_active) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return 0;
202}
203
204static int lapic_nmi_resume(struct sys_device *dev)
205{
Shaohua Li4038f902006-09-26 10:52:27 +0200206 /* only CPU0 goes here, other CPUs should be offline */
207 if (nmi_pm_active > 0) {
208 setup_apic_nmi_watchdog(NULL);
209 touch_nmi_watchdog();
210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return 0;
212}
213
214static struct sysdev_class nmi_sysclass = {
215 set_kset_name("lapic_nmi"),
216 .resume = lapic_nmi_resume,
217 .suspend = lapic_nmi_suspend,
218};
219
220static struct sys_device device_lapic_nmi = {
221 .id = 0,
222 .cls = &nmi_sysclass,
223};
224
225static int __init init_lapic_nmi_sysfs(void)
226{
227 int error;
228
Don Zickusf2802e72006-09-26 10:52:26 +0200229 /* should really be a BUG_ON but b/c this is an
230 * init call, it just doesn't work. -dcz
231 */
232 if (nmi_watchdog != NMI_LOCAL_APIC)
233 return 0;
234
235 if ( atomic_read(&nmi_active) < 0 )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return 0;
237
238 error = sysdev_class_register(&nmi_sysclass);
239 if (!error)
240 error = sysdev_register(&device_lapic_nmi);
241 return error;
242}
243/* must come after the local APIC's device_initcall() */
244late_initcall(init_lapic_nmi_sysfs);
245
246#endif /* CONFIG_PM */
247
Don Zickusf2802e72006-09-26 10:52:26 +0200248void setup_apic_nmi_watchdog(void *unused)
249{
Andi Kleen05cb0072007-05-02 19:27:20 +0200250 if (__get_cpu_var(wd_enabled) == 1)
Shaohua Li4038f902006-09-26 10:52:27 +0200251 return;
252
253 /* cheap hack to support suspend/resume */
254 /* if cpu0 is not active neither should the other cpus */
255 if ((smp_processor_id() != 0) && (atomic_read(&nmi_active) <= 0))
256 return;
257
Andi Kleen05cb0072007-05-02 19:27:20 +0200258 switch (nmi_watchdog) {
259 case NMI_LOCAL_APIC:
260 __get_cpu_var(wd_enabled) = 1;
261 if (lapic_watchdog_init(nmi_hz) < 0) {
262 __get_cpu_var(wd_enabled) = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200263 return;
264 }
Andi Kleen05cb0072007-05-02 19:27:20 +0200265 /* FALL THROUGH */
266 case NMI_IO_APIC:
267 __get_cpu_var(wd_enabled) = 1;
268 atomic_inc(&nmi_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
Don Zickusf2802e72006-09-26 10:52:26 +0200270}
271
Shaohua Li4038f902006-09-26 10:52:27 +0200272void stop_apic_nmi_watchdog(void *unused)
Don Zickusf2802e72006-09-26 10:52:26 +0200273{
274 /* only support LOCAL and IO APICs for now */
275 if ((nmi_watchdog != NMI_LOCAL_APIC) &&
276 (nmi_watchdog != NMI_IO_APIC))
277 return;
Andi Kleen05cb0072007-05-02 19:27:20 +0200278 if (__get_cpu_var(wd_enabled) == 0)
Shaohua Li4038f902006-09-26 10:52:27 +0200279 return;
Andi Kleen05cb0072007-05-02 19:27:20 +0200280 if (nmi_watchdog == NMI_LOCAL_APIC)
281 lapic_watchdog_stop();
282 __get_cpu_var(wd_enabled) = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200283 atomic_dec(&nmi_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
285
286/*
287 * the best way to detect whether a CPU has a 'hard lockup' problem
288 * is to check it's local APIC timer IRQ counts. If they are not
289 * changing then that CPU has some problem.
290 *
291 * as these watchdog NMI IRQs are generated on every CPU, we only
292 * have to check the current processor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 */
294
Andi Kleen75152112005-05-16 21:53:34 -0700295static DEFINE_PER_CPU(unsigned, last_irq_sum);
296static DEFINE_PER_CPU(local_t, alert_counter);
297static DEFINE_PER_CPU(int, nmi_touch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Andrew Morton567f3e42007-07-17 04:03:58 -0700299void touch_nmi_watchdog(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Jan Beulich99019e92006-02-16 23:41:55 +0100301 if (nmi_watchdog > 0) {
302 unsigned cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Jan Beulich99019e92006-02-16 23:41:55 +0100304 /*
305 * Tell other CPUs to reset their alert counters. We cannot
306 * do it ourselves because the alert count increase is not
307 * atomic.
308 */
Andrew Morton567f3e42007-07-17 04:03:58 -0700309 for_each_present_cpu(cpu) {
310 if (per_cpu(nmi_touch, cpu) != 1)
311 per_cpu(nmi_touch, cpu) = 1;
312 }
Jan Beulich99019e92006-02-16 23:41:55 +0100313 }
Ingo Molnar8446f1d2005-09-06 15:16:27 -0700314
315 touch_softlockup_watchdog();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Don Zickus3adbbcce2006-09-26 10:52:26 +0200318int __kprobes nmi_watchdog_tick(struct pt_regs * regs, unsigned reason)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Andi Kleen75152112005-05-16 21:53:34 -0700320 int sum;
321 int touched = 0;
Andrew Mortonbb81a092006-12-07 02:14:01 +0100322 int cpu = smp_processor_id();
Andi Kleen05cb0072007-05-02 19:27:20 +0200323 int rc = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200324
325 /* check for other users first */
326 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
327 == NOTIFY_STOP) {
Don Zickus3adbbcce2006-09-26 10:52:26 +0200328 rc = 1;
Don Zickusf2802e72006-09-26 10:52:26 +0200329 touched = 1;
330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 sum = read_pda(apic_timer_irqs);
Andi Kleen75152112005-05-16 21:53:34 -0700333 if (__get_cpu_var(nmi_touch)) {
334 __get_cpu_var(nmi_touch) = 0;
335 touched = 1;
336 }
Don Zickusf2802e72006-09-26 10:52:26 +0200337
Andrew Mortonbb81a092006-12-07 02:14:01 +0100338 if (cpu_isset(cpu, backtrace_mask)) {
339 static DEFINE_SPINLOCK(lock); /* Serialise the printks */
340
341 spin_lock(&lock);
342 printk("NMI backtrace for cpu %d\n", cpu);
343 dump_stack();
344 spin_unlock(&lock);
345 cpu_clear(cpu, backtrace_mask);
346 }
347
Andi Kleen553f2652006-04-07 19:49:57 +0200348#ifdef CONFIG_X86_MCE
349 /* Could check oops_in_progress here too, but it's safer
350 not too */
351 if (atomic_read(&mce_entry) > 0)
352 touched = 1;
353#endif
Don Zickusf2802e72006-09-26 10:52:26 +0200354 /* if the apic timer isn't firing, this cpu isn't doing much */
Andi Kleen75152112005-05-16 21:53:34 -0700355 if (!touched && __get_cpu_var(last_irq_sum) == sum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 /*
357 * Ayiee, looks like this CPU is stuck ...
358 * wait a few IRQs (5 seconds) before doing the oops ...
359 */
Andi Kleen75152112005-05-16 21:53:34 -0700360 local_inc(&__get_cpu_var(alert_counter));
Don Zickusf2802e72006-09-26 10:52:26 +0200361 if (local_read(&__get_cpu_var(alert_counter)) == 5*nmi_hz)
Andi Kleenfac58552006-09-26 10:52:27 +0200362 die_nmi("NMI Watchdog detected LOCKUP on CPU %d\n", regs,
363 panic_on_timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 } else {
Andi Kleen75152112005-05-16 21:53:34 -0700365 __get_cpu_var(last_irq_sum) = sum;
366 local_set(&__get_cpu_var(alert_counter), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
Don Zickusf2802e72006-09-26 10:52:26 +0200368
369 /* see if the nmi watchdog went off */
Andi Kleen05cb0072007-05-02 19:27:20 +0200370 if (!__get_cpu_var(wd_enabled))
371 return rc;
372 switch (nmi_watchdog) {
373 case NMI_LOCAL_APIC:
374 rc |= lapic_wd_event(nmi_hz);
375 break;
376 case NMI_IO_APIC:
377 /* don't know how to accurately check for this.
378 * just assume it was a watchdog timer interrupt
379 * This matches the old behaviour.
380 */
381 rc = 1;
382 break;
Andi Kleen75152112005-05-16 21:53:34 -0700383 }
Don Zickus3adbbcce2006-09-26 10:52:26 +0200384 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
Andi Kleen8f4e9562007-07-22 11:12:32 +0200387static unsigned ignore_nmis;
388
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100389asmlinkage __kprobes void do_nmi(struct pt_regs * regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 nmi_enter();
392 add_pda(__nmi_count,1);
Andi Kleen8f4e9562007-07-22 11:12:32 +0200393 if (!ignore_nmis)
394 default_do_nmi(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 nmi_exit();
396}
397
Don Zickus3adbbcce2006-09-26 10:52:26 +0200398int do_nmi_callback(struct pt_regs * regs, int cpu)
399{
Don Zickus2fbe7b22006-09-26 10:52:27 +0200400#ifdef CONFIG_SYSCTL
401 if (unknown_nmi_panic)
402 return unknown_nmi_panic_callback(regs, cpu);
403#endif
404 return 0;
Don Zickus3adbbcce2006-09-26 10:52:26 +0200405}
406
Andi Kleen8f4e9562007-07-22 11:12:32 +0200407void stop_nmi(void)
408{
409 acpi_nmi_disable();
410 ignore_nmis++;
411}
412
413void restart_nmi(void)
414{
415 ignore_nmis--;
416 acpi_nmi_enable();
417}
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#ifdef CONFIG_SYSCTL
420
421static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
422{
423 unsigned char reason = get_nmi_reason();
424 char buf[64];
425
Don Zickus2fbe7b22006-09-26 10:52:27 +0200426 sprintf(buf, "NMI received for unknown reason %02x\n", reason);
Andi Kleenfac58552006-09-26 10:52:27 +0200427 die_nmi(buf, regs, 1); /* Always panic here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 return 0;
429}
430
Don Zickus407984f2006-09-26 10:52:27 +0200431/*
432 * proc handler for /proc/sys/kernel/nmi
433 */
434int proc_nmi_enabled(struct ctl_table *table, int write, struct file *file,
435 void __user *buffer, size_t *length, loff_t *ppos)
436{
437 int old_state;
438
439 nmi_watchdog_enabled = (atomic_read(&nmi_active) > 0) ? 1 : 0;
440 old_state = nmi_watchdog_enabled;
441 proc_dointvec(table, write, file, buffer, length, ppos);
442 if (!!old_state == !!nmi_watchdog_enabled)
443 return 0;
444
445 if (atomic_read(&nmi_active) < 0) {
446 printk( KERN_WARNING "NMI watchdog is permanently disabled\n");
Don Zickuse33e89a2006-09-26 10:52:27 +0200447 return -EIO;
Don Zickus407984f2006-09-26 10:52:27 +0200448 }
449
450 /* if nmi_watchdog is not set yet, then set it */
451 nmi_watchdog_default();
452
Don Zickuse33e89a2006-09-26 10:52:27 +0200453 if (nmi_watchdog == NMI_LOCAL_APIC) {
Don Zickus407984f2006-09-26 10:52:27 +0200454 if (nmi_watchdog_enabled)
455 enable_lapic_nmi_watchdog();
456 else
457 disable_lapic_nmi_watchdog();
Don Zickus407984f2006-09-26 10:52:27 +0200458 } else {
Don Zickuse33e89a2006-09-26 10:52:27 +0200459 printk( KERN_WARNING
Don Zickus407984f2006-09-26 10:52:27 +0200460 "NMI watchdog doesn't know what hardware to touch\n");
461 return -EIO;
462 }
463 return 0;
464}
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#endif
467
Andrew Mortonbb81a092006-12-07 02:14:01 +0100468void __trigger_all_cpu_backtrace(void)
469{
470 int i;
471
472 backtrace_mask = cpu_online_map;
473 /* Wait for up to 10 seconds for all CPUs to do the backtrace */
474 for (i = 0; i < 10 * 1000; i++) {
475 if (cpus_empty(backtrace_mask))
476 break;
477 mdelay(1);
478 }
479}
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481EXPORT_SYMBOL(nmi_active);
482EXPORT_SYMBOL(nmi_watchdog);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483EXPORT_SYMBOL(touch_nmi_watchdog);