qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 00/48] block: do not drain while holding the graph lock
@ 2025-05-30 15:10 Fiona Ebner
  2025-05-30 15:10 ` [PATCH v4 01/48] block: remove outdated comments about AioContext locking Fiona Ebner
                   ` (49 more replies)
  0 siblings, 50 replies; 60+ messages in thread
From: Fiona Ebner @ 2025-05-30 15:10 UTC (permalink / raw)
  To: qemu-block
  Cc: qemu-devel, kwolf, den, andrey.drobyshev, hreitz, stefanha,
	eblake, jsnow, vsementsov, xiechanglong.d, wencongyang2, berto,
	fam, ari

Previous discussions:
v3: [0]
v2: [1]
v1: [2]

Changes in v4:
* Document requirement to drain all block nodes for affected
  functions.
* Also cover the generated bdrv_co_unref_child().
* Remove now superfluous drain_bs variable in bdrv_set_backing_hd().
* Mark bdrv_graph_wrlock_drained() wrapper as GRAPH_UNLOCKED.
* Unify bdrv_set_backing_hd() with its drained_variant.
* Mark more functions up the call-stack as GRAPH_UNLOCKED. This is
  almost all of the new patches in the latter half of the series, most
  do not require substantial changes, but there are a few where
  something needed to be done. I did not mark functions outside the
  block layer like qemu_cleanup(), save_snapshot(), qmp_xyz(), etc.
  and also not functions that explicitly do a rdunlock_main_loop()
  before calling a function that is GRAPH_UNLOCKED.

There were no changes for patches 01/48-09/48 and 17/48-23/48, endpoints
inclusive. All patches starting from 25/48 are new in v4.

Changes in v3:
* Also add bdrv_drain_all_begin() and bdrv_drain_all() as
  GRAPH_UNLOCKED.
* Extend drained section in bdrv_try_change_aio_context() until after
  the transaction is finalized.
* Also mark definition of static bdrv_change_aio_context() as
  GRAPH_RDLOCK, not only the declaration.
* Add comments for bdrv_{child,parent}_change_aio_context() and
  change_aio_ctx().
* Improve commit messages: typos/language/clarification.

Changes in v2:
* Split the big patch moving the drain outside of
  bdrv_change_aio_context(), mark functions along the way with graph
  lock annotations.
* In {internal,external}_snapshot_action, check that associated bs did
  not change after drain and re-acquiring the lock.
* Improve error handling using goto where appropriate.
* Add bdrv_graph_wrlock_drained() convenience wrapper rather than
  adding a flag argument.
* Don't use atomics to access bs->quiesce_counter field, add a patch
  to adapt the two existing places that used atomics.
* Re-use 'top' image for graph-changes-while-io test case and rename
  the other image to 'mid'. Remove the image files after the test.
* Use "must be" instead of "needs to be" in documentation, use single
  line comments where possible.
* Remove yet another outdated comment.
* I did not add Kevin's R-b for the patch marking bdrv_drained_begin()
  GRAPH_RDLOCK, as the earlier patches/preconditions changed.

This series is an attempt to fix a deadlock issue reported by Andrey
here [3].

bdrv_drained_begin() polls and is not allowed to be called with the
block graph lock held. Mark the function as GRAPH_UNLOCKED.

This alone does not catch the issue reported by Andrey, because there
is a bdrv_graph_rdunlock_main_loop() before bdrv_drained_begin() in
the function bdrv_change_aio_context(). That unlock is of course
ineffective if the exclusive lock is held, but it prevents TSA from
finding the issue.

Thus the bdrv_drained_begin() call from inside
bdrv_change_aio_context() needs to be moved up the call stack before
acquiring the locks. This is the bulk of the series.

Granular draining is not trivially possible, because many of the
affected functions can recursively call themselves.

In place where bdrv_drained_begin() calls were removed, assertions
are added, checking the quiesced_counter to ensure that the nodes
already got drained further up in the call stack.

NOTE:
there are pre-existing test failures on current master, e.g. '240' for
all formats, '295 296 inactive-node-nbd luks-detached-header' for
luks. For me, the failures do not change after this series.
For '240', a patch is already available [4].

[0]: https://lore.kernel.org/qemu-devel/20250526132140.1641377-1-f.ebner@proxmox.com/
[1]: https://lore.kernel.org/qemu-devel/20250520103012.424311-1-f.ebner@proxmox.com/
[2]: https://lore.kernel.org/qemu-devel/20250508140936.3344485-1-f.ebner@proxmox.com/
[3]: https://lore.kernel.org/qemu-devel/73839c04-7616-407e-b057-80ca69e63f51@virtuozzo.com/
[4]: https://lore.kernel.org/qemu-devel/20250529203147.180338-1-stefanha@redhat.com/


Andrey Drobyshev (1):
  iotests/graph-changes-while-io: add test case with removal of lower
    snapshot

