[PATCH 2/2] x86/cea: Index exception stacks by the ordering enum
From: Sohil Mehta
Date: Fri Nov 20 2026 - 18:53:10 EST
The exception stacks are generated by ESTACKS_MEMBERS(), which pastes
each stack name into a member name, once for the physical storage and
once for the CEA mapping.
The macro used to be the only thing keeping the two structures in the
same order, but there is no ordering requirement left to enforce. The
stacks are mapped one at a time and have been paired by name for a
while. Also, the sizes stopped matching once the #VC stacks became
config dependent.
So, spell out the physical storage and index the mapping by the stack
ordering enum. Also drop CEA_ESTACK_SIZE, which just duplicated
EXCEPTION_STKSZ.
The stack addresses and the guard pages are unchanged. No functional
change intended.
Signed-off-by: Sohil Mehta <sohil.mehta@xxxxxxxxx>
---
v1:
- Drop the conversion of __this_cpu_ist_{bottom,top}_va() from macros
to functions. KVM does not need the accessor exported any more.
- Expand struct exception_stacks explicitly and drop ESTACKS_MEMBERS()
altogether.
- Name the new array stacks[] rather than event_stacks[].
- Switch authorship due to significant changes to Xin's original patch.
- Drop Binbin's and Dave's tags.
FRED KVM v10:
- https://lore.kernel.org/lkml/20260911213659.2025974-6-sohil.mehta@xxxxxxxxx/
---
arch/x86/include/asm/cpu_entry_area.h | 52 +++++++++++----------------
arch/x86/kernel/dumpstack_64.c | 4 +--
arch/x86/mm/cpu_entry_area.c | 2 +-
3 files changed, 24 insertions(+), 34 deletions(-)
diff --git a/arch/x86/include/asm/cpu_entry_area.h b/arch/x86/include/asm/cpu_entry_area.h
index d0f884c28178..ba6456a04180 100644
--- a/arch/x86/include/asm/cpu_entry_area.h
+++ b/arch/x86/include/asm/cpu_entry_area.h
@@ -16,32 +16,6 @@
#define VC_EXCEPTION_STKSZ 0
#endif
-/* Macro to enforce the same ordering and stack sizes */
-#define ESTACKS_MEMBERS(guardsize, optional_stack_size) \
- char ESTACK_DF_stack_guard[guardsize]; \
- char ESTACK_DF_stack[EXCEPTION_STKSZ]; \
- char ESTACK_NMI_stack_guard[guardsize]; \
- char ESTACK_NMI_stack[EXCEPTION_STKSZ]; \
- char ESTACK_DB_stack_guard[guardsize]; \
- char ESTACK_DB_stack[EXCEPTION_STKSZ]; \
- char ESTACK_MCE_stack_guard[guardsize]; \
- char ESTACK_MCE_stack[EXCEPTION_STKSZ]; \
- char ESTACK_VC_stack_guard[guardsize]; \
- char ESTACK_VC_stack[optional_stack_size]; \
- char ESTACK_VC2_stack_guard[guardsize]; \
- char ESTACK_VC2_stack[optional_stack_size]; \
- char ESTACK_IST_top_guard[guardsize]; \
-
-/* The exception stacks' physical storage. No guard pages required */
-struct exception_stacks {
- ESTACKS_MEMBERS(0, VC_EXCEPTION_STKSZ)
-};
-
-/* The effective cpu entry area mapping with guard pages. */
-struct cea_exception_stacks {
- ESTACKS_MEMBERS(PAGE_SIZE, EXCEPTION_STKSZ)
-};
-
/*
* The exception stack ordering in [cea_]exception_stacks
*/
@@ -55,17 +29,33 @@ enum exception_stack_ordering {
N_EXCEPTION_STACKS
};
-#define CEA_ESTACK_SIZE(st) \
- sizeof(((struct cea_exception_stacks *)0)->st## _stack)
+/* The exception stacks' physical storage. No guard pages required */
+struct exception_stacks {
+ char ESTACK_DF_stack[EXCEPTION_STKSZ];
+ char ESTACK_NMI_stack[EXCEPTION_STKSZ];
+ char ESTACK_DB_stack[EXCEPTION_STKSZ];
+ char ESTACK_MCE_stack[EXCEPTION_STKSZ];
+ char ESTACK_VC_stack[VC_EXCEPTION_STKSZ];
+ char ESTACK_VC2_stack[VC_EXCEPTION_STKSZ];
+};
+
+/* The effective cpu entry area mapping with guard pages. */
+struct cea_exception_stacks {
+ struct {
+ char stack_guard[PAGE_SIZE];
+ char stack[EXCEPTION_STKSZ];
+ } stacks[N_EXCEPTION_STACKS];
+ char IST_top_guard[PAGE_SIZE];
+};
#define CEA_ESTACK_BOT(ceastp, st) \
- ((unsigned long)&(ceastp)->st## _stack)
+ ((unsigned long)&(ceastp)->stacks[st].stack)
#define CEA_ESTACK_TOP(ceastp, st) \
- (CEA_ESTACK_BOT(ceastp, st) + CEA_ESTACK_SIZE(st))
+ (CEA_ESTACK_BOT(ceastp, st) + EXCEPTION_STKSZ)
#define CEA_ESTACK_OFFS(st) \
- offsetof(struct cea_exception_stacks, st## _stack)
+ offsetof(struct cea_exception_stacks, stacks[st].stack)
#define CEA_ESTACK_PAGES \
(sizeof(struct cea_exception_stacks) / PAGE_SIZE)
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
index 40f51e278171..93b10b264e53 100644
--- a/arch/x86/kernel/dumpstack_64.c
+++ b/arch/x86/kernel/dumpstack_64.c
@@ -70,9 +70,9 @@ struct estack_pages {
#define EPAGERANGE(st) \
[PFN_DOWN(CEA_ESTACK_OFFS(st)) ... \
- PFN_DOWN(CEA_ESTACK_OFFS(st) + CEA_ESTACK_SIZE(st) - 1)] = { \
+ PFN_DOWN(CEA_ESTACK_OFFS(st) + EXCEPTION_STKSZ - 1)] = { \
.offs = CEA_ESTACK_OFFS(st), \
- .size = CEA_ESTACK_SIZE(st), \
+ .size = EXCEPTION_STKSZ, \
.type = STACK_TYPE_EXCEPTION + st, }
/*
diff --git a/arch/x86/mm/cpu_entry_area.c b/arch/x86/mm/cpu_entry_area.c
index 9fa371af8abc..570e60fde79c 100644
--- a/arch/x86/mm/cpu_entry_area.c
+++ b/arch/x86/mm/cpu_entry_area.c
@@ -132,7 +132,7 @@ static void __init percpu_setup_debug_store(unsigned int cpu)
#define cea_map_stack(name) do { \
npages = sizeof(estacks->name## _stack) / PAGE_SIZE; \
- cea_map_percpu_pages(cea->estacks.name## _stack, \
+ cea_map_percpu_pages(cea->estacks.stacks[name].stack, \
estacks->name## _stack, npages, PAGE_KERNEL); \
} while (0)
--
2.43.0