From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4ADr-0007Ic-MX for qemu-devel@nongnu.org; Fri, 17 Jan 2014 09:16:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W4ADl-0006Qz-Nk for qemu-devel@nongnu.org; Fri, 17 Jan 2014 09:16:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44627) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4ADl-0006Q8-Eq for qemu-devel@nongnu.org; Fri, 17 Jan 2014 09:16:29 -0500 From: Kevin Wolf Date: Fri, 17 Jan 2014 15:15:09 +0100 Message-Id: <1389968119-24771-20-git-send-email-kwolf@redhat.com> In-Reply-To: <1389968119-24771-1-git-send-email-kwolf@redhat.com> References: <1389968119-24771-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v3 19/29] block: Allow wait_serialising_requests() at any point List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pl@kamp.de, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, xiawenc@linux.vnet.ibm.com We can only have a single wait_serialising_requests() call per request because otherwise we can run into deadlocks where requests are waiting for each other. The same is true when wait_serialising_requests() is not at the very beginning of a request, so that other requests can be issued between the start of the tracking and wait_serialising_requests(). Fix this by changing wait_serialising_requests() to ignore requests that are already (directly or indirectly) waiting for the calling request. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 13 ++++++++++--- include/block/block_int.h | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index e72966a..55e8c69 100644 --- a/block.c +++ b/block.c @@ -2148,9 +2148,16 @@ static void coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self) */ assert(qemu_coroutine_self() != req->co); - qemu_co_queue_wait(&req->wait_queue); - retry = true; - break; + /* If the request is already (indirectly) waiting for us, or + * will wait for us as soon as it wakes up, then just go on + * (instead of producing a deadlock in the former case). */ + if (!req->waiting_for) { + self->waiting_for = req; + qemu_co_queue_wait(&req->wait_queue); + self->waiting_for = NULL; + retry = true; + break; + } } } } while (retry); diff --git a/include/block/block_int.h b/include/block/block_int.h index ccd2c68..fdf0e0b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -68,6 +68,8 @@ typedef struct BdrvTrackedRequest { QLIST_ENTRY(BdrvTrackedRequest) list; Coroutine *co; /* owner, used for deadlock detection */ CoQueue wait_queue; /* coroutines blocked on this request */ + + struct BdrvTrackedRequest *waiting_for; } BdrvTrackedRequest; struct BlockDriver { -- 1.8.1.4