From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMpXg-0002PS-NG for qemu-devel@nongnu.org; Sat, 14 Feb 2015 22:06:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YMpXa-00009D-IS for qemu-devel@nongnu.org; Sat, 14 Feb 2015 22:06:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36435) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMpXa-000097-B2 for qemu-devel@nongnu.org; Sat, 14 Feb 2015 22:06:38 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1F36bYX031714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Sat, 14 Feb 2015 22:06:37 -0500 From: Fam Zheng Date: Sun, 15 Feb 2015 11:06:30 +0800 Message-Id: <1423969591-23646-2-git-send-email-famz@redhat.com> In-Reply-To: <1423969591-23646-1-git-send-email-famz@redhat.com> References: <1423969591-23646-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v3 1/2] block: Forbid bdrv_set_aio_context outside BQL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, Paolo Bonzini , stefanha@redhat.com Even if the caller has both the old and the new AioContext's, there can be a deadlock, due to the leading bdrv_drain_all. Suppose there are four io threads (A, B, A0, B0) with A and B owning a BDS for each (bs_a, bs_b); Now A wants to move bs_a to iothread A0, and B wants to move bs_b to B0, at the same time: iothread A iothread B -------------------------------------------------------------------------- aio_context_acquire(A0) /* OK */ aio_context_acquire(B0) /* OK */ bdrv_set_aio_context(bs_a, A0) bdrv_set_aio_context(bs_b, B0) -> bdrv_drain_all() -> bdrv_drain_all() -> acquire A /* OK */ -> acquire A /* blocked */ -> acquire B /* blocked */ -> acquire B ... ... Deadlock happens because A is waiting for B, and B is waiting for A. Signed-off-by: Fam Zheng Reviewed-by: Paolo Bonzini --- include/block/block.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 321295e..4fce25d 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -546,8 +546,7 @@ AioContext *bdrv_get_aio_context(BlockDriverState *bs); * Changes the #AioContext used for fd handlers, timers, and BHs by this * BlockDriverState and all its children. * - * This function must be called from the old #AioContext or with a lock held so - * the old #AioContext is not executing. + * This function must be called with iothread lock held. */ void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context); -- 2.1.0