All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [PULL 06/16] block-backend: Allow concurrent context changes
Date: Wed,  7 Feb 2024 22:55:56 +0100	[thread overview]
Message-ID: <20240207215606.206038-7-kwolf@redhat.com> (raw)
In-Reply-To: <20240207215606.206038-1-kwolf@redhat.com>

From: Hanna Czenczek <hreitz@redhat.com>

Since AioContext locks have been removed, a BlockBackend's AioContext
may really change at any time (only exception is that it is often
confined to a drained section, as noted in this patch).  Therefore,
blk_get_aio_context() cannot rely on its root node's context always
matching that of the BlockBackend.

In practice, whether they match does not matter anymore anyway: Requests
can be sent to BDSs from any context, so anyone who requests the BB's
context should have no reason to require the root node to have the same
context.  Therefore, we can and should remove the assertion to that
effect.

In addition, because the context can be set and queried from different
threads concurrently, it has to be accessed with atomic operations.

Buglink: https://issues.redhat.com/browse/RHEL-19381
Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Message-ID: <20240202144755.671354-2-hreitz@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/block-backend.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 209eb07528..9c4de79e6b 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -44,7 +44,7 @@ struct BlockBackend {
     char *name;
     int refcnt;
     BdrvChild *root;
-    AioContext *ctx;
+    AioContext *ctx; /* access with atomic operations only */
     DriveInfo *legacy_dinfo;    /* null unless created by drive_new() */
     QTAILQ_ENTRY(BlockBackend) link;         /* for block_backends */
     QTAILQ_ENTRY(BlockBackend) monitor_link; /* for monitor_block_backends */
@@ -2414,22 +2414,22 @@ void blk_op_unblock_all(BlockBackend *blk, Error *reason)
     }
 }
 
+/**
+ * Return BB's current AioContext.  Note that this context may change
+ * concurrently at any time, with one exception: If the BB has a root node
+ * attached, its context will only change through bdrv_try_change_aio_context(),
+ * which creates a drained section.  Therefore, incrementing such a BB's
+ * in-flight counter will prevent its context from changing.
+ */
 AioContext *blk_get_aio_context(BlockBackend *blk)
 {
-    BlockDriverState *bs;
     IO_CODE();
 
     if (!blk) {
         return qemu_get_aio_context();
     }
 
-    bs = blk_bs(blk);
-    if (bs) {
-        AioContext *ctx = bdrv_get_aio_context(blk_bs(blk));
-        assert(ctx == blk->ctx);
-    }
-
-    return blk->ctx;
+    return qatomic_read(&blk->ctx);
 }
 
 int blk_set_aio_context(BlockBackend *blk, AioContext *new_context,
@@ -2442,7 +2442,7 @@ int blk_set_aio_context(BlockBackend *blk, AioContext *new_context,
     GLOBAL_STATE_CODE();
 
     if (!bs) {
-        blk->ctx = new_context;
+        qatomic_set(&blk->ctx, new_context);
         return 0;
     }
 
@@ -2471,7 +2471,7 @@ static void blk_root_set_aio_ctx_commit(void *opaque)
     AioContext *new_context = s->new_ctx;
     ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
 
-    blk->ctx = new_context;
+    qatomic_set(&blk->ctx, new_context);
     if (tgm->throttle_state) {
         throttle_group_detach_aio_context(tgm);
         throttle_group_attach_aio_context(tgm, new_context);
-- 
2.43.0



  parent reply	other threads:[~2024-02-07 21:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07 21:55 [PULL 00/16] Block layer patches Kevin Wolf
2024-02-07 21:55 ` [PULL 01/16] virtio-blk: enforce iothread-vq-mapping validation Kevin Wolf
2024-02-07 21:55 ` [PULL 02/16] virtio-blk: clarify that there is at least 1 virtqueue Kevin Wolf
2024-02-07 21:55 ` [PULL 03/16] virtio-blk: add vq_rq[] bounds check in virtio_blk_dma_restart_cb() Kevin Wolf
2024-02-07 21:55 ` [PULL 04/16] virtio-blk: declare VirtIOBlock::rq with a type Kevin Wolf
2024-02-07 21:55 ` [PULL 05/16] monitor: use aio_co_reschedule_self() Kevin Wolf
2024-02-07 21:55 ` Kevin Wolf [this message]
2024-02-07 21:55 ` [PULL 07/16] scsi: Await request purging Kevin Wolf
2024-02-07 21:55 ` [PULL 08/16] iotests: fix leak of tmpdir in dry-run mode Kevin Wolf
2024-02-07 21:55 ` [PULL 09/16] iotests: give tempdir an identifying name Kevin Wolf
2024-02-07 21:56 ` [PULL 10/16] virtio-blk: do not use C99 mixed declarations Kevin Wolf
2024-02-07 21:56 ` [PULL 11/16] scsi: Don't ignore most usb-storage properties Kevin Wolf
2024-02-07 21:56 ` [PULL 12/16] blkio: Respect memory-alignment for bounce buffer allocations Kevin Wolf
2024-02-07 21:56 ` [PULL 13/16] virtio-scsi: Attach event vq notifier with no_poll Kevin Wolf
2024-02-07 21:56 ` [PULL 14/16] virtio: Re-enable notifications after drain Kevin Wolf
2024-02-07 21:56 ` [PULL 15/16] virtio-blk: Use ioeventfd_attach in start_ioeventfd Kevin Wolf
2024-02-07 21:56 ` [PULL 16/16] virtio-blk: avoid using ioeventfd state in irqfd conditional Kevin Wolf
2024-02-09 11:22 ` [PULL 00/16] Block layer patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240207215606.206038-7-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.