From: "Denis V. Lunev" <den@openvz.org>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v3 2/5] dm-qcow2: fix backward merge of an inner image racing its reads
Date: Wed, 4 Nov 2026 19:01:02 +0100 [thread overview]
Message-ID: <20261104180105.1807820-3-den@openvz.org> (raw)
In-Reply-To: <20261104180105.1807820-1-den@openvz.org>
From: Denis V. Lunev <den@openvz.org>
set_backward_merge_in_process() sets the flag of an image other than the
top one without stopping submission, as nothing writes to it. It is
still read: a read of a cluster the top image does not map goes on to
the lower image, and when that image is writable its worker tests the
flag twice for the qio. When the merge starts between the two tests, the
first one, in handle_metadata(), skips prepare_backward_merge() and
leaves qio->ext NULL, the second one, in process_one_qio(), takes the
merge path and submit_top_delta_read() dereferences qio->ext.
Pause submission and switch the inflight refs for every image. The
pause flag is only tested on the top image, where all qios enter, so
pause that one; clearing the flag of an inner image paused the inner
image itself, which held nothing back.
Starting or stopping a merge of an inner image now pauses guest I/O to
the top image for the inflight ref switch, as a merge of the top image
always did.
Fixes: 8e522723a085 ("dm-qcow2: allow specifying depth to merge intermediate images")
https://virtuozzo.atlassian.net/browse/VSTOR-153049
Feature: dm-qcow2: block device over QCOW2 files driver
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Reviewed-by: Konstantin Khorenko <khorenko@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
drivers/md/dm-qcow2-cmd.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index e520d8fd6929..0e2c810f657b 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -149,34 +149,28 @@ static int qcow2_break_l1cow(struct qcow2_target *tgt, struct qcow2 *qcow2)
static void set_backward_merge_in_process(struct qcow2_target *tgt,
struct qcow2 *qcow2, bool set)
{
+ struct qcow2 *top = tgt->top;
LIST_HEAD(list);
- /*
- * There are no writes if it is not the top qcow2 image.
- * so we do not need to stop and flush requests when setting
- */
- if (qcow2 != tgt->top && set) {
- qcow2->backward_merge_in_process = set;
- return;
- }
-
/*
* To avoid race between allocations and COWS
* we completely stop queueing qios and wait
* for pending qios. Lock is for visability.
+ * A lower image has no guest writes, but it is read by
+ * qios of the top one, so stop the top image even then.
*/
- spin_lock_irq(&qcow2->deferred_lock);
- qcow2->pause_submitting_qios = true;
- spin_unlock_irq(&qcow2->deferred_lock);
+ spin_lock_irq(&top->deferred_lock);
+ top->pause_submitting_qios = true;
+ spin_unlock_irq(&top->deferred_lock);
qcow2_inflight_ref_switch(tgt);
/* queue is stopped */
- spin_lock_irq(&qcow2->deferred_lock);
+ spin_lock_irq(&top->deferred_lock);
WARN_ON_ONCE(qcow2->backward_merge_in_process == set);
qcow2->backward_merge_in_process = set;
- qcow2->pause_submitting_qios = false;
- list_splice_init(&qcow2->paused_qios, &list);
- spin_unlock_irq(&qcow2->deferred_lock);
+ top->pause_submitting_qios = false;
+ list_splice_init(&top->paused_qios, &list);
+ spin_unlock_irq(&top->deferred_lock);
qcow2_submit_embedded_qios(tgt, &list);
}
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-04 18:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 18:01 [Devel] [PATCH hci-8.1 v3 0/5] dm-qcow2: fix merges not stopping the users of the images they change Denis V. Lunev
2026-11-04 18:01 ` [Devel] [PATCH hci-8.1 v3 1/5] dm-qcow2: fix a failed refcount table relocation leaking md pages Denis V. Lunev
2026-11-04 18:52 ` no-reply
2026-11-04 18:01 ` Denis V. Lunev [this message]
2026-11-04 18:52 ` [Devel] [PATCH hci-8.1 v3 2/5] dm-qcow2: fix backward merge of an inner image racing its reads no-reply
2026-11-04 18:01 ` [Devel] [PATCH hci-8.1 v3 3/5] dm-qcow2: fix SEEK_HOLE/SEEK_DATA using an image freed by a merge Denis V. Lunev
2026-11-04 18:54 ` no-reply
2026-11-04 18:01 ` [Devel] [PATCH hci-8.1 v3 4/5] dm-qcow2: fix SEEK_HOLE/SEEK_DATA hanging after a failed metadata read Denis V. Lunev
2026-11-04 18:55 ` no-reply
2026-11-04 18:01 ` [Devel] [PATCH hci-8.1 v3 5/5] dm-qcow2: fix a refcount table relocation failing on a valid image Denis V. Lunev
2026-11-04 18:55 ` no-reply
2026-11-04 18:30 ` [Devel] [PATCH hci-8.1 v3 0/5] dm-qcow2: fix merges not stopping the users of the images they change 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=20261104180105.1807820-3-den@openvz.org \
--to=den@openvz.org \
--cc=andrey.zhadchenko@virtuozzo.com \
--cc=devel@openvz.org \
/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.