Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LBUQp-0000GJ-Hi for qemu-devel@nongnu.org; Sat, 13 Dec 2008 08:21:19 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LBUQo-0000EA-7N for qemu-devel@nongnu.org; Sat, 13 Dec 2008 08:21:18 -0500 Received: from [199.232.76.173] (port=47204 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LBUQo-0000Dp-0c for qemu-devel@nongnu.org; Sat, 13 Dec 2008 08:21:18 -0500 Received: from soufre.accelance.net ([213.162.48.15]:63744) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LBUQn-0006em-EH for qemu-devel@nongnu.org; Sat, 13 Dec 2008 08:21:17 -0500 Received: from [192.168.0.3] (potipota.net [88.168.176.51]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by soufre.accelance.net (Postfix) with ESMTP id 1C30E4503E for ; Sat, 13 Dec 2008 14:21:16 +0100 (CET) Subject: Re: [Qemu-devel] Re: [linux-user] Fixed Qemu crash using Gdbstub From: Lionel Landwerlin In-Reply-To: <4943B1B6.9010707@web.de> References: <1229125944.3898.39.camel@cocoduo.atr> <1229126410.3898.42.camel@cocoduo.atr> <49438B8B.8050709@web.de> <1229171501.3898.53.camel@cocoduo.atr> <4943B1B6.9010707@web.de> Content-Type: text/plain; charset=UTF-8 Date: Sat, 13 Dec 2008 14:21:13 +0100 Message-Id: <1229174473.3898.61.camel@cocoduo.atr> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Le samedi 13 d=C3=A9cembre 2008 =C3=A0 13:59 +0100, Jan Kiszka a =C3=A9cr= it : > Lionel Landwerlin wrote: > > Le samedi 13 d=C3=A9cembre 2008 =C3=A0 11:16 +0100, Jan Kiszka a =C3=A9= crit : > >> Lionel Landwerlin wrote: > >>> I just forgot to remove 2 printf ... > >>> Here the good patch : > >>> > >>> > >>> > >>> > >>> >From 2b3fe65ea3f2ee8dd3efbb52b66a2f4e53b788ea Mon Sep 17 00:00:00 = 2001 > >>> From: Lionel Landwerlin > >>> Date: Sat, 13 Dec 2008 00:32:04 +0100 > >>> Subject: [PATCH] [linux-user] Fixed Qemu crash using Gdbstub > >>> > >>> When using gdb with qemu (via gdbstub), if your emulated > >>> application is multithreaded and does a segfault then qemu > >>> crashes. > >>> > >>> Qemu crashes because the break/watch points are shared betwee= n > >>> cpus. The TAILQ structure which handles the list of break/wat= ch > >>> points is copied inside each CPUState structure. When the las= t > >>> breakpoint is removed (this happens on a segfault), it is > >>> removed across all cpus but because of the copied TAILQ > >>> structure a same breakpoint can be freed N times with N the > >>> current number of cpus. > >> OK, now I got the problem: user space emulation spawns additional VC= PUs > >> to emulate fork. Those VCPUs are cloned via cpu_copy which simply > >> duplicates the CPUState of the parent, including the breakpoint and > >> watchpoint TAILQ headers. This is doomed to fail. > >> > >> But your approach to let the cloned VCPU point to the same TAILQ hea= der > >> as its parent is not correct as well. It will cause troubles to gdbs= tub > >> which manages breakpoints on all VCPUs by adding duplicate instances= on > >> a per-VCPU base. If you inject a breakpoint before a fork and then > >> remove it afterwards, gdbstub will report an error because it will o= nly > >> find the breakpoint once, not n times (n =3D number of VCPUs). > >> > >> What you have to do is to cleanly duplicate the breakpoint and > >> watchpoint lists on cpu_copy (filter out BP_CPU types for cleanness > >> reasons, although they do not occur in user emulation ATM). > >=20 > > Hello Jan, > >=20 > > Thanks for reviewing my patch. > >=20 > > Duplication of all break/watchpoints will makes the patch bigger, > > because it will required break/watchpoint_copy functions etc... > >=20 > > Another problem is that threads are also emulated by vcpus in user > > emulation. But we also need to share break/watchpoints between thread= s. > > This explain the way my patch do the thing. > >=20 > > Finally, this makes the modification a lot more complicated than what= I > > expected, because breakpoints on emulated forks should not apply. >=20 > Sorry, but shouldn't we prefer correct solutions over simpler but broke= n > ones...? >=20 > Before my gdbstub changes, break/watchpoints were per-VCPU and > automatically duplicated on cpu_copy (as they were stored in a static > array inside CPUState). Now they are kept in lists, but still per-VCPU. > All that has to be done now is to fix cpu_copy to take this into > account. If that takes additional simple helpers to clone breakpoints, > so what? >=20 > Jan >=20 Ok, I will do that Regards, --=20 =EF=BB=BFLione Landwerlin =20 =EF=BB=BF O p e n W i d e 14, rue Gaillon 75002 Paris