From patchwork Wed Oct 7 18:49:47 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 35356 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 92BB3B7B83 for ; Thu, 8 Oct 2009 05:52:12 +1100 (EST) Received: from localhost ([127.0.0.1]:34677 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvbcO-00045z-Bs for incoming@patchwork.ozlabs.org; Wed, 07 Oct 2009 14:52:08 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvbaJ-0003F2-DP for qemu-devel@nongnu.org; Wed, 07 Oct 2009 14:49:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvbaE-00039v-Fb for qemu-devel@nongnu.org; Wed, 07 Oct 2009 14:49:58 -0400 Received: from [199.232.76.173] (port=42267 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvbaE-00039n-B0 for qemu-devel@nongnu.org; Wed, 07 Oct 2009 14:49:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20638) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvbaD-0000uj-Qq for qemu-devel@nongnu.org; Wed, 07 Oct 2009 14:49:54 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n97InrWI019861; Wed, 7 Oct 2009 14:49:53 -0400 Received: from localhost.localdomain (vpn-13-129.rdu.redhat.com [10.11.13.129]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n97Innnm015624; Wed, 7 Oct 2009 14:49:51 -0400 From: Glauber Costa To: qemu-devel@nongnu.org Date: Wed, 7 Oct 2009 15:49:47 -0300 Message-Id: <1254941388-12556-2-git-send-email-glommer@redhat.com> In-Reply-To: <1254941388-12556-1-git-send-email-glommer@redhat.com> References: <1254941388-12556-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Glauber Costa , aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Glauber Costa Without this, kvm will hold the mutex while it issues its run ioctl, and never be able to step out of it, causing a deadlock. Signed-off-by: Glauber Costa --- kvm-all.c | 2 ++ qemu-common.h | 3 +++ vl.c | 8 ++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 7dcc553..11f4414 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -605,7 +605,9 @@ int kvm_cpu_exec(CPUState *env) } kvm_arch_pre_run(env, run); + qemu_mutex_unlock_iothread(); ret = kvm_vcpu_ioctl(env, KVM_RUN, 0); + qemu_mutex_lock_iothread(); kvm_arch_post_run(env, run); if (ret == -EINTR || ret == -EAGAIN) { diff --git a/qemu-common.h b/qemu-common.h index 12e7dd0..820dd37 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -146,6 +146,9 @@ char *qemu_strndup(const char *str, size_t size); void *get_mmap_addr(unsigned long size); +void qemu_mutex_lock_iothread(void); +void qemu_mutex_unlock_iothread(void); + /* Error handling. */ void QEMU_NORETURN hw_error(const char *fmt, ...) diff --git a/vl.c b/vl.c index eb01da7..3012141 100644 --- a/vl.c +++ b/vl.c @@ -3445,8 +3445,8 @@ void qemu_notify_event(void) } } -#define qemu_mutex_lock_iothread() do { } while (0) -#define qemu_mutex_unlock_iothread() do { } while (0) +void qemu_mutex_lock_iothread(void) {} +void qemu_mutex_unlock_iothread(void) {} void vm_stop(int reason) { @@ -3640,7 +3640,7 @@ static void qemu_signal_lock(unsigned int msecs) qemu_mutex_unlock(&qemu_fair_mutex); } -static void qemu_mutex_lock_iothread(void) +void qemu_mutex_lock_iothread(void) { if (kvm_enabled()) { qemu_mutex_lock(&qemu_fair_mutex); @@ -3650,7 +3650,7 @@ static void qemu_mutex_lock_iothread(void) qemu_signal_lock(100); } -static void qemu_mutex_unlock_iothread(void) +void qemu_mutex_unlock_iothread(void) { qemu_mutex_unlock(&qemu_global_mutex); }