]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: x86: Explicitly disable TSC scaling without CONSTANT_TSC
authorDavid Woodhouse <dwmw@amazon.co.uk>
Thu, 18 Apr 2024 08:28:24 +0000 (09:28 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 2 Aug 2024 14:51:45 +0000 (15:51 +0100)
KVM does make an attempt to cope with non-constant TSC, and has notifiers
to handle host TSC frequency changes. However, it *only* adjusts the KVM
clock, and doesn't adjust TSC frequency scaling when the host changes.

This is presumably because non-constant TSCs were fixed in hardware long
before TSC scaling was implemented, so there should never be real CPUs
which have TSC scaling but *not* CONSTANT_TSC.

Such a combination could potentially happen in some odd L1 nesting
environment, but it isn't worth trying to support it. Just make the
dependency explicit.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
arch/x86/kvm/svm/svm.c
arch/x86/kvm/vmx/vmx.c

index c115d26844f7f6b737bd0423645da08875f7bb50..115c409c092c6706e79d1cd831a8236a6b6727c4 100644 (file)
@@ -5261,7 +5261,8 @@ static __init int svm_hardware_setup(void)
                kvm_enable_efer_bits(EFER_FFXSR);
 
        if (tsc_scaling) {
-               if (!boot_cpu_has(X86_FEATURE_TSCRATEMSR)) {
+               if (!boot_cpu_has(X86_FEATURE_TSCRATEMSR) ||
+                   !boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
                        tsc_scaling = false;
                } else {
                        pr_info("TSC scaling supported\n");
index f18c2d8c7476e180005cef514953ab0e2ecb80bb..3922e26bcca113e7b8914daa996f040a6962a744 100644 (file)
@@ -8477,7 +8477,7 @@ __init int vmx_hardware_setup(void)
        if (!enable_apicv || !cpu_has_vmx_ipiv())
                enable_ipiv = false;
 
-       if (cpu_has_vmx_tsc_scaling())
+       if (cpu_has_vmx_tsc_scaling() && boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
                kvm_caps.has_tsc_control = true;
 
        kvm_caps.max_tsc_scaling_ratio = KVM_VMX_TSC_MULTIPLIER_MAX;