<feed xmlns='http://www.w3.org/2005/Atom'>
<title>qemu/qemu.git/blockdev.c, branch master</title>
<subtitle>QEMU main repository</subtitle>
<id>https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/atom?h=master</id>
<link rel='self' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/'/>
<updated>2025-12-15T16:31:08+00:00</updated>
<entry>
<title>block: Fix BDS use after free during shutdown</title>
<updated>2025-12-15T16:31:08+00:00</updated>
<author>
<name>Kevin Wolf</name>
<email>kwolf@redhat.com</email>
</author>
<published>2025-12-15T15:07:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=307bc43095b8ab1765fd66c26003d5da06681c05'/>
<id>urn:sha1:307bc43095b8ab1765fd66c26003d5da06681c05</id>
<content type='text'>
During shutdown, blockdev_close_all_bdrv_states() drops any block node
references that are still owned by the monitor (i.e. the user). However,
in doing so, it forgot to also remove the node from monitor_bdrv_states
(which qmp_blockdev_del() correctly does), which means that later calls
of bdrv_first()/bdrv_next() will still return the (now stale) pointer to
the node.

Usually there is no such call after this point, but in some cases it can
happen. In the reported case, there was an ongoing migration, and the
migration thread wasn't shut down yet: migration_shutdown() called by
qemu_cleanup() doesn't actually wait for the migration to be shut down,
but may just move it to MIGRATION_STATUS_CANCELLING. The next time
migration_iteration_finish() runs, it sees the status and tries to
re-activate all block devices that migration may have previously
inactivated. This is where bdrv_first()/bdrv_next() get called and the
access to the already freed node happens.

It is debatable if migration_shutdown() should really return before
migration has settled, but leaving a dangling pointer in the list of
monitor-owned block nodes is clearly a bug either way and fixing it
solves the immediate problem, so fix it.

Cc: qemu-stable@nongnu.org
Reported-by: Thomas Huth &lt;thuth@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Message-ID: &lt;20251215150714.130214-1-kwolf@redhat.com&gt;
Reviewed-by: Thomas Huth &lt;thuth@redhat.com&gt;
Tested-by: Thomas Huth &lt;thuth@redhat.com&gt;
Reviewed-by: Stefan Hajnoczi &lt;stefanha@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
<entry>
<title>block: enable stats-intervals for storage devices</title>
<updated>2025-10-29T11:10:09+00:00</updated>
<author>
<name>Chandan Somani</name>
<email>csomani@redhat.com</email>
</author>
<published>2025-10-03T21:59:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=9f0c763e16c65d3aab5f3f17768df58321874685'/>
<id>urn:sha1:9f0c763e16c65d3aab5f3f17768df58321874685</id>
<content type='text'>
This patch allows stats-intervals to be used for storage
devices with the -device option. It accepts a list of interval
lengths in JSON format.

It configures and collects the stats in the BlockBackend layer
through the storage device that consumes the BlockBackend.

Signed-off-by: Chandan Somani &lt;csomani@redhat.com&gt;
Message-ID: &lt;20251003220039.1336663-1-csomani@redhat.com&gt;
Reviewed-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
<entry>
<title>block: mark bdrv_inactivate() as GRAPH_RDLOCK and move drain to callers</title>
<updated>2025-07-14T13:42:07+00:00</updated>
<author>
<name>Fiona Ebner</name>
<email>f.ebner@proxmox.com</email>
</author>
<published>2025-05-30T15:11:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=e2d9cc57905eaabd2b212de2f77993935a7fc271'/>
<id>urn:sha1:e2d9cc57905eaabd2b212de2f77993935a7fc271</id>
<content type='text'>
The function bdrv_inactivate() calls bdrv_drain_all_begin(), which
needs to be called with the graph unlocked, so either
bdrv_inactivate() should be marked as GRAPH_UNLOCKED or the drain
needs to be moved to the callers. The caller in
qmp_blockdev_set_active() requires that the locked section covers
bdrv_find_node() too, so the latter alternative is chosen.

