* [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target
@ 2026-11-18 23:37 Denis V. Lunev
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy() Denis V. Lunev
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Denis V. Lunev @ 2026-11-18 23:37 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis; +Cc: devel
dm-qcow2 never stops enospc_timer and event_work when a target is
destroyed. An ENOSPC write around a suspend leaves the timer armed, and
removing the device frees the target under it; the timer fires 20 s
later in __run_timers() on freed memory.
https://virtuozzo.atlassian.net/browse/VSTOR-155933
Tested in an HCI 8.2 VM: the crash reproduces on stock and not with the
series, and the ploop test suite passes in qcow2 and ploop formats.
Denis V. Lunev (2):
dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy()
dm-qcow2: arm enospc_timer under event_lock so suspend leaves none
behind
drivers/md/dm-qcow2-map.c | 3 +--
drivers/md/dm-qcow2-target.c | 3 +++
2 files changed, 4 insertions(+), 2 deletions(-)
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Devel] [PATCH hci-8.2 1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy()
2026-11-18 23:37 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target Denis V. Lunev
@ 2026-11-18 23:37 ` Denis V. Lunev
2026-11-18 23:43 ` no-reply
2026-11-19 16:26 ` Konstantin Khorenko
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind Denis V. Lunev
` (3 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Denis V. Lunev @ 2026-11-18 23:37 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis; +Cc: devel
From: Denis V. Lunev <den@openvz.org>
The destructor never stops enospc_timer or event_work.
qcow2_try_delay_enospc() arms the timer and queues the work after it
drops event_lock, and nothing orders that against
timer_delete_sync_try() in qcow2_presuspend(). A write that fails with
ENOSPC around the presuspend leaves the timer pending after the suspend.
Once the device is removed, the timer expires on the qcow2_target that
qcow2_dtr() freed, and __run_timers() walks the freed timer. A retry
that fails while the device suspends also queues event_work, and
qcow2_event_work() reads tgt->ti from the freed target the same way.
Shut the timer down at the start of qcow2_tgt_destroy(), as its handler
resubmits qios onto tgt->wq, and cancel the work after the deferred
activity is flushed and the workqueue destroyed, so nothing in the
teardown can queue it again. alloc_qcow2_target() sets both up before
it returns a target, so they are valid on every path that reaches the
destructor.
https://virtuozzo.atlassian.net/browse/VSTOR-155933
Fixes: 6e2ec304689f ("dm-qcow2: Pause IO and notify about ENOSPC events")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
drivers/md/dm-qcow2-target.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 4cd5f2c0ed36..2f792d823e7b 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -244,6 +244,8 @@ static void qcow2_tgt_destroy(struct qcow2_target *tgt)
struct qcow2 *lower, *qcow2 = tgt->top;
unsigned int i;
+ timer_shutdown_sync(&tgt->enospc_timer);
+
if (tgt->wq) {
/*
* All activity from DM bios are already done,
@@ -253,6 +255,7 @@ static void qcow2_tgt_destroy(struct qcow2_target *tgt)
/* Now kill the queue */
destroy_workqueue(tgt->wq);
}
+ cancel_work_sync(&tgt->event_work);
qcow2_merge_backward_cancel(tgt);
mempool_destroy(tgt->qio_pool);
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Devel] [PATCH hci-8.2 2/2] dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind
2026-11-18 23:37 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target Denis V. Lunev
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy() Denis V. Lunev
@ 2026-11-18 23:37 ` Denis V. Lunev
2026-11-18 23:42 ` no-reply
2026-11-19 16:26 ` Konstantin Khorenko
2026-11-19 8:32 ` [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target Alexander Ivanov
` (2 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Denis V. Lunev @ 2026-11-18 23:37 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis; +Cc: devel
From: Denis V. Lunev <den@openvz.org>
qcow2_try_delay_enospc() queues the qio on enospc_qios under event_lock
but arms enospc_timer and queues event_work only after the unlock. An
endio that stalls in between lets qcow2_presuspend() set wants_suspend,
take the qio and resubmit it, and the retry fail and complete the
request. The endio then arms the timer on the suspended target with
nothing left to retry. postsuspend waits for the endio through its
inflight reference, but not for the timer, so the timer stays armed for
ENOSPC_TIMEOUT_JI after the suspend.
Arm the timer and queue the work before dropping event_lock.
qcow2_set_wants_suspend() sets wants_suspend under the same lock, so
either presuspend finds the qio with the timer already armed and runs
it, or the endio sees the flag and its caller completes the request.
The path runs only on ENOSPC.
https://virtuozzo.atlassian.net/browse/VSTOR-155933
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
drivers/md/dm-qcow2-map.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 32373114580e..ec07bcce6150 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4584,11 +4584,10 @@ static bool qcow2_try_delay_enospc(struct qcow2_target *tgt, struct qcow2_rq *qr
tgt->event_enospc = true;
list_add_tail(&qio->link, &tgt->enospc_qios);
unlock:
- spin_unlock_irqrestore(&tgt->event_lock, flags);
-
if (delayed)
mod_timer(&tgt->enospc_timer, jiffies + ENOSPC_TIMEOUT_JI);
schedule_work(&tgt->event_work);
+ spin_unlock_irqrestore(&tgt->event_lock, flags);
return delayed;
}
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 2/2] dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind Denis V. Lunev
@ 2026-11-18 23:42 ` no-reply
2026-11-19 16:26 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: no-reply @ 2026-11-18 23:42 UTC (permalink / raw)
To: Denis V. Lunev, alexander.ivanov, vasileios.almpanis; +Cc: devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dm-qcow2: bug-fix commit lacks Fixes: trailer for 6e2ec304689f
--
commit 337a91b80d8571c54a02b3a45dee37a52bfd569a
Author: Denis V. Lunev <den@openvz.org>
> dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind
>
> qcow2_try_delay_enospc() queues the qio on enospc_qios under event_lock
> but arms enospc_timer and queues event_work only after the unlock. An
> endio that stalls in between lets qcow2_presuspend() set wants_suspend,
> take the qio and resubmit it, and the retry fail and complete the
> request. The endio then arms the timer on the suspended target with
> nothing left to retry. postsuspend waits for the endio through its
> inflight reference, but not for the timer, so the timer stays armed for
> ENOSPC_TIMEOUT_JI after the suspend.
>
> Arm the timer and queue the work before dropping event_lock.
> qcow2_set_wants_suspend() sets wants_suspend under the same lock, so
> either presuspend finds the qio with the timer already armed and runs
> it, or the endio sees the flag and its caller completes the request.
> The path runs only on ENOSPC.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-155933
>
> Feature: dm-qcow2: block device over QCOW2 files driver
> Signed-off-by: Denis V. Lunev <den@openvz.org>
[Severity: Low]
This fixes a real race, and the misordering was introduced by
6e2ec304689f ("dm-qcow2: Pause IO and notify about ENOSPC events"), which
added qcow2_try_delay_enospc() with spin_unlock_irqrestore() ahead of
mod_timer() and schedule_work(). Should this include:
Fixes: 6e2ec304689f ("dm-qcow2: Pause IO and notify about ENOSPC events")
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/20261118233705.3974832-1-den@openvz.org?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy()
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy() Denis V. Lunev
@ 2026-11-18 23:43 ` no-reply
2026-11-19 16:26 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: no-reply @ 2026-11-18 23:43 UTC (permalink / raw)
To: Denis V. Lunev, alexander.ivanov, vasileios.almpanis; +Cc: devel
> From: Denis V. Lunev <den@openvz.org>
>
> The destructor never stops enospc_timer or event_work.
> qcow2_try_delay_enospc() arms the timer and queues the work after it
> drops event_lock, and nothing orders that against
> timer_delete_sync_try() in qcow2_presuspend(). A write that fails with
> ENOSPC around the presuspend leaves the timer pending after the suspend.
> Once the device is removed, the timer expires on the qcow2_target that
> qcow2_dtr() freed, and __run_timers() walks the freed timer. A retry
> that fails while the device suspends also queues event_work, and
> qcow2_event_work() reads tgt->ti from the freed target the same way.
>
> Shut the timer down at the start of qcow2_tgt_destroy(), as its handler
> resubmits qios onto tgt->wq, and cancel the work after the deferred
> activity is flushed and the workqueue destroyed, so nothing in the
> teardown can queue it again. alloc_qcow2_target() sets both up before
> it returns a target, so they are valid on every path that reaches the
> destructor.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-155933
>
> Fixes: 6e2ec304689f ("dm-qcow2: Pause IO and notify about ENOSPC events")
> 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/20261118233705.3974832-1-den@openvz.org?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target
2026-11-18 23:37 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target Denis V. Lunev
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy() Denis V. Lunev
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind Denis V. Lunev
@ 2026-11-19 8:32 ` Alexander Ivanov
2026-11-19 16:26 ` Konstantin Khorenko
2026-11-19 16:26 ` Konstantin Khorenko
4 siblings, 0 replies; 10+ messages in thread
From: Alexander Ivanov @ 2026-11-19 8:32 UTC (permalink / raw)
To: Denis V. Lunev, vasileios.almpanis; +Cc: devel
LGTM
Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target
2026-11-18 23:37 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target Denis V. Lunev
` (2 preceding siblings ...)
2026-11-19 8:32 ` [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target Alexander Ivanov
@ 2026-11-19 16:26 ` Konstantin Khorenko
2026-11-19 16:26 ` Konstantin Khorenko
4 siblings, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:26 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying the series with these fixes on my side:
1. 1/2: split the first paragraph of the message: the race, then the
use-after-frees.
2. 2/2: added Fixes: 6e2ec304689f ("dm-qcow2: Pause IO and notify about
ENOSPC events"), as Sashiko asked.
3. 2/2: reworded "presuspend finds the qio with the timer already armed
and runs it".
On Thu, 19 Nov 2026 00:37:03 +0100, Denis V. Lunev wrote:
> Tested in an HCI 8.2 VM: the crash reproduces on stock and not with the
> series, and the ploop test suite passes in qcow2 and ploop formats.
How did you hit the window between the unlock and mod_timer()? It is a
few instructions wide. Please put the reproducer into VSTOR-155933.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy()
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy() Denis V. Lunev
2026-11-18 23:43 ` no-reply
@ 2026-11-19 16:26 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:26 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying with these fixes on my side:
- Item 1 of the cover letter reply: split the first paragraph of the
message.
On Thu, 19 Nov 2026 00:37:04 +0100, Denis V. Lunev wrote:
> timer_delete_sync_try() in qcow2_presuspend(). A write that fails with
> ENOSPC around the presuspend leaves the timer pending after the suspend.
It had seven sentences; the race and the two use-after-frees now go in
two paragraphs.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 2/2] dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind Denis V. Lunev
2026-11-18 23:42 ` no-reply
@ 2026-11-19 16:26 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:26 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying with these fixes on my side:
- Item 2 of the cover letter reply: added the Fixes: trailer.
- Item 3 of the cover letter reply: "presuspend finds the qio with the
timer already armed and runs it" -> "presuspend or the armed timer
resubmits the qio".
On Thu, 19 Nov 2026 00:37:05 +0100, Denis V. Lunev wrote:
> qcow2_set_wants_suspend() sets wants_suspend under the same lock, so
> either presuspend finds the qio with the timer already armed and runs
> it, or the endio sees the flag and its caller completes the request.
When the timer handler is running at that moment,
timer_delete_sync_try() returns -1 and presuspend runs nothing: the
re-armed timer resubmits the qio and the suspend waits for the request.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target
2026-11-18 23:37 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target Denis V. Lunev
` (3 preceding siblings ...)
2026-11-19 16:26 ` Konstantin Khorenko
@ 2026-11-19 16:26 ` Konstantin Khorenko
4 siblings, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:26 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis, Denis V. Lunev; +Cc: devel
On Thu, 19 Nov 2026 00:37:03 +0100, Denis V. Lunev wrote:
> dm-qcow2: fix the ENOSPC timer left armed on a removed target
>
> dm-qcow2 never stops enospc_timer and event_work when a target is
> destroyed. An ENOSPC write around a suspend leaves the timer armed, and
> removing the device frees the target under it; the timer fires 20 s
> later in __run_timers() on freed memory.
>
> [...]
Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.4.vz10, thanks!
[1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy()
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/34d2a673f0c9
[2/2] dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/6ff19961ee2c
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-19 16:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 23:37 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target Denis V. Lunev
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: stop enospc_timer and event_work in qcow2_tgt_destroy() Denis V. Lunev
2026-11-18 23:43 ` no-reply
2026-11-19 16:26 ` Konstantin Khorenko
2026-11-18 23:37 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: arm enospc_timer under event_lock so suspend leaves none behind Denis V. Lunev
2026-11-18 23:42 ` no-reply
2026-11-19 16:26 ` Konstantin Khorenko
2026-11-19 8:32 ` [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix the ENOSPC timer left armed on a removed target Alexander Ivanov
2026-11-19 16:26 ` Konstantin Khorenko
2026-11-19 16:26 ` Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox