mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "seanjc@google.com" <seanjc@google.com>
Cc: "weixq1@chinatelecom.cn" <weixq1@chinatelecom.cn>,
	"zhangzg12@chinatelecom.cn" <zhangzg12@chinatelecom.cn>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"bp@alien8.de" <bp@alien8.de>,
	"hanht2@chinatelecom.cn" <hanht2@chinatelecom.cn>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"tglx@kernel.org" <tglx@kernel.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"18341265598@163.com" <18341265598@163.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: [PATCH] vmx/nested: Set the SGX feature flag only when hardware supported.
Date: Tue, 31 Mar 2026 21:07:01 +0000	[thread overview]
Message-ID: <8fbedc9183f61400c772b36562963cfc8c3a8797.camel@intel.com> (raw)
In-Reply-To: <acv2jIBRxKp94oP5@google.com>

On Tue, 2026-03-31 at 09:30 -0700, Sean Christopherson wrote:
> 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.

Exactly.  I think we can ignore this unless we can get more info from the
author :-)

  reply	other threads:[~2026-03-31 21:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24  3:27 18341265598
2026-03-24 10:11 ` Huang, Kai
2026-03-31 16:30   ` Sean Christopherson
2026-03-31 21:07     ` Huang, Kai [this message]
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=8fbedc9183f61400c772b36562963cfc8c3a8797.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=18341265598@163.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hanht2@chinatelecom.cn \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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

all inboxes | Powered by JetHome®