lkml.org 
[lkml]   [2010]   [Jun]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 4/5] x86: Add new callback for unhandled NMIs
Date
This patch introduces new NMI callback, controlled via sysctl variable
`unknown_nmi_dump_log'. When kernel is in dump capture mode, and user
presses NMI button on chassis or sends such event via control console,
callback extracts and prints kernel log and CPU registers from
captured vmcore, and also prints state of running kernel.

Signed-off-by: Vitaly Mayatskikh <v.mayatskih@gmail.com>
---
arch/x86/include/asm/nmi.h | 1 +
arch/x86/kernel/apic/nmi.c | 27 +++++++++++++++++++++++++++
include/linux/sysctl.h | 1 +
kernel/sysctl.c | 7 +++++++
kernel/sysctl_binary.c | 1 +
5 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
index 93da9c3..5ca20cf 100644
--- a/arch/x86/include/asm/nmi.h
+++ b/arch/x86/include/asm/nmi.h
@@ -42,6 +42,7 @@ struct ctl_table;
extern int proc_nmi_enabled(struct ctl_table *, int ,
void __user *, size_t *, loff_t *);
extern int unknown_nmi_panic;
+extern int unknown_nmi_dump_log;

void arch_trigger_all_cpu_backtrace(void);
#define arch_trigger_all_cpu_backtrace arch_trigger_all_cpu_backtrace
diff --git a/arch/x86/kernel/apic/nmi.c b/arch/x86/kernel/apic/nmi.c
index 1edaf15..22a2688 100644
--- a/arch/x86/kernel/apic/nmi.c
+++ b/arch/x86/kernel/apic/nmi.c
@@ -37,7 +37,10 @@

#include <asm/mach_traps.h>

+#include <linux/crash_dump.h>
+
int unknown_nmi_panic;
+int unknown_nmi_dump_log;
int nmi_watchdog_enabled;

/* For reliability, we're prepared to waste bits here. */
@@ -507,6 +510,28 @@ static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
return 0;
}

+static int __init setup_unknown_nmi_dump_log(char *str)
+{
+ unknown_nmi_dump_log = 1;
+ return 1;
+}
+__setup("unknown_nmi_dump_log", setup_unknown_nmi_dump_log);
+
+static int unknown_nmi_dump_log_callback(struct pt_regs *regs, int cpu)
+{
+ printk(KERN_WARNING "NMI received for unknown reason %02x\n",
+ get_nmi_reason());
+#ifdef CONFIG_CRASH_DUMP
+ if (is_kdump_kernel()) {
+ dump_old_log();
+ printk(KERN_INFO "--- kdump kernel state begins here---\n");
+ show_state();
+ printk(KERN_INFO "--- kdump kernel state ends here---\n");
+ }
+#endif
+ return 0;
+}
+
/*
* proc handler for /proc/sys/kernel/nmi
*/
@@ -552,6 +577,8 @@ int do_nmi_callback(struct pt_regs *regs, int cpu)
#ifdef CONFIG_SYSCTL
if (unknown_nmi_panic)
return unknown_nmi_panic_callback(regs, cpu);
+ if (unknown_nmi_dump_log)
+ return unknown_nmi_dump_log_callback(regs, cpu);
#endif
return 0;
}
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 7bb5cb6..7d2489d 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -153,6 +153,7 @@ enum
KERN_MAX_LOCK_DEPTH=74, /* int: rtmutex's maximum lock depth */
KERN_NMI_WATCHDOG=75, /* int: enable/disable nmi watchdog */
KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
+ KERN_UNKNOWN_NMI_DUMP_LOG=77, /* int: unknown nmi dump log flag */
};


diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 997080f..03cc3c5 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -719,6 +719,13 @@ static struct ctl_table kern_table[] = {
.proc_handler = proc_dointvec,
},
{
+ .procname = "unknown_nmi_dump_log",
+ .data = &unknown_nmi_dump_log,
+ .maxlen = sizeof (int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec,
+ },
+ {
.procname = "nmi_watchdog",
.data = &nmi_watchdog_enabled,
.maxlen = sizeof (int),
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
index 1357c57..e59d0b1 100644
--- a/kernel/sysctl_binary.c
+++ b/kernel/sysctl_binary.c
@@ -128,6 +128,7 @@ static const struct bin_table bin_kern_table[] = {
{ CTL_INT, KERN_SPARC_SCONS_PWROFF, "scons-poweroff" },
/* KERN_HZ_TIMER "hz_timer" no longer used */
{ CTL_INT, KERN_UNKNOWN_NMI_PANIC, "unknown_nmi_panic" },
+ { CTL_INT, KERN_UNKNOWN_NMI_DUMP_LOG, "unknown_nmi_dump_log" },
{ CTL_INT, KERN_BOOTLOADER_TYPE, "bootloader_type" },
{ CTL_INT, KERN_RANDOMIZE, "randomize_va_space" },

--
1.7.1


\
 
 \ /
  Last update: 2010-06-02 11:49    [from the cache]
©2003-2011 Jasper Spaans