On Sat, Nov 22, 2026, [email protected] wrote:
> 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.

Confirmed, and this time it reproduces.  A debug sleep holding the
prefetch buffer (widening the hold_count == 1 window to 10ms per
block) while dmsetup remove runs on the active device gives the
WARN_ONs in warn_leak() and drop_buffers() and the "leaked buffer"
message -- the destroy path really has no drain between passing
dm_suspended() and the reset.

v5 adds a new patch 1 that mirrors the suspend path in __dm_destroy():
set DMF_SUSPENDED, drop the SRCU read lock, synchronize_srcu(), then
run postsuspend.  With it, the remove blocks until the message
finishes and the same test is clean.  It is a core asymmetry rather
than a verity bug -- every target with messages currently masks it
with a private lock (multipath's work_mutex) -- so the fix belongs in
dm core; verity keeps only the -EBUSY check.

> 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().

Yes, that is the reachable path.  For completeness I also checked the
other __dm_destroy() callers: dev_remove and remove_all call
dm_sync_table() and dm_table_destroy() for the inactive table before
dm_destroy(), but the live table is still bound there, so the
postsuspend in __dm_destroy() runs for it; the error paths cannot have
concurrent messages.  The fix covers all of them.

Thanks for the review,
Yongpeng

Reply via email to