Commit 886b470cb14733a0286e365c77f1844c240c33a4

Authored by Marcelo Tosatti
1 parent 51c19b4f59

KVM: x86: pass host_tsc to read_l1_tsc

Allow the caller to pass host tsc value to kvm_x86_ops->read_l1_tsc().

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Showing 5 changed files with 9 additions and 9 deletions Side-by-side Diff

arch/x86/include/asm/kvm_host.h
... ... @@ -700,7 +700,7 @@
700 700 void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset);
701 701  
702 702 u64 (*compute_tsc_offset)(struct kvm_vcpu *vcpu, u64 target_tsc);
703   - u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu);
  703 + u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu, u64 host_tsc);
704 704  
705 705 void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2);
706 706  
arch/x86/kvm/lapic.c
... ... @@ -1011,7 +1011,7 @@
1011 1011 local_irq_save(flags);
1012 1012  
1013 1013 now = apic->lapic_timer.timer.base->get_time();
1014   - guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu);
  1014 + guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu, native_read_tsc());
1015 1015 if (likely(tscdeadline > guest_tsc)) {
1016 1016 ns = (tscdeadline - guest_tsc) * 1000000ULL;
1017 1017 do_div(ns, this_tsc_khz);
... ... @@ -3005,11 +3005,11 @@
3005 3005 return 0;
3006 3006 }
3007 3007  
3008   -u64 svm_read_l1_tsc(struct kvm_vcpu *vcpu)
  3008 +u64 svm_read_l1_tsc(struct kvm_vcpu *vcpu, u64 host_tsc)
3009 3009 {
3010 3010 struct vmcb *vmcb = get_host_vmcb(to_svm(vcpu));
3011 3011 return vmcb->control.tsc_offset +
3012   - svm_scale_tsc(vcpu, native_read_tsc());
  3012 + svm_scale_tsc(vcpu, host_tsc);
3013 3013 }
3014 3014  
3015 3015 static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
... ... @@ -1839,11 +1839,10 @@
1839 1839 * Like guest_read_tsc, but always returns L1's notion of the timestamp
1840 1840 * counter, even if a nested guest (L2) is currently running.
1841 1841 */
1842   -u64 vmx_read_l1_tsc(struct kvm_vcpu *vcpu)
  1842 +u64 vmx_read_l1_tsc(struct kvm_vcpu *vcpu, u64 host_tsc)
1843 1843 {
1844   - u64 host_tsc, tsc_offset;
  1844 + u64 tsc_offset;
1845 1845  
1846   - rdtscll(host_tsc);
1847 1846 tsc_offset = is_guest_mode(vcpu) ?
1848 1847 to_vmx(vcpu)->nested.vmcs01_tsc_offset :
1849 1848 vmcs_read64(TSC_OFFSET);
... ... @@ -1150,7 +1150,7 @@
1150 1150  
1151 1151 /* Keep irq disabled to prevent changes to the clock */
1152 1152 local_irq_save(flags);
1153   - tsc_timestamp = kvm_x86_ops->read_l1_tsc(v);
  1153 + tsc_timestamp = kvm_x86_ops->read_l1_tsc(v, native_read_tsc());
1154 1154 kernel_ns = get_kernel_ns();
1155 1155 this_tsc_khz = __get_cpu_var(cpu_tsc_khz);
1156 1156 if (unlikely(this_tsc_khz == 0)) {
... ... @@ -5338,7 +5338,8 @@
5338 5338 if (hw_breakpoint_active())
5339 5339 hw_breakpoint_restore();
5340 5340  
5341   - vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu);
  5341 + vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu,
  5342 + native_read_tsc());
5342 5343  
5343 5344 vcpu->mode = OUTSIDE_GUEST_MODE;
5344 5345 smp_wmb();