From: Alan Cox The default Linux behaviour on an NMI of either memory or unknown is to continue operation. For many environments such as scientific computing it is preferable that the box is taken out and the error dealt with than an uncorrected parity/ECC error get propogated. A small number of systems do generate NMI's for bizarre random reasons such as power management so the default is unchanged. In other respects the new proc/sys entry works like the existing panic controls already in that directory. This is separate to the edac support - EDAC allows supported chipsets to handle ECC errors well, this change allows unsupported cases to at least panic rather than cause problems further down the line. (akpm: the infrastructure is there for all architectures. It is implemented for x86 and x86_64 only). Signed-off-by: Alan Cox Cc: Andi Kleen Signed-off-by: Andrew Morton --- arch/i386/kernel/traps.c | 6 ++++++ arch/x86_64/kernel/traps.c | 6 ++++++ include/linux/kernel.h | 1 + include/linux/sysctl.h | 1 + kernel/panic.c | 1 + kernel/sysctl.c | 8 ++++++++ 6 files changed, 23 insertions(+) diff -puN arch/i386/kernel/traps.c~allow-users-to-force-a-panic-on-nmi arch/i386/kernel/traps.c --- 25/arch/i386/kernel/traps.c~allow-users-to-force-a-panic-on-nmi Tue Jan 17 16:24:10 2006 +++ 25-akpm/arch/i386/kernel/traps.c Tue Jan 17 16:24:10 2006 @@ -580,6 +580,9 @@ static void mem_parity_error(unsigned ch printk(KERN_EMERG "You probably have a hardware problem with your RAM " "chips\n"); + if (panic_on_unrecovered_nmi) + panic("NMI: Not continuing"); + /* Clear and disable the memory parity error line. */ clear_mem_error(reason); } @@ -614,6 +617,9 @@ static void unknown_nmi_error(unsigned c reason, smp_processor_id()); printk("Dazed and confused, but trying to continue\n"); printk("Do you have a strange power saving mode enabled?\n"); + + if (panic_on_unrecovered_nmi) + panic("NMI: Not continuing"); } static DEFINE_SPINLOCK(nmi_print_lock); diff -puN arch/x86_64/kernel/traps.c~allow-users-to-force-a-panic-on-nmi arch/x86_64/kernel/traps.c --- 25/arch/x86_64/kernel/traps.c~allow-users-to-force-a-panic-on-nmi Tue Jan 17 16:24:10 2006 +++ 25-akpm/arch/x86_64/kernel/traps.c Tue Jan 17 16:24:10 2006 @@ -580,6 +580,9 @@ static void mem_parity_error(unsigned ch printk("Uhhuh. NMI received. Dazed and confused, but trying to continue\n"); printk("You probably have a hardware problem with your RAM chips\n"); + if (panic_on_unrecovered_nmi) + panic("NMI: Not continuing"); + /* Clear and disable the memory parity error line. */ reason = (reason & 0xf) | 4; outb(reason, 0x61); @@ -602,6 +605,9 @@ static void unknown_nmi_error(unsigned c { printk("Uhhuh. NMI received for unknown reason %02x.\n", reason); printk("Dazed and confused, but trying to continue\n"); printk("Do you have a strange power saving mode enabled?\n"); + + if (panic_on_unrecovered_nmi) + panic("NMI: Not continuing"); } /* Runs on IST stack. This code must keep interrupts off all the time. diff -puN include/linux/sysctl.h~allow-users-to-force-a-panic-on-nmi include/linux/sysctl.h --- 25/include/linux/sysctl.h~allow-users-to-force-a-panic-on-nmi Tue Jan 17 16:24:10 2006 +++ 25-akpm/include/linux/sysctl.h Tue Jan 17 16:24:10 2006 @@ -146,6 +146,7 @@ enum KERN_RANDOMIZE=68, /* int: randomize virtual address space */ KERN_SETUID_DUMPABLE=69, /* int: behaviour of dumps for setuid core */ KERN_SPIN_RETRY=70, /* int: number of spinlock retries */ + KERN_PANIC_ON_NMI=71, /* int: whether we will panic on an unrecovered NMI */ }; diff -puN kernel/panic.c~allow-users-to-force-a-panic-on-nmi kernel/panic.c --- 25/kernel/panic.c~allow-users-to-force-a-panic-on-nmi Tue Jan 17 16:24:10 2006 +++ 25-akpm/kernel/panic.c Tue Jan 17 16:24:10 2006 @@ -22,6 +22,7 @@ int panic_timeout; int panic_on_oops; +int panic_on_unrecovered_nmi; int tainted; EXPORT_SYMBOL(panic_timeout); diff -puN kernel/sysctl.c~allow-users-to-force-a-panic-on-nmi kernel/sysctl.c --- 25/kernel/sysctl.c~allow-users-to-force-a-panic-on-nmi Tue Jan 17 16:24:10 2006 +++ 25-akpm/kernel/sysctl.c Tue Jan 17 16:24:10 2006 @@ -596,6 +596,14 @@ static ctl_table kern_table[] = { .proc_handler = &proc_dointvec, }, { + .ctl_name = KERN_PANIC_ON_NMI, + .procname = "panic_on_unrecovered_nmi", + .data = &panic_on_unrecovered_nmi, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec, + }, + { .ctl_name = KERN_PRINTK_RATELIMIT, .procname = "printk_ratelimit", .data = &printk_ratelimit_jiffies, diff -puN include/linux/kernel.h~allow-users-to-force-a-panic-on-nmi include/linux/kernel.h --- 25/include/linux/kernel.h~allow-users-to-force-a-panic-on-nmi Tue Jan 17 16:24:10 2006 +++ 25-akpm/include/linux/kernel.h Tue Jan 17 16:24:10 2006 @@ -174,6 +174,7 @@ extern void bust_spinlocks(int yes); extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ extern __deprecated_for_modules int panic_timeout; extern int panic_on_oops; +extern int panic_on_unrecovered_nmi; extern int tainted; extern const char *print_tainted(void); extern void add_taint(unsigned); _