All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2] dm-qcow2: fix a zeroed cluster under allocation reading as backing data
@ 2026-11-23 18:38 Denis V. Lunev
  2026-11-24 23:21 ` Andrey Zhadchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Denis V. Lunev @ 2026-11-23 18:38 UTC (permalink / raw)
  To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel

From: Denis V. Lunev <den@openvz.org>

On an image without extended L2 entries, parse_l2() zero-fills a read
of a cluster whose L2 entry is dirty or under writeback and returns as
for an unallocated cluster: the map takes the zero flag from the new
entry, which has none, and leaves data_clu_alloced unset.
process_read_qio() then sends the read to the backing image, which
overwrites the zeroes. So for a cluster that reads as zeroes through
the zero flag, with or without a preallocated host cluster, a read
racing the allocating write returns data of the backing image, which
the cluster never held.

Take the zero flag from the old entry instead. Only entries changed by
prepare_l1l2_allocation() get here, as the replacing updates lock the
index until their writeback is done. Such an entry was 0, or it had the
zero flag and was saved in pe_page, which is where
revert_l_entries_update() takes the old entries from. A read of a zero
flagged cluster now returns zeroes, and one of an unallocated cluster
still reads through to the backing image, its old content.
process_read_qio() does the zero-fill, so parse_l2() no longer does it.

Delaying the read until the writeback is done would also work, but it
would lose the fast zero-fill of a cluster under allocation.

https://virtuozzo.atlassian.net/browse/VSTOR-156741

Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
Depends on "dm-qcow2: fix a SEEK_DATA/SEEK_HOLE oops on a cluster under
allocation":
http://lore.virtuozzo.com/kernel/20261123153805.128513-1-den@openvz.org/

 drivers/md/dm-qcow2-map.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 06902a4830b7..248c79705a43 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -1952,22 +1952,27 @@ static loff_t parse_l2(struct qcow2 *qcow2, struct qcow2_map *map,
 						  qio, wants_alloc))
 			goto out;
 		/*
-		 * When cluster is under allocation, READ should see zeroes.
-		 * On writeback, we could delay READ like for WRITE is done,
-		 * but fast zeroing may be useful optimizations on big
-		 * clusters (say, 1Mb).
+		 * When cluster is under allocation, READ sees the old content:
+		 * zeroes, or the lower delta if the old entry was unallocated.
+		 * The old entry is in pe_page if it had the zero flag, and it
+		 * is 0 otherwise.
 		 * In case of md is dirty, WRITE is not delayed. It becomes
 		 * referred to md->wbd in perform_rw_mapped(), and it runs
 		 * in parallel with md writeback (accompanying qio).
 		 */
 		if (!write && dirty_or_writeback(qcow2, l2->md, l2->index_in_page)) {
+			struct page *pe_page = l2->md->wbd->pe_page;
+			u64 old = 0;
+
 			if ((*qio)->queue_list_id == QLIST_SEEK) {
 				/* No pages to zero: wait for the entry to settle */
 				list_add_tail(&(*qio)->link, &l2->md->wait_list);
 				*qio = NULL;
-			} else {
-				perform_zero_read(*qio, (*qio)->bi_iter.bi_size);
+				goto out;
 			}
+			if (pe_page)
+				old = get_u64_from_be_page(pe_page, l2->index_in_page);
+			map->all_zeroes = old & L2_READS_ALL_ZEROES;
 			goto out;
 		}
 	} else {
-- 
2.55.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30 13:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 18:38 [Devel] [PATCH hci-8.2] dm-qcow2: fix a zeroed cluster under allocation reading as backing data Denis V. Lunev
2026-11-24 23:21 ` Andrey Zhadchenko
2026-11-30 13:22 ` Konstantin Khorenko
2026-11-30 13:23 ` Konstantin Khorenko

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.