From patchwork Wed Oct 14 13:52:31 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 53678 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 n9EE1Y9D017480 for ; Wed, 14 Oct 2009 14:01:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761784AbZJNNxA (ORCPT ); Wed, 14 Oct 2009 09:53:00 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1761779AbZJNNxA (ORCPT ); Wed, 14 Oct 2009 09:53:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9475 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761777AbZJNNw7 (ORCPT ); Wed, 14 Oct 2009 09:52:59 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9EDqXpu004844 for ; Wed, 14 Oct 2009 09:52:33 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9EDqWKr030266; Wed, 14 Oct 2009 09:52:33 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 0EB7B18D410; Wed, 14 Oct 2009 15:52:32 +0200 (IST) From: Gleb Natapov To: mtosatti@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCHv2 1/2] Complete cpu initialization before signaling main thread. Date: Wed, 14 Oct 2009 15:52:31 +0200 Message-Id: <1255528352-21171-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/qemu-kvm.c b/qemu-kvm.c index 62ca050..a104ab8 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,28 @@ 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); + + /* re-initialize cpu_single_env after re-acquiring qemu_mutex */ + cpu_single_env = env; kvm_main_loop_cpu(env); return NULL;