All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sohil Mehta <sohil.mehta@intel.com>
To: Dave Hansen <dave.hansen@intel.com>,
	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>, <kvm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] x86/cea: Index exception stacks by the ordering enum
Date: Mon, 23 Nov 2026 10:34:51 -0800	[thread overview]
Message-ID: <5cb0a2d8-d9bb-4464-848b-4e83d1ae2eda@intel.com> (raw)
In-Reply-To: <4c51d4e3-2628-4b51-94ef-60c941c09dd4@intel.com>

On 11/23/2026 8:19 AM, Dave Hansen wrote:
> On 11/20/26 15:50, Sohil Mehta wrote:
>> +/* 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];
> 	/* The #VC stack storage is conditionally compiled out: */
>> +	char ESTACK_VC_stack [VC_EXCEPTION_STKSZ];
>> +	char ESTACK_VC2_stack[VC_EXCEPTION_STKSZ];
>> +};
> 
> Please vertically align the [EXCEPTION_STKSZ] like I did ^. 

Sure, will do.

> Also, please add some kind of comment about why the VC stacks need to
> be different.
> 
> Honestly, though, looking at this, two #ifdefs would be perfectly
> readable here.
> 

I think commit 541ac97186d9 ("x86/sev: Make the #VC exception stacks
part of the default stacks storage") added the #ifdefs in the header
file to avoid the #ifdefs in percpu_setup_exception_stacks().

> 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];
> #ifdef CONFIG_AMD_MEM_ENCRYPT
> 	char ESTACK_VC_stack [EXCEPTION_STKSZ];
> 	char ESTACK_VC2_stack[EXCEPTION_STKSZ];
> #endif
> };
> 
> Because, without it, we have to explain VC_EXCEPTION_STKSZ anyway.
> 


I tried a few variations to get rid of VC_EXCEPTION_STKSZ but they all
make the C files uglier. C code refers ESTACK_VC/VC2 unconditionally or
under IS_ENABLED(). I am inclined to add the comment instead because it
keeps those C functions cleaner.

>> +/* 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];
>> +};
> 
> I dislike the asymmetry here. I'd rather just have two explicit lists of
> stacks. 

This request seems to have originated from you to simplify the accessors :)

https://lore.kernel.org/all/720bc7ac-7e81-4ad9-8cc5-29ac540be283@intel.com/

It would have been ideal if we could move everything over to the enum as
you requested below. But I can't figure out a clean way to do it without
making other code worse.

https://lore.kernel.org/all/ba8434fb-8bbd-4d4a-bd01-1bdb2219979b@intel.com/

It is a trade-off between using name pasting vs array indexing. If we
want to keep the symmetry then keeping the existing ESTACKS_MEMBERS()
macro seems better. Should I drop this patch and create another one to
fix the comments and add the VC_EXCEPTION_STKSZ explanation?


> This also begs the question but doesn't offer an answer about
> why it's OK to have EXCEPTION_STKSZ vs. VC_EXCEPTION_STKSZ in the
> "exception_stacks" but have EXCEPTION_STKSZ for all in
> "cea_exception_stacks".


The exception_stacks tracks to real storage so it uses
VC_EXCEPTION_STKSZ to save space in case CONFIG_AMD_MEM_ENCRYPT isn't
enabled. The cea_exception_stacks only reserve a slot with no PTEs so
they are using EXCEPTION_STKSZ for simplicity.

Though, I agree, this should be explained properly if we decide to go
ahead with this patch.



  reply	other threads:[~2026-11-23 18:34 UTC|newest]

Thread overview: 8+ 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-23 16:31   ` [tip: x86/entry] " tip-bot2 for Xin Li (Intel)
2026-11-20 23:50 ` [PATCH 2/2] x86/cea: Index exception stacks by the ordering enum Sohil Mehta
2026-11-23  6:56   ` Binbin Wu
2026-11-23 16:19   ` Dave Hansen
2026-11-23 18:34     ` Sohil Mehta [this message]
2026-11-23 20:41       ` Sohil Mehta

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=5cb0a2d8-d9bb-4464-848b-4e83d1ae2eda@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.