All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
To: "Denis V. Lunev" <den@openvz.org>,
	alexander.ivanov@virtuozzo.com, vasileios.almpanis@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.2] dm-qcow2: fix a zeroed cluster under allocation reading as backing data
Date: Wed, 25 Nov 2026 00:21:48 +0100	[thread overview]
Message-ID: <f711a1ea-3c0b-428c-ba0d-fd2b63ec8039@virtuozzo.com> (raw)
In-Reply-To: <20261123183816.190058-1-den@openvz.org>

Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>

On 11/23/26 19:38, Denis V. Lunev wrote:
> 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 {

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

  reply	other threads:[~2026-11-24 23:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 18:38 Denis V. Lunev
2026-11-24 23:21 ` Andrey Zhadchenko [this message]
2026-11-30 13:22 ` Konstantin Khorenko
2026-11-30 13:23 ` Konstantin Khorenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f711a1ea-3c0b-428c-ba0d-fd2b63ec8039@virtuozzo.com \
    --to=andrey.zhadchenko@virtuozzo.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=devel@openvz.org \
    --cc=vasileios.almpanis@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.