From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
To: "Denis V. Lunev" <den@virtuozzo.com>,
"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 0/2] dm-qcow2: fix image I/O completions using a freed target
Date: Fri, 20 Nov 2026 03:22:44 +0100 [thread overview]
Message-ID: <aac508a5-d6bf-43d9-995c-244926c99904@virtuozzo.com> (raw)
In-Reply-To: <aeddcfc6-bd04-4b7d-bf25-f91158d5eb4e@virtuozzo.com>
On 11/19/26 15:50, Denis V. Lunev wrote:
> On 11/19/26 14:12, Andrey Zhadchenko wrote:
>> Nack, at least with the current commit messages.
>> I have not read the patches itself in detail, but the series fails to
>> address a simple question 'why add a new counter if inflight_ref
>> exists'. The correct way is to count such qios in inflight ref and the
>> patches does not explain why is it not possible.
>>
>> Best regards,
>> Andrey
>>
>> On 11/19/26 12:49, Denis V. Lunev wrote:
>>> Suspend waits only for the inflight references, so a completion in the
>>> backing file system's context can still free a helper qio into the
>>> target's pool, or queue work on its workqueue, after a remove has
>>> destroyed them. Make the destructor wait for image I/O completions,
>>> as the dm-ploop fix for VSTOR-155932 does, and queue the worker before
>>> the published qio can be ended.
>>>
>>> https://virtuozzo.atlassian.net/browse/VSTOR-156036
>>>
>>> Applies on top of the series "dm-qcow2: fix the ENOSPC timer left armed
>>> on a removed target".
>>>
>>> Tested in an HCI 8.2 VM with a completion held after its request ended:
>>> remove oopses in mempool_free() on stock and waits the hold out with
>>> the series, and the ploop test suite passes in qcow2 and ploop formats.
>>>
>>> Denis V. Lunev (2):
>>> dm-qcow2: fix image I/O completions running on a freed target
>>> dm-qcow2: queue the worker before dropping deferred_lock in
>>> completions
>>>
>>> drivers/md/dm-qcow2-map.c | 7 +++----
>>> drivers/md/dm-qcow2-target.c | 25 +++++++++++++++++++++++++
>>> drivers/md/dm-qcow2.h | 2 ++
>>> 3 files changed, 30 insertions(+), 4 deletions(-)
>>>
>
> It is possible, and the messages should have said why I did not do it.
> Let us agree on the design before I respin.
>
> Today only the request qios (qcow2_submit_embedded_qio()) and the md
> page qios hold an inflight reference. The qios the bug is about hold
> none: split children, the COW and sliced reads and writes, the
> compressed read, the backward merge aux qio and the merge service
> qios. Counting them in inflight_ref means a reference taken at each of
> those allocation sites from the owner's index, one for the service
> qios, and freeing the qio before the put in do_qio_endio(). That
> works, and suspend would then also wait for the completion tails.
>
> I put the reference at the one place every image I/O goes through
> instead: taken in qcow2_call_rw_iter() and dropped in
> qcow2_aio_do_completion() after ->complete() returns. It covers every
> qio type, including ones added later, without touching the allocation
> sites. The bug exists because helper qios were left out of the
> counting, and an inflight_ref per site invites the next one to be left
> out too. The completion tails it waits for only free memory into the
> target's pools, so it is enough for the destructor to wait for them;
> suspend does not need to. The dm-ploop fix for the same class
> (VSTOR-155932, in review) uses the same choke point.
>
> Which way do you prefer? The second patch, queueing the worker before
> dropping deferred_lock, is needed either way.
I don't like the new counter because it is a bandaid fix that will not
age well. It tries to solve a problem 'there is no rugpull after
endio_cb' but the problem is much bigger in general: we need to ensure
there are no places where we access potentially freed data. As dm-qcow2
does most of it's work from a single work item, we stumble upon this
problem from other various places: submission from user context, timers,
io completions. We are also planning to add more work types to dm-qcow2
so this problem will surely be bigger than just 'count everything that
has a completion'.
endio_cb is actually the easiest: looks like we can completely drop qio
argument from endio_cb (the only user is qrq and it can get around) and
just call mempool_free() before calling endio_cb. This way we also don't
need to count everything in inflight_ref.
The next part of the problem is queueing something onto potentially
non-existing queue which your patch #2 fixes. Looks like the same gap
exists in qcow2_submit_embedded_qio() so please fix it too.
Besides looks like we have another problems from the same class:
slow_wb_timer callback uses queue_work without any guarantees (and also
we never disarm it). service_qio_endio() calls wake_up(&tgt->service_wq)
after the atomic_dec() the waiter checks, so tgt can be freed under it.
Also in your suggested patches you do destroy_wokrqueue() before
percpu_ref_kill() which doesn't sounds right: you counted IO will
happily reuse destroyed workqueue. Looks like we won't proceed with new
counter, but please double-check destruction sequence anyway so we don't
lose anything else, e.g. carefully stop timers, merge, event_work, etc,
then final flush + percpu_ref_kill and only then freeing (maybe the same
problems after successfull merge?)
Best regards,
Andrey
>
> Den
>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
prev parent reply other threads:[~2026-11-20 2:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 11:49 Denis V. Lunev
2026-11-19 11:49 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: fix image I/O completions running on " Denis V. Lunev
2026-11-19 11:49 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: queue the worker before dropping deferred_lock in completions Denis V. Lunev
2026-11-19 12:53 ` [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix image I/O completions using a freed target Alexander Ivanov
2026-11-19 13:12 ` Andrey Zhadchenko
2026-11-19 14:50 ` Denis V. Lunev
2026-11-20 2:22 ` Andrey Zhadchenko [this message]
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=aac508a5-d6bf-43d9-995c-244926c99904@virtuozzo.com \
--to=andrey.zhadchenko@virtuozzo.com \
--cc=alexander.ivanov@virtuozzo.com \
--cc=den@openvz.org \
--cc=den@virtuozzo.com \
--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.