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>
This commit is contained in:
parent
51c19b4f59
commit
886b470cb1
|
@ -700,7 +700,7 @@ struct kvm_x86_ops {
|
||||||
void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset);
|
void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset);
|
||||||
|
|
||||||
u64 (*compute_tsc_offset)(struct kvm_vcpu *vcpu, u64 target_tsc);
|
u64 (*compute_tsc_offset)(struct kvm_vcpu *vcpu, u64 target_tsc);
|
||||||
u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu);
|
u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu, u64 host_tsc);
|
||||||
|
|
||||||
void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2);
|
void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2);
|
||||||
|
|
||||||
|
|
|
@ -1011,7 +1011,7 @@ static void start_apic_timer(struct kvm_lapic *apic)
|
||||||
local_irq_save(flags);
|
local_irq_save(flags);
|
||||||
|
|
||||||
now = apic->lapic_timer.timer.base->get_time();
|
now = apic->lapic_timer.timer.base->get_time();
|
||||||
guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu);
|
guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu, native_read_tsc());
|
||||||
if (likely(tscdeadline > guest_tsc)) {
|
if (likely(tscdeadline > guest_tsc)) {
|
||||||
ns = (tscdeadline - guest_tsc) * 1000000ULL;
|
ns = (tscdeadline - guest_tsc) * 1000000ULL;
|
||||||
do_div(ns, this_tsc_khz);
|
do_div(ns, this_tsc_khz);
|
||||||
|
|
|
@ -3005,11 +3005,11 @@ static int cr8_write_interception(struct vcpu_svm *svm)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 svm_read_l1_tsc(struct kvm_vcpu *vcpu)
|
u64 svm_read_l1_tsc(struct kvm_vcpu *vcpu, u64 host_tsc)
|
||||||
{
|
{
|
||||||
struct vmcb *vmcb = get_host_vmcb(to_svm(vcpu));
|
struct vmcb *vmcb = get_host_vmcb(to_svm(vcpu));
|
||||||
return vmcb->control.tsc_offset +
|
return vmcb->control.tsc_offset +
|
||||||
svm_scale_tsc(vcpu, native_read_tsc());
|
svm_scale_tsc(vcpu, host_tsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
|
static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
|
||||||
|
|
|
@ -1839,11 +1839,10 @@ static u64 guest_read_tsc(void)
|
||||||
* Like guest_read_tsc, but always returns L1's notion of the timestamp
|
* Like guest_read_tsc, but always returns L1's notion of the timestamp
|
||||||
* counter, even if a nested guest (L2) is currently running.
|
* counter, even if a nested guest (L2) is currently running.
|
||||||
*/
|
*/
|
||||||
u64 vmx_read_l1_tsc(struct kvm_vcpu *vcpu)
|
u64 vmx_read_l1_tsc(struct kvm_vcpu *vcpu, u64 host_tsc)
|
||||||
{
|
{
|
||||||
u64 host_tsc, tsc_offset;
|
u64 tsc_offset;
|
||||||
|
|
||||||
rdtscll(host_tsc);
|
|
||||||
tsc_offset = is_guest_mode(vcpu) ?
|
tsc_offset = is_guest_mode(vcpu) ?
|
||||||
to_vmx(vcpu)->nested.vmcs01_tsc_offset :
|
to_vmx(vcpu)->nested.vmcs01_tsc_offset :
|
||||||
vmcs_read64(TSC_OFFSET);
|
vmcs_read64(TSC_OFFSET);
|
||||||
|
|
|
@ -1150,7 +1150,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
|
||||||
|
|
||||||
/* Keep irq disabled to prevent changes to the clock */
|
/* Keep irq disabled to prevent changes to the clock */
|
||||||
local_irq_save(flags);
|
local_irq_save(flags);
|
||||||
tsc_timestamp = kvm_x86_ops->read_l1_tsc(v);
|
tsc_timestamp = kvm_x86_ops->read_l1_tsc(v, native_read_tsc());
|
||||||
kernel_ns = get_kernel_ns();
|
kernel_ns = get_kernel_ns();
|
||||||
this_tsc_khz = __get_cpu_var(cpu_tsc_khz);
|
this_tsc_khz = __get_cpu_var(cpu_tsc_khz);
|
||||||
if (unlikely(this_tsc_khz == 0)) {
|
if (unlikely(this_tsc_khz == 0)) {
|
||||||
|
@ -5338,7 +5338,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
|
||||||
if (hw_breakpoint_active())
|
if (hw_breakpoint_active())
|
||||||
hw_breakpoint_restore();
|
hw_breakpoint_restore();
|
||||||
|
|
||||||
vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu);
|
vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu,
|
||||||
|
native_read_tsc());
|
||||||
|
|
||||||
vcpu->mode = OUTSIDE_GUEST_MODE;
|
vcpu->mode = OUTSIDE_GUEST_MODE;
|
||||||
smp_wmb();
|
smp_wmb();
|
||||||
|
|
Loading…
Reference in New Issue