Blame SOURCES/kvm-block-io-Update-BSC-only-if-want_zero-is-true.patch

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