KVM: vmx/nested: avoid blindly setting SECONDARY_EXEC_ENCLS_EXITING when sgx is enabled
Message ID | 20221024124845.1927035-1-eesposit@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp489030wru; Mon, 24 Oct 2022 07:40:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6TBCng7vWM1zYZZnDUGa/1ymaPKnrFhjygTLYYao9Zkpv/oE5aZm+p6nJ9QB4x6DNoLzxp X-Received: by 2002:a05:6a00:189f:b0:56b:b192:cda with SMTP id x31-20020a056a00189f00b0056bb1920cdamr8230529pfh.2.1666622407507; Mon, 24 Oct 2022 07:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666622407; cv=none; d=google.com; s=arc-20160816; b=YJP7k/5g8ChXb4DqXVTcqygiIotCr62a4PrSYMRzP3cw/mvM/YFvm/piB0gjg00JTN aD7ov5yOCUVt55Q55BXbVCebTVBV/6wneyQGQgv2slce3vaWaPC1ffBstw4umhLrCzeQ F7aLJA/Fw0BMx4d6C8AUlEppcetAR1PCq2FMIKZobPvODgWzMfh0IakNqSAfuZiva/6t 7W8JoT6m5G9jSi9Z7Qxgd+Fc8JH4uXFXiWl/tQ0RFkyfX7t6aoguOqY/ATPKqOqsZ4nv mONTRbRIX2Hf8zEiGeTJ1bZDfNcqtilpvWGv6xwrlelzU97fR2R2UI/gO1PaVFX933jC MnYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=kJsLl4LmziKHBgnDcaNe3l0TTFQxVoF0LS9oUPYIa6g=; b=AkOUJ7/lorTk/iXDK9Cc3YF+Z5AlOtOR7xzfTDSn23wQHV01MAsPwl+DlTf22iL75i UU9mpFfpEHn8zZApkd9eUU1jIw2LkrWLb/bynGqfKGvOwEdMtBjESZiFNqyx1qyFFOJH RK3nBHa+0+wvca7JmL7nyosD4H8ZgnqP1EXfS5MEIjBabjEZlAz+Ov8e5TUXIZxxuuGJ aW6rwm9oDkkS1KZg5oSN4fHozUWfnG4K5eyK2YNfA6MNUVmFM54ODqkTOzvJOJvkdWTm 8idD2okaUvUdx31HWaTThVUEheaoJJ3qj8H0EczWbeFksv1rzGeGSyD3A6o8oMsECCxH 5yWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aSNROS5Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a17090a8a0e00b0020a84ae69b1si7742353pjn.71.2022.10.24.07.39.29; Mon, 24 Oct 2022 07:40:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aSNROS5Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235864AbiJXOcc (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Mon, 24 Oct 2022 10:32:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235272AbiJXOcO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Oct 2022 10:32:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18107CBFF4 for <linux-kernel@vger.kernel.org>; Mon, 24 Oct 2022 06:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666616589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=kJsLl4LmziKHBgnDcaNe3l0TTFQxVoF0LS9oUPYIa6g=; b=aSNROS5ZRzSYuyn1dsvlFkIEVotHi1FyS/Kf7J69rK5B1HjZteNByN2h1N/b1jD8mrMbc/ LA8sGQBXeXqDFOIarim/+XrLMPA0C1ntT56AtBjEteX2VWfd3FZa78QivBJIsSYDbcCmSU mG9x7RDTdmPkHUrFfJWm2lu9IWWudLE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-dKeT6KaQMvKsjQq2qmeFTQ-1; Mon, 24 Oct 2022 08:48:49 -0400 X-MC-Unique: dKeT6KaQMvKsjQq2qmeFTQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7C18B3804064; Mon, 24 Oct 2022 12:48:48 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02DCE1415114; Mon, 24 Oct 2022 12:48:47 +0000 (UTC) From: Emanuele Giuseppe Esposito <eesposit@redhat.com> To: kvm@vger.kernel.org Cc: Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, Bandan Das <bsd@redhat.com>, linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito <eesposit@redhat.com> Subject: [PATCH] KVM: vmx/nested: avoid blindly setting SECONDARY_EXEC_ENCLS_EXITING when sgx is enabled Date: Mon, 24 Oct 2022 08:48:45 -0400 Message-Id: <20221024124845.1927035-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747580257676184266?= X-GMAIL-MSGID: =?utf-8?q?1747580257676184266?= |
Series |
KVM: vmx/nested: avoid blindly setting SECONDARY_EXEC_ENCLS_EXITING when sgx is enabled
|
|
Commit Message
Emanuele Giuseppe Esposito
Oct. 24, 2022, 12:48 p.m. UTC
Currently vmx enables SECONDARY_EXEC_ENCLS_EXITING even when sgx
is not set in the host MSR.
This was probably introduced when sgx was not yet fully supported, and
we wanted to trap guests trying to use the feature.
When booting a guest, KVM checks that the cpuid bit is actually set
in vmx.c, and if not, it does not enable the feature.
However, in nesting this control bit is blindly copied, and will be
propagated to VMCS12 and VMCS02. Therefore, when L1 tries to boot
the guest, the host will try to execute VMLOAD with VMCS02 containing
a feature that the hardware does not support, making it fail with
hardware error 0x7.
According with section A.3.3 of Intel System Programming Guide,
we should *always* check the value in the actual
MSR_IA32_VMX_PROCBASED_CTLS2 before enabling this bit.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2127128
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
arch/x86/kvm/vmx/nested.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
Comments
"nVMX" instead of "vmx/nested" On Mon, Oct 24, 2022, Emanuele Giuseppe Esposito wrote: > Currently vmx enables SECONDARY_EXEC_ENCLS_EXITING even when sgx > is not set in the host MSR. > This was probably introduced when sgx was not yet fully supported, and > we wanted to trap guests trying to use the feature. Nah, it's just a boneheaded bug. > When booting a guest, KVM checks that the cpuid bit is actually set > in vmx.c, and if not, it does not enable the feature. The CPUID thing is a red herring. That's an _additional_ restriction, KVM honors MSR_IA32_VMX_PROCBASED_CTLS2 when configuring vmcs01. See adjust_vmx_controls() for secondary controls in setup_vmcs_config(). > However, in nesting this control bit is blindly copied, and will be It's not "copied", KVM sets the bit in the nVMX MSR irrespective of host support, which is the problem. > propagated to VMCS12 and VMCS02. Therefore, when L1 tries to boot > the guest, the host will try to execute VMLOAD with VMCS02 containing > a feature that the hardware does not support, making it fail with > hardware error 0x7. > > According with section A.3.3 of Intel System Programming Guide, > we should *always* check the value in the actual s/we/software > MSR_IA32_VMX_PROCBASED_CTLS2 before enabling this bit. > > RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2127128 > Fixes: 72add915fbd5 ("KVM: VMX: Enable SGX virtualization for SGX1, SGX2 and LC") Cc: stable@vger.kernel.org > Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> > --- > arch/x86/kvm/vmx/nested.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > index 8f67a9c4a287..f651084010cc 100644 > --- a/arch/x86/kvm/vmx/nested.c > +++ b/arch/x86/kvm/vmx/nested.c > @@ -6678,6 +6678,25 @@ static u64 nested_vmx_calc_vmcs_enum_msr(void) > return (u64)max_idx << VMCS_FIELD_INDEX_SHIFT; > } > > +/* > + * According with section A.3.3 of Avoid referencing sections/tables by "number" in comments (and changelogs), as the comment is all but guaranteed to become stale because future versions of the SDM will shift things around. The slightly more robust way to reference a specific SDM/APM section is to use the title, e.g. According to section "Secondary Processor-Based VM-Execution Controls" in Intel's SDM ...", as hardware vendors are less likely to arbitrarily rename sections and tables. It's a bit more work for readers, but any decent PDF viewer can search these days. > Intel System Programming Guide KVM typically uses "Intel's SDM" (and "AMD's APM"). Like "VMX" or "SVM", it's ok to use the SDM acronym without introducing since "SDM" is > + * we *can* set the guest MSR control X (in our case Avoid pronouns in comments. "we" and "us" are ambiguous, e.g. "we" can mean KVM, the developer, the user, etc... > + * SECONDARY_EXEC_ENCLS_EXITING) *iff* bit 32+X of > + * MSR_IA32_VMX_PROCBASED_CTLS2 is set to 1. > + * Otherwise it must remain zero. As a general rule, if you find yourself writing a comment and a helper for something that KVM absolutely needs to get right (honoring VMX MSRs), then odds are very good that there's a simpler/easier fix, i.e. that you're effectively re-inventing part of the weel. > + */ > +static void nested_vmx_setup_encls_exiting(struct nested_vmx_msrs *msrs) > +{ > + u32 vmx_msr_procb_low, vmx_msr_procb_high; > + > + rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2, vmx_msr_procb_low, vmx_msr_procb_high); > + > + WARN_ON(vmx_msr_procb_low & SECONDARY_EXEC_ENCLS_EXITING); > + > + if (enable_sgx && (vmx_msr_procb_high & SECONDARY_EXEC_ENCLS_EXITING)) > + msrs->secondary_ctls_high |= SECONDARY_EXEC_ENCLS_EXITING; > +} > + > /* > * nested_vmx_setup_ctls_msrs() sets up variables containing the values to be > * returned for the various VMX controls MSRs when nested VMX is enabled. > @@ -6874,8 +6893,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps) > msrs->secondary_ctls_high |= > SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES; > > - if (enable_sgx) > - msrs->secondary_ctls_high |= SECONDARY_EXEC_ENCLS_EXITING; The issue here is that I, who wrote this code long, long ago, copied the pattern used for enable_unrestricted_guest, flexpriority_enabled, etc... without fully appreciating the logic. Unlike those module params, enable_sgx doesn't track hardware support, i.e. enable_sgx isn't cleared when SGX can't be enabled due to lack of hardware support. As a result, KVM effectively enumerates to L1 that the control is always available, i.e. that KVM emulates ENCLS-exiting for L1, but KVM obviously doesn't actually emulating the behavior. Not updating enable_sgx is responsible for a second bug: vmx_set_cpu_caps() doesn't clear the SGX bits when hardware support is unavailable. This is a much less problematic bug as as it only pops up if SGX is soft-disabled (the case being handled by cpu_has_sgx()) or if SGX is supported for bare metal but not in the VMCS (will never happen when running on bare metal, but can theoertically happen when running in a VM). Last but not least, KVM should ideally have module params reflect KVM's actual configuration. Killing all birds with one stone, simply clear enable_sgx when ENCLS-exiting isn't supported. The #ifdef is a little gross, but I think it's marginally less ugly than having vmx.c define a dummy boolean. Compile tested only... diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 9dba04b6b019..65f092e4a81b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -8263,6 +8263,11 @@ static __init int hardware_setup(void) if (!cpu_has_virtual_nmis()) enable_vnmi = 0; +#ifdef CONFIG_X86_SGX_KVM + if (!cpu_has_vmx_encls_vmexit()) + enable_sgx = false; +#endif + /* * set_apic_access_page_addr() is used to reload apic access * page upon invalidation. No need to do anything if not
Am 24/10/2022 um 18:52 schrieb Sean Christopherson: > "nVMX" instead of "vmx/nested" > > On Mon, Oct 24, 2022, Emanuele Giuseppe Esposito wrote: >> Currently vmx enables SECONDARY_EXEC_ENCLS_EXITING even when sgx >> is not set in the host MSR. >> This was probably introduced when sgx was not yet fully supported, and >> we wanted to trap guests trying to use the feature. > > Nah, it's just a boneheaded bug. > >> When booting a guest, KVM checks that the cpuid bit is actually set >> in vmx.c, and if not, it does not enable the feature. > > The CPUID thing is a red herring. That's an _additional_ restriction, KVM honors > MSR_IA32_VMX_PROCBASED_CTLS2 when configuring vmcs01. See adjust_vmx_controls() > for secondary controls in setup_vmcs_config(). > >> However, in nesting this control bit is blindly copied, and will be > > It's not "copied", KVM sets the bit in the nVMX MSR irrespective of host support, > which is the problem. > >> propagated to VMCS12 and VMCS02. Therefore, when L1 tries to boot >> the guest, the host will try to execute VMLOAD with VMCS02 containing >> a feature that the hardware does not support, making it fail with >> hardware error 0x7. >> >> According with section A.3.3 of Intel System Programming Guide, >> we should *always* check the value in the actual > > s/we/software > >> MSR_IA32_VMX_PROCBASED_CTLS2 before enabling this bit. >> >> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2127128 >> > > Fixes: 72add915fbd5 ("KVM: VMX: Enable SGX virtualization for SGX1, SGX2 and LC") > Cc: stable@vger.kernel.org > >> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> >> --- >> arch/x86/kvm/vmx/nested.c | 22 ++++++++++++++++++++-- >> 1 file changed, 20 insertions(+), 2 deletions(-) >> >> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c >> index 8f67a9c4a287..f651084010cc 100644 >> --- a/arch/x86/kvm/vmx/nested.c >> +++ b/arch/x86/kvm/vmx/nested.c >> @@ -6678,6 +6678,25 @@ static u64 nested_vmx_calc_vmcs_enum_msr(void) >> return (u64)max_idx << VMCS_FIELD_INDEX_SHIFT; >> } >> >> +/* >> + * According with section A.3.3 of > > Avoid referencing sections/tables by "number" in comments (and changelogs), as the > comment is all but guaranteed to become stale because future versions of the SDM > will shift things around. > > The slightly more robust way to reference a specific SDM/APM section is to use the > title, e.g. According to section "Secondary Processor-Based VM-Execution Controls" > in Intel's SDM ...", as hardware vendors are less likely to arbitrarily rename > sections and tables. It's a bit more work for readers, but any decent PDF viewer > can search these days. > >> Intel System Programming Guide > > KVM typically uses "Intel's SDM" (and "AMD's APM"). Like "VMX" or "SVM", it's ok > to use the SDM acronym without introducing since "SDM" is > >> + * we *can* set the guest MSR control X (in our case > > Avoid pronouns in comments. "we" and "us" are ambiguous, e.g. "we" can mean KVM, > the developer, the user, etc... > >> + * SECONDARY_EXEC_ENCLS_EXITING) *iff* bit 32+X of >> + * MSR_IA32_VMX_PROCBASED_CTLS2 is set to 1. >> + * Otherwise it must remain zero. > > As a general rule, if you find yourself writing a comment and a helper for > something that KVM absolutely needs to get right (honoring VMX MSRs), then odds > are very good that there's a simpler/easier fix, i.e. that you're effectively > re-inventing part of the weel. > >> + */ >> +static void nested_vmx_setup_encls_exiting(struct nested_vmx_msrs *msrs) >> +{ >> + u32 vmx_msr_procb_low, vmx_msr_procb_high; >> + >> + rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2, vmx_msr_procb_low, vmx_msr_procb_high); >> + >> + WARN_ON(vmx_msr_procb_low & SECONDARY_EXEC_ENCLS_EXITING); >> + >> + if (enable_sgx && (vmx_msr_procb_high & SECONDARY_EXEC_ENCLS_EXITING)) >> + msrs->secondary_ctls_high |= SECONDARY_EXEC_ENCLS_EXITING; >> +} >> + >> /* >> * nested_vmx_setup_ctls_msrs() sets up variables containing the values to be >> * returned for the various VMX controls MSRs when nested VMX is enabled. >> @@ -6874,8 +6893,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps) >> msrs->secondary_ctls_high |= >> SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES; >> >> - if (enable_sgx) >> - msrs->secondary_ctls_high |= SECONDARY_EXEC_ENCLS_EXITING; > > The issue here is that I, who wrote this code long, long ago, copied the pattern > used for enable_unrestricted_guest, flexpriority_enabled, etc... without fully > appreciating the logic. Unlike those module params, enable_sgx doesn't track > hardware support, i.e. enable_sgx isn't cleared when SGX can't be enabled due to > lack of hardware support. As a result, KVM effectively enumerates to L1 that the > control is always available, i.e. that KVM emulates ENCLS-exiting for L1, but KVM > obviously doesn't actually emulating the behavior. > > Not updating enable_sgx is responsible for a second bug: vmx_set_cpu_caps() doesn't > clear the SGX bits when hardware support is unavailable. This is a much less > problematic bug as as it only pops up if SGX is soft-disabled (the case being > handled by cpu_has_sgx()) or if SGX is supported for bare metal but not in the > VMCS (will never happen when running on bare metal, but can theoertically happen > when running in a VM). > > Last but not least, KVM should ideally have module params reflect KVM's actual > configuration. > > Killing all birds with one stone, simply clear enable_sgx when ENCLS-exiting isn't > supported. The #ifdef is a little gross, but I think it's marginally less ugly > than having vmx.c define a dummy boolean. > > Compile tested only... > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 9dba04b6b019..65f092e4a81b 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -8263,6 +8263,11 @@ static __init int hardware_setup(void) > if (!cpu_has_virtual_nmis()) > enable_vnmi = 0; > > +#ifdef CONFIG_X86_SGX_KVM > + if (!cpu_has_vmx_encls_vmexit()) > + enable_sgx = false; > +#endif > + > /* > * set_apic_access_page_addr() is used to reload apic access > * page upon invalidation. No need to do anything if not > Thanks for all the suggestions and explanations, I am going to apply your changes and send v2! Emanuele
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 8f67a9c4a287..f651084010cc 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6678,6 +6678,25 @@ static u64 nested_vmx_calc_vmcs_enum_msr(void) return (u64)max_idx << VMCS_FIELD_INDEX_SHIFT; } +/* + * According with section A.3.3 of Intel System Programming Guide, + * we *can* set the guest MSR control X (in our case + * SECONDARY_EXEC_ENCLS_EXITING) *iff* bit 32+X of + * MSR_IA32_VMX_PROCBASED_CTLS2 is set to 1. + * Otherwise it must remain zero. + */ +static void nested_vmx_setup_encls_exiting(struct nested_vmx_msrs *msrs) +{ + u32 vmx_msr_procb_low, vmx_msr_procb_high; + + rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2, vmx_msr_procb_low, vmx_msr_procb_high); + + WARN_ON(vmx_msr_procb_low & SECONDARY_EXEC_ENCLS_EXITING); + + if (enable_sgx && (vmx_msr_procb_high & SECONDARY_EXEC_ENCLS_EXITING)) + msrs->secondary_ctls_high |= SECONDARY_EXEC_ENCLS_EXITING; +} + /* * nested_vmx_setup_ctls_msrs() sets up variables containing the values to be * returned for the various VMX controls MSRs when nested VMX is enabled. @@ -6874,8 +6893,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps) msrs->secondary_ctls_high |= SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES; - if (enable_sgx) - msrs->secondary_ctls_high |= SECONDARY_EXEC_ENCLS_EXITING; + nested_vmx_setup_encls_exiting(msrs); /* miscellaneous data */ msrs->misc_low = (u32)vmcs_conf->misc & VMX_MISC_SAVE_EFER_LMA;