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, richard.henderson@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 02/21] block/throttle-groups: fix crash when enabling I/O limits on a busy disk
Date: Wed,  7 Oct 2026 18:32:43 +0200	[thread overview]
Message-ID: <20261007163302.332250-3-kwolf@redhat.com> (raw)
In-Reply-To: <20261007163302.332250-1-kwolf@redhat.com>

From: "Denis V. Lunev" <den@openvz.org>

throttle_group_register_tgm() stores tgm->throttle_state before it takes
tg->lock, so the I/O path can see a member whose group still has NULL
tokens[] and an empty member list. A request in an iothread then reaches
throttle_group_co_io_limits_intercept(), wins tg->lock ahead of the
registering thread, and next_throttle_token() passes the NULL token to
throttle_group_next_tgm(), which dereferences it:

  throttle_group_next_tgm (tgm=0x0) at block/throttle-groups.c:185
  next_throttle_token (tgm=..., direction=THROTTLE_READ)
  throttle_group_co_io_limits_intercept (tgm=..., bytes=8192, ...)
  blk_co_do_preadv_part (blk=..., offset=..., bytes=8192, ...)
  blk_aio_read_entry (opaque=...)
  coroutine_trampoline (i0=..., i1=...)

blk_io_limits_enable() does not drain the BlockBackend, unlike its disable
counterpart, so nothing keeps requests away while the group is built. A
guest probing a disk that libvirt has just attached, at the moment the QoS
settings for it are applied, is enough to hit this.

