From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Luob4-0008I4-0E for qemu-devel@nongnu.org; Fri, 17 Apr 2009 09:59:14 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Luob3-0008Hs-HQ for qemu-devel@nongnu.org; Fri, 17 Apr 2009 09:59:13 -0400 Received: from [199.232.76.173] (port=41057 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Luob3-0008Hp-BK for qemu-devel@nongnu.org; Fri, 17 Apr 2009 09:59:13 -0400 Received: from qw-out-1920.google.com ([74.125.92.145]:18339) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Luob2-0004xF-Sz for qemu-devel@nongnu.org; Fri, 17 Apr 2009 09:59:13 -0400 Received: by qw-out-1920.google.com with SMTP id 5so710119qwf.4 for ; Fri, 17 Apr 2009 06:59:12 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20090417135359.GA23731@amt.cnet> References: <1239945321-3903-1-git-send-email-glommer@redhat.com> <20090417135359.GA23731@amt.cnet> Date: Fri, 17 Apr 2009 10:59:11 -0300 Message-ID: <5d6222a80904170659o208ddd47ldf0668b568ec2e70@mail.gmail.com> From: Glauber Costa Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [PATCH] return default values for apic probe functions. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcelo Tosatti Cc: qemu-devel@nongnu.org, Glauber Costa , avi@redhat.com, kvm@vger.kernel.org, aliguori@us.ibm.com On Fri, Apr 17, 2009 at 10:53 AM, Marcelo Tosatti wro= te: > Hi Glauber, > > On Fri, Apr 17, 2009 at 01:15:21AM -0400, Glauber Costa wrote: >> 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 execut= ions >> of cpu hotplug on rainy sundays fail with a segfault. > > =C2=A0 =C2=A0/* and wait for machine initialization */ > =C2=A0 =C2=A0while (!qemu_system_ready) > =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_cond_wait(&qemu_system_cond); > =C2=A0 =C2=A0pthread_mutex_unlock(&qemu_mutex); > > Shouldnt this cover the cpu hotplug case too? Perhaps have: > > =C2=A0 =C2=A0/* wait for machine initialization */ > =C2=A0 =C2=A0while (!qemu_system_ready) > =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_cond_wait(&qemu_system_cond); > =C2=A0 =C2=A0/* wait for vcpu initialization */ > =C2=A0 =C2=A0while (!env->initialized) > =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_cond_wait(&qemu_system_cond); > =C2=A0 =C2=A0pthread_mutex_unlock(&qemu_mutex); > > And then set env->initialized when the cpu is good to go. >>From my understanding, all this is only useful when the whole machine is starting, since they are global locks that wait for a system wide condit= ion. This is not the case with cpu hotplug, since the box is already on. > > Because there could be other dependencies other than APIC > initialization, for eg in pc_new_cpu > > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (cpu !=3D 0) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0env->halted =3D 1; it is okay for the cpu to be halted. Btw, I believe this should be moved inside cpu init.