From: Sohil Mehta <sohil.mehta@intel.com>
To: Dave Hansen <dave.hansen@linux.intel.com>,
Borislav Petkov <bp@alien8.de>
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
Xin Li <xin@zytor.com>, Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Binbin Wu <binbin.wu@linux.intel.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
"Chang S . Bae" <chang.seok.bae@intel.com>,
Chao Gao <chao.gao@intel.com>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Dave Hansen <dave.hansen@intel.com>,
Sohil Mehta <sohil.mehta@intel.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] x86/cea: Index exception stacks by the ordering enum
Date: Fri, 20 Nov 2026 15:50:25 -0800 [thread overview]
Message-ID: <20261120235025.2809042-3-sohil.mehta@intel.com> (raw)
In-Reply-To: <20261120235025.2809042-1-sohil.mehta@intel.com>
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@intel.com>
---
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@intel.com/
---
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
prev parent reply other threads:[~2026-11-20 23:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 23:50 [PATCH 0/2] x86/cea: Clean up the exception stack names and declarations Sohil Mehta
2026-11-20 23:50 ` [PATCH 1/2] x86/cea: Prefix exception stack names with ESTACK_ Sohil Mehta
2026-11-20 23:50 ` Sohil Mehta [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120235025.2809042-3-sohil.mehta@intel.com \
--to=sohil.mehta@intel.com \
--cc=binbin.wu@linux.intel.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=tglx@kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
--cc=xin@zytor.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®