Skip to content

Commit 343acdd

Browse files
committed
KVM: x86: Disable support for IBT and SHSTK if allow_smaller_maxphyaddr is true
Make IBT and SHSTK virtualization mutually exclusive with "officially" supporting setups with guest.MAXPHYADDR < host.MAXPHYADDR, i.e. if the allow_smaller_maxphyaddr module param is set. Running a guest with a smaller MAXPHYADDR requires intercepting #PF, and can also trigger emulation of arbitrary instructions. Intercepting and reacting to #PFs doesn't play nice with SHSTK, as KVM's MMU hasn't been taught to handle Shadow Stack accesses, and emulating arbitrary instructions doesn't play nice with IBT or SHSTK, as KVM's emulator doesn't handle the various side effects, e.g. doesn't enforce end-branch markers or model Shadow Stack updates. Note, hiding IBT and SHSTK based solely on allow_smaller_maxphyaddr is overkill, as allow_smaller_maxphyaddr is only problematic if the guest is actually configured to have a smaller MAXPHYADDR. However, KVM's ABI doesn't provide a way to express that IBT and SHSTK may break if enabled in conjunction with guest.MAXPHYADDR < host.MAXPHYADDR. I.e. the alternative is to do nothing in KVM and instead update documentation and hope KVM users are thorough readers. Go with the conservative-but-correct approach; worst case scenario, this restriction can be dropped if there's a strong use case for enabling CET on hosts with allow_smaller_maxphyaddr. Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Link: https://lore.kernel.org/r/20250919223258.1604852-28-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent f705de1 commit 343acdd

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

arch/x86/kvm/cpuid.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,16 @@ void kvm_set_cpu_caps(void)
982982
F(FLUSH_L1D),
983983
);
984984

985+
/*
986+
* Disable support for IBT and SHSTK if KVM is configured to emulate
987+
* accesses to reserved GPAs, as KVM's emulator doesn't support IBT or
988+
* SHSTK, nor does KVM handle Shadow Stack #PFs (see above).
989+
*/
990+
if (allow_smaller_maxphyaddr) {
991+
kvm_cpu_cap_clear(X86_FEATURE_SHSTK);
992+
kvm_cpu_cap_clear(X86_FEATURE_IBT);
993+
}
994+
985995
if (boot_cpu_has(X86_FEATURE_AMD_IBPB_RET) &&
986996
boot_cpu_has(X86_FEATURE_AMD_IBPB) &&
987997
boot_cpu_has(X86_FEATURE_AMD_IBRS))

0 commit comments

Comments
 (0)