Fiona Ebner (47):
  block: remove outdated comments about AioContext locking
  block: move drain outside of read-locked bdrv_reopen_queue_child()
  block/snapshot: move drain outside of read-locked
    bdrv_snapshot_delete()
  block: move drain outside of read-locked bdrv_inactivate_recurse()
  block: mark bdrv_parent_change_aio_context() GRAPH_RDLOCK
  block: mark change_aio_ctx() callback and instances as
    GRAPH_RDLOCK(_PTR)
  block: mark bdrv_child_change_aio_context() GRAPH_RDLOCK
  block: move drain outside of bdrv_change_aio_context() and mark
    GRAPH_RDLOCK
  block: move drain outside of bdrv_try_change_aio_context()
  block: move drain outside of bdrv_attach_child_common(_abort)()
  block: move drain outside of bdrv_set_backing_hd_drained()
  block: move drain outside of bdrv_root_attach_child()
  block: move drain outside of bdrv_attach_child()
  block: move drain outside of quorum_add_child()
  block: move drain outside of bdrv_root_unref_child()
  block: move drain outside of quorum_del_child()
  blockdev: drain while unlocked in internal_snapshot_action()
  blockdev: drain while unlocked in external_snapshot_action()
  block: mark bdrv_drained_begin() and friends as GRAPH_UNLOCKED
  iotests/graph-changes-while-io: remove image file after test
  block/io: remove duplicate GLOBAL_STATE_CODE() in
    bdrv_do_drained_end()
  block: never use atomics to access bs->quiesce_counter
  block: add bdrv_graph_wrlock_drained() convenience wrapper
  block/mirror: switch to bdrv_set_backing_hd_drained() variant
  block/commit: switch to bdrv_set_backing_hd_drained() variant
  block: call bdrv_set_backing_hd() while unlocked in
    bdrv_open_backing_file()
  block: mark bdrv_set_backing_hd() as GRAPH_UNLOCKED
  blockdev: avoid locking and draining multiple times in
    external_snapshot_abort()
  block: drop wrapper for bdrv_set_backing_hd_drained()
  block-backend: mark blk_drain_all() as GRAPH_UNLOCKED
  block/snapshot: mark bdrv_all_delete_snapshot() as GRAPH_UNLOCKED
  block/stream: mark stream_prepare() as GRAPH_UNLOCKED
  block: mark bdrv_reopen_queue() and bdrv_reopen_multiple() as
    GRAPH_UNLOCKED
  block: mark bdrv_inactivate() as GRAPH_RDLOCK and move drain to
    callers
  block: mark bdrv_inactivate_all() as GRAPH_UNLOCKED
  block: mark blk_remove_bs() as GRAPH_UNLOCKED
  block: mark blk_drain() as GRAPH_UNLOCKED
  block-backend: mark blk_io_limits_disable() as GRAPH_UNLOCKED
  block/commit: mark commit_abort() as GRAPH_UNLOCKED
  block: mark bdrv_new() as GRAPH_UNLOCKED
  block: mark bdrv_replace_child_bs() as GRAPH_UNLOCKED
  block: mark bdrv_insert_node() as GRAPH_UNLOCKED
  block: mark bdrv_drop_intermediate() as GRAPH_UNLOCKED
  block: mark bdrv_close_all() as GRAPH_UNLOCKED
  block: mark bdrv_close() as GRAPH_UNLOCKED
  block: mark bdrv_open_child_common() and its callers GRAPH_UNLOCKED
  blockjob: mark block_job_remove_all_bdrv() as GRAPH_UNLOCKED

 block.c                                       | 270 +++++++++++-------
 block/backup.c                                |   2 +-
 block/blklogwrites.c                          |   4 +-
 block/blkverify.c                             |   2 +-
 block/block-backend.c                         |  10 +-
 block/commit.c                                |  30 +-
 block/graph-lock.c                            |  40 ++-
 block/io.c                                    |   8 +-
 block/mirror.c                                |  12 +-
 block/monitor/block-hmp-cmds.c                |  15 +-
 block/qcow2.c                                 |   4 +-
 block/quorum.c                                |   4 +-
 block/replication.c                           |   7 +-
 block/snapshot.c                              |  28 +-
 block/stream.c                                |  23 +-
 block/vmdk.c                                  |  16 +-
 blockdev.c                                    | 174 +++++++----
 blockjob.c                                    |  10 +-
 include/block/block-global-state.h            |  67 +++--
 include/block/block-io.h                      |   2 +-
 include/block/block_int-common.h              |  36 ++-
 include/block/blockjob.h                      |   4 +-
 include/block/graph-lock.h                    |  11 +
 include/block/snapshot.h                      |   6 +-
 include/qemu/job.h                            |   4 +-
 include/system/block-backend-global-state.h   |   8 +-
 qemu-img.c                                    |   2 +
 .../qemu-iotests/tests/graph-changes-while-io | 102 ++++++-
 .../tests/graph-changes-while-io.out          |   4 +-
 tests/unit/test-bdrv-drain.c                  |  34 ++-
 tests/unit/test-bdrv-graph-mod.c              |  10 +-
 31 files changed, 642 insertions(+), 307 deletions(-)

