Skip to content

Commit f9a8866

Browse files
committed
KVM: VMX: Ensure CPU is stable when probing basic VMX support
Disable migration when probing VMX support during module load to ensure the CPU is stable, mostly to match similar SVM logic, where allowing migration effective requires deliberately writing buggy code. As a bonus, KVM won't report the wrong CPU to userspace if VMX is unsupported, but in practice that is a very, very minor bonus as the only way that reporting the wrong CPU would actually matter is if hardware is broken or if the system is misconfigured, i.e. if KVM gets migrated from a CPU that _does_ support VMX to a CPU that does _not_ support VMX. Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://lore.kernel.org/r/20230721201859.2307736-16-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c4db4f2 commit f9a8866

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

arch/x86/kvm/vmx/vmx.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,9 +2718,9 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
27182718
return 0;
27192719
}
27202720

2721-
static bool kvm_is_vmx_supported(void)
2721+
static bool __kvm_is_vmx_supported(void)
27222722
{
2723-
int cpu = raw_smp_processor_id();
2723+
int cpu = smp_processor_id();
27242724

27252725
if (!(cpuid_ecx(1) & feature_bit(VMX))) {
27262726
pr_err("VMX not supported by CPU %d\n", cpu);
@@ -2736,13 +2736,24 @@ static bool kvm_is_vmx_supported(void)
27362736
return true;
27372737
}
27382738

2739+
static bool kvm_is_vmx_supported(void)
2740+
{
2741+
bool supported;
2742+
2743+
migrate_disable();
2744+
supported = __kvm_is_vmx_supported();
2745+
migrate_enable();
2746+
2747+
return supported;
2748+
}
2749+
27392750
static int vmx_check_processor_compat(void)
27402751
{
27412752
int cpu = raw_smp_processor_id();
27422753
struct vmcs_config vmcs_conf;
27432754
struct vmx_capability vmx_cap;
27442755

2745-
if (!kvm_is_vmx_supported())
2756+
if (!__kvm_is_vmx_supported())
27462757
return -EIO;
27472758

27482759
if (setup_vmcs_config(&vmcs_conf, &vmx_cap) < 0) {

0 commit comments

Comments
 (0)