Skip to content

Commit a97439a

Browse files
amlutoIngo Molnar
authored andcommitted
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 <[email protected]> Reviewed-by: Steven Rostedt <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 36f1a77 commit a97439a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

arch/x86/Kconfig.debug

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,18 @@ config OPTIMIZE_INLINING
297297

298298
If unsure, say N.
299299

300+
config DEBUG_ENTRY
301+
bool "Debug low-level entry code"
302+
depends on DEBUG_KERNEL
303+
---help---
304+
This option enables sanity checks in x86's low-level entry code.
305+
Some of these sanity checks may slow down kernel entries and
306+
exits or otherwise impact performance.
307+
308+
This is currently used to help test NMI code.
309+
310+
If unsure, say N.
311+
300312
config DEBUG_NMI_SELFTEST
301313
bool "NMI Selftest"
302314
depends on DEBUG_KERNEL && X86_LOCAL_APIC

arch/x86/entry/entry_64.S

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,21 @@ first_nmi:
14541454

14551455
/* Everything up to here is safe from nested NMIs */
14561456

1457+
#ifdef CONFIG_DEBUG_ENTRY
1458+
/*
1459+
* For ease of testing, unmask NMIs right away. Disabled by
1460+
* default because IRET is very expensive.
1461+
*/
1462+
pushq $0 /* SS */
1463+
pushq %rsp /* RSP (minus 8 because of the previous push) */
1464+
addq $8, (%rsp) /* Fix up RSP */
1465+
pushfq /* RFLAGS */
1466+
pushq $__KERNEL_CS /* CS */
1467+
pushq $1f /* RIP */
1468+
INTERRUPT_RETURN /* continues at repeat_nmi below */
1469+
1:
1470+
#endif
1471+
14571472
repeat_nmi:
14581473
/*
14591474
* If there was a nested NMI, the first NMI's iret will return

0 commit comments

Comments
 (0)