diff mbox series

[for-8.2] block: Fix AioContext locking in qmp_block_resize()

Message ID 20231208124352.30295-1-kwolf@redhat.com (mailing list archive)
State New, archived
Headers show
Series [for-8.2] block: Fix AioContext locking in qmp_block_resize() | expand

Commit Message

Kevin Wolf Dec. 8, 2023, 12:43 p.m. UTC
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.

Cc: qemu-stable@nongnu.org
Fixes: https://issues.redhat.com/browse/RHEL-15965
Fixes: 0c7d204f50c382c6baac8c94bd57af4a022b3888
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 blockdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Stefan Hajnoczi Dec. 11, 2023, 2:48 p.m. UTC | #1
On Fri, 8 Dec 2023 at 07:44, Kevin Wolf <kwolf@redhat.com> wrote:
>
> 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.
>
> Cc: qemu-stable@nongnu.org
> Fixes: https://issues.redhat.com/browse/RHEL-15965
> Fixes: 0c7d204f50c382c6baac8c94bd57af4a022b3888
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  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.

>
> diff --git a/blockdev.c b/blockdev.c
> index 4c1177e8db..c91f49e7b6 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -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
>
>
Stefan Hajnoczi Dec. 13, 2023, 5:22 p.m. UTC | #2
Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/8.2 for any user-visible changes.
diff mbox series

Patch

diff --git a/blockdev.c b/blockdev.c
index 4c1177e8db..c91f49e7b6 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -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,