Signed-off-by: Fiona Ebner &lt;f.ebner@proxmox.com&gt;
Message-ID: &lt;20250530151125.955508-36-f.ebner@proxmox.com&gt;
Reviewed-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
<entry>
<title>block: drop wrapper for bdrv_set_backing_hd_drained()</title>
<updated>2025-07-14T13:41:58+00:00</updated>
<author>
<name>Fiona Ebner</name>
<email>f.ebner@proxmox.com</email>
</author>
<published>2025-05-30T15:11:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=54eb59d668d6e4e7584188628ca44f3e9bd39d17'/>
<id>urn:sha1:54eb59d668d6e4e7584188628ca44f3e9bd39d17</id>
<content type='text'>
Nearly all callers (outside of the tests) are already using the
_drained() variant of the function. It doesn't seem worth keeping.
Simply adapt the remaining callers of bdrv_set_backing_hd() and rename
bdrv_set_backing_hd_drained() to bdrv_set_backing_hd().

Signed-off-by: Fiona Ebner &lt;f.ebner@proxmox.com&gt;
Message-ID: &lt;20250530151125.955508-31-f.ebner@proxmox.com&gt;
Reviewed-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
<entry>
<title>blockdev: avoid locking and draining multiple times in external_snapshot_abort()</title>
<updated>2025-07-14T13:41:57+00:00</updated>
<author>
<name>Fiona Ebner</name>
<email>f.ebner@proxmox.com</email>
</author>
<published>2025-05-30T15:11:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=c7af387c7b58f8ffcd412b175768f6ccd591b1fc'/>
<id>urn:sha1:c7af387c7b58f8ffcd412b175768f6ccd591b1fc</id>
<content type='text'>
By using the appropriate variants bdrv_set_backing_hd_drained() and
bdrv_try_change_aio_context_locked(), there only needs to be a single
drained and write-locked section in external_snapshot_abort().

Signed-off-by: Fiona Ebner &lt;f.ebner@proxmox.com&gt;
Message-ID: &lt;20250530151125.955508-30-f.ebner@proxmox.com&gt;
Reviewed-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
<entry>
<title>block: add bdrv_graph_wrlock_drained() convenience wrapper</title>
<updated>2025-07-14T13:40:58+00:00</updated>
<author>
<name>Fiona Ebner</name>
<email>f.ebner@proxmox.com</email>
</author>
<published>2025-05-30T15:11:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=6b89e851fabf78d7fb090bcdc71789ea1ef55c9b'/>
<id>urn:sha1:6b89e851fabf78d7fb090bcdc71789ea1ef55c9b</id>
<content type='text'>
Many write-locked sections are also drained sections. A new
bdrv_graph_wrunlock_drained() wrapper around bdrv_graph_wrunlock() is
introduced, which will begin a drained section first. A global
variable is used so bdrv_graph_wrunlock() knows if it also needs
to end such a drained section. Both the aio_poll call in
bdrv_graph_wrlock() and the aio_bh_poll() in bdrv_graph_wrunlock()
can re-enter a write-locked section. While for the latter, ending the
drain could be moved to before the call, the former requires that the
variable is a counter and not just a boolean.

Since the wrapper calls bdrv_drain_all_begin(), which must be called
with the graph unlocked, mark the wrapper as GRAPH_UNLOCKED too.

The switch to the new helpers was generated with the following
commands and then manually checked:
find . -name '*.c' -exec sed -i -z 's/bdrv_drain_all_begin();\n\s*bdrv_graph_wrlock();/bdrv_graph_wrlock_drained();/g' {} ';'
find . -name '*.c' -exec sed -i -z 's/bdrv_graph_wrunlock();\n\s*bdrv_drain_all_end();/bdrv_graph_wrunlock();/g' {} ';'

Suggested-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Signed-off-by: Fiona Ebner &lt;f.ebner@proxmox.com&gt;
Message-ID: &lt;20250530151125.955508-25-f.ebner@proxmox.com&gt;
[kwolf: Removed redundant GRAPH_UNLOCKED]
Reviewed-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
<entry>
<title>blockdev: drain while unlocked in external_snapshot_action()</title>
<updated>2025-06-04T16:16:34+00:00</updated>
<author>
<name>Fiona Ebner</name>
<email>f.ebner@proxmox.com</email>
</author>
<published>2025-05-30T15:10:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=195a8a946a8681dfe7e8aa8d49db415693db5311'/>
<id>urn:sha1:195a8a946a8681dfe7e8aa8d49db415693db5311</id>
<content type='text'>
This is in preparation to mark bdrv_drained_begin() as GRAPH_UNLOCKED.

