Skip to content

Commit 8809931

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: x86: SVM: fix tsc scaling when the host doesn't support it
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>
1 parent f37b735 commit 8809931

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4752,10 +4752,10 @@ static __init int svm_hardware_setup(void)
47524752
} else {
47534753
pr_info("TSC scaling supported\n");
47544754
kvm_has_tsc_control = true;
4755-
kvm_max_tsc_scaling_ratio = SVM_TSC_RATIO_MAX;
4756-
kvm_tsc_scaling_ratio_frac_bits = 32;
47574755
}
47584756
}
4757+
kvm_max_tsc_scaling_ratio = SVM_TSC_RATIO_MAX;
4758+
kvm_tsc_scaling_ratio_frac_bits = 32;
47594759

47604760
tsc_aux_uret_slot = kvm_add_user_return_msr(MSR_TSC_AUX);
47614761

arch/x86/kvm/vmx/vmx.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7980,12 +7980,11 @@ static __init int hardware_setup(void)
79807980
if (!enable_apicv)
79817981
vmx_x86_ops.sync_pir_to_irr = NULL;
79827982

7983-
if (cpu_has_vmx_tsc_scaling()) {
7983+
if (cpu_has_vmx_tsc_scaling())
79847984
kvm_has_tsc_control = true;
7985-
kvm_max_tsc_scaling_ratio = KVM_VMX_TSC_MULTIPLIER_MAX;
7986-
kvm_tsc_scaling_ratio_frac_bits = 48;
7987-
}
79887985

7986+
kvm_max_tsc_scaling_ratio = KVM_VMX_TSC_MULTIPLIER_MAX;
7987+
kvm_tsc_scaling_ratio_frac_bits = 48;
79897988
kvm_has_bus_lock_exit = cpu_has_vmx_bus_lock_detection();
79907989

79917990
set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */

arch/x86/kvm/x86.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11602,10 +11602,8 @@ int kvm_arch_hardware_setup(void *opaque)
1160211602
u64 max = min(0x7fffffffULL,
1160311603
__scale_tsc(kvm_max_tsc_scaling_ratio, tsc_khz));
1160411604
kvm_max_guest_tsc_khz = max;
11605-
11606-
kvm_default_tsc_scaling_ratio = 1ULL << kvm_tsc_scaling_ratio_frac_bits;
1160711605
}
11608-
11606+
kvm_default_tsc_scaling_ratio = 1ULL << kvm_tsc_scaling_ratio_frac_bits;
1160911607
kvm_init_msr_list();
1161011608
return 0;
1161111609
}

0 commit comments

Comments
 (0)