]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Avoid double CPUID lookup when updating MWAIT at runtime
authorSean Christopherson <seanjc@google.com>
Thu, 28 Nov 2024 01:34:12 +0000 (17:34 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 22:20:10 +0000 (14:20 -0800)
Move the handling of X86_FEATURE_MWAIT during CPUID runtime updates to
utilize the lookup done for other CPUID.0x1 features.

No functional change intended.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20241128013424.4096668-46-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.c

index b02f5098108abaaddd2b7650df6f5580e0ec623f..688c7c36c73bb238ca03f3a8a160f48dc5713ac8 100644 (file)
@@ -304,6 +304,11 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
 
                cpuid_entry_change(best, X86_FEATURE_APIC,
                           vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE);
+
+               if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT))
+                       cpuid_entry_change(best, X86_FEATURE_MWAIT,
+                                          vcpu->arch.ia32_misc_enable_msr &
+                                          MSR_IA32_MISC_ENABLE_MWAIT);
        }
 
        best = kvm_find_cpuid_entry_index(vcpu, 7, 0);
@@ -319,14 +324,6 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
        if (best && (cpuid_entry_has(best, X86_FEATURE_XSAVES) ||
                     cpuid_entry_has(best, X86_FEATURE_XSAVEC)))
                best->ebx = xstate_required_size(vcpu->arch.xcr0, true);
-
-       if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT)) {
-               best = kvm_find_cpuid_entry(vcpu, 0x1);
-               if (best)
-                       cpuid_entry_change(best, X86_FEATURE_MWAIT,
-                                          vcpu->arch.ia32_misc_enable_msr &
-                                          MSR_IA32_MISC_ENABLE_MWAIT);
-       }
 }
 EXPORT_SYMBOL_GPL(kvm_update_cpuid_runtime);