Skip to content

Commit 27cca94

Browse files
Haozhong Zhangbonzini
authored andcommitted
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>
1 parent 4ba7653 commit 27cca94

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ static void kvm_gen_update_masterclock(struct kvm *kvm)
17071707

17081708
static int kvm_guest_time_update(struct kvm_vcpu *v)
17091709
{
1710-
unsigned long flags, this_tsc_khz;
1710+
unsigned long flags, this_tsc_khz, tgt_tsc_khz;
17111711
struct kvm_vcpu_arch *vcpu = &v->arch;
17121712
struct kvm_arch *ka = &v->kvm->arch;
17131713
s64 kernel_ns;
@@ -1770,7 +1770,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
17701770
return 0;
17711771

17721772
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,
17741776
&vcpu->hv_clock.tsc_shift,
17751777
&vcpu->hv_clock.tsc_to_system_mul);
17761778
vcpu->hw_tsc_khz = this_tsc_khz;

0 commit comments

Comments
 (0)