]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
KVM: x86: SVM: fix tsc scaling when the host doesn't support it
authorMaxim Levitsky <mlevitsk@redhat.com>
Tue, 22 Mar 2022 17:24:48 +0000 (19:24 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 2 Apr 2022 09:37:26 +0000 (05:37 -0400)
It was decided that when TSC scaling is not supported,
the virtual MSR_AMD64_TSC_RATIO should still have the default '1.0'
value.

However in this case kvm_max_tsc_scaling_ratio is not set,
which breaks various assumptions.

Fix this by always calculating kvm_max_tsc_scaling_ratio regardless of
host support.  For consistency, do the same for VMX.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Message-Id: <20220322172449.235575-8-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/svm.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c

index cff941989431bfe524742de0436e73b6cd4fd3ec..bd4c64b362d24a06c9a2e48de0de9803d700c47f 100644 (file)
@@ -4752,10 +4752,10 @@ static __init int svm_hardware_setup(void)
                } else {
                        pr_info("TSC scaling supported\n");
                        kvm_has_tsc_control = true;
-                       kvm_max_tsc_scaling_ratio = SVM_TSC_RATIO_MAX;
-                       kvm_tsc_scaling_ratio_frac_bits = 32;
                }
        }
+       kvm_max_tsc_scaling_ratio = SVM_TSC_RATIO_MAX;
+       kvm_tsc_scaling_ratio_frac_bits = 32;
 
        tsc_aux_uret_slot = kvm_add_user_return_msr(MSR_TSC_AUX);
 
index fb8d5b6d05f7011d59e8cae1d851a23b642bc02e..1bbd3e97694c2f46abd9b6d2ad628fe48cd8af5a 100644 (file)
@@ -7980,12 +7980,11 @@ static __init int hardware_setup(void)
        if (!enable_apicv)
                vmx_x86_ops.sync_pir_to_irr = NULL;
 
-       if (cpu_has_vmx_tsc_scaling()) {
+       if (cpu_has_vmx_tsc_scaling())
                kvm_has_tsc_control = true;
-               kvm_max_tsc_scaling_ratio = KVM_VMX_TSC_MULTIPLIER_MAX;
-               kvm_tsc_scaling_ratio_frac_bits = 48;
-       }
 
+       kvm_max_tsc_scaling_ratio = KVM_VMX_TSC_MULTIPLIER_MAX;
+       kvm_tsc_scaling_ratio_frac_bits = 48;
        kvm_has_bus_lock_exit = cpu_has_vmx_bus_lock_detection();
 
        set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */
index bc63ba52c4d632759d169e865ec5cbb3a3ea5206..498cd4aaa2cb362915439441bd89915a43db50a6 100644 (file)
@@ -11602,10 +11602,8 @@ int kvm_arch_hardware_setup(void *opaque)
                u64 max = min(0x7fffffffULL,
                              __scale_tsc(kvm_max_tsc_scaling_ratio, tsc_khz));
                kvm_max_guest_tsc_khz = max;
-
-               kvm_default_tsc_scaling_ratio = 1ULL << kvm_tsc_scaling_ratio_frac_bits;
        }
-
+       kvm_default_tsc_scaling_ratio = 1ULL << kvm_tsc_scaling_ratio_frac_bits;
        kvm_init_msr_list();
        return 0;
 }