From: "Dennis Reußwig" <dennis@reusswig.codes>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@kernel.org>,
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>,
Jon Kohler <jon@nutanix.com>, Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Shuah Khan <shuah@kernel.org>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org,
"Chao Gao" <chao.gao@intel.com>,
"Maxim Levitsky" <mlevitsk@redhat.com>,
"Vitaly Kuznetsov" <vkuznets@redhat.com>,
"Panayotis Katsaloulis" <panayotis@panayotis.com>,
"Dennis Reußwig" <dennis@reusswig.codes>
Subject: [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for nested EPT
Date: Fri, 04 Dec 2026 00:49:19 +0100 [thread overview]
Message-ID: <20261204-nested-sss-v1-6-57de06f58b2b@reusswig.codes> (raw)
In-Reply-To: <20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes>
Since commit 606ddbfb4c02 ("KVM: nVMX: advertise MBEC to nested
guests"), Windows Hyper-V is offered MBEC and then enables CET for its
guests. It requires supervisor shadow-stack control for EPT
(IA32_VMX_EPT_VPID_CAP bit 23), which KVM never advertised, and Windows
with virtualization-based security stops booting (Automatic Repair).
Advertise the capability if the CPU supports it, KVM supports shadow
stacks and advanced VM-exit information is offered, which is needed to
tell supervisor from user shadow-stack accesses. Accept EPTP bit 7 in
nested_vmx_check_eptp() only if the capability is offered; bits 11:8
stay reserved.
The VMM must also expose bit 23 to L1; QEMU names it separately.
Fixes: 606ddbfb4c02 ("KVM: nVMX: advertise MBEC to nested guests")
Reported-by: Panayotis Katsaloulis <panayotis@panayotis.com>
Closes: https://lore.kernel.org/kvm/58dcd595e3187d335e103a042d196cb7@panayotis.com/
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
arch/x86/include/asm/vmx.h | 1 +
arch/x86/kvm/vmx/nested.c | 20 ++++++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index df6feba112f7..22e890f35435 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -545,6 +545,7 @@ enum vmcs_field {
#define VMX_EPT_INVEPT_BIT (1ull << 20)
#define VMX_EPT_AD_BIT (1ull << 21)
#define VMX_EPT_ADVANCED_VMEXIT_INFO_BIT (1ull << 22)
+#define VMX_EPT_SSS_BIT (1ull << 23)
#define VMX_EPT_EXTENT_CONTEXT_BIT (1ull << 25)
#define VMX_EPT_EXTENT_GLOBAL_BIT (1ull << 26)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index dc7199855497..f7bcf1891716 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2930,7 +2930,12 @@ static bool nested_vmx_check_eptp(struct kvm_vcpu *vcpu, u64 new_eptp)
}
/* Reserved bits should not be set */
- if (CC(!kvm_vcpu_is_legal_gpa(vcpu, new_eptp) || ((new_eptp >> 7) & 0x1f)))
+ if (CC(!kvm_vcpu_is_legal_gpa(vcpu, new_eptp) || ((new_eptp >> 8) & 0xf)))
+ return false;
+
+ /* Supervisor shadow-stack control, if set, should be supported */
+ if (CC((new_eptp & VMX_EPTP_SSS_BIT) &&
+ !(vmx->nested.msrs.ept_caps & VMX_EPT_SSS_BIT)))
return false;
/* AD, if set, should be supported */
@@ -7251,9 +7256,20 @@ static void nested_vmx_setup_secondary_ctls(u32 ept_caps,
VMX_EPTP_WB_BIT |
VMX_EPT_INVEPT_BIT |
VMX_EPT_EXECUTE_ONLY_BIT |
- VMX_EPT_ADVANCED_VMEXIT_INFO_BIT;
+ VMX_EPT_ADVANCED_VMEXIT_INFO_BIT |
+ VMX_EPT_SSS_BIT;
msrs->ept_caps &= ept_caps;
+
+ /*
+ * Supervisor shadow-stack control needs shadow stacks for the
+ * guest, and advanced VM-exit information to tell supervisor
+ * from user shadow-stack accesses in EPT violations.
+ */
+ if (!kvm_cpu_cap_has(X86_FEATURE_SHSTK) ||
+ !(msrs->ept_caps & VMX_EPT_ADVANCED_VMEXIT_INFO_BIT))
+ msrs->ept_caps &= ~VMX_EPT_SSS_BIT;
+
msrs->ept_caps |= VMX_EPT_EXTENT_GLOBAL_BIT |
VMX_EPT_EXTENT_CONTEXT_BIT | VMX_EPT_2MB_PAGE_BIT |
VMX_EPT_1GB_PAGE_BIT;
--
2.53.0
next prev parent reply other threads:[~2026-12-03 23:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 01/10] KVM: nVMX: Allow CET entry/exit controls with enlightened VMCS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 02/10] KVM: x86/mmu: Move TDP A/D tracking type to SPTE bits 56-57 Dennis Reußwig
2026-12-03 23:49 ` [PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit Dennis Reußwig
2026-12-03 23:49 ` [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT Dennis Reußwig
2026-12-03 23:49 ` Dennis Reußwig [this message]
2026-12-03 23:49 ` [PATCH 07/10] KVM: selftests: Add helpers for nested EPT shadow-stack and MBEC tests Dennis Reußwig
2026-12-03 23:49 ` [PATCH 08/10] KVM: selftests: Add nested EPT supervisor shadow-stack test Dennis Reußwig
2026-12-03 23:49 ` [PATCH 09/10] KVM: selftests: Add nested EPT mode-based execute control test Dennis Reußwig
2026-12-03 23:49 ` [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC Dennis Reußwig
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=20261204-nested-sss-v1-6-57de06f58b2b@reusswig.codes \
--to=dennis@reusswig.codes \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jon@nutanix.com \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=panayotis@panayotis.com \
--cc=pbonzini@redhat.com \
--cc=rdunlap@infradead.org \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tglx@kernel.org \
--cc=vkuznets@redhat.com \
--cc=x86@kernel.org \
/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®