Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LfLpa-0008IW-J9 for qemu-devel@nongnu.org; Thu, 05 Mar 2009 17:14:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LfLpZ-0008I9-Sn for qemu-devel@nongnu.org; Thu, 05 Mar 2009 17:14:18 -0500 Received: from [199.232.76.173] (port=57503 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfLpZ-0008I0-Nq for qemu-devel@nongnu.org; Thu, 05 Mar 2009 17:14:17 -0500 Received: from hall.aurel32.net ([88.191.82.174]:56752) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LfLpZ-0000qs-2f for qemu-devel@nongnu.org; Thu, 05 Mar 2009 17:14:17 -0500 Received: from aurel32 by hall.aurel32.net with local (Exim 4.69) (envelope-from ) id 1LfLpU-0008MT-II for qemu-devel@nongnu.org; Thu, 05 Mar 2009 23:14:12 +0100 Date: Thu, 5 Mar 2009 23:14:12 +0100 From: Aurelien Jarno Message-ID: <20090305221412.GI17410@hall.aurel32.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Sender: Aurelien Jarno Subject: [Qemu-devel] Race condition between signal handler and cpu_exec() 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 Hi, I have just found the root of a long standing but rare problem, the freeze of QEMU for a few seconds when using -clock dynticks. Laurent Vivier, while working on the DMA support in MACIO remarked that running 'dbench 1' in the PPC target almost always trigger the bug after some time. This helped finding the problem. The problem is caused by a race condition between the signal handler and cpu_exec(): - host_alarm_handler() calls cpu_interrupt(env, CPU_INTERRUPT_EXIT); - cpu_interrupt(CPUState *env, int mask) does env->interrupt_request |= mask; - it can happen while cpu_exec() does: | if (env->interrupt_request & CPU_INTERRUPT_EXITTB) { | env->interrupt_request &= ~CPU_INTERRUPT_EXITTB; - the corresponding x86_64 assembly code is: | movl 624(%r14), %eax | testb $4, %al | je .L26 | andl $-5, %eax | movl %eax, 624(%r14) That is a non atomic operation. This cause an endless loop in cpu_exec(). I guess it can happens at other place modifying env->interrupt_request, but this seems to occurs that as this code is executed very often. This does not happens with clocks other than dynticks, as they trigger SIGALRM again and again which at the end sets the correct value. I am currently too tired to find a proper solution (which should only use read/write to a variable to keep the operations atomic), I'll look at that tomorrow, but patches are welcome in the meanwhile. -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurelien@aurel32.net http://www.aurel32.net