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