From patchwork Tue May 26 21:32:59 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 26104 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 n4QLXr2b027508 for ; Tue, 26 May 2009 21:33:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756245AbZEZVdG (ORCPT ); Tue, 26 May 2009 17:33:06 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756563AbZEZVdF (ORCPT ); Tue, 26 May 2009 17:33:05 -0400 Received: from mx2.redhat.com ([66.187.237.31]:49577 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755563AbZEZVdB (ORCPT ); Tue, 26 May 2009 17:33:01 -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 n4QLX30Q005905 for ; Tue, 26 May 2009 17:33:03 -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 n4QLX2eo019378; Tue, 26 May 2009 17:33:02 -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 n4QLX1QK013830; Tue, 26 May 2009 17:33:02 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH 2/4] only execute lapic load when cpu is already initialized Date: Tue, 26 May 2009 17:32:59 -0400 Message-Id: <1243373581-18085-3-git-send-email-glommer@redhat.com> In-Reply-To: <1243373581-18085-2-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> 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 In a later patch, we will reorder the execution of vcpu initialization. After that, the first call to KVM_SET_LAPIC ioctl will not find an existant vcpu. So we introduce a function that tell us that the vcpu is already initialized, and is it safe to call the ioctl. This patch is included first rather than after, so nothing breaks, and we can keep the tree bisectable. Signed-off-by: Glauber Costa --- hw/apic.c | 21 +++++++++++---------- qemu-kvm.c | 5 +++++ qemu-kvm.h | 4 ++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/hw/apic.c b/hw/apic.c index 21aff15..86aa6b6 100644 --- a/hw/apic.c +++ b/hw/apic.c @@ -891,6 +891,15 @@ static void kvm_kernel_lapic_load_from_user(APICState *s) #endif +void qemu_kvm_load_lapic(CPUState *env) +{ +#ifdef KVM_CAP_IRQCHIP + if (kvm_enabled() && kvm_vcpu_inited(env) && qemu_kvm_irqchip_in_kernel()) { + kvm_kernel_lapic_load_from_user(env->apic_state); + } +#endif +} + static void apic_save(QEMUFile *f, void *opaque) { APICState *s = opaque; @@ -965,11 +974,7 @@ static int apic_load(QEMUFile *f, void *opaque, int version_id) if (version_id >= 2) qemu_get_timer(f, s->timer); -#ifdef KVM_CAP_IRQCHIP - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { - kvm_kernel_lapic_load_from_user(s); - } -#endif + qemu_kvm_load_lapic(s->cpu_env); return 0; } @@ -991,11 +996,7 @@ static void apic_reset(void *opaque) */ s->lvt[APIC_LVT_LINT0] = 0x700; } -#ifdef KVM_CAP_IRQCHIP - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { - kvm_kernel_lapic_load_from_user(s); - } -#endif + qemu_kvm_load_lapic(s->cpu_env); } static CPUReadMemoryFunc *apic_mem_read[3] = { diff --git a/qemu-kvm.c b/qemu-kvm.c index d16917f..68d3b92 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -462,6 +462,11 @@ void kvm_init_vcpu(CPUState *env) qemu_cond_wait(&qemu_vcpu_cond); } +int kvm_vcpu_inited(CPUState *env) +{ + return env->kvm_cpu_state.created; +} + int kvm_init_ap(void) { #ifdef TARGET_I386 diff --git a/qemu-kvm.h b/qemu-kvm.h index e74ab90..725589b 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -16,6 +16,7 @@ int kvm_main_loop(void); int kvm_qemu_init(void); int kvm_qemu_create_context(void); int kvm_init_ap(void); +int kvm_vcpu_inited(CPUState *env); void kvm_qemu_destroy(void); void kvm_load_registers(CPUState *env); void kvm_save_registers(CPUState *env); @@ -31,6 +32,9 @@ int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap); int kvm_qemu_init_env(CPUState *env); int kvm_qemu_check_extension(int ext); void kvm_apic_init(CPUState *env); +/* called from vcpu initialization */ +void qemu_kvm_load_lapic(CPUState *env); + int kvm_set_irq(int irq, int level, int *status); int kvm_physical_memory_set_dirty_tracking(int enable);