public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Kai Huang <kai.huang@intel.com>
Cc: "dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"bp@alien8.de" <bp@alien8.de>,  "hpa@zytor.com" <hpa@zytor.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"tglx@kernel.org" <tglx@kernel.org>,
	 "pbonzini@redhat.com" <pbonzini@redhat.com>,
	"18341265598@163.com" <18341265598@163.com>,
	 "hanht2@chinatelecom.cn" <hanht2@chinatelecom.cn>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	 "weixq1@chinatelecom.cn" <weixq1@chinatelecom.cn>,
	 "zhangzg12@chinatelecom.cn" <zhangzg12@chinatelecom.cn>
Subject: Re: [PATCH] vmx/nested: Set the SGX feature flag only when hardware supported.
Date: Tue, 31 Mar 2026 09:30:33 -0700	[thread overview]
Message-ID: <acv2jIBRxKp94oP5@google.com> (raw)
In-Reply-To: <95c13b532d2958977d176e965efc433f1f4793c4.camel@intel.com>

On Tue, Mar 24, 2026, Kai Huang wrote:
> On Tue, 2026-03-24 at 11:27 +0800, 18341265598@163.com wrote:
> > From: "zhaoge.zhang" <zhangzg12@chinatelecom.cn>
> > 
> > If the hardware does not support the SGX feature and we set the
> > corresponding flag, when the L1 hypervisor enables the corresponding
> > feature in VMCS12, the VM entry will fail.
> > 
> > Reported-by: wei xiaoqiong <weixq1@chinatelecom.cn>
> > Signed-off-by: zhaoge.zhang <zhangzg12@chinatelecom.cn>
> > Reviewed-by: Huaitong Han <hanht2@chinatelecom.cn>
> > ---
> >  arch/x86/kvm/vmx/nested.c |  2 +-
> >  arch/x86/kvm/vmx/vmx.c    | 11 -----------
> >  arch/x86/kvm/vmx/vmx.h    | 11 +++++++++++
> >  3 files changed, 12 insertions(+), 12 deletions(-)
> > 
> > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> > index 937aeb4..396ac07 100644
> > --- a/arch/x86/kvm/vmx/nested.c
> > +++ b/arch/x86/kvm/vmx/nested.c
> > @@ -7278,7 +7278,7 @@ static void nested_vmx_setup_secondary_ctls(u32 ept_caps,
> >  		msrs->secondary_ctls_high |=
> >  			SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;
> >  
> > -	if (enable_sgx)
> > +	if (enable_sgx && cpu_has_sgx())
> >  		msrs->secondary_ctls_high |= SECONDARY_EXEC_ENCLS_EXITING;
> >  }
> 
> Are you seeing the case where enable_sgx is true but cpu_has_sgx() reports
> false?
> 
> It's quite strange because during KVM load, if cpu_has_sgx() is false,
> enable_sgx is guaranteed to be false.
> 
> The only case that I can think of is after KVM loads somehow machine check
> happens, which "soft disables" SGX (CPUID reports SGX1 as 0).
> 
> Is this the case you are meeting?

It's a moot point (unless I'm getting -ENOCOFFEE, which is very possible at the
moment), because "enable_sgx" is cleared if ENCLS-exiting isn't supported.

	if (!cpu_has_vmx_encls_vmexit())
		enable_sgx = false;

Where cpu_has_vmx_encls_vmexit() is peeking at vmcs_config.cpu_based_2nd_exec_ctrl:

  static inline bool cpu_has_vmx_encls_vmexit(void)
  {
	return vmcs_config.cpu_based_2nd_exec_ctrl &
		SECONDARY_EXEC_ENCLS_EXITING;
  }

And thus already incorporates this code:

	if (!cpu_has_sgx())
		_cpu_based_2nd_exec_control &= ~SECONDARY_EXEC_ENCLS_EXITING;


I suppose the #MC could happen between setup_vmcs_config() and
nested_vmx_setup_ctls_msrs(), but at that point, KVM is hosed no matter what.

  reply	other threads:[~2026-03-31 16:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24  3:27 [PATCH] vmx/nested: Set the SGX feature flag only when hardware supported 18341265598
2026-03-24 10:11 ` Huang, Kai
2026-03-31 16:30   ` Sean Christopherson [this message]
2026-03-31 21:07     ` Huang, Kai
2026-03-31 23:20       ` zhaogezhang
2026-03-29  8:30 ` kernel test robot
2026-03-29  9:05 ` kernel test robot

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=acv2jIBRxKp94oP5@google.com \
    --to=seanjc@google.com \
    --cc=18341265598@163.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hanht2@chinatelecom.cn \
    --cc=hpa@zytor.com \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=tglx@kernel.org \
    --cc=weixq1@chinatelecom.cn \
    --cc=zhangzg12@chinatelecom.cn \
    /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