[PATCH 3/3] boot: add early NMI counter
From: Fernando Luis VÃzquez Cao
Date: Fri Mar 09 2012 - 05:01:51 EST
Subject: [PATCH 3/3] boot: add early NMI counter
From: Fernando Luis Vazquez Cao <fernando@xxxxxxxxxxxxx>
We currently ignore early NMIs but it would be nice to be able to
know whether they actually occurred.
This patch adds an early NMI counter, whose count is moved over to
the per-cpu NMI counter before the kernel frees the init sections.
Signed-off-by: Fernando Luis Vazquez Cao <fernando@xxxxxxxxxxxxx>
---
diff -urNp linux-3.3-rc6-orig/arch/x86/include/asm/processor.h linux-3.3-rc6/arch/x86/include/asm/processor.h
--- linux-3.3-rc6-orig/arch/x86/include/asm/processor.h 2012-03-09 17:48:04.547492663 +0900
+++ linux-3.3-rc6/arch/x86/include/asm/processor.h 2012-03-09 18:37:32.060194673 +0900
@@ -402,6 +402,11 @@ DECLARE_PER_CPU(char *, irq_stack_ptr);
DECLARE_PER_CPU(unsigned int, irq_count);
extern unsigned long kernel_eflags;
extern asmlinkage void ignore_sysret(void);
+/*
+ * early_nmi_count is in the .init.text ELF section so it can only be accessed
+ * before the init sections are freed by the kernel.
+ */
+extern unsigned int early_nmi_count;
#else /* X86_64 */
#ifdef CONFIG_CC_STACKPROTECTOR
/*
diff -urNp linux-3.3-rc6-orig/arch/x86/kernel/head_64.S linux-3.3-rc6/arch/x86/kernel/head_64.S
--- linux-3.3-rc6-orig/arch/x86/kernel/head_64.S 2012-03-09 18:36:18.051281524 +0900
+++ linux-3.3-rc6/arch/x86/kernel/head_64.S 2012-03-09 18:38:47.673129036 +0900
@@ -340,6 +340,7 @@ early_exception_handler:
jmp 1b
early_nmi_handler:
+ incl early_nmi_count(%rip)
iretq
#ifdef CONFIG_EARLY_PRINTK
@@ -351,6 +352,9 @@ early_idt_msg:
early_idt_ripmsg:
.asciz "RIP %s\n"
#endif /* CONFIG_EARLY_PRINTK */
+ .globl early_nmi_count
+early_nmi_count:
+ .long 0
.previous
#define NEXT_PAGE(name) \
diff -urNp linux-3.3-rc6-orig/arch/x86/kernel/traps.c linux-3.3-rc6/arch/x86/kernel/traps.c
--- linux-3.3-rc6-orig/arch/x86/kernel/traps.c 2012-03-09 17:48:04.567492912 +0900
+++ linux-3.3-rc6/arch/x86/kernel/traps.c 2012-03-09 18:39:23.665574123 +0900
@@ -719,6 +719,7 @@ void __init trap_init(void)
x86_init.irqs.trap_init();
#ifdef CONFIG_X86_64
+ percpu_add(irq_stat.__nmi_count, early_nmi_count);
memcpy(&nmi_idt_table, &idt_table, IDT_ENTRIES * 16);
set_nmi_gate(1, &debug);
set_nmi_gate(3, &int3);