Skip to content

Commit be7b263

Browse files
Haozhong Zhangbonzini
authored andcommitted
KVM: VMX: Use a scaled host TSC for guest readings of MSR_IA32_TSC
This patch makes kvm-intel to return a scaled host TSC plus the TSC offset when handling guest readings to MSR_IA32_TSC. Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent ff2c3a1 commit be7b263

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎arch/x86/kvm/vmx.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,15 +2371,16 @@ static void setup_msrs(struct vcpu_vmx *vmx)
23712371

23722372
/*
23732373
* reads and returns guest's timestamp counter "register"
2374-
* guest_tsc = host_tsc + tsc_offset -- 21.3
2374+
* guest_tsc = (host_tsc * tsc multiplier) >> 48 + tsc_offset
2375+
* -- Intel TSC Scaling for Virtualization White Paper, sec 1.3
23752376
*/
2376-
static u64 guest_read_tsc(void)
2377+
static u64 guest_read_tsc(struct kvm_vcpu *vcpu)
23772378
{
23782379
u64 host_tsc, tsc_offset;
23792380

23802381
host_tsc = rdtsc();
23812382
tsc_offset = vmcs_read64(TSC_OFFSET);
2382-
return host_tsc + tsc_offset;
2383+
return kvm_scale_tsc(vcpu, host_tsc) + tsc_offset;
23832384
}
23842385

23852386
/*
@@ -2771,7 +2772,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
27712772
case MSR_EFER:
27722773
return kvm_get_msr_common(vcpu, msr_info);
27732774
case MSR_IA32_TSC:
2774-
msr_info->data = guest_read_tsc();
2775+
msr_info->data = guest_read_tsc(vcpu);
27752776
break;
27762777
case MSR_IA32_SYSENTER_CS:
27772778
msr_info->data = vmcs_read32(GUEST_SYSENTER_CS);

0 commit comments

Comments
 (0)