Skip to contentSkip to conversation

block: Fix AioContext locking in qmp_block_resize()

PATCH Applied Kevin Wolf 3 participants 3 messages Dec 8, 2023 – Dec 13, 2023

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 block: Fix AioContext locking in qmp_block_resize()

The AioContext must be unlocked before calling blk_co_unref(), because it takes the AioContext lock internally in blk_unref_bh(), which is scheduled in the main thread. If we don't unlock, the AioContext is locked twice and nested event loops such as in bdrv_graph_wrlock() will deadlock.

Fixes 0c7d204f50c382c6baac8c94bd57af4a022b3888
---
 blockdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
blockdev.c +2 -1
index 4c1177e8db..c91f49e7b6 100644
@@ -2400,8 +2400,9 @@ void coroutine_fn qmp_block_resize(const char *device, const char *node_name,
 
     bdrv_co_lock(bs);
     bdrv_drained_end(bs);
-    blk_co_unref(blk);
     bdrv_co_unlock(bs);
+
+    blk_co_unref(blk);
 }
 
 void qmp_block_stream(const char *job_id, const char *device,
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · Kevin Wolf

The AioContext must be unlocked before calling blk_co_unref(), because it takes the AioContext lock internally in blk_unref_bh(), which is scheduled in the main thread. If we don't unlock, the AioContext is locked twice and nested event loops such as in bdrv_graph_wrlock() will deadlock.

Quoted 7 lines
Fixes 0c7d204f50c382c6baac8c94bd57af4a022b3888
---
 blockdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

From IRC:

09:40 < stefanha> kwolf: "[PATCH for-8.2] block: Fix AioContext locking in qmp_block_resize()" fixes QEMU 8.1 bug and is not a regression?
09:41 < stefanha> I'm trying to understand the nature of the issue and whether to roll an -rc4 tomorrow and delay the QEMU 8.2 release by a week.
09:41 < kwolf> stefanha: Looks like it, yes
09:41 < kwolf> stefanha: Probably not worth an -rc4 on its own if there are no other fixes
09:42 < stefanha> Okay, thanks. If nothing else comes up by tomorrow I will tag v8.2.0 (final) and we can merge this immediately when the development window and -stable tree opens.

Quoted 20 lines
blockdev.c +2 -2
index 4c1177e8db..c91f49e7b6 100644
@@ -2400,8 +2400,9 @@ void coroutine_fn qmp_block_resize(const char *device, const char *node_name,
 
     bdrv_co_lock(bs);
     bdrv_drained_end(bs);
-    blk_co_unref(blk);
     bdrv_co_unlock(bs);
+
+    blk_co_unref(blk);
 }
 
 void qmp_block_stream(const char *job_id, const char *device,
--

2.43.0