summaryrefslogtreecommitdiff
path: root/drivers/md/dm-thin.c
diff options
context:
space:
mode:
authorMike Snitzer <snitzer@kernel.org>2023-03-26 00:52:01 +0300
committerMike Snitzer <snitzer@kernel.org>2023-03-30 22:57:51 +0300
commit3f8d3f5432078a558151e27230e20bcf93c23ffe (patch)
tree9c6ae4c1ea3197281a7dad244a55c503dad30a8a /drivers/md/dm-thin.c
parente2dd8aca2d76f937f1f08d03041684f3532e9df4 (diff)
downloadlinux-3f8d3f5432078a558151e27230e20bcf93c23ffe.tar.xz
dm bio prison v1: add dm_cell_key_has_valid_range
Don't have bio_detain() BUG_ON if a dm_cell_key is beyond BIO_PRISON_MAX_RANGE or spans a boundary. Update dm-thin.c:build_key() to use dm_cell_key_has_valid_range() which will do this checking without using BUG_ON. Also update process_discard_bio() to check the discard bio that DM core passes in (having first imposed max_discard_granularity based splitting). dm_cell_key_has_valid_range() will merely WARN_ON_ONCE if it returns false because if it does: it is programmer error that should be caught with proper testing. So relax the BUG_ONs to be WARN_ON_ONCE. Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Diffstat (limited to 'drivers/md/dm-thin.c')
-rw-r--r--drivers/md/dm-thin.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 33ad5695f959..2b13c949bd72 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -118,25 +118,27 @@ enum lock_space {
PHYSICAL
};
-static void build_key(struct dm_thin_device *td, enum lock_space ls,
+static bool build_key(struct dm_thin_device *td, enum lock_space ls,
dm_block_t b, dm_block_t e, struct dm_cell_key *key)
{
key->virtual = (ls == VIRTUAL);
key->dev = dm_thin_dev_id(td);
key->block_begin = b;
key->block_end = e;
+
+ return dm_cell_key_has_valid_range(key);
}
static void build_data_key(struct dm_thin_device *td, dm_block_t b,
struct dm_cell_key *key)
{
- build_key(td, PHYSICAL, b, b + 1llu, key);
+ (void) build_key(td, PHYSICAL, b, b + 1llu, key);
}
static void build_virtual_key(struct dm_thin_device *td, dm_block_t b,
struct dm_cell_key *key)
{
- build_key(td, VIRTUAL, b, b + 1llu, key);
+ (void) build_key(td, VIRTUAL, b, b + 1llu, key);
}
/*----------------------------------------------------------------*/
@@ -1702,7 +1704,8 @@ static void break_up_discard_bio(struct thin_c *tc, dm_block_t begin, dm_block_t
<< BIO_PRISON_MAX_RANGE_SHIFT;
len = min_t(sector_t, data_end - data_begin, next_boundary - data_begin);
- build_key(tc->td, PHYSICAL, data_begin, data_begin + len, &data_key);
+ /* This key is certainly within range given the above splitting */
+ (void) build_key(tc->td, PHYSICAL, data_begin, data_begin + len, &data_key);
if (bio_detain(tc->pool, &data_key, NULL, &data_cell)) {
/* contention, we'll give up with this range */
data_begin += len;
@@ -1778,8 +1781,13 @@ static void process_discard_bio(struct thin_c *tc, struct bio *bio)
return;
}
- build_key(tc->td, VIRTUAL, begin, end, &virt_key);
- if (bio_detain(tc->pool, &virt_key, bio, &virt_cell))
+ if (unlikely(!build_key(tc->td, VIRTUAL, begin, end, &virt_key))) {
+ DMERR_LIMIT("Discard doesn't respect bio prison limits");
+ bio_endio(bio);
+ return;
+ }
+
+ if (bio_detain(tc->pool, &virt_key, bio, &virt_cell)) {
/*
* Potential starvation issue: We're relying on the
* fs/application being well behaved, and not trying to
@@ -1788,6 +1796,7 @@ static void process_discard_bio(struct thin_c *tc, struct bio *bio)
* cell will never be granted.
*/
return;
+ }
tc->pool->process_discard_cell(tc, virt_cell);
}