All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yongpeng Yang" <yangyongpeng.storage@gmail.com>,
	agk@redhat.com, bmarzins@redhat.com, mpatocka@redhat.com,
	snitzer@kernel.org, okozina@redhat.com, zkabelac@redhat.com,
	dm-devel@lists.linux.dev
Cc: yangyongpeng@xiaomi.com
Subject: Re: [PATCH v4 4/4] dm-verity: add messages to prefetch and drop the hash cache
Date: Sat, 21 Nov 2026 08:55:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-226847@kernel.org> (raw)
In-Reply-To: <20261121084119.3418879-6-yangyongpeng.storage@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dm-verity: race between verity_message() and __dm_destroy()
  postsuspend
--

commit f3898ae3e053835b95d79be7c97db5541a15ab64
Author: Yongpeng Yang <yangyongpeng@xiaomi.com>

dm-verity: add messages to prefetch and drop the hash cache

This commit adds the prefetch_hash and drop_hash target messages to
dm-verity to allow userspace to warm or evict blocks from the hash cache.

> diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
> index 44b95dbdaebbc..04a986c343666 100644
> --- a/drivers/md/dm-verity-target.c
> +++ b/drivers/md/dm-verity-target.c

[ ... ]

> @@ -1885,6 +1990,21 @@ static int verity_message(struct dm_target *ti, unsigned int argc, char **argv,
>  	if (!strcasecmp(argv[0], "retain_bytes"))
>  		return verity_retain_bytes(v, argc, argv, result, maxlen);
>  
> +	/*
> +	 * prefetch/drop touch the bufio cache and the backing device, whose
> +	 * reads bypass the suspended dm queue: reject them while suspended.
> +	 */
> +	if (dm_suspended(ti)) {
> +		DMERR("message during suspend");
> +		return -EBUSY;
> +	}
> +
> +	if (!strcasecmp(argv[0], "prefetch_hash"))
> +		return verity_prefetch_hash(v, argc, argv, result, maxlen);
> +
> +	if (!strcasecmp(argv[0], "drop_hash"))
> +		return verity_drop_hash(v, argc, argv, result, maxlen);

[Severity: Medium]
Can verity_prefetch_hash() still race with verity_postsuspend() when an
active, unsuspended device is removed?

Unlike __dm_suspend(), __dm_destroy() sets DMF_SUSPENDED and immediately
calls dm_table_postsuspend_targets() without an intervening
synchronize_srcu(&md->io_barrier) and before waiting for md->holders to
drain:

drivers/md/dm.c:__dm_destroy() {
    ...
	if (!dm_suspended_md(md)) {
		dm_table_presuspend_targets(map);
		set_bit(DMF_SUSPENDED, &md->flags);
		set_bit(DMF_POST_SUSPENDING, &md->flags);
		dm_table_postsuspend_targets(map);
	}
    ...
}

Because target_message() only takes a holder reference (via find_device())
and does not increment md->open_count, removing an unmounted device via
dev_remove() while prefetch_hash is running allows verity_postsuspend() to
run concurrently with dm_bufio_prefetch():

CPU0                                  CPU1
target_message()
  dm_get_live_table()
  verity_message()
    dm_suspended(ti) -> false
    verity_prefetch_hash()
      dm_bufio_prefetch()
        __bufio_new()
          /* b->hold_count == 1 */
        dm_bufio_unlock(c)
                                      dev_remove()
                                        __dm_destroy()
                                          set_bit(DMF_SUSPENDED, ...)
                                          dm_table_postsuspend_targets()
                                            verity_postsuspend()
                                              dm_bufio_client_reset()
                                                drop_buffers()
                                                  <-- fails eviction / WARN_ON
        submit_io(...)
        dm_bufio_release(b)

When drop_buffers() encounters the buffer held with hold_count == 1 outside
dm_bufio_lock, eviction fails and triggers WARN_ON in warn_leak() and
drop_buffers() (or a use-after-free if CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
is enabled, where warn_leak() zeroes b->hold_count and drop_buffers() frees
b while __dm_bufio_prefetch() is still submitting I/O on it).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261121084119.3418879-2-yangyongpeng.storage@gmail.com?part=4

      reply	other threads:[~2026-11-21  8:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  8:41 [PATCH v4 0/4] dm-bufio per-client retain and dm-verity cache control Yongpeng Yang
2026-11-21  8:41 ` [PATCH v4 1/4] dm-bufio: make the retain target per client Yongpeng Yang
2026-11-21  8:41 ` [PATCH v4 2/4] dm-verity: size the hash retain target from the hash area Yongpeng Yang
2026-11-21  8:41 ` [PATCH v4 3/4] dm-verity: add retain_bytes message to inspect and tune the cache floor Yongpeng Yang
2026-11-21  8:41 ` [PATCH v4 4/4] dm-verity: add messages to prefetch and drop the hash cache Yongpeng Yang
2026-11-21  8:55   ` sashiko-bot [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=sashiko-outbox-226847@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agk@redhat.com \
    --cc=bmarzins@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=mpatocka@redhat.com \
    --cc=okozina@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=snitzer@kernel.org \
    --cc=yangyongpeng.storage@gmail.com \
    --cc=yangyongpeng@xiaomi.com \
    --cc=zkabelac@redhat.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.