All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: qemu-devel@nongnu.org
Cc: qemu-stable@nongnu.org, Fiona Ebner <f.ebner@proxmox.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Michael Tokarev <mjt@tls.msk.ru>
Subject: [Stable-8.2.1 59/71] block/io: clear BDRV_BLOCK_RECURSE flag after recursing in bdrv_co_block_status
Date: Sun, 28 Jan 2024 20:50:22 +0300	[thread overview]
Message-ID: <20240128175035.812352-5-mjt@tls.msk.ru> (raw)
In-Reply-To: <qemu-stable-8.2.1-20240128204849@cover.tls.msk.ru>

From: Fiona Ebner <f.ebner@proxmox.com>

Using fleecing backup like in [0] on a qcow2 image (with metadata
preallocation) can lead to the following assertion failure:

> bdrv_co_do_block_status: Assertion `!(ret & BDRV_BLOCK_ZERO)' failed.

In the reproducer [0], it happens because the BDRV_BLOCK_RECURSE flag
will be set by the qcow2 driver, so the caller will recursively check
the file child. Then the BDRV_BLOCK_ZERO set too. Later up the call
chain, in bdrv_co_do_block_status() for the snapshot-access driver,
the assertion failure will happen, because both flags are set.

To fix it, clear the recurse flag after the recursive check was done.

In detail:

> #0  qcow2_co_block_status

Returns 0x45 = BDRV_BLOCK_RECURSE | BDRV_BLOCK_DATA |
BDRV_BLOCK_OFFSET_VALID.

> #1  bdrv_co_do_block_status

Because of the data flag, bdrv_co_do_block_status() will now also set
BDRV_BLOCK_ALLOCATED. Because of the recurse flag,
bdrv_co_do_block_status() for the bdrv_file child will be called,
which returns 0x16 = BDRV_BLOCK_ALLOCATED | BDRV_BLOCK_OFFSET_VALID |
BDRV_BLOCK_ZERO. Now the return value inherits the zero flag.

Returns 0x57 = BDRV_BLOCK_RECURSE | BDRV_BLOCK_DATA |
BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_ALLOCATED | BDRV_BLOCK_ZERO.

> #2  bdrv_co_common_block_status_above
> #3  bdrv_co_block_status_above
> #4  bdrv_co_block_status
> #5  cbw_co_snapshot_block_status
> #6  bdrv_co_snapshot_block_status
> #7  snapshot_access_co_block_status
> #8  bdrv_co_do_block_status

Return value is propagated all the way up to here, where the assertion
failure happens, because BDRV_BLOCK_RECURSE and BDRV_BLOCK_ZERO are
both set.

> #9  bdrv_co_common_block_status_above
> #10 bdrv_co_block_status_above
> #11 block_copy_block_status
> #12 block_copy_dirty_clusters
> #13 block_copy_common
> #14 block_copy_async_co_entry
> #15 coroutine_trampoline

[0]:

> #!/bin/bash
> rm /tmp/disk.qcow2
> ./qemu-img create /tmp/disk.qcow2 -o preallocation=metadata -f qcow2 1G
> ./qemu-img create /tmp/fleecing.qcow2 -f qcow2 1G
> ./qemu-img create /tmp/backup.qcow2 -f qcow2 1G
> ./qemu-system-x86_64 --qmp stdio \
> --blockdev qcow2,node-name=node0,file.driver=file,file.filename=/tmp/disk.qcow2 \
> --blockdev qcow2,node-name=node1,file.driver=file,file.filename=/tmp/fleecing.qcow2 \
> --blockdev qcow2,node-name=node2,file.driver=file,file.filename=/tmp/backup.qcow2 \
> <<EOF
> {"execute": "qmp_capabilities"}
> {"execute": "blockdev-add", "arguments": { "driver": "copy-before-write", "file": "node0", "target": "node1", "node-name": "node3" } }
> {"execute": "blockdev-add", "arguments": { "driver": "snapshot-access", "file": "node3", "node-name": "snap0" } }
> {"execute": "blockdev-backup", "arguments": { "device": "snap0", "target": "node1", "sync": "full", "job-id": "backup0" } }
> EOF

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-id: 20240116154839.401030-1-f.ebner@proxmox.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit 8a9be7992426c8920d4178e7dca59306a18c7a3a)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/block/io.c b/block/io.c
index 7e62fabbf5..d202987770 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2619,6 +2619,16 @@ bdrv_co_do_block_status(BlockDriverState *bs, bool want_zero,
                 ret |= (ret2 & BDRV_BLOCK_ZERO);
             }
         }
+
+        /*
+         * Now that the recursive search was done, clear the flag. Otherwise,
+         * with more complicated block graphs like snapshot-access ->
+         * copy-before-write -> qcow2, where the return value will be propagated
+         * further up to a parent bdrv_co_do_block_status() call, both the
+         * BDRV_BLOCK_RECURSE and BDRV_BLOCK_ZERO flags would be set, which is
+         * not allowed.
+         */
+        ret &= ~BDRV_BLOCK_RECURSE;
     }
 
 out:
-- 
2.39.2



  parent reply	other threads:[~2024-01-28 17:55 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-28 17:50 [Stable-8.2.1 00/71] Patch Round-up for stable 8.2.1, frozen on 2024-01-27 Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 55/71] acpi/tests/avocado/bits: wait for 200 seconds for SHUTDOWN event from bits VM Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 56/71] accel/tcg: Revert mapping of PCREL translation block to multiple virtual addresses Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 57/71] tcg/s390x: Fix encoding of VRIc, VRSa, VRSc insns Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 58/71] coroutine-ucontext: Save fake stack for pooled coroutine Michael Tokarev
2024-01-28 17:50 ` Michael Tokarev [this message]
2024-01-28 17:50 ` [Stable-8.2.1 60/71] linux-user: Fixed cpu restore with pc 0 on SIGBUS Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 61/71] linux-user/riscv: Adjust vdso signal frame cfa offsets Michael Tokarev
2024-03-03 10:33   ` Andreas Schwab
2024-03-03 11:06     ` Andreas Schwab
2024-03-03 12:58     ` Michael Tokarev
2024-03-03 15:11       ` Andreas Schwab
2024-03-06  4:27     ` Alistair Francis
2024-03-06 11:31       ` Andreas Schwab
2024-03-28 13:41       ` Andreas Schwab
2024-01-28 17:50 ` [Stable-8.2.1 62/71] tcg/arm: Fix SIGILL in tcg_out_qemu_st_direct Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 63/71] virtio-net: correctly copy vnet header when flushing TX Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 64/71] block/blklogwrites: Fix a bug when logging "write zeroes" operations Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 65/71] iotests: add filter_qmp_generated_node_ids() Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 66/71] iotests: port 141 to Python for reliable QMP testing Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 67/71] monitor: only run coroutine commands in qemu_aio_context Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 68/71] qtest: bump aspeed_smc-test timeout to 6 minutes Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 69/71] target/xtensa: fix OOB TLB entry access Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 70/71] target/arm: Fix A64 scalar SQSHRN and SQRSHRN Michael Tokarev
2024-01-28 17:50 ` [Stable-8.2.1 71/71] target/arm: Fix incorrect aa64_tidcp1 feature check Michael Tokarev

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=20240128175035.812352-5-mjt@tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=f.ebner@proxmox.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vsementsov@yandex-team.ru \
    /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.