From patchwork Tue May 26 21:33:01 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 26106 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4QLXr2d027508 for ; Tue, 26 May 2009 21:33:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756805AbZEZVdK (ORCPT ); Tue, 26 May 2009 17:33:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756563AbZEZVdI (ORCPT ); Tue, 26 May 2009 17:33:08 -0400 Received: from mx2.redhat.com ([66.187.237.31]:49579 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754598AbZEZVdC (ORCPT ); Tue, 26 May 2009 17:33:02 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4QLX4lt005913 for ; Tue, 26 May 2009 17:33:04 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n4QLX3Nk019386; Tue, 26 May 2009 17:33:03 -0400 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n4QLX1QM013830; Tue, 26 May 2009 17:33:02 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH 4/4] make sure kvm_vpu_init is the last thing called in cpu initialization Date: Tue, 26 May 2009 17:33:01 -0400 Message-Id: <1243373581-18085-5-git-send-email-glommer@redhat.com> In-Reply-To: <1243373581-18085-4-git-send-email-glommer@redhat.com> References: <1243373581-18085-1-git-send-email-glommer@redhat.com> <1243373581-18085-2-git-send-email-glommer@redhat.com> <1243373581-18085-3-git-send-email-glommer@redhat.com> <1243373581-18085-4-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org KVM access some state that is only present late in cpu initialization. This happens in kvm_vcpu_init(). APIC is an example of that. So we have to make sure that kvm_vcpu_init is the last thing called in the initialization process. We also have to explicitly call qemu_kvm_load_apic(), since the first call will find the vcpu non initialized. Signed-off-by: Glauber Costa --- hw/pc.c | 5 +++++ qemu-kvm-x86.c | 2 ++ target-i386/helper.c | 2 -- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index 9e99b7c..45de6d9 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -844,6 +844,11 @@ CPUState *pc_new_cpu(int cpu, const char *cpu_model, int pci_enabled) if (pci_enabled) { apic_init(env); } + + /* kvm needs this to run after the apic is initialized. Otherwise, + * it can access invalid state and crash. + */ + qemu_init_vcpu(env); return env; } diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index fcb594c..98aa530 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -527,6 +527,8 @@ int kvm_arch_qemu_init_env(CPUState *cenv) CPUState copy; uint32_t i, j, limit; + qemu_kvm_load_lapic(cenv); + copy = *cenv; #ifdef KVM_CPUID_SIGNATURE diff --git a/target-i386/helper.c b/target-i386/helper.c index 848d05b..6dc0111 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -1699,7 +1699,5 @@ CPUX86State *cpu_x86_init(const char *cpu_model) kqemu_init(env); #endif - qemu_init_vcpu(env); - return env; }