Signed-off-by: Fiona Ebner &lt;f.ebner@proxmox.com&gt;
Message-ID: &lt;20250530151125.955508-19-f.ebner@proxmox.com&gt;
Reviewed-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
<entry>
<title>blockdev: drain while unlocked in internal_snapshot_action()</title>
<updated>2025-06-04T16:16:34+00:00</updated>
<author>
<name>Fiona Ebner</name>
<email>f.ebner@proxmox.com</email>
</author>
<published>2025-05-30T15:10:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=6f101614f95c889399352b8301917c0ac7919ae7'/>
<id>urn:sha1:6f101614f95c889399352b8301917c0ac7919ae7</id>
<content type='text'>
This is in preparation to mark bdrv_drained_begin() as GRAPH_UNLOCKED.

Signed-off-by: Fiona Ebner &lt;f.ebner@proxmox.com&gt;
Message-ID: &lt;20250530151125.955508-18-f.ebner@proxmox.com&gt;
Reviewed-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
<entry>
<title>block: move drain outside of quorum_add_child()</title>
<updated>2025-06-04T16:16:34+00:00</updated>
<author>
<name>Fiona Ebner</name>
<email>f.ebner@proxmox.com</email>
</author>
<published>2025-05-30T15:10:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=0414930d3adfa89299eaea5ce92accab15d9fba5'/>
<id>urn:sha1:0414930d3adfa89299eaea5ce92accab15d9fba5</id>
<content type='text'>
This is part of resolving the deadlock mentioned in commit "block:
move draining out of bdrv_change_aio_context() and mark GRAPH_RDLOCK".

The quorum_add_child() callback runs under the graph lock, so it is
not allowed to drain. It is only called as the .bdrv_add_child()
callback, which is only called in the bdrv_add_child() function, which
also runs under the graph lock.

The bdrv_add_child() function is called by qmp_x_blockdev_change(),
where a drained section is introduced.

Signed-off-by: Fiona Ebner &lt;f.ebner@proxmox.com&gt;
Message-ID: &lt;20250530151125.955508-15-f.ebner@proxmox.com&gt;
Reviewed-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
<entry>
<title>block: move drain outside of bdrv_try_change_aio_context()</title>
<updated>2025-06-04T16:16:34+00:00</updated>
<author>
<name>Fiona Ebner</name>
<email>f.ebner@proxmox.com</email>
</author>
<published>2025-05-30T15:10:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.rulkc.org/pub/scm/virt/qemu/qemu.git/commit/?id=a1ea8eb5912256c0b2be16fae5d3786aebc80cb1'/>
<id>urn:sha1:a1ea8eb5912256c0b2be16fae5d3786aebc80cb1</id>
<content type='text'>
This is part of resolving the deadlock mentioned in commit "block:
move draining out of bdrv_change_aio_context() and mark GRAPH_RDLOCK".

Convert the function to a _locked() version that has to be called with
the graph lock held and add a convenience wrapper that has to be
called with the graph unlocked, which drains and takes the lock
itself. Since bdrv_try_change_aio_context() is global state code, the
wrapper is too.

Callers are adapted to use the appropriate variant, depending on
whether the caller already holds the lock. In the
test_set_aio_context() unit test, prior drains can be removed, because
draining already happens inside the new wrapper.

Note that bdrv_attach_child_common_abort(), bdrv_attach_child_common()
and bdrv_root_unref_child() hold the graph lock and are not actually
allowed to drain either. This will be addressed in the following
commits.

Functions like qmp_blockdev_mirror() query the nodes to act on before
draining and locking. In theory, draining could invalidate those nodes.
This kind of issue is not addressed by these commits.

Signed-off-by: Fiona Ebner &lt;f.ebner@proxmox.com&gt;
Reviewed-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
Message-ID: &lt;20250530151125.955508-10-f.ebner@proxmox.com&gt;
Signed-off-by: Kevin Wolf &lt;kwolf@redhat.com&gt;
</content>
</entry>
</feed>
