From patchwork Fri Apr 17 05:15:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 18621 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 n3H5FT84004003 for ; Fri, 17 Apr 2009 05:15:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754244AbZDQFP1 (ORCPT ); Fri, 17 Apr 2009 01:15:27 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754241AbZDQFP1 (ORCPT ); Fri, 17 Apr 2009 01:15:27 -0400 Received: from mx2.redhat.com ([66.187.237.31]:35730 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751005AbZDQFP0 (ORCPT ); Fri, 17 Apr 2009 01:15:26 -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 n3H5FOXY017488; Fri, 17 Apr 2009 01:15:24 -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 n3H5FM00032009; Fri, 17 Apr 2009 01:15:23 -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 n3H5FMUb009931; Fri, 17 Apr 2009 01:15:22 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org Subject: [PATCH] return default values for apic probe functions. Date: Fri, 17 Apr 2009 01:15:21 -0400 Message-Id: <1239945321-3903-1-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 As KVM cpus runs on threads, it is possible that we call kvm_load_registers() from a cpu thread, while the apic has not yet fully initialized. kvm_load_registers() is called from ap_main_loop. This is not a problem when we're starting the whole machine together, but is a problem for hotplug, since we don't have the protection of the locks that protect machine initialization. Currently, some executions of cpu hotplug on rainy sundays fail with a segfault. Moving apic initialization to before kvm_init_vpcu proved fruitful, as there are some dependencies involved. (kvm irqchip would fail to initialize). This patch provides default values to be used for tpr and apic_base, that will be returned when the apic is not yet properly initialized. It is aimed at kvm, where the problem exists, but it could equally be used for qemu too, if there is agreement. Signed-off-by: Glauber Costa --- qemu/hw/apic.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/qemu/hw/apic.c b/qemu/hw/apic.c index b926508..06fb9b5 100644 --- a/qemu/hw/apic.c +++ b/qemu/hw/apic.c @@ -301,7 +301,12 @@ uint64_t cpu_get_apic_base(CPUState *env) #ifdef DEBUG_APIC printf("cpu_get_apic_base: %016" PRIx64 "\n", (uint64_t)s->apicbase); #endif - return s->apicbase; + if (s) { + return s->apicbase; + } + else { + return 0xfee00000 | MSR_IA32_APICBASE_ENABLE; + } } void cpu_set_apic_tpr(CPUX86State *env, uint8_t val) @@ -314,7 +319,10 @@ void cpu_set_apic_tpr(CPUX86State *env, uint8_t val) uint8_t cpu_get_apic_tpr(CPUX86State *env) { APICState *s = env->apic_state; - return s->tpr >> 4; + if (s) + return s->tpr >> 4; + else + return 0; } /* return -1 if no bit is set */