Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: x86: Use the correct vcpu's TSC rate to compute time scale

This patch makes KVM use virtual_tsc_khz rather than the host TSC rate
as vcpu's TSC rate to compute the time scale if TSC scaling is enabled.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Haozhong Zhang and committed by
Paolo Bonzini
27cca94e 4ba76538

+4 -2
+4 -2
arch/x86/kvm/x86.c
··· 1707 1707 1708 1708 static int kvm_guest_time_update(struct kvm_vcpu *v) 1709 1709 { 1710 - unsigned long flags, this_tsc_khz; 1710 + unsigned long flags, this_tsc_khz, tgt_tsc_khz; 1711 1711 struct kvm_vcpu_arch *vcpu = &v->arch; 1712 1712 struct kvm_arch *ka = &v->kvm->arch; 1713 1713 s64 kernel_ns; ··· 1770 1770 return 0; 1771 1771 1772 1772 if (unlikely(vcpu->hw_tsc_khz != this_tsc_khz)) { 1773 - kvm_get_time_scale(NSEC_PER_SEC / 1000, this_tsc_khz, 1773 + tgt_tsc_khz = kvm_has_tsc_control ? 1774 + vcpu->virtual_tsc_khz : this_tsc_khz; 1775 + kvm_get_time_scale(NSEC_PER_SEC / 1000, tgt_tsc_khz, 1774 1776 &vcpu->hv_clock.tsc_shift, 1775 1777 &vcpu->hv_clock.tsc_to_system_mul); 1776 1778 vcpu->hw_tsc_khz = this_tsc_khz;