x86/virt: KVM: Open code cpu_has_vmx() in KVM VMX
authorSean Christopherson <seanjc@google.com>
Fri, 21 Jul 2023 20:18:49 +0000 (13:18 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 3 Aug 2023 22:37:14 +0000 (15:37 -0700)
Fold the raw CPUID check for VMX into kvm_is_vmx_supported(), its sole
user.  Keep the check even though KVM also checks X86_FEATURE_VMX, as the
intent is to provide a unique error message if VMX is unsupported by
hardware, whereas X86_FEATURE_VMX may be clear due to firmware and/or
kernel actions.

No functional change intended.

Reviewed-by: Kai Huang <kai.huang@intel.com>
Link: https://lore.kernel.org/r/20230721201859.2307736-10-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/virtext.h
arch/x86/kvm/vmx/vmx.c

index aaed66249ccf3c3782057d0337be7899a43bb616..b1171a5ad452534518266551e9d5bff08bc0434b 100644 (file)
 /*
  * VMX functions:
  */
-
-static inline int cpu_has_vmx(void)
-{
-       unsigned long ecx = cpuid_ecx(1);
-       return test_bit(5, &ecx); /* CPUID.1:ECX.VMX[bit 5] -> VT */
-}
-
-
 /**
  * cpu_vmxoff() - Disable VMX on the current CPU
  *
@@ -61,8 +53,6 @@ static inline int cpu_vmx_enabled(void)
 }
 
 /** Disable VMX if it is enabled on the current CPU
- *
- * You shouldn't call this if cpu_has_vmx() returns 0.
  */
 static inline void __cpu_emergency_vmxoff(void)
 {
index df991f15baf49ee25523759a560bd32d9bb52ecb..4b9d6882617266409f4559b34f4fa4791d2c850a 100644 (file)
@@ -2699,7 +2699,7 @@ static bool kvm_is_vmx_supported(void)
 {
        int cpu = raw_smp_processor_id();
 
-       if (!cpu_has_vmx()) {
+       if (!(cpuid_ecx(1) & feature_bit(VMX))) {
                pr_err("VMX not supported by CPU %d\n", cpu);
                return false;
        }