Skip to content

Commit 431caaf

Browse files
finikorgjhedberg
authored andcommitted
tests: nmi: Add test verifying right stack switched to
Verify that we use right nmi_stack[] in exception. Signed-off-by: Andrei Emeltchenko <[email protected]>
1 parent ddc5139 commit 431caaf

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

tests/arch/x86/nmi/src/main.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,37 @@
1717

1818
static volatile int int_handler_executed;
1919

20+
extern uint8_t _nmi_stack[];
21+
extern uint8_t _nmi_stack1[];
22+
extern uint8_t _nmi_stack2[];
23+
extern uint8_t _nmi_stack3[];
24+
25+
uint8_t *nmi_stacks[] = {
26+
_nmi_stack,
27+
#if CONFIG_MP_NUM_CPUS > 1
28+
_nmi_stack1,
29+
#if CONFIG_MP_NUM_CPUS > 2
30+
_nmi_stack2,
31+
#if CONFIG_MP_NUM_CPUS > 3
32+
_nmi_stack3
33+
#endif
34+
#endif
35+
#endif
36+
};
37+
2038
bool z_x86_do_kernel_nmi(const z_arch_esf_t *esf)
2139
{
40+
uint64_t stack;
41+
42+
_get_esp(stack);
43+
44+
TC_PRINT("ESP: 0x%llx CPU %d nmi_stack %p\n", stack,
45+
arch_curr_cpu()->id, nmi_stacks[arch_curr_cpu()->id]);
46+
47+
zassert_true(stack > (uint64_t)nmi_stacks[arch_curr_cpu()->id] &&
48+
stack < (uint64_t)nmi_stacks[arch_curr_cpu()->id] +
49+
CONFIG_X86_EXCEPTION_STACK_SIZE, "Incorrect stack");
50+
2251
int_handler_executed++;
2352

2453
return true;

tests/arch/x86/nmi/src/test_asm_inline_gcc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515

1616
#define _trigger_isr_handler(irq) __asm__ volatile("int %0" : : "i" (irq) : "memory")
1717

18+
#define _get_esp(x) __asm__("movq %%rsp, %0" : "=r" (x))
19+
1820
#endif /* _TEST_ASM_INLINE_GCC_H */

tests/arch/x86/nmi/testcase.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
common:
2+
arch_allow: x86
3+
filter: CONFIG_X86_64
4+
tags: interrupt nmi
15
tests:
26
arch.interrupt.nmi:
3-
arch_allow: x86
4-
platform_allow: qemu_x86_64
5-
tags: interrupt
7+
extra_configs:
8+
- CONFIG_USERSPACE=n
9+
arch.interrupt.nmi.kpti:
10+
extra_configs:
11+
- CONFIG_USERSPACE=y

0 commit comments

Comments
 (0)