From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVjCi-0008TZ-UP for qemu-devel@nongnu.org; Wed, 30 Nov 2011 07:24:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RVjCg-0007T6-D7 for qemu-devel@nongnu.org; Wed, 30 Nov 2011 07:24:00 -0500 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:45532) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVjCg-0007RG-2Q for qemu-devel@nongnu.org; Wed, 30 Nov 2011 07:23:58 -0500 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 30 Nov 2011 12:23:54 -0000 Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pAUCNpwd2662434 for ; Wed, 30 Nov 2011 12:23:51 GMT Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pAUCNoP9027310 for ; Wed, 30 Nov 2011 05:23:51 -0700 From: Stefan Hajnoczi Date: Wed, 30 Nov 2011 12:23:42 +0000 Message-Id: <1322655824-31778-3-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1322655824-31778-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1322655824-31778-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 2/3] block: wait_for_overlapping_requests() deadlock detection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi Debugging a reentrant request deadlock was fun but in the future we need a quick and obvious way of detecting such bugs. Add an assert that checks we are not about to deadlock when waiting for another request. Suggested-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- block.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 4310eb5..37a96f3 100644 --- a/block.c +++ b/block.c @@ -1099,6 +1099,7 @@ struct BdrvTrackedRequest { int nb_sectors; bool is_write; QLIST_ENTRY(BdrvTrackedRequest) list; + Coroutine *co; /* owner, used for deadlock detection */ CoQueue wait_queue; /* coroutines blocked on this request */ }; @@ -1126,6 +1127,7 @@ static void tracked_request_begin(BdrvTrackedRequest *req, .sector_num = sector_num, .nb_sectors = nb_sectors, .is_write = is_write, + .co = qemu_coroutine_self(), }; qemu_co_queue_init(&req->wait_queue); @@ -1189,6 +1191,12 @@ static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs, QLIST_FOREACH(req, &bs->tracked_requests, list) { if (tracked_request_overlaps(req, cluster_sector_num, cluster_nb_sectors)) { + /* Hitting this means there was a reentrant request, for + * example, a block driver issuing nested requests. This must + * never happen since it means deadlock. + */ + assert(qemu_coroutine_self() != req->co); + qemu_co_queue_wait(&req->wait_queue); retry = true; break; -- 1.7.7.3