[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/22] block: temporarily hold the new AioContext of bs_top in bdr
From: |
Kevin Wolf |
Subject: |
[PULL 19/22] block: temporarily hold the new AioContext of bs_top in bdrv_append() |
Date: |
Fri, 17 Feb 2023 16:09:51 +0100 |
From: Stefano Garzarella <sgarzare@redhat.com>
bdrv_append() is called with bs_top AioContext held, but
bdrv_attach_child_noperm() could change the AioContext of bs_top.
bdrv_replace_node_noperm() calls bdrv_drained_begin() starting from
commit 2398747128 ("block: Don't poll in bdrv_replace_child_noperm()").
bdrv_drained_begin() can call BDRV_POLL_WHILE that assumes the new lock
is taken, so let's temporarily hold the new AioContext to prevent QEMU
from failing in BDRV_POLL_WHILE when it tries to release the wrong
AioContext.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2168209
Reported-by: Aihua Liang <aliang@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20230214171621.11574-1-sgarzare@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/block.c b/block.c
index 122aa9a9ac..0c807d15cd 100644
--- a/block.c
+++ b/block.c
@@ -5265,6 +5265,8 @@ int bdrv_drop_filter(BlockDriverState *bs, Error **errp)
* child.
*
* This function does not create any image files.
+ *
+ * The caller must hold the AioContext lock for @bs_top.
*/
int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
Error **errp)
@@ -5272,11 +5274,14 @@ int bdrv_append(BlockDriverState *bs_new,
BlockDriverState *bs_top,
int ret;
BdrvChild *child;
Transaction *tran = tran_new();
+ AioContext *old_context, *new_context = NULL;
GLOBAL_STATE_CODE();
assert(!bs_new->backing);
+ old_context = bdrv_get_aio_context(bs_top);
+
child = bdrv_attach_child_noperm(bs_new, bs_top, "backing",
&child_of_bds, bdrv_backing_role(bs_new),
tran, errp);
@@ -5285,6 +5290,19 @@ int bdrv_append(BlockDriverState *bs_new,
BlockDriverState *bs_top,
goto out;
}
+ /*
+ * bdrv_attach_child_noperm could change the AioContext of bs_top.
+ * bdrv_replace_node_noperm calls bdrv_drained_begin, so let's temporarily
+ * hold the new AioContext, since bdrv_drained_begin calls BDRV_POLL_WHILE
+ * that assumes the new lock is taken.
+ */
+ new_context = bdrv_get_aio_context(bs_top);
+
+ if (old_context != new_context) {
+ aio_context_release(old_context);
+ aio_context_acquire(new_context);
+ }
+
ret = bdrv_replace_node_noperm(bs_top, bs_new, true, tran, errp);
if (ret < 0) {
goto out;
@@ -5296,6 +5314,11 @@ out:
bdrv_refresh_limits(bs_top, NULL, NULL);
+ if (new_context && old_context != new_context) {
+ aio_context_release(new_context);
+ aio_context_acquire(old_context);
+ }
+
return ret;
}
--
2.39.2
- [PULL 09/22] qcow: Fix .bdrv_co_create(_opts) to open images with no_co_wrapper, (continued)
- [PULL 09/22] qcow: Fix .bdrv_co_create(_opts) to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 12/22] vdi: Fix .bdrv_co_create(_opts) to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 08/22] parallels: Fix .bdrv_co_create(_opts) to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 17/22] block: Assert non-coroutine context for bdrv_open_inherit(), Kevin Wolf, 2023/02/17
- [PULL 13/22] vhdx: Fix .bdrv_co_create(_opts) to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 05/22] block-coroutine-wrapper: Introduce no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 07/22] luks: Fix .bdrv_co_create(_opts) to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 18/22] block: Handle curl 7.55.0, 7.85.0 version changes, Kevin Wolf, 2023/02/17
- [PULL 11/22] qed: Fix .bdrv_co_create(_opts) to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 10/22] qcow2: Fix open/create to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 19/22] block: temporarily hold the new AioContext of bs_top in bdrv_append(),
Kevin Wolf <=
- [PULL 20/22] MAINTAINERS: drop Vladimir from parallels block driver, Kevin Wolf, 2023/02/17
- [PULL 21/22] block/file-posix: don't use functions calling AIO_WAIT_WHILE in worker threads, Kevin Wolf, 2023/02/17
- [PULL 15/22] vpc: Fix .bdrv_co_create(_opts) to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 16/22] block: Fix bdrv_co_create_opts_simple() to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 14/22] vmdk: Fix .bdrv_co_create(_opts) to open images with no_co_wrapper, Kevin Wolf, 2023/02/17
- [PULL 22/22] hbitmap: fix hbitmap_status() return value for first dirty bit case, Kevin Wolf, 2023/02/17
- Re: [PULL 00/22] Block layer patches, Peter Maydell, 2023/02/20