OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>,
	andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v7 09/10] dm-ploop: reload metadata on resume
Date: Tue, 17 Nov 2026 17:36:44 +0000	[thread overview]
Message-ID: <010701a1ea9521fc-2863651a-c499-436d-a3b4-6a3ee388f43c-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261117171743.3216794-10-alexander.ivanov@virtuozzo.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] dm-ploop: killed prealloc wait in postsuspend() leaves old
  allocator unfenced
- [Medium] dm-ploop: postsuspend waits uninterruptibly on inflight_md
  even in standby
- [Low] dm-ploop: sticky ploop->standby flag disables reload and
  prealloc on later resumes
--

commit 351119f1dd440a802da0e2263d32e93b2a12c2df
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

dm-ploop: reload metadata on resume

This patch makes ploop_preresume() reload the top delta header, the BAT of every delta and the delta file sizes. It also rebuilds the BAT tree and holes_bitmap, so a ploop created by "dmsetup reload" does not resume with stale metadata. It moves preallocation from ploop_ctr() to after the reload, makes the postsuspend wait for preallocation killable, and tracks standby per ploop instance.

> diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
> index 442537340b51..e7571b383f00 100644
> --- a/drivers/md/dm-ploop-map.c
> +++ b/drivers/md/dm-ploop-map.c
> @@ -1267,6 +1267,12 @@ int ploop_no_pending_prealloc(struct ploop *ploop)
>  	return ret;
>  }
>  
> +void ploop_wait_prealloc(struct ploop *ploop)
> +{
> +	wait_event_killable(ploop->dispatcher_wq_prealloc,
> +			    ploop_no_pending_prealloc(ploop));
> +}
> +

[Severity: Medium]
Does dropping the return value of wait_event_killable() leave the old allocator unfenced?

If dmsetup gets a fatal signal while a preallocation is pending, the wait returns -ERESTARTSYS. ploop_postsuspend() returns void, so it carries on and marks the device suspended while the allocator may still be running.

ploop_preallocate_cluster() computes new_len = top->file_size + prealloc_in_progress and calls do_ftruncate() or vfs_fallocate() with no suspend check. It can then resize the top delta under a new ploop that has already reloaded the size. ploop_preresume() of the new ploop only checks its own prealloc state, which is zero.

That can corrupt the top delta image. Could the killed wait be reported to the caller, or the old allocator be stopped from touching the file once suspended?

