From 44340a1e70bd462a8f0b264ed00826669da8be34 Mon Sep 17 00:00:00 2001 From: Jeffrey Cody Date: Wed, 21 Mar 2012 21:55:00 +0100 Subject: [PATCH 33/55] block: wait_for_overlapping_requests() deadlock detection RH-Author: Jeffrey Cody Message-id: Patchwork-id: 38884 O-Subject: [RHEL6.3 qemu-kvm PATCH v8 33/54] block: wait_for_overlapping_requests() deadlock detection Bugzilla: 582475 RH-Acked-by: Paolo Bonzini RH-Acked-by: Marcelo Tosatti RH-Acked-by: Kevin Wolf From: 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 Signed-off-by: Kevin Wolf (cherry picked from commit 5f8b6491f20732e0a31e64bbf75b62def579e044) Signed-off-by: Stefan Hajnoczi Signed-off-by: Anthony Liguori Signed-off-by: Jeff Cody --- block.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) Signed-off-by: Michal Novotny --- block.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 7ab68e3..1cb1a51 100644 --- a/block.c +++ b/block.c @@ -1104,6 +1104,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 */ }; @@ -1131,6 +1132,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); @@ -1194,6 +1196,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.6