Publish tgm->throttle_state with a release store once the member is
linked into the group and its timers exist, and read it with an acquire
load on the two unlocked I/O paths. A request that sees the new pointer
then also sees a fully built group.

Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Hanna Reitz <hreitz@redhat.com>
Cc: Alberto Garcia <berto@igalia.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
Message-ID: <20260908145554.3215221-2-den@openvz.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Acked-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/block-backend.c   | 12 ++++++------
 block/throttle-groups.c |  4 +++-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 37ba7e9fc40..5e59bac1a3c 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1338,6 +1338,7 @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes,
                       QEMUIOVector *qiov, size_t qiov_offset,
                       BdrvRequestFlags flags)
 {
+    ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
     int ret;
     BlockDriverState *bs;
     IO_CODE();
@@ -1357,9 +1358,8 @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes,
     bdrv_inc_in_flight(bs);
 
     /* throttling disk I/O */
-    if (blk->public.throttle_group_member.throttle_state) {
-        throttle_group_co_io_limits_intercept(&blk->public.throttle_group_member,
-                bytes, THROTTLE_READ);
+    if (qatomic_load_acquire(&tgm->throttle_state)) {
+        throttle_group_co_io_limits_intercept(tgm, bytes, THROTTLE_READ);
     }
 
     ret = bdrv_co_preadv_part(blk->root, offset, bytes, qiov, qiov_offset,
@@ -1413,6 +1413,7 @@ blk_co_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes,
                        QEMUIOVector *qiov, size_t qiov_offset,
                        BdrvRequestFlags flags)
 {
+    ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
     int ret;
     BlockDriverState *bs;
     IO_CODE();
@@ -1431,9 +1432,8 @@ blk_co_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes,
 
     bdrv_inc_in_flight(bs);
     /* throttling disk I/O */
-    if (blk->public.throttle_group_member.throttle_state) {
-        throttle_group_co_io_limits_intercept(&blk->public.throttle_group_member,
-                bytes, THROTTLE_WRITE);
+    if (qatomic_load_acquire(&tgm->throttle_state)) {
+        throttle_group_co_io_limits_intercept(tgm, bytes, THROTTLE_WRITE);
     }
 
     if (!blk->enable_write_cache) {
diff --git a/block/throttle-groups.c b/block/throttle-groups.c
index 2dfd9d62aac..37814b84fe0 100644
--- a/block/throttle-groups.c
+++ b/block/throttle-groups.c
@@ -581,7 +581,6 @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm,
     ThrottleState *ts = throttle_group_incref(groupname);
     ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
 
-    tgm->throttle_state = ts;
     tgm->aio_context = ctx;
     qatomic_set(&tgm->restart_pending, 0);
 
@@ -602,6 +601,9 @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm,
                          read_timer_cb,
                          write_timer_cb,
                          tgm);
+
+    /* The I/O path reads this without tg->lock, so publish it last */
+    qatomic_store_release(&tgm->throttle_state, ts);
 }
 
 /* Unregister a ThrottleGroupMember from its group, removing it from the list,
-- 
2.56.0



  parent reply	other threads:[~2026-10-07 16:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 16:32 [PULL 00/21] Block layer patches Kevin Wolf
2026-10-07 16:32 ` [PULL 01/21] block-common: fix BDRV_WANT_PRECISE duplicating BDRV_WANT_OFFSET_VALID Kevin Wolf
2026-10-07 16:32 ` Kevin Wolf [this message]
2026-10-07 16:32 ` [PULL 03/21] block: fix bdrv_next() skipping monitor-owned nodes Kevin Wolf
2026-10-07 16:32 ` [PULL 04/21] block: allocate aligned write buffer for 'truncate -m full' Kevin Wolf
2026-10-07 16:32 ` [PULL 05/21] scripts/qemugdb: coroutine: Fix selected frame leak on error path Kevin Wolf
2026-10-07 16:32 ` [PULL 06/21] scripts/qemugdb: coroutine: Get rid of fallback pattern when dumping backtrace Kevin Wolf
2026-10-07 16:32 ` [PULL 07/21] scripts/qemugdb: coroutine: Only attempt to restore regs in coredump Kevin Wolf
2026-10-07 16:32 ` [PULL 08/21] scripts/qemugdb: coroutine: Don't unwind past the outermost frame Kevin Wolf
2026-10-07 16:32 ` [PULL 09/21] scripts/qemugdb: coroutine: Fix patching pt_regs in the coredump Kevin Wolf
2026-10-07 16:32 ` [PULL 10/21] scripts/qemugdb: coroutine: Fix '--detailed' description Kevin Wolf
2026-10-07 16:32 ` [PULL 11/21] scripts/qemugdb: coroutine: Handle target absence gracefully Kevin Wolf
2026-10-07 16:32 ` [PULL 12/21] scripts/qemugdb: coroutine: Speed up coroutine lookup in a coredump Kevin Wolf
2026-10-07 16:32 ` [PULL 13/21] scripts/qemugdb: coroutine: Don't touch the coredump for a plain backtrace Kevin Wolf
2026-10-07 16:32 ` [PULL 14/21] iotests: remove unused 'owner=' variable assignment Kevin Wolf
2026-10-07 16:32 ` [PULL 15/21] hw/block/fdc: account for read and write requests Kevin Wolf
2026-10-07 16:32 ` [PULL 16/21] iotests: annotate TestRunner.shared_self for mypy 2.4 Kevin Wolf
2026-10-07 16:32 ` [PULL 17/21] file-posix: add statx(STATX_DIOALIGN) support Kevin Wolf
2026-10-07 16:32 ` [PULL 18/21] qcow2: do not clear the dirty bit when reopening a read-only node Kevin Wolf
2026-10-07 16:33 ` [PULL 19/21] block: reject a reopen of an unusable node instead of crashing Kevin Wolf
2026-10-07 16:33 ` [PULL 20/21] block: Fix corruption from broken RMW atomicity Kevin Wolf
2026-10-07 16:33 ` [PULL 21/21] block: Remove now redundant bdrv_wait_serialising_requests() calls Kevin Wolf
2026-10-09 12:29 ` [PULL 00/21] Block layer patches Richard Henderson

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=20261007163302.332250-3-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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.