dm: always manage discard support in terms of max_hw_discard_sectors
authorMike Snitzer <snitzer@kernel.org>
Mon, 20 May 2024 17:34:06 +0000 (13:34 -0400)
committerMike Snitzer <snitzer@kernel.org>
Mon, 20 May 2024 19:51:19 +0000 (15:51 -0400)
commit825d8bbd2f32cb229c3b6653bd454832c3c20acb
treed9ab547be7777d2d39f1bc3ba6b8597e99224130
parent69381cf88a8dfa0ab27fb801b78be813e7e8fb80
dm: always manage discard support in terms of max_hw_discard_sectors

Commit 4f563a64732d ("block: add a max_user_discard_sectors queue
limit") changed block core to set max_discard_sectors to:
 min(lim->max_hw_discard_sectors, lim->max_user_discard_sectors)

Since commit 1c0e720228ad ("dm: use queue_limits_set") it was reported
dm-thinp was failing in a few fstests (generic/347 and generic/405)
with the first WARN_ON_ONCE in dm_cell_key_has_valid_range() being
reported, e.g.:
WARNING: CPU: 1 PID: 30 at drivers/md/dm-bio-prison-v1.c:128 dm_cell_key_has_valid_range+0x3d/0x50

blk_set_stacking_limits() sets max_user_discard_sectors to UINT_MAX,
so given how block core now sets max_discard_sectors (detailed above)
it follows that blk_stack_limits() stacks up the underlying device's
max_hw_discard_sectors and max_discard_sectors is set to match it. If
max_hw_discard_sectors exceeds dm's BIO_PRISON_MAX_RANGE, then
dm_cell_key_has_valid_range() will trigger the warning with:
WARN_ON_ONCE(key->block_end - key->block_begin > BIO_PRISON_MAX_RANGE)

Aside from this warning, the discard will fail.  Fix this and other DM
issues by governing discard support in terms of max_hw_discard_sectors
instead of max_discard_sectors.

Reported-by: Theodore Ts'o <tytso@mit.edu>
Fixes: 1c0e720228ad ("dm: use queue_limits_set")
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
drivers/md/dm-cache-target.c
drivers/md/dm-clone-target.c
drivers/md/dm-log-writes.c
drivers/md/dm-snap.c
drivers/md/dm-target.c
drivers/md/dm-thin.c
drivers/md/dm-zero.c
drivers/md/dm-zoned-target.c
drivers/md/dm.c