KVM: SVM: Fix tsc offset adjustment when running nested
authorJoerg Roedel <joerg.roedel@amd.com>
Wed, 16 Sep 2009 13:24:17 +0000 (15:24 +0200)
committerAvi Kivity <avi@redhat.com>
Sun, 4 Oct 2009 11:57:22 +0000 (13:57 +0200)
When svm_vcpu_load is called while the vcpu is running in
guest mode the tsc adjustment made there is lost on the next
emulated #vmexit. This causes the tsc running backwards in
the guest. This patch fixes the issue by also adjusting the
tsc_offset in the emulated hsave area so that it will not
get lost.

Cc: stable@kernel.org
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/kvm/svm.c

index 944cc9c04b3cea96be481838bf2fd890ed1edc5a..bf5799dc4f9ff9aa9bb32584142a50a7a911e02d 100644 (file)
@@ -767,6 +767,8 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
                rdtscll(tsc_this);
                delta = vcpu->arch.host_tsc - tsc_this;
                svm->vmcb->control.tsc_offset += delta;
+               if (is_nested(svm))
+                       svm->nested.hsave->control.tsc_offset += delta;
                vcpu->cpu = cpu;
                kvm_migrate_timers(vcpu);
                svm->asid_generation = 0;