Skip to content

Commit f7336d4

Browse files
committed
KVM: VMX: Configure nested capabilities after CPU capabilities
Swap the order between configuring nested VMX capabilities and base CPU capabilities, so that nested VMX support can be conditioned on core KVM support, e.g. to allow conditioning support for LOAD_CET_STATE on the presence of IBT or SHSTK. Because the sanity checks on nested VMX config performed by vmx_check_processor_compat() run _after_ vmx_hardware_setup(), any use of kvm_cpu_cap_has() when configuring nested VMX support will lead to failures in vmx_check_processor_compat(). While swapping the order of two (or more) configuration flows can lead to a game of whack-a-mole, in this case nested support inarguably should be done after base support. KVM should never condition base support on nested support, because nested support is fully optional, while obviously it's desirable to condition nested support on base support. And there's zero evidence the current ordering was intentional, e.g. commit 66a6950 ("KVM: x86: Introduce kvm_cpu_caps to replace runtime CPUID masking") likely placed the call to kvm_set_cpu_caps() after nested setup because it looked pretty. Reviewed-by: Chao Gao <chao.gao@intel.com> Link: https://lore.kernel.org/r/20250919223258.1604852-30-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e140467 commit f7336d4

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

arch/x86/kvm/vmx/vmx.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8597,6 +8597,13 @@ __init int vmx_hardware_setup(void)
85978597

85988598
setup_default_sgx_lepubkeyhash();
85998599

8600+
vmx_set_cpu_caps();
8601+
8602+
/*
8603+
* Configure nested capabilities after core CPU capabilities so that
8604+
* nested support can be conditional on base support, e.g. so that KVM
8605+
* can hide/show features based on kvm_cpu_cap_has().
8606+
*/
86008607
if (nested) {
86018608
nested_vmx_setup_ctls_msrs(&vmcs_config, vmx_capability.ept);
86028609

@@ -8605,8 +8612,6 @@ __init int vmx_hardware_setup(void)
86058612
return r;
86068613
}
86078614

8608-
vmx_set_cpu_caps();
8609-
86108615
r = alloc_kvm_area();
86118616
if (r && nested)
86128617
nested_vmx_hardware_unsetup();

0 commit comments

Comments
 (0)