[Devel] [PATCH hci-8.2 v2 5/8] dm-qcow2: fix qcow2_flush_deferred_activity() skipping a running timer

Denis V. Lunev den at openvz.org
Mon Nov 23 18:36:37 MSK 2026


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

qcow2_flush_deferred_activity() runs the slow writeback timer callback
itself in each of its two passes, so that dirty R1/R2 pages are
written, but skips that when timer_delete_sync_try() finds the callback
running on another CPU. A callback skipped in the first pass is over by
the second, as the inflight reference switch in between waits for an
RCU grace period. The timer can however be rearmed by an R1/R2 page
that the first pass failed to write with ENOSPC, and expire just as the
second pass starts. That callback queues the worker after the last
flush_workqueue(), so the pages are written after the flush returns:
after suspend has cleared the dirty bit of the image, or, at backward
merge complete, on an image that is already freed.

Wait for the callback with timer_delete_sync() and then run it
unconditionally. Every caller can sleep and none holds md_pages_lock.

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

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 at openvz.org>
---
 drivers/md/dm-qcow2-target.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index f839b444b328..2a51beaebcab 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -177,8 +177,8 @@ void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2
 	/* Do not redirty R1/R2 failed with ENOSPC on the last pass */
 	for (i = 0; i < 2; i++) {
 		WRITE_ONCE(qcow2->md_wb_no_retry, i == 1);
-		if (timer_delete_sync_try(&qcow2->slow_wb_timer) != -1)
-			qcow2_slow_wb_timer_fn(&qcow2->slow_wb_timer);
+		timer_delete_sync(&qcow2->slow_wb_timer);
+		qcow2_slow_wb_timer_fn(&qcow2->slow_wb_timer);
 		/* Start md writeback */
 		flush_workqueue(tgt->wq);
 		/* Wait AIO of md wb */
-- 
2.55.0



More information about the Devel mailing list