From 82e3d9414d671c75334a630b976806f5a1ddae5f Mon Sep 17 00:00:00 2001 From: Zachary Amsden <zamsden@redhat.com> Date: Wed, 24 Nov 2010 01:14:37 -0200 Subject: [PATCH] KVM: fix AMD initial TSC offset problems RH-Author: Zachary Amsden <zamsden@redhat.com> Message-id: <patch-13872-clone-for-rhel55-rhel55> Patchwork-id: 13946 O-Subject: [PATCH RHEL 5.6 1/1] KVM: fix AMD initial TSC offset problems Bugzilla: 656984 RH-Acked-by: Avi Kivity <avi@redhat.com> RH-Acked-by: Glauber Costa <glommer@redhat.com> RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com> I combined the two patches and tested a kmod build on a 5.5 machine. Please ack. Fixes BZ 642659. Zach commit c5915d734121b506fe599e91bfb1ea184afeef1d Author: Zachary Amsden <zamsden@redhat.com> Date: Thu Nov 18 16:00:16 2010 -1000 KVM: x86: Fix SVM VMCB reset Backport of upstream commit 58877679fd393d3ef71aa383031ac7817561463d Backport of upstream commit 47008cd887c1836bcadda123ba73e1863de7a6c4 Resolves: 642659 The VMCB is reset whenever we receive a startup IPI, so Linux is setting TSC back to zero happens very late in the boot process and destabilizing the TSC. Instead, just set TSC to zero once at VCPU creation time. Also, on reset, VMCB TSC should be set to zero. Instead, code was setting tsc_offset to zero, which passes through the underlying TSC. Signed-off-by: Zachary Amsden <zamsden@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- arch/x86/kvm/svm.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 529940a..67d01fc 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -551,7 +551,6 @@ static void init_vmcb(struct vcpu_svm *svm) control->iopm_base_pa = iopm_base; control->msrpm_base_pa = __pa(svm->msrpm); - control->tsc_offset = 0; control->int_ctl = V_INTR_MASKING_MASK; init_seg(&save->es); @@ -668,6 +667,11 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id) svm->asid_generation = 0; memset(svm->db_regs, 0, sizeof(svm->db_regs)); init_vmcb(svm); + { + u64 tsc; + rdtscll(tsc); + svm->vmcb->control.tsc_offset = 0-tsc; + } fx_init(&svm->vcpu); svm->vcpu.fpu_active = 1; -- 1.7.3.2