]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: x86: Use feature_bit() to clear CONSTANT_TSC when emulating CPUID
authorSean Christopherson <seanjc@google.com>
Thu, 28 Nov 2024 01:33:28 +0000 (17:33 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 22:19:22 +0000 (14:19 -0800)
When clearing CONSTANT_TSC during CPUID emulation due to a Hyper-V quirk,
use feature_bit() instead of SF() to ensure the bit is actually cleared.
SF() evaluates to zero if the _host_ doesn't support the feature.  I.e.
KVM could keep the bit set if userspace advertised CONSTANT_TSC despite
it not being supported in hardware.

Note, translating from a scattered feature to a the hardware version is
done by __feature_translate(), not SF().  The sole purpose of SF() is to
check kernel support for the scattered feature, *before* translation.

Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20241128013424.4096668-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.c

index ae0b438a2c991ceb6a28af84914808e4df913b5b..701bbbf58124348ec5265bd6b84f52e93cd8bf67 100644 (file)
@@ -1651,7 +1651,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
                                *ebx &= ~(F(RTM) | F(HLE));
                } else if (function == 0x80000007) {
                        if (kvm_hv_invtsc_suppressed(vcpu))
-                               *edx &= ~SF(CONSTANT_TSC);
+                               *edx &= ~feature_bit(CONSTANT_TSC);
                }
        } else {
                *eax = *ebx = *ecx = *edx = 0;