-- 
2.39.5




^ permalink raw reply	[flat|nested] 60+ messages in thread

end of thread, other threads:[~2025-07-15 14:05 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-30 15:10 [PATCH v4 00/48] block: do not drain while holding the graph lock Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 01/48] block: remove outdated comments about AioContext locking Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 02/48] block: move drain outside of read-locked bdrv_reopen_queue_child() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 03/48] block/snapshot: move drain outside of read-locked bdrv_snapshot_delete() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 04/48] block: move drain outside of read-locked bdrv_inactivate_recurse() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 05/48] block: mark bdrv_parent_change_aio_context() GRAPH_RDLOCK Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 06/48] block: mark change_aio_ctx() callback and instances as GRAPH_RDLOCK(_PTR) Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 07/48] block: mark bdrv_child_change_aio_context() GRAPH_RDLOCK Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 08/48] block: move drain outside of bdrv_change_aio_context() and mark GRAPH_RDLOCK Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 09/48] block: move drain outside of bdrv_try_change_aio_context() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 10/48] block: move drain outside of bdrv_attach_child_common(_abort)() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 11/48] block: move drain outside of bdrv_set_backing_hd_drained() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 12/48] block: move drain outside of bdrv_root_attach_child() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 13/48] block: move drain outside of bdrv_attach_child() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 14/48] block: move drain outside of quorum_add_child() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 15/48] block: move drain outside of bdrv_root_unref_child() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 16/48] block: move drain outside of quorum_del_child() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 17/48] blockdev: drain while unlocked in internal_snapshot_action() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 18/48] blockdev: drain while unlocked in external_snapshot_action() Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 19/48] block: mark bdrv_drained_begin() and friends as GRAPH_UNLOCKED Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 20/48] iotests/graph-changes-while-io: remove image file after test Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 21/48] iotests/graph-changes-while-io: add test case with removal of lower snapshot Fiona Ebner
2025-05-30 15:10 ` [PATCH v4 22/48] block/io: remove duplicate GLOBAL_STATE_CODE() in bdrv_do_drained_end() Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 23/48] block: never use atomics to access bs->quiesce_counter Fiona Ebner
2025-06-02 14:45   ` Fiona Ebner
2025-07-01 11:24     ` Kevin Wolf
2025-05-30 15:11 ` [PATCH v4 24/48] block: add bdrv_graph_wrlock_drained() convenience wrapper Fiona Ebner
2025-07-01 11:37   ` Kevin Wolf
2025-05-30 15:11 ` [PATCH v4 25/48] block/mirror: switch to bdrv_set_backing_hd_drained() variant Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 26/48] block/commit: " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 27/48] block: call bdrv_set_backing_hd() while unlocked in bdrv_open_backing_file() Fiona Ebner
2025-07-01 13:13   ` Kevin Wolf
2025-05-30 15:11 ` [PATCH v4 28/48] block: mark bdrv_set_backing_hd() as GRAPH_UNLOCKED Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 29/48] blockdev: avoid locking and draining multiple times in external_snapshot_abort() Fiona Ebner
2025-06-02  8:56   ` Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 30/48] block: drop wrapper for bdrv_set_backing_hd_drained() Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 31/48] block-backend: mark blk_drain_all() as GRAPH_UNLOCKED Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 32/48] block/snapshot: mark bdrv_all_delete_snapshot() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 33/48] block/stream: mark stream_prepare() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 34/48] block: mark bdrv_reopen_queue() and bdrv_reopen_multiple() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 35/48] block: mark bdrv_inactivate() as GRAPH_RDLOCK and move drain to callers Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 36/48] block: mark bdrv_inactivate_all() as GRAPH_UNLOCKED Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 37/48] block: mark blk_remove_bs() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 38/48] block: mark blk_drain() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 39/48] block-backend: mark blk_io_limits_disable() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 40/48] block/commit: mark commit_abort() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 41/48] block: mark bdrv_new() " Fiona Ebner
2025-07-01 16:55   ` Kevin Wolf
2025-05-30 15:11 ` [PATCH v4 42/48] block: mark bdrv_replace_child_bs() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 43/48] block: mark bdrv_insert_node() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 44/48] block: mark bdrv_drop_intermediate() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 45/48] block: mark bdrv_close_all() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 46/48] block: mark bdrv_close() " Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 47/48] block: mark bdrv_open_child_common() and its callers GRAPH_UNLOCKED Fiona Ebner
2025-05-30 15:11 ` [PATCH v4 48/48] blockjob: mark block_job_remove_all_bdrv() as GRAPH_UNLOCKED Fiona Ebner
2025-06-03 14:54 ` [PATCH v4 00/48] block: do not drain while holding the graph lock Kevin Wolf
2025-06-04  7:38   ` Fiona Ebner
2025-07-01 17:16 ` Kevin Wolf
2025-07-14 13:43   ` Kevin Wolf
2025-07-15 13:24     ` Fiona Ebner

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).