From 6bc0bcc89f847839cf3d459a55290dda8801d9d3 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Wed, 15 Nov 2023 18:20:10 +0100 Subject: block: Fix deadlocks in bdrv_graph_wrunlock() bdrv_graph_wrunlock() calls aio_poll(), which may run callbacks that have a nested event loop. Nested event loops can depend on other iothreads making progress, so in order to allow them to make progress it must not hold the AioContext lock of another thread while calling aio_poll(). This introduces a @bs parameter to bdrv_graph_wrunlock() whose AioContext is temporarily dropped (which matches bdrv_graph_wrlock()), and a bdrv_graph_wrunlock_ctx() that can be used if the BlockDriverState doesn't necessarily exist any more when unlocking. This also requires a change to bdrv_schedule_unref(), which was relying on the incorrectly taken lock. It needs to take the lock itself now. While this is a separate bug, it can't be fixed a separate patch because otherwise the intermediate state would either deadlock or try to release a lock that we don't even hold. Signed-off-by: Kevin Wolf Message-ID: <20231115172012.112727-3-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi [kwolf: Fixed up bdrv_schedule_unref()] Signed-off-by: Kevin Wolf --- scripts/block-coroutine-wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/block-coroutine-wrapper.py') diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-wrapper.py index a601c3c672..a38e5833fb 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -262,7 +262,7 @@ def gen_no_co_wrapper(func: FuncDecl) -> str: graph_unlock=' bdrv_graph_rdunlock_main_loop();' elif func.graph_wrlock: graph_lock=' bdrv_graph_wrlock(NULL);' - graph_unlock=' bdrv_graph_wrunlock();' + graph_unlock=' bdrv_graph_wrunlock(NULL);' return f"""\ /* -- cgit 1.4.1