x86/entry/64, x86/nmi/64: Add CONFIG_DEBUG_ENTRY NMI testing code
It turns out to be rather tedious to test the NMI nesting code. Make it easier: add a new CONFIG_DEBUG_ENTRY option that causes the NMI handler to pre-emptively unmask NMIs. With this option set, errors in the repeat_nmi logic or failures to detect that we're in a nested NMI will result in quick panics under perf (especially if multiple counters are running at high frequency) instead of requiring an unusual workload that generates page faults or breakpoints inside NMIs. I called it CONFIG_DEBUG_ENTRY instead of CONFIG_DEBUG_NMI_ENTRY because I want to add new non-NMI checks elsewhere in the entry code in the future, and I'd rather not add too many new config options or add this option and then immediately rename it. Signed-off-by: Andy Lutomirski <luto@kernel.org> Reviewed-by: Steven Rostedt <rostedt@goodmis.org> Cc: Borislav Petkov <bp@suse.de> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
36f1a77b3a
commit
a97439aa1a
2 changed files with 27 additions and 0 deletions
|
@ -297,6 +297,18 @@ config OPTIMIZE_INLINING
|
||||||
|
|
||||||
If unsure, say N.
|
If unsure, say N.
|
||||||
|
|
||||||
|
config DEBUG_ENTRY
|
||||||
|
bool "Debug low-level entry code"
|
||||||
|
depends on DEBUG_KERNEL
|
||||||
|
---help---
|
||||||
|
This option enables sanity checks in x86's low-level entry code.
|
||||||
|
Some of these sanity checks may slow down kernel entries and
|
||||||
|
exits or otherwise impact performance.
|
||||||
|
|
||||||
|
This is currently used to help test NMI code.
|
||||||
|
|
||||||
|
If unsure, say N.
|
||||||
|
|
||||||
config DEBUG_NMI_SELFTEST
|
config DEBUG_NMI_SELFTEST
|
||||||
bool "NMI Selftest"
|
bool "NMI Selftest"
|
||||||
depends on DEBUG_KERNEL && X86_LOCAL_APIC
|
depends on DEBUG_KERNEL && X86_LOCAL_APIC
|
||||||
|
|
|
@ -1454,6 +1454,21 @@ first_nmi:
|
||||||
|
|
||||||
/* Everything up to here is safe from nested NMIs */
|
/* Everything up to here is safe from nested NMIs */
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG_ENTRY
|
||||||
|
/*
|
||||||
|
* For ease of testing, unmask NMIs right away. Disabled by
|
||||||
|
* default because IRET is very expensive.
|
||||||
|
*/
|
||||||
|
pushq $0 /* SS */
|
||||||
|
pushq %rsp /* RSP (minus 8 because of the previous push) */
|
||||||
|
addq $8, (%rsp) /* Fix up RSP */
|
||||||
|
pushfq /* RFLAGS */
|
||||||
|
pushq $__KERNEL_CS /* CS */
|
||||||
|
pushq $1f /* RIP */
|
||||||
|
INTERRUPT_RETURN /* continues at repeat_nmi below */
|
||||||
|
1:
|
||||||
|
#endif
|
||||||
|
|
||||||
repeat_nmi:
|
repeat_nmi:
|
||||||
/*
|
/*
|
||||||
* If there was a nested NMI, the first NMI's iret will return
|
* If there was a nested NMI, the first NMI's iret will return
|
||||||
|
|
Loading…
Reference in a new issue