[PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for nested EPT
From: Dennis Reußwig
Date: Thu Dec 03 2026 - 18:50:27 EST
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@xxxxxxxxxxxxx>
Closes: https://lore.kernel.org/kvm/58dcd595e3187d335e103a042d196cb7@xxxxxxxxxxxxx/
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