Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 3160499aacb81f6735941eb4c372d87a > files > 385

kvm-83-164.el5_5.30.src.rpm

From 1ee4c25f53c188c1b084bf25dde71cb059ee18dc Mon Sep 17 00:00:00 2001
From: Eduardo Habkost <ehabkost@redhat.com>
Date: Tue, 27 Oct 2009 13:09:30 -0200
Subject: [PATCH] KVM: SVM: Reset cr0 properly on vcpu reset

RH-Author: Eduardo Habkost <ehabkost@redhat.com>
Message-id: <20091026150654.GK17006@blackpad.lan.raisama.net>
Patchwork-id: 3628
O-Subject: [RHEL-5.5 KVM PATCH] KVM: SVM: Reset cr0 properly on vcpu reset
Bugzilla: 525699
RH-Acked-by: Avi Kivity <avi@redhat.com>
RH-Acked-by: Gleb Natapov <gleb@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=525699

This fixes CPU onlining/offlining by guests. Without this fix, the guest
CPU-reset bootstrap routine fails and hangs the guest (sometimes crashing it),
on AMD hosts without NPT support.

RH-Upstream-status: applied, commit 9e69c02e3fe0f246c509b9c951e53e26f29905fb

commit 9e69c02e3fe0f246c509b9c951e53e26f29905fb
Author: Eduardo Habkost <ehabkost@redhat.com>
Date:   Sat Oct 24 02:49:59 2009 -0200

    KVM: SVM: Reset cr0 properly on vcpu reset

    svm_vcpu_reset() was not properly resetting the contents of the guest-visible
    cr0 register, causing the following issue:
    https://bugzilla.redhat.com/show_bug.cgi?id=525699

    Without resetting cr0 properly, the vcpu was running the SIPI bootstrap routine
    with paging enabled, making the vcpu get a pagefault exception while trying to
    run it.

    Instead of setting vmcb->save.cr0 directly, the new code just resets
    kvm->arch.cr0 and calls kvm_set_cr0(). The bits that were set/cleared on
    vmcb->save.cr0 (PG, WP, !CD, !NW) will be set properly by svm_set_cr0().

    kvm_set_cr0() is used instead of calling svm_set_cr0() directly to make sure
    kvm_mmu_reset_context() is called to reset the mmu to nonpaging mode.

    Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
    Signed-off-by: Avi Kivity <avi@redhat.com>

---
 arch/x86/kvm/svm.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 arch/x86/kvm/svm.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 1b2c744..1cda0b1 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -586,11 +586,12 @@ static void init_vmcb(struct vcpu_svm *svm)
 	save->rip = 0x0000fff0;
 	svm->vcpu.arch.regs[VCPU_REGS_RIP] = save->rip;
 
-	/*
-	 * cr0 val on cpu init should be 0x60000010, we enable cpu
-	 * cache by default. the orderly way is to enable cache in bios.
+	/* This is the guest-visible cr0 value.
+	 * svm_set_cr0() sets PG and WP and clears NW and CD on save->cr0.
 	 */
-	save->cr0 = 0x00000010 | X86_CR0_PG | X86_CR0_WP;
+	svm->vcpu.arch.cr0 = X86_CR0_NW | X86_CR0_CD | X86_CR0_ET;
+	kvm_set_cr0(&svm->vcpu, svm->vcpu.arch.cr0);
+
 	save->cr4 = X86_CR4_PAE;
 	/* rdx = ?? */
 
-- 
1.6.3.rc4.29.g8146