thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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