From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRQEe-000780-Js for qemu-devel@nongnu.org; Fri, 27 Feb 2015 14:06:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YRQEd-0005Ql-32 for qemu-devel@nongnu.org; Fri, 27 Feb 2015 14:06:04 -0500 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]:41370) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRQEc-0005QA-Gh for qemu-devel@nongnu.org; Fri, 27 Feb 2015 14:06:02 -0500 Received: by wghl18 with SMTP id l18so22217358wgh.8 for ; Fri, 27 Feb 2015 11:06:02 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 27 Feb 2015 20:05:51 +0100 Message-Id: <1425063951-16967-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1425063951-16967-1-git-send-email-pbonzini@redhat.com> References: <1425063951-16967-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] cpus: be more paranoid in avoiding deadlocks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: leon.alrae@imgtec.com, gson@gson.org For good measure, ensure that the following sequence: thread 1 calls qemu_mutex_lock_iothread thread 2 calls qemu_mutex_lock_iothread VCPU thread are created VCPU thread enters execution loop results in the VCPU threads letting the other two threads run and obeying iothread_requesting_mutex even if the VCPUs are not halted. To do this, check iothread_requesting_mutex before execution starts. I could not reproduce this problem; it was only found by inspection. Signed-off-by: Paolo Bonzini --- cpus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cpus.c b/cpus.c index 83c078e..0fac143 100644 --- a/cpus.c +++ b/cpus.c @@ -1025,6 +1025,9 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } } + /* process any pending work */ + exit_request = 1; + while (1) { tcg_exec_all(); @@ -1115,10 +1118,11 @@ bool qemu_in_vcpu_thread(void) void qemu_mutex_lock_iothread(void) { + atomic_inc(&iothread_requesting_mutex); if (!tcg_enabled() || !first_cpu) { qemu_mutex_lock(&qemu_global_mutex); + atomic_dec(&iothread_requesting_mutex); } else { - atomic_inc(&iothread_requesting_mutex); if (qemu_mutex_trylock(&qemu_global_mutex)) { qemu_cpu_kick_thread(first_cpu); qemu_mutex_lock(&qemu_global_mutex); -- 2.3.0