From: Gleb Natapov Subject: [PATCH 1/2] Complete cpu initialization before signaling main thread. Date: Tue, 13 Oct 2009 14:17:19 +0200 Message-ID: <1255436240-994-1-git-send-email-gleb@redhat.com> Cc: kvm@vger.kernel.org To: mtosatti@redhat.com Return-path: Received: from mx1.redhat.com ([209.132.183.28]:26299 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754679AbZJMMRr (ORCPT ); Tue, 13 Oct 2009 08:17:47 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9DCHM7J008224 for ; Tue, 13 Oct 2009 08:17:22 -0400 Sender: kvm-owner@vger.kernel.org List-ID: Otherwise some cpus may start executing code before others are fully initialized. Signed-off-by: Gleb Natapov --- qemu-kvm.c | 26 ++++++++++++-------------- 1 files changed, 12 insertions(+), 14 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index 62ca050..3765818 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -1954,18 +1954,6 @@ static void process_irqchip_events(CPUState *env) static int kvm_main_loop_cpu(CPUState *env) { - setup_kernel_sigmask(env); - - pthread_mutex_lock(&qemu_mutex); - - kvm_arch_init_vcpu(env); -#ifdef TARGET_I386 - kvm_tpr_vcpu_start(env); -#endif - - cpu_single_env = env; - kvm_arch_load_regs(env); - while (1) { int run_cpu = !is_cpu_stopped(env); if (run_cpu && !kvm_irqchip_in_kernel(kvm_context)) { @@ -2003,15 +1991,25 @@ static void *ap_main_loop(void *_env) on_vcpu(env, kvm_arch_do_ioperm, data); #endif - /* signal VCPU creation */ + setup_kernel_sigmask(env); + pthread_mutex_lock(&qemu_mutex); + cpu_single_env = env; + + kvm_arch_init_vcpu(env); +#ifdef TARGET_I386 + kvm_tpr_vcpu_start(env); +#endif + + kvm_arch_load_regs(env); + + /* signal VCPU creation */ current_env->created = 1; pthread_cond_signal(&qemu_vcpu_cond); /* and wait for machine initialization */ while (!qemu_system_ready) qemu_cond_wait(&qemu_system_cond); - pthread_mutex_unlock(&qemu_mutex); kvm_main_loop_cpu(env); return NULL; -- 1.6.3.3