* [Devel] [PATCH hci-8.2 v2] dm-qcow2: fix stale host data showing in a zero cluster after a write
@ 2026-11-24 12:46 Denis V. Lunev
2026-11-24 13:16 ` Konstantin Khorenko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Denis V. Lunev @ 2026-11-24 12:46 UTC (permalink / raw)
To: andrey.zhadchenko, alexander.ivanov, vasileios.almpanis; +Cc: devel
From: Denis V. Lunev <den@openvz.org>
An L2 entry with the zero flag may keep its host cluster, and a zero
subcluster of an extended L2 entry keeps its part of the host cluster.
Their host blocks may hold stale data: qemu leaves it there after a
zero write without unmap. An unallocated subcluster of an allocated
cluster may hold stale data as well, since qemu allocates a cluster for
a write into one subcluster and may reuse a freed one for it. A write
that covers such a unit only in part drops the zero flag or bit, or
sets the alloc bit, but writes only its own range, so the rest of the
unit reads back the stale data instead of zeroes:
prepare_l1l2_allocation() reuses the host cluster as it is, and the
backing file COW of a write with one border in an unallocated
subcluster and the other in a zero subcluster copies only the
unallocated one.
Send such a write through the sliced COW, as a write with a border in
an unallocated unit over a backing image already goes; an unallocated
subcluster is taken only when the write starts outside the backing data.
The slices come from the map as zeroes, with no read from disk, and are
written into the host cluster in place together with the data, so the
cluster stays where it is. only_set_ext_l2 cannot mark such an in-place
write on an image without extended L2 entries, where the L2 entry must
still be rewritten to drop the zero flag, so qio_ext gets cow_in_place,
set in both modes.
As in qemu, the first partial write into such a unit now writes the
whole unit. On an image with extended L2 entries and no backing data
this includes the first partial write into each subcluster of a cluster
dm-qcow2 allocated and zeroed itself, which the driver cannot tell from
one allocated by qemu.
https://virtuozzo.atlassian.net/browse/VSTOR-156774
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>
---
v2: also cover an unallocated subcluster of an allocated cluster without
backing data, share the border mask helper with
qio_border_is_inside_unmapped_unit(), leave the unchanged lines alone
and reword the message, per Konstantin's review.
v1: http://lore.virtuozzo.com/kernel/20261123191317.199611-1-den@openvz.org/
drivers/md/dm-qcow2-map.c | 87 ++++++++++++++++++++++++++++++---------
drivers/md/dm-qcow2.h | 1 +
2 files changed, 69 insertions(+), 19 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 853e7a1230ee..2ab14fd939c8 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -56,7 +56,7 @@ struct qcow2_map {
* read" or "sublu is not allocated" may be set).
*/
bool data_clu_alloced:1;
- bool backing_file_cow:1;
+ bool sliced_cow:1;
u32 compressed_sectors;
u32 subclus_mask;
@@ -1756,14 +1756,28 @@ static u32 qio_all_zeroes_size(struct qcow2 *qcow2, struct qio *qio,
return qio_subclus_covered_start_size(qcow2, qio, map->ext_l2 >> 32);
}
+/* Subclusters of @mask that a border of @qio falls inside */
+static u32 qio_border_subclus_mask(struct qcow2 *qcow2, struct qio *qio,
+ u32 mask)
+{
+ u64 start_off = bytes_off_in_cluster(qcow2, qio);
+ u64 end_off = start_off + qio->bi_iter.bi_size;
+ u8 start_bit, end_bit;
+ u32 ret = 0;
+
+ start_bit = qio_subclu_indexes(qcow2, qio, &end_bit);
+ if (SUBCLU_OFF(qcow2, start_off) && (mask & (1 << start_bit)))
+ ret |= 1 << start_bit;
+ if (SUBCLU_OFF(qcow2, end_off) && (mask & (1 << end_bit)))
+ ret |= 1 << end_bit;
+ return ret;
+}
+
static bool qio_border_is_inside_unmapped_unit(struct qcow2 *qcow2,
struct qio *qio,
struct qcow2_map *map)
{
- u64 start_off, end_off;
- u8 start_bit, end_bit;
u32 mapped_mask;
- bool ret;
if (WARN_ON_ONCE(!(map->level & L2_LEVEL)))
return false;
@@ -1774,14 +1788,44 @@ static bool qio_border_is_inside_unmapped_unit(struct qcow2 *qcow2,
if (!qcow2->ext_l2)
return !map->data_clu_alloced && !map->all_zeroes;
- start_bit = qio_subclu_indexes(qcow2, qio, &end_bit);
- start_off = bytes_off_in_cluster(qcow2, qio);
- end_off = start_off + qio->bi_iter.bi_size;
mapped_mask = (u32)map->ext_l2 | (map->ext_l2 >> 32);
+ return qio_border_subclus_mask(qcow2, qio, ~mapped_mask) != 0;
+}
- ret = SUBCLU_OFF(qcow2, start_off) != 0 && ((1 << start_bit) & ~mapped_mask);
- ret |= SUBCLU_OFF(qcow2, end_off) != 0 && ((1 << end_bit) & ~mapped_mask);
- return ret;
+/*
+ * Subclusters of an allocated cluster with a border of @qio inside, which
+ * read as zeroes over host blocks: zero ones, and unallocated ones when
+ * @qio starts outside the backing data.
+ */
+static u32 qio_border_stale_subclus_mask(struct qcow2 *qcow2, struct qio *qio,
+ struct qcow2_map *map)
+{
+ u32 zeroes = map->ext_l2 >> 32;
+ u32 mask = zeroes;
+
+ if (!map->data_clu_alloced || map->clu_is_cow)
+ return 0;
+ if (!maybe_mapped_in_lower_delta(qcow2, qio))
+ mask |= ~((u32)map->ext_l2 | zeroes);
+ return qio_border_subclus_mask(qcow2, qio, mask);
+}
+
+/*
+ * A zero cluster, or a zero or unallocated subcluster of an allocated
+ * cluster, may keep host blocks with stale data. A write that does not
+ * cover it entirely must zero the rest.
+ */
+static bool qio_border_is_inside_stale_unit(struct qcow2 *qcow2,
+ struct qio *qio,
+ struct qcow2_map *map)
+{
+ if (qio->bi_iter.bi_size == qcow2->clu_size)
+ return false;
+
+ if (!qcow2->ext_l2)
+ return map->prealloced;
+
+ return qio_border_stale_subclus_mask(qcow2, qio, map) != 0;
}
static bool qio_is_fully_alloced(struct qcow2 *qcow2, struct qio *qio,
@@ -3563,15 +3607,18 @@ static void submit_read_sliced_cow_clu(struct qcow2_map *map, struct qio *qio)
WARN_ON_ONCE(!(map->level & L2_LEVEL));
+ if (map->data_clu_alloced && !map->clu_is_cow) {
+ qio->ext->cow_in_place = true;
+ qio->ext->allocated_clu_pos = map->data_clu_pos;
+ }
+
if (qcow2->ext_l2) {
mask = map->ext_l2 & ~((u64)map->subclus_mask << 32);
qio->ext->new_ext_l2 = mask | map->subclus_mask;
- if (map->data_clu_alloced && !map->clu_is_cow) {
- qio->ext->only_set_ext_l2 = true;
- qio->ext->allocated_clu_pos = map->data_clu_pos;
- }
+ qio->ext->only_set_ext_l2 = qio->ext->cow_in_place;
qio->ext->cow_mask = calc_cow_mask(qcow2, map->ext_l2, qio,
true, map->clu_is_cow, false);
+ qio->ext->cow_mask |= qio_border_stale_subclus_mask(qcow2, qio, map);
}
submit_read_sliced_clu(map, qio, sliced_cow_read_complete);
@@ -3785,14 +3832,16 @@ static int handle_metadata(struct qcow2 *qcow2, struct qio **qio,
/* COW to compressed or shared with snapshot cluster */
ret = prepare_l1l2_replace(qcow2, *qio, map);
} else if ((map->level & L2_LEVEL) &&
- qio_border_is_inside_unmapped_unit(qcow2, *qio, map) &&
- maybe_mapped_in_lower_delta(qcow2, *qio)) {
+ ((qio_border_is_inside_unmapped_unit(qcow2, *qio, map) &&
+ maybe_mapped_in_lower_delta(qcow2, *qio)) ||
+ qio_border_is_inside_stale_unit(qcow2, *qio, map))) {
/*
* Backing file is about data COW, and it is
* never about metadata COW (unlike internal
* snapshots). Here is data COW on L2_LEVEL.
+ * A stale unit COWs zeroes over its host blocks.
*/
- map->backing_file_cow = true;
+ map->sliced_cow = true;
if (delay_if_l2_dirty(qcow2, map, qio))
ret = 0;
else
@@ -3937,7 +3986,7 @@ static void process_one_qio(struct qcow2 *qcow2, struct qio *qio)
} else { /* write */
if (unlikely(map.clu_is_cow && !(map.level & L2_LEVEL)))
submit_read_whole_cow_clu(&map, qio);
- else if (unlikely(map.clu_is_cow || map.backing_file_cow))
+ else if (unlikely(map.clu_is_cow || map.sliced_cow))
submit_read_sliced_cow_clu(&map, qio);
else
perform_rw_mapped(&map, qio);
@@ -4375,7 +4424,7 @@ static void process_cow_data_write(struct qcow2 *qcow2, struct list_head *cow_li
break;
ext = qio->ext;
- if (ext->only_set_ext_l2) {
+ if (ext->cow_in_place) {
WARN_ON_ONCE(ext->lx_level != L2_LEVEL);
pos = ext->allocated_clu_pos;
goto submit;
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 4acddbe7c95f..c2460c2bea06 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -325,6 +325,7 @@ struct qio_ext {
u64 new_ext_l2;
u32 cow_mask;
bool only_set_ext_l2:1;
+ bool cow_in_place:1;
bool set_all_zeroes:1;
bool wait_writers:1;
--
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* Re: [Devel] [PATCH hci-8.2 v2] dm-qcow2: fix stale host data showing in a zero cluster after a write
2026-11-24 12:46 [Devel] [PATCH hci-8.2 v2] dm-qcow2: fix stale host data showing in a zero cluster after a write Denis V. Lunev
@ 2026-11-24 13:16 ` Konstantin Khorenko
2026-11-25 1:07 ` Andrey Zhadchenko
2026-12-01 0:06 ` no-reply
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-11-24 13:16 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
I won't apply this version, please send v3 with the changes below.
On Tue, 24 Nov 2026 13:46:13 +0100, Denis V. Lunev wrote:
> dm-qcow2: fix stale host data showing in a zero cluster after a write
- Keep the unallocated subcluster case, but do not pay for it on
clusters dm-qcow2 allocated itself: their unused subclusters are
zero on disk already.
- Commit message: split the last sentence of the first paragraph, and
the subject should cover unallocated subclusters too.
All four v1 asks are done, and the code is correct. The problem is the
price of my first v1 ask as it is done here.
> + if (!maybe_mapped_in_lower_delta(qcow2, qio))
> + mask |= ~((u32)map->ext_l2 | zeroes);
prepare_l1l2_allocation() sets the alloc bits of the written
subclusters only, so every cluster dm-qcow2 allocates has unallocated
subclusters, and without backing data each of them now takes this
path. ploop creates images with 1M clusters and extended L2 entries,
so this is the default CT disk without snapshots. A 4K write into a
fresh subcluster used to set the bit and go out at once, with the L2
writeback in parallel. Now it waits for a dirty L2, locks the L2 entry
so all I/O to the 1M cluster waits, writes 32K of which 28K are
zeroes, and completes only after its own L2 writeback. That is up to
31 times per cluster, and host holes become allocated blocks.
Those zeroes buy nothing: prepare_unused_cluster() punches a reused
area below file_preallocated_area_start and the area past it is fresh,
and our own discard punches too. Stale data can come only from
clusters qemu wrote. One way: when dm-qcow2 allocates a cluster that
has no backing data, set all its alloc bits at once (the check must
look at the cluster, not at the write start); then only qemu-written
clusters take the COW. If you see a cheaper way, fine too, but please
show fio numbers for 4K random and sequential writes on a fresh 1M
extended L2 image without backing, before and after.
> unit reads back the stale data instead of zeroes:
> prepare_l1l2_allocation() reuses the host cluster as it is, and the
> backing file COW of a write with one border in an unallocated
> subcluster and the other in a zero subcluster copies only the
> unallocated one.
This sentence runs eight lines and joins two mechanisms with a colon;
please split it. The subject still says "zero cluster" while the patch
now fixes unallocated subclusters as well.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Devel] [PATCH hci-8.2 v2] dm-qcow2: fix stale host data showing in a zero cluster after a write
2026-11-24 12:46 [Devel] [PATCH hci-8.2 v2] dm-qcow2: fix stale host data showing in a zero cluster after a write Denis V. Lunev
2026-11-24 13:16 ` Konstantin Khorenko
@ 2026-11-25 1:07 ` Andrey Zhadchenko
2026-12-01 0:06 ` no-reply
2 siblings, 0 replies; 4+ messages in thread
From: Andrey Zhadchenko @ 2026-11-25 1:07 UTC (permalink / raw)
To: Denis V. Lunev, alexander.ivanov, vasileios.almpanis; +Cc: devel
On 11/24/26 13:46, Denis V. Lunev wrote:
> From: Denis V. Lunev <den@openvz.org>
>
> An L2 entry with the zero flag may keep its host cluster, and a zero
> subcluster of an extended L2 entry keeps its part of the host cluster.
> Their host blocks may hold stale data: qemu leaves it there after a
> zero write without unmap. An unallocated subcluster of an allocated
> cluster may hold stale data as well, since qemu allocates a cluster for
> a write into one subcluster and may reuse a freed one for it. A write
> that covers such a unit only in part drops the zero flag or bit, or
> sets the alloc bit, but writes only its own range, so the rest of the
> unit reads back the stale data instead of zeroes:
> prepare_l1l2_allocation() reuses the host cluster as it is, and the
> backing file COW of a write with one border in an unallocated
> subcluster and the other in a zero subcluster copies only the
> unallocated one.
>
> Send such a write through the sliced COW, as a write with a border in
> an unallocated unit over a backing image already goes; an unallocated
> subcluster is taken only when the write starts outside the backing data.
> The slices come from the map as zeroes, with no read from disk, and are
> written into the host cluster in place together with the data, so the
> cluster stays where it is. only_set_ext_l2 cannot mark such an in-place
> write on an image without extended L2 entries, where the L2 entry must
> still be rewritten to drop the zero flag, so qio_ext gets cow_in_place,
> set in both modes.
>
> As in qemu, the first partial write into such a unit now writes the
> whole unit. On an image with extended L2 entries and no backing data
> this includes the first partial write into each subcluster of a cluster
> dm-qcow2 allocated and zeroed itself, which the driver cannot tell from
> one allocated by qemu.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-156774
>
> 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>
> ---
> v2: also cover an unallocated subcluster of an allocated cluster without
> backing data, share the border mask helper with
> qio_border_is_inside_unmapped_unit(), leave the unchanged lines alone
> and reword the message, per Konstantin's review.
> v1: http://lore.virtuozzo.com/kernel/20261123191317.199611-1-den@openvz.org/
>
> drivers/md/dm-qcow2-map.c | 87 ++++++++++++++++++++++++++++++---------
> drivers/md/dm-qcow2.h | 1 +
> 2 files changed, 69 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
> index 853e7a1230ee..2ab14fd939c8 100644
> --- a/drivers/md/dm-qcow2-map.c
> +++ b/drivers/md/dm-qcow2-map.c
> @@ -56,7 +56,7 @@ struct qcow2_map {
> * read" or "sublu is not allocated" may be set).
> */
> bool data_clu_alloced:1;
> - bool backing_file_cow:1;
> + bool sliced_cow:1;
>
> u32 compressed_sectors;
> u32 subclus_mask;
> @@ -1756,14 +1756,28 @@ static u32 qio_all_zeroes_size(struct qcow2 *qcow2, struct qio *qio,
> return qio_subclus_covered_start_size(qcow2, qio, map->ext_l2 >> 32);
> }
>
> +/* Subclusters of @mask that a border of @qio falls inside */
> +static u32 qio_border_subclus_mask(struct qcow2 *qcow2, struct qio *qio,
> + u32 mask)
> +{
> + u64 start_off = bytes_off_in_cluster(qcow2, qio);
> + u64 end_off = start_off + qio->bi_iter.bi_size;
> + u8 start_bit, end_bit;
> + u32 ret = 0;
> +
> + start_bit = qio_subclu_indexes(qcow2, qio, &end_bit);
> + if (SUBCLU_OFF(qcow2, start_off) && (mask & (1 << start_bit)))
> + ret |= 1 << start_bit;
nit: explicit 1U is better here
> + if (SUBCLU_OFF(qcow2, end_off) && (mask & (1 << end_bit)))
> + ret |= 1 << end_bit;
> + return ret;
> +}
> +
> static bool qio_border_is_inside_unmapped_unit(struct qcow2 *qcow2,
> struct qio *qio,
> struct qcow2_map *map)
> {
> - u64 start_off, end_off;
> - u8 start_bit, end_bit;
> u32 mapped_mask;
> - bool ret;
>
> if (WARN_ON_ONCE(!(map->level & L2_LEVEL)))
> return false;
> @@ -1774,14 +1788,44 @@ static bool qio_border_is_inside_unmapped_unit(struct qcow2 *qcow2,
> if (!qcow2->ext_l2)
> return !map->data_clu_alloced && !map->all_zeroes;
>
> - start_bit = qio_subclu_indexes(qcow2, qio, &end_bit);
> - start_off = bytes_off_in_cluster(qcow2, qio);
> - end_off = start_off + qio->bi_iter.bi_size;
> mapped_mask = (u32)map->ext_l2 | (map->ext_l2 >> 32);
> + return qio_border_subclus_mask(qcow2, qio, ~mapped_mask) != 0;
> +}
>
> - ret = SUBCLU_OFF(qcow2, start_off) != 0 && ((1 << start_bit) & ~mapped_mask);
> - ret |= SUBCLU_OFF(qcow2, end_off) != 0 && ((1 << end_bit) & ~mapped_mask);
> - return ret;
> +/*
> + * Subclusters of an allocated cluster with a border of @qio inside, which
> + * read as zeroes over host blocks: zero ones, and unallocated ones when
> + * @qio starts outside the backing data.
> + */
> +static u32 qio_border_stale_subclus_mask(struct qcow2 *qcow2, struct qio *qio,
> + struct qcow2_map *map)
> +{
> + u32 zeroes = map->ext_l2 >> 32;
> + u32 mask = zeroes;
> +
> + if (!map->data_clu_alloced || map->clu_is_cow)
> + return 0;
> + if (!maybe_mapped_in_lower_delta(qcow2, qio))
> + mask |= ~((u32)map->ext_l2 | zeroes);
I think this is unneeded. We can just use ~(u32)map->ext_l2 as mask in
qio_border_subclus_mask():
- In submit_read_sliced_cow_clu(), calc_cow_mask(..., true, ...)
already sets unallocated border subclusters unconditionally
- In handle_metadata(), when maybe_mapped_in_lower_delta() is true,
unallocated border subclusters are already matched by
qio_border_is_inside_unmapped_unit() && maybe_mapped_in_lower_delta()
(which is also what catches a qio that starts < lower->hdr.size in an
allocated subcluster and ends > lower->hdr.size inside an unallocated
subcluster)
> + return qio_border_subclus_mask(qcow2, qio, mask);
> +}
> +
> +/*
> + * A zero cluster, or a zero or unallocated subcluster of an allocated
> + * cluster, may keep host blocks with stale data. A write that does not
> + * cover it entirely must zero the rest.
> + */
> +static bool qio_border_is_inside_stale_unit(struct qcow2 *qcow2,
> + struct qio *qio,
> + struct qcow2_map *map)
> +{
> + if (qio->bi_iter.bi_size == qcow2->clu_size)
> + return false;
> +
> + if (!qcow2->ext_l2)
> + return map->prealloced;
> +
> + return qio_border_stale_subclus_mask(qcow2, qio, map) != 0;
> }
>
> static bool qio_is_fully_alloced(struct qcow2 *qcow2, struct qio *qio,
> @@ -3563,15 +3607,18 @@ static void submit_read_sliced_cow_clu(struct qcow2_map *map, struct qio *qio)
>
> WARN_ON_ONCE(!(map->level & L2_LEVEL));
>
> + if (map->data_clu_alloced && !map->clu_is_cow) {
> + qio->ext->cow_in_place = true;
> + qio->ext->allocated_clu_pos = map->data_clu_pos;
> + }
> +
> if (qcow2->ext_l2) {
> mask = map->ext_l2 & ~((u64)map->subclus_mask << 32);
> qio->ext->new_ext_l2 = mask | map->subclus_mask;
> - if (map->data_clu_alloced && !map->clu_is_cow) {
> - qio->ext->only_set_ext_l2 = true;
> - qio->ext->allocated_clu_pos = map->data_clu_pos;
> - }
> + qio->ext->only_set_ext_l2 = qio->ext->cow_in_place;
With this patch, every first partial write into a subcluster of an
allocated ext_l2 cluster sets ext->only_set_ext_l2 = true. In
process_indexes_write() WARN_ON_ONCE(ret < 0) assumed the first
prepare_l_entry_update() already allocated lx_md->wbd and wbd->pe_page.
When ext->only_set_ext_l2 jumps to set_ext_l2:, that call is the first
one and can return -ENOMEM (alloc_wbd() / alloc_page()), which then
warns and either NULL-derefs lx_md->wbd or completes qio without
updating ext_l2.
Would be nice if you fix it as a separate patch.
> qio->ext->cow_mask = calc_cow_mask(qcow2, map->ext_l2, qio,
> true, map->clu_is_cow, false);
> + qio->ext->cow_mask |= qio_border_stale_subclus_mask(qcow2, qio, map);
> }
>
> submit_read_sliced_clu(map, qio, sliced_cow_read_complete);
> @@ -3785,14 +3832,16 @@ static int handle_metadata(struct qcow2 *qcow2, struct qio **qio,
> /* COW to compressed or shared with snapshot cluster */
> ret = prepare_l1l2_replace(qcow2, *qio, map);
> } else if ((map->level & L2_LEVEL) &&
> - qio_border_is_inside_unmapped_unit(qcow2, *qio, map) &&
> - maybe_mapped_in_lower_delta(qcow2, *qio)) {
> + ((qio_border_is_inside_unmapped_unit(qcow2, *qio, map) &&
> + maybe_mapped_in_lower_delta(qcow2, *qio)) ||
> + qio_border_is_inside_stale_unit(qcow2, *qio, map))) {
> /*
> * Backing file is about data COW, and it is
> * never about metadata COW (unlike internal
> * snapshots). Here is data COW on L2_LEVEL.
> + * A stale unit COWs zeroes over its host blocks.
> */
> - map->backing_file_cow = true;
> + map->sliced_cow = true;
> if (delay_if_l2_dirty(qcow2, map, qio))
> ret = 0;
> else
> @@ -3937,7 +3986,7 @@ static void process_one_qio(struct qcow2 *qcow2, struct qio *qio)
> } else { /* write */
> if (unlikely(map.clu_is_cow && !(map.level & L2_LEVEL)))
> submit_read_whole_cow_clu(&map, qio);
> - else if (unlikely(map.clu_is_cow || map.backing_file_cow))
> + else if (unlikely(map.clu_is_cow || map.sliced_cow))
> submit_read_sliced_cow_clu(&map, qio);
> else
> perform_rw_mapped(&map, qio);
> @@ -4375,7 +4424,7 @@ static void process_cow_data_write(struct qcow2 *qcow2, struct list_head *cow_li
> break;
> ext = qio->ext;
>
> - if (ext->only_set_ext_l2) {
> + if (ext->cow_in_place) {
> WARN_ON_ONCE(ext->lx_level != L2_LEVEL);
> pos = ext->allocated_clu_pos;
> goto submit;
> diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
> index 4acddbe7c95f..c2460c2bea06 100644
> --- a/drivers/md/dm-qcow2.h
> +++ b/drivers/md/dm-qcow2.h
> @@ -325,6 +325,7 @@ struct qio_ext {
> u64 new_ext_l2;
> u32 cow_mask;
> bool only_set_ext_l2:1;
> + bool cow_in_place:1;
copy-on-write-in-place sounds oxymoronic. I think you can remove this
and just check ext->allocated_clu_pos as it is set only from
submit_read_sliced_cow_clu.
Or at least rename this to something more appropriate like 'reuse_clu'
> bool set_all_zeroes:1;
> bool wait_writers:1;
>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [Devel] [PATCH hci-8.2 v2] dm-qcow2: fix stale host data showing in a zero cluster after a write
2026-11-24 12:46 [Devel] [PATCH hci-8.2 v2] dm-qcow2: fix stale host data showing in a zero cluster after a write Denis V. Lunev
2026-11-24 13:16 ` Konstantin Khorenko
2026-11-25 1:07 ` Andrey Zhadchenko
@ 2026-12-01 0:06 ` no-reply
2 siblings, 0 replies; 4+ messages in thread
From: no-reply @ 2026-12-01 0:06 UTC (permalink / raw)
To: Denis V. Lunev, andrey.zhadchenko, alexander.ivanov, vasileios.almpanis
Cc: devel
> From: Denis V. Lunev <den@openvz.org>
>
> An L2 entry with the zero flag may keep its host cluster, and a zero
> subcluster of an extended L2 entry keeps its part of the host cluster.
> Their host blocks may hold stale data: qemu leaves it there after a
> zero write without unmap. An unallocated subcluster of an allocated
> cluster may hold stale data as well, since qemu allocates a cluster for
> a write into one subcluster and may reuse a freed one for it. A write
> that covers such a unit only in part drops the zero flag or bit, or
> sets the alloc bit, but writes only its own range, so the rest of the
> unit reads back the stale data instead of zeroes:
> prepare_l1l2_allocation() reuses the host cluster as it is, and the
> backing file COW of a write with one border in an unallocated
> subcluster and the other in a zero subcluster copies only the
> unallocated one.
> [ ... ]
> https://virtuozzo.atlassian.net/browse/VSTOR-156774
>
> 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>
Sashiko has reviewed this patch and found no issues.
Carry the trailer below into the next revision and Sashiko will not review this patch again.
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261124124613.455047-1-den@openvz.org?part=1
_______________________________________________
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-12-01 0:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 12:46 [Devel] [PATCH hci-8.2 v2] dm-qcow2: fix stale host data showing in a zero cluster after a write Denis V. Lunev
2026-11-24 13:16 ` Konstantin Khorenko
2026-11-25 1:07 ` Andrey Zhadchenko
2026-12-01 0:06 ` no-reply
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.