>  static int ploop_allocate_cluster(struct ploop *ploop, u32 *dst_clu, struct file *file)
>  {
>  	struct ploop_delta *top = ploop_top_delta(ploop);
> @@ -1443,6 +1449,7 @@ static void ploop_check_standby_mode(struct ploop *ploop, long res)
>  	spin_lock_irqsave(&q->queue_lock, flags);
>  	prev = test_and_set_bit(QUEUE_FLAG_STANDBY, &q->queue_flags);
>  	spin_unlock_irqrestore(&q->queue_lock, flags);
> +	WRITE_ONCE(ploop->standby, true);
>  
>  	if (!prev)
>  		PL_INFO("was switched into the standby mode");

[Severity: Low]
Is it intended that ploop->standby is never cleared?

This is the only writer. The queue bit it shadows is cleared by ploop_ctr() of a new table. Suppose an instance enters standby, a new table's ploop_ctr() clears the queue bit, and the new table is then abandoned. The old instance serves IO again, but ploop_preresume() keeps skipping ploop_reload_metadata() and ploop_should_prealloc() for it, and ploop_postsuspend() keeps skipping the prealloc wait.

If userspace then changes the images on the suspended device (merge or snapshot trim) and resumes this same instance, it keeps a stale BAT. That is the corruption this patch is meant to prevent. Normal recovery through dm_replace() creates a new instance, so it is not affected. Should the flag be cleared when the instance leaves standby?

[ ... ]

> diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
> index bfadca7f12ae..968a608c67f4 100644
> --- a/drivers/md/dm-ploop-target.c
> +++ b/drivers/md/dm-ploop-target.c

[ ... ]

> @@ -755,18 +755,47 @@ static void ploop_postsuspend(struct dm_target *ti)
>  {
>  	struct ploop *ploop = ti->private;
>  
> -	wait_event(ploop->dispatcher_wq_prealloc,
> -		   ploop_no_pending_prealloc(ploop));
> +	/*
> +	 * Let the next resumed ploop (maybe of reloaded table)
> +	 * see final size of the top delta. Don't wait in standby
> +	 * mode: the allocator may be stuck on the dead file, while
> +	 * dm_replace() of libploop must be able to suspend the device
> +	 * to recover it. The wait is killable for the same reason.
> +	 * If the wait is skipped or killed, a ploop of a reloaded
> +	 * table may see a stale size, and a late truncate of our
> +	 * allocator may shrink the file under it.
> +	 */
> +	if (!ploop_is_standby(ploop))
> +		ploop_wait_prealloc(ploop);
> +	/*
> +	 * Data bios are completed before BAT writeback is finished
> +	 * (see ploop_put_piwb()), so wait for it explicitly to make
> +	 * md pages clean for ploop_reload_metadata().
> +	 */
> +	wait_event(ploop->inflight_md_wq, !atomic_read(&ploop->inflight_md));
>  	ploop_set_suspended(ti, true);
>  }

[Severity: Medium]
Can this wait_event() hang suspend in standby?

The comment above explains that the prealloc wait is skipped in standby and made killable because the backing file may be dead. The inflight_md wait right below has neither a standby bypass nor a killable variant. A BAT index write stuck on a hung delta file keeps inflight_md non-zero, so ploop_postsuspend() sits in D state and the dm_replace() recovery stalls.

ploop_presuspend() does not drain BAT writes. The kt_worker->inflight_pios counter it waits on drops once the pio is handed to a runner through ploop_runners_add_work() in ploop_index_wb_submit(), not when the write completes.

Skipping the wait in standby looks safe, since ploop_preresume() skips the reload there. The final patch of the series, "dm-ploop: truncate unused tail of top delta on suspend", keeps this wait and moves it under ctl_rwsem held for write, so a hang would then also block ploop_message() and ploop_preresume().

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261117171743.3216794-1-alexander.ivanov@virtuozzo.com?part=9

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-11-17 17:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 17:17 [Devel] [PATCH hci-8.1 v7 00/10] dm-ploop: give back unused tail of top delta on suspend Alexander Ivanov
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 01/10] dm-ploop: reject a delta header whose BAT does not cover the target Alexander Ivanov
2026-11-17 17:22   ` no-reply
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 02/10] dm-ploop: reject empty deltas Alexander Ivanov
2026-11-17 17:22   ` no-reply
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 03/10] dm-ploop: set delta is_raw before applying its mappings Alexander Ivanov
2026-11-17 17:25   ` no-reply
2026-11-17 18:23   ` Konstantin Khorenko
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 04/10] dm-ploop: factor out ploop_read_delta() from ploop_add_delta() Alexander Ivanov
2026-11-17 17:24   ` no-reply
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 05/10] dm-ploop: take bat_lock around md page lookup in ploop_llseek_hole() Alexander Ivanov
2026-11-17 17:27   ` no-reply
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 06/10] dm-ploop: use wake_up() for inflight_md_wq Alexander Ivanov
2026-11-17 17:26   ` no-reply
2026-11-17 18:23   ` Konstantin Khorenko
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 07/10] dm-ploop: fix use-after-free on the last inflight_md decrement Alexander Ivanov
2026-11-17 17:32   ` no-reply
2026-11-17 18:23   ` Konstantin Khorenko
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 08/10] dm-ploop: fix flip_upper_deltas racing with resume Alexander Ivanov
2026-11-17 17:28   ` no-reply
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 09/10] dm-ploop: reload metadata on resume Alexander Ivanov
2026-11-17 17:36   ` no-reply [this message]
2026-11-17 18:23   ` Konstantin Khorenko
2026-11-17 17:17 ` [Devel] [PATCH hci-8.1 v7 10/10] dm-ploop: truncate unused tail of top delta on suspend Alexander Ivanov
2026-11-17 17:40   ` no-reply
2026-11-17 18:23   ` Konstantin Khorenko
2026-11-17 18:23 ` [Devel] [PATCH hci-8.1 v7 00/10] dm-ploop: give back " 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=010701a1ea9521fc-2863651a-c499-436d-a3b4-6a3ee388f43c-000000@eu-central-1.amazonses.com \
    --to=no-reply@sashiko.virtuozzo.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox