From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: no-reply@sashiko.virtuozzo.com, den@openvz.org
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v6 12/12] dm-ploop: truncate unused tail of top delta on suspend
Date: Tue, 13 Oct 2026 14:53:11 +0200 [thread overview]
Message-ID: <fe0ba982-ec1d-4338-9978-df192d480fa0@virtuozzo.com> (raw)
In-Reply-To: <010701a1350e61fe-081a10ef-015a-4b2f-a854-028f6374f46d-000000@eu-central-1.amazonses.com>
On 10/13/26 13:38, no-reply@sashiko.virtuozzo.com wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] dm-ploop: ploop_postsuspend() holds ctl_rwsem across unbounded waits and fs I/O
> --
>
> commit 1aa3a8ea27bee4e747c238df1ff3b02cb36cb3fd
> Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
>
> dm-ploop: truncate unused tail of top delta on suspend
>
> This patch adds ploop_calc_used_end() and ploop_truncate_unused_tail().
> ploop_postsuspend() now truncates the unused tail of the top delta. It
> does this under ctl_rwsem, so that ploop messages don't change the image
> in parallel.
>
> Link: https://virtuozzo.atlassian.net/browse/VSTOR-148171
>
>> diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
>> --- a/drivers/md/dm-ploop-target.c
>> +++ b/drivers/md/dm-ploop-target.c
> [ ... ]
>
>> static void ploop_postsuspend(struct dm_target *ti)
>> {
>> struct ploop *ploop = ti->private;
>> + unsigned int noio_flags;
>>
>> + down_write(&ploop->ctl_rwsem);
>> /*
>> * Let the next resumed ploop (maybe of reloaded table)
>> * see final size of the top delta. Don't wait in standby
> [ ... ]
>
>> wait_event(ploop->inflight_md_wq, !atomic_read(&ploop->inflight_md));
>> - ploop_set_suspended(ti, true);
>> + /* The device is suspended, see ploop_preresume() */
>> + noio_flags = memalloc_noio_save();
>> + ploop_truncate_unused_tail(ploop);
>> + memalloc_noio_restore(noio_flags);
>> + ploop->suspended = true;
>> + up_write(&ploop->ctl_rwsem);
>> }
> [Severity: Low]
> Is it necessary to take ctl_rwsem for write before the waits in
> ploop_postsuspend()?
>
> The write lock is now taken before the killable ploop_wait_prealloc() and
> the uninterruptible wait_event(ploop->inflight_md_wq, ...), and it stays
> held through ploop_truncate_unused_tail(), which calls vfs_iter_read()
> (via ploop_calc_used_end()), vfs_fsync() and do_ftruncate().
>
> Before this patch the lock was only taken briefly in ploop_set_suspended(),
> after both waits. Those waits could already block for a long time. In
> standby, or with a dead or stuck backing file, inflight_md may never reach
> zero. Now other ctl_rwsem users block behind them as well:
>
> ploop_status()
> down_read(&ploop->ctl_rwsem); /* STATUSTYPE_TABLE */
>
> ploop_message()
> if (read)
> down_read(&ploop->ctl_rwsem);
> else
> down_write(&ploop->ctl_rwsem);
>
> Every message handler except get_event would hang while postsuspend is
> stalled. The same stall can come from a slow vfs_fsync() or do_ftruncate()
> on a stuck filesystem.
>
> I don't see a deadlock. Nothing on the inflight_md completion path or in
> the allocator takes ctl_rwsem. dm_suspend() also already hangs in that
> state with md->suspend_lock held, so the practical impact looks small.
>
> The two waits don't appear to need the lock. Only
> ploop_truncate_unused_tail() and the store to ploop->suspended do. Would
> it make sense to take the lock after the waits? That would avoid
> extending the blocking to status and message handlers while the wait
> phase is stuck.
The extra blocking only happens when postsuspend is already stuck:
dm_suspend() hangs with md->suspend_lock held and the device can't be
recovered either way. Holding the lock across the waits keeps messages
(e.g. resize) from slipping in between the waits and the truncation and
leaving new preallocation behind, which would make us skip the
truncation. So I'd keep it as is.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
prev parent reply other threads:[~2026-10-13 12:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 11:15 [Devel] [PATCH hci-8.1 v6 00/12] dm-ploop: give back " Alexander Ivanov
2026-10-13 11:15 ` [Devel] [PATCH hci-8.1 v6 01/12] dm-ploop: fix u32 overflow of the delta BAT byte size Alexander Ivanov
2026-10-13 11:23 ` no-reply
2026-10-13 11:15 ` [Devel] [PATCH hci-8.1 v6 02/12] dm-ploop: fix lost wakeup in ploop_allocator() Alexander Ivanov
2026-10-13 11:21 ` no-reply
2026-10-13 11:15 ` [Devel] [PATCH hci-8.1 v6 03/12] dm-ploop: reject a delta header whose BAT does not cover the target Alexander Ivanov
2026-10-13 11:22 ` no-reply
2026-10-13 11:15 ` [Devel] [PATCH hci-8.1 v6 04/12] dm-ploop: reject empty deltas Alexander Ivanov
2026-10-13 11:24 ` no-reply
2026-10-13 11:15 ` [Devel] [PATCH hci-8.1 v6 05/12] dm-ploop: set delta is_raw before applying its mappings Alexander Ivanov
2026-10-13 11:24 ` no-reply
2026-10-13 11:15 ` [Devel] [PATCH hci-8.1 v6 06/12] dm-ploop: factor out ploop_read_delta() from ploop_add_delta() Alexander Ivanov
2026-10-13 11:25 ` no-reply
2026-10-13 11:15 ` [Devel] [PATCH hci-8.1 v6 07/12] dm-ploop: take bat_lock around md page lookup in ploop_llseek_hole() Alexander Ivanov
2026-10-13 11:26 ` no-reply
2026-10-13 11:16 ` [Devel] [PATCH hci-8.1 v6 08/12] dm-ploop: use wake_up() for inflight_md_wq and dispatcher_wq_prealloc Alexander Ivanov
2026-10-13 11:26 ` no-reply
2026-10-13 11:16 ` [Devel] [PATCH hci-8.1 v6 09/12] dm-ploop: fix use-after-free on the last inflight_md decrement Alexander Ivanov
2026-10-13 11:30 ` no-reply
2026-10-13 11:16 ` [Devel] [PATCH hci-8.1 v6 10/12] dm-ploop: fix flip_upper_deltas racing with resume Alexander Ivanov
2026-10-13 11:28 ` no-reply
2026-10-13 11:16 ` [Devel] [PATCH hci-8.1 v6 11/12] dm-ploop: reload metadata on resume Alexander Ivanov
2026-10-13 11:35 ` no-reply
2026-10-13 12:46 ` Alexander Ivanov
2026-10-13 11:16 ` [Devel] [PATCH hci-8.1 v6 12/12] dm-ploop: truncate unused tail of top delta on suspend Alexander Ivanov
2026-10-13 11:38 ` no-reply
2026-10-13 12:53 ` Alexander Ivanov [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=fe0ba982-ec1d-4338-9978-df192d480fa0@virtuozzo.com \
--to=alexander.ivanov@virtuozzo.com \
--cc=den@openvz.org \
--cc=devel@openvz.org \
--cc=no-reply@sashiko.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox