Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 505

kvm-83-270.el5_11.src.rpm

From 95734f1ba74ad23b30255e7e75d2d6036e91b03b 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: <4CEC66FD.3080908@redhat.com>
Patchwork-id: 13872
O-Subject: [PATCH RHEL 5.6 1/1] KVM: fix AMD initial TSC offset problems
Bugzilla: 642659
RH-Acked-by: Glauber Costa <glommer@redhat.com>
RH-Acked-by: Avi Kivity <avi@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