qemu-devel.nongnu.org archive mirror
 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 01/15] mirror: Don't call job_pause_point() under graph lock
Date: Mon, 18 Mar 2024 14:01:04 +0100	[thread overview]
Message-ID: <20240318130118.358920-2-kwolf@redhat.com> (raw)
In-Reply-To: <20240318130118.358920-1-kwolf@redhat.com>

Calling job_pause_point() while holding the graph reader lock
potentially results in a deadlock: bdrv_graph_wrlock() first drains
everything, including the mirror job, which pauses it. The job is only
unpaused at the end of the drain section, which is when the graph writer
lock has been successfully taken. However, if the job happens to be
paused at a pause point where it still holds the reader lock, the writer
lock can't be taken as long as the job is still paused.

Mark job_pause_point() as GRAPH_UNLOCKED and fix mirror accordingly.

Cc: qemu-stable@nongnu.org
Buglink: https://issues.redhat.com/browse/RHEL-28125
Fixes: 004915a96a7a ("block: Protect bs->backing with graph_lock")
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20240313153000.33121-1-kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/qemu/job.h |  2 +-
 block/mirror.c     | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/qemu/job.h b/include/qemu/job.h
index 9ea98b5927..2b873f2576 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -483,7 +483,7 @@ void job_enter(Job *job);
  *
  * Called with job_mutex *not* held.
  */
-void coroutine_fn job_pause_point(Job *job);
+void coroutine_fn GRAPH_UNLOCKED job_pause_point(Job *job);
 
 /**
  * @job: The job that calls the function.
diff --git a/block/mirror.c b/block/mirror.c
index 5145eb53e1..1bdce3b657 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -479,9 +479,9 @@ static unsigned mirror_perform(MirrorBlockJob *s, int64_t offset,
     return bytes_handled;
 }
 
-static void coroutine_fn GRAPH_RDLOCK mirror_iteration(MirrorBlockJob *s)
+static void coroutine_fn GRAPH_UNLOCKED mirror_iteration(MirrorBlockJob *s)
 {
-    BlockDriverState *source = s->mirror_top_bs->backing->bs;
+    BlockDriverState *source;
     MirrorOp *pseudo_op;
     int64_t offset;
     /* At least the first dirty chunk is mirrored in one iteration. */
@@ -489,6 +489,10 @@ static void coroutine_fn GRAPH_RDLOCK mirror_iteration(MirrorBlockJob *s)
     bool write_zeroes_ok = bdrv_can_write_zeroes_with_unmap(blk_bs(s->target));
     int max_io_bytes = MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES);
 
+    bdrv_graph_co_rdlock();
+    source = s->mirror_top_bs->backing->bs;
+    bdrv_graph_co_rdunlock();
+
     bdrv_dirty_bitmap_lock(s->dirty_bitmap);
     offset = bdrv_dirty_iter_next(s->dbi);
     if (offset < 0) {
@@ -1066,9 +1070,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
                 mirror_wait_for_free_in_flight_slot(s);
                 continue;
             } else if (cnt != 0) {
-                bdrv_graph_co_rdlock();
                 mirror_iteration(s);
-                bdrv_graph_co_rdunlock();
             }
         }
 
-- 
2.44.0



  reply	other threads:[~2024-03-18 13:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 13:01 [PULL 00/15] Block layer patches Kevin Wolf
2024-03-18 13:01 ` Kevin Wolf [this message]
2024-03-18 13:01 ` [PULL 02/15] nbd/server: Fix race in draining the export Kevin Wolf
2024-03-18 13:01 ` [PULL 03/15] iotests: Add test for reset/AioContext switches with NBD exports Kevin Wolf
2024-03-18 13:01 ` [PULL 04/15] blockdev: Fix blockdev-snapshot-sync error reporting for no medium Kevin Wolf
2024-03-18 13:01 ` [PULL 05/15] qemu-img: Fix Column Width and Improve Formatting in snapshot list Kevin Wolf
2024-03-18 13:01 ` [PULL 06/15] tests/qemu-iotests: Fix test 033 for running with non-file protocols Kevin Wolf
2024-03-18 13:01 ` [PULL 07/15] tests/qemu-iotests: Restrict test 066 to the 'file' protocol Kevin Wolf
2024-03-18 13:01 ` [PULL 08/15] tests/qemu-iotests: Restrict test 114 " Kevin Wolf
2024-03-18 13:01 ` [PULL 09/15] tests/qemu-iotests: Restrict test 130 " Kevin Wolf
2024-03-18 13:01 ` [PULL 10/15] tests/qemu-iotests: Restrict test 134 and 158 " Kevin Wolf
2024-03-18 13:01 ` [PULL 11/15] tests/qemu-iotests: Restrict test 156 " Kevin Wolf
2024-03-18 13:01 ` [PULL 12/15] tests/qemu-iotests: Restrict tests that use --image-opts " Kevin Wolf
2024-03-18 13:01 ` [PULL 13/15] tests/qemu-iotests: Fix some tests that use --image-opts for other protocols Kevin Wolf
2024-03-18 13:01 ` [PULL 14/15] tests/qemu-iotests: Restrict tests using "--blockdev file" to the file protocol Kevin Wolf
2024-03-18 13:01 ` [PULL 15/15] iotests: adapt to output change for recently introduced 'detached header' field Kevin Wolf
2024-03-19 10:23 ` [PULL 00/15] 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=20240318130118.358920-2-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).