]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Update OS{XSAVE,PKE} bits in guest CPUID irrespective of host support
authorSean Christopherson <seanjc@google.com>
Thu, 28 Nov 2024 01:34:14 +0000 (17:34 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 22:20:12 +0000 (14:20 -0800)
When making runtime CPUID updates, change OSXSAVE and OSPKE even if their
respective base features (XSAVE, PKU) are not supported by the host.  KVM
already incorporates host support in the vCPU's effective reserved CR4 bits.
I.e. OSXSAVE and OSPKE can be set if and only if the host supports them.

And conversely, since KVM's ABI is that KVM owns the dynamic OS feature
flags, clearing them when they obviously aren't supported and thus can't
be enabled is arguably a fix.

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-48-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.c

index ced3c08a99c2ea5ff4dce59489f32a6298a3821c..d298b640ff74a0c4bc8f148fe0f082b70b7e07d5 100644 (file)
@@ -297,10 +297,8 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
 
        best = kvm_find_cpuid_entry(vcpu, 1);
        if (best) {
-               /* Update OSXSAVE bit */
-               if (boot_cpu_has(X86_FEATURE_XSAVE))
-                       cpuid_entry_change(best, X86_FEATURE_OSXSAVE,
-                                          kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE));
+               cpuid_entry_change(best, X86_FEATURE_OSXSAVE,
+                                  kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE));
 
                cpuid_entry_change(best, X86_FEATURE_APIC,
                           vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE);
@@ -312,7 +310,7 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
        }
 
        best = kvm_find_cpuid_entry_index(vcpu, 7, 0);
-       if (best && boot_cpu_has(X86_FEATURE_PKU))
+       if (best)
                cpuid_entry_change(best, X86_FEATURE_OSPKE,
                                   kvm_is_cr4_bit_set(vcpu, X86_CR4_PKE));