aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-06-13 19:55:28 +0300
committerAvi Kivity <avi@qumranet.com>2007-07-16 12:05:47 +0300
commit7700270ee3c1324c18f5b7c36ee5ba1a4165919a (patch)
treeb5b1f47ca6ab565bcfb7974ea614da6ddebce0a4 /drivers/kvm
parent94cea1bb9d050c3200b36420cc03ba744dfd4338 (diff)
downloadkernel_samsung_smdk4412-7700270ee3c1324c18f5b7c36ee5ba1a4165919a.zip
kernel_samsung_smdk4412-7700270ee3c1324c18f5b7c36ee5ba1a4165919a.tar.gz
kernel_samsung_smdk4412-7700270ee3c1324c18f5b7c36ee5ba1a4165919a.tar.bz2
KVM: VMX: Ensure vcpu time stamp counter is monotonous
If the time stamp counter goes backwards, a guest delay loop can become infinite. This can happen if a vcpu is migrated to another cpu, where the counter has a lower value than the first cpu. Since we're doing an IPI to the first cpu anyway, we can use that to pick up the old tsc, and use that to calculate the adjustment we need to make to the tsc offset. Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm')
-rw-r--r--drivers/kvm/vmx.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 0b2aace..d06c362 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -160,6 +160,7 @@ static void __vcpu_clear(void *arg)
vmcs_clear(vcpu->vmcs);
if (per_cpu(current_vmcs, cpu) == vcpu->vmcs)
per_cpu(current_vmcs, cpu) = NULL;
+ rdtscll(vcpu->host_tsc);
}
static void vcpu_clear(struct kvm_vcpu *vcpu)
@@ -376,6 +377,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu)
{
u64 phys_addr = __pa(vcpu->vmcs);
int cpu;
+ u64 tsc_this, delta;
cpu = get_cpu();
@@ -409,6 +411,13 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu)
rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
+
+ /*
+ * Make sure the time stamp counter is monotonous.
+ */
+ rdtscll(tsc_this);
+ delta = vcpu->host_tsc - tsc_this;
+ vmcs_write64(TSC_OFFSET, vmcs_read64(TSC_OFFSET) + delta);
}
}