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 v3 4/4] dm-verity: add messages to prefetch and drop the hash cache
Date: Thu, 19 Nov 2026 16:50:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-223579@kernel.org> (raw)
In-Reply-To: <20261119163110.1630269-7-yangyongpeng.storage@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] dm-verity: verity_prefetch_hash() races with suspend and breaks
quiescence
--
commit d29b7b5d122e67887bc98258e3fe7f3b2d2db059
Author: Yongpeng Yang <yangyongpeng@xiaomi.com>
dm-verity: add messages to prefetch and drop the hash cache
This commit adds prefetch_hash and drop_hash target messages to warm or
drop hash blocks in the dm-verity bufio cache.
> diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
> index 44b95dbdaebbc..622c427949a35 100644
> --- a/drivers/md/dm-verity-target.c
> +++ b/drivers/md/dm-verity-target.c
> @@ -1828,12 +1828,117 @@ static void verity_postsuspend(struct dm_target *ti)
> verity_security_clear_integrity(ti);
> }
>
> +static int verity_prefetch_hash(struct dm_verity *v, unsigned int argc,
> + char **argv, char *result, unsigned int maxlen)
> +{
> + sector_t total = v->hash_end - v->hash_start;
> + sector_t start, n;
> + unsigned long long value;
> + unsigned int sz = 0;
> +
> + /*
> + * On a no_sleep client a buffer being read cannot be evicted or
> + * waited for, so an unfinished prefetch would outlive a suspend or
> + * teardown; drop_hash rejects this case for the same reason.
> + */
> + if (v->use_bh_wq) {
> + DMERR("prefetch_hash unsupported on tasklet-verifying device");
> + return -EOPNOTSUPP;
> + }
> +
> + if (argc == 1) {
> + start = 0;
> + n = total;
> + } else if (argc == 3) {
> + if (kstrtoull(argv[1], 0, &value) || (sector_t)value != value)
> + return -EINVAL;
> + start = value;
> +
> + if (kstrtoull(argv[2], 0, &value) || (sector_t)value != value)
> + return -EINVAL;
> + n = value;
> + } else {
> + return -EINVAL;
> + }
> +
> + if (start >= total) {
> + if (!total) {
> + n = 0;
> + goto out;
> + }
> + DMERR("prefetch_hash start %llu beyond hash area (%llu blocks)",
> + (unsigned long long)start, (unsigned long long)total);
> + return -EINVAL;
> + }
> +
> + n = min(n, total - start);
> + n = min_t(sector_t, n, UINT_MAX);
> +
> +out:
> + dm_bufio_prefetch(v->bufio, v->hash_start + start, n);
[Severity: High]
Can verity_prefetch_hash() race with verity_postsuspend() or run while the
device is suspended?
target_message() in drivers/md/dm-ioctl.c only takes the SRCU read lock via
dm_get_live_table() and does not take md->suspend_lock or check whether the
device is suspending or suspended. In dm_suspend(), __dm_suspend()
completes synchronize_srcu(&md->io_barrier) before calling
dm_table_postsuspend_targets() -> verity_postsuspend().
CPU0 CPU1
target_message()
verity_message()
verity_prefetch_hash()
__dm_bufio_prefetch()
dm_bufio_lock(c)
b = __bufio_new(...)
b->hold_count = 1
dm_bufio_unlock(c)
dm_suspend()
__dm_suspend()
verity_postsuspend()
dm_bufio_client_reset(v->bufio)
drop_buffers()
cache_iterate(..., warn_leak)
WARN_ON(cache_count(...))
submit_io(b, ...)
dm_bufio_release(b) <-- use-after-free if
CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
While __dm_bufio_prefetch() drops dm_bufio_lock(c) across submit_io() and
dm_bufio_release(), b remains in c->cache with hold_count == 1. A
concurrent dm_bufio_client_reset() skips b in __get_unclaimed_buffer(),
triggers the leak WARN_ONs in warn_leak() and drop_buffers(), and under
CONFIG_DM_DEBUG_BLOCK_STACK_TRACING zeroes b->hold_count and frees b while
CPU0 still holds it.
Also, contrary to the documentation note in verity.rst, v->bufio is bound
to v->hash_dev->bdev rather than the top-level DM device, so calling
prefetch_hash while suspended submits read bios directly to the underlying
hash device instead of queueing them until resume, breaking the suspend
quiescence fixed by commit 2de510fccbca ("dm-verity: fix
prefetch-vs-suspend race").
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119163110.1630269-2-yangyongpeng.storage@gmail.com?part=4
prev parent reply other threads:[~2026-11-19 16:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 16:31 [PATCH v3 0/4] dm-bufio per-client retain and dm-verity cache control Yongpeng Yang
2026-11-19 16:31 ` [PATCH v3 1/4] dm-bufio: make the retain target per client Yongpeng Yang
2026-11-19 16:31 ` [PATCH v3 2/4] dm-verity: size the hash retain target from the hash area Yongpeng Yang
2026-11-19 16:31 ` [PATCH v3 3/4] dm-verity: add retain_bytes message to inspect and tune the cache floor Yongpeng Yang
2026-11-19 16:31 ` [PATCH v3 4/4] dm-verity: add messages to prefetch and drop the hash cache Yongpeng Yang
2026-11-19 16:50 ` 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-223579@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.