[Devel] [PATCH RHEL7 COMMIT] ms/KVM: VMX: Use a scaled host TSC for guest readings of MSR_IA32_TSC

Konstantin Khorenko khorenko at virtuozzo.com
Wed Nov 16 04:46:01 PST 2016


The commit is pushed to "branch-rh7-3.10.0-327.36.1.vz7.19.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.36.1.vz7.19.9
------>
commit 744cccce6718f6a5b76600d777a1e59bf29a4f70
Author: Haozhong Zhang <haozhong.zhang at intel.com>
Date:   Wed Nov 16 16:46:01 2016 +0400

    ms/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 at intel.com>
    Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
    (cherry-picked from commit be7b263ea925324e54e48c3558d4719be5374053)
    Signed-off-by: Denis Plotnikov <dplotnikov at virtuozzo.com>
    Signed-off-by: Roman Kagan <rkagan at virtuozzo.com>
---
 arch/x86/kvm/vmx.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 265bc0e..9f3c26a 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2176,15 +2176,16 @@ static void setup_msrs(struct vcpu_vmx *vmx)
 
 /*
  * reads and returns guest's timestamp counter "register"
- * guest_tsc = host_tsc + tsc_offset    -- 21.3
+ * guest_tsc = (host_tsc * tsc multiplier) >> 48 + tsc_offset
+ * -- Intel TSC Scaling for Virtualization White Paper, sec 1.3
  */
-static u64 guest_read_tsc(void)
+static u64 guest_read_tsc(struct kvm_vcpu *vcpu)
 {
 	u64 host_tsc, tsc_offset;
 
 	rdtscll(host_tsc);
 	tsc_offset = vmcs_read64(TSC_OFFSET);
-	return host_tsc + tsc_offset;
+	return kvm_scale_tsc(vcpu, host_tsc) + tsc_offset;
 }
 
 /*
@@ -2539,7 +2540,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 	case MSR_EFER:
 		return kvm_get_msr_common(vcpu, msr_info);
 	case MSR_IA32_TSC:
-		msr_info->data = guest_read_tsc();
+		msr_info->data = guest_read_tsc(vcpu);
 		break;
 	case MSR_IA32_SYSENTER_CS:
 		msr_info->data = vmcs_read32(GUEST_SYSENTER_CS);


More information about the Devel mailing list