432cb7
From 4c6eff78f4b31ec4bd7b42440396760d19fde63e Mon Sep 17 00:00:00 2001
432cb7
From: Hanna Reitz <hreitz@redhat.com>
432cb7
Date: Tue, 18 Jan 2022 17:59:59 +0100
432cb7
Subject: [PATCH 6/7] block/io: Update BSC only if want_zero is true
432cb7
432cb7
RH-Author: Hanna Reitz <hreitz@redhat.com>
432cb7
RH-MergeRequest: 112: block/io: Update BSC only if want_zero is true
432cb7
RH-Commit: [1/2] a202de1f52110d1e871c3b5b58f2d9e9b5d17570
432cb7
RH-Bugzilla: 2041480
432cb7
RH-Acked-by: Eric Blake <eblake@redhat.com>
432cb7
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
432cb7
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
432cb7
432cb7
We update the block-status cache whenever we get new information from a
432cb7
bdrv_co_block_status() call to the block driver.  However, if we have
432cb7
passed want_zero=false to that call, it may flag areas containing zeroes
432cb7
as data, and so we would update the block-status cache with wrong
432cb7
information.
432cb7
432cb7
Therefore, we should not update the cache with want_zero=false.
432cb7
432cb7
Reported-by: Nir Soffer <nsoffer@redhat.com>
432cb7
Fixes: 0bc329fbb00 ("block: block-status cache for data regions")
432cb7
Reviewed-by: Nir Soffer <nsoffer@redhat.com>
432cb7
Cc: qemu-stable@nongnu.org
432cb7
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
432cb7
Message-Id: <20220118170000.49423-2-hreitz@redhat.com>
432cb7
Reviewed-by: Eric Blake <eblake@redhat.com>
432cb7
Signed-off-by: Eric Blake <eblake@redhat.com>
432cb7
(cherry picked from commit 113b727ce788335cf76f65355d670c9bc130fd75)
432cb7
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
432cb7
---
432cb7
 block/io.c | 6 +++++-
432cb7
 1 file changed, 5 insertions(+), 1 deletion(-)
432cb7
432cb7
diff --git a/block/io.c b/block/io.c
432cb7
index bb0a254def..4e4cb556c5 100644
432cb7
--- a/block/io.c
432cb7
+++ b/block/io.c
432cb7
@@ -2497,8 +2497,12 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
432cb7
              * non-protocol nodes, and then it is never used.  However, filling
432cb7
              * the cache requires an RCU update, so double check here to avoid
432cb7
              * such an update if possible.
432cb7
+             *
432cb7
+             * Check want_zero, because we only want to update the cache when we
432cb7
+             * have accurate information about what is zero and what is data.
432cb7
              */
432cb7
-            if (ret == (BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID) &&
432cb7
+            if (want_zero &&
432cb7
+                ret == (BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID) &&
432cb7
                 QLIST_EMPTY(&bs->children))
432cb7
             {
432cb7
                 /*
432cb7
-- 
432cb7
2.27.0
432cb7