Skip to content

Commit e21d12c

Browse files
damien-lemoalaxboe
authored andcommitted
block: Improve checks on zone resource limits
Make sure that the zone resource limits of a zoned block device are correct by checking that: (a) If the device has a max active zones limit, make sure that the max open zones limit is lower than the max active zones limit. (b) If the device has zone resource limits, check that the limits values are lower than the number of sequential zones of the device. If it is not, assume that the zoned device has no limits by setting the limits to 0. For (a), a check is added to blk_validate_zoned_limits() and an error returned if the max open zones limit exceeds the value of the max active zone limit (if there is one). For (b), given that we need the number of sequential zones of the zoned device, this check is added to disk_update_zone_resources(). This is safe to do as that function is executed with the disk queue frozen and the check executed after queue_limits_start_update() which takes the queue limits lock. Of note is that the early return in this function for zoned devices that do not use zone write plugging (e.g. DM devices using native zone append) is moved to after the new check and adjustment of the zone resource limits so that the check applies to any zoned device. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Niklas Cassel <[email protected]> Reviewed-by: Benjamin Marzinski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 5e3b700 commit e21d12c

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

block/blk-settings.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ static int blk_validate_zoned_limits(struct queue_limits *lim)
8080
if (WARN_ON_ONCE(!IS_ENABLED(CONFIG_BLK_DEV_ZONED)))
8181
return -EINVAL;
8282

83+
/*
84+
* Given that active zones include open zones, the maximum number of
85+
* open zones cannot be larger than the maximum number of active zones.
86+
*/
87+
if (lim->max_active_zones &&
88+
lim->max_open_zones > lim->max_active_zones)
89+
return -EINVAL;
90+
8391
if (lim->zone_write_granularity < lim->logical_block_size)
8492
lim->zone_write_granularity = lim->logical_block_size;
8593

block/blk-zoned.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,8 +1647,22 @@ static int disk_update_zone_resources(struct gendisk *disk,
16471647
return -ENODEV;
16481648
}
16491649

1650+
lim = queue_limits_start_update(q);
1651+
1652+
/*
1653+
* Some devices can advertize zone resource limits that are larger than
1654+
* the number of sequential zones of the zoned block device, e.g. a
1655+
* small ZNS namespace. For such case, assume that the zoned device has
1656+
* no zone resource limits.
1657+
*/
1658+
nr_seq_zones = disk->nr_zones - nr_conv_zones;
1659+
if (lim.max_open_zones >= nr_seq_zones)
1660+
lim.max_open_zones = 0;
1661+
if (lim.max_active_zones >= nr_seq_zones)
1662+
lim.max_active_zones = 0;
1663+
16501664
if (!disk->zone_wplugs_pool)
1651-
return 0;
1665+
goto commit;
16521666

16531667
/*
16541668
* If the device has no limit on the maximum number of open and active
@@ -1657,9 +1671,6 @@ static int disk_update_zone_resources(struct gendisk *disk,
16571671
* dynamic zone write plug allocation when simultaneously writing to
16581672
* more zones than the size of the mempool.
16591673
*/
1660-
lim = queue_limits_start_update(q);
1661-
1662-
nr_seq_zones = disk->nr_zones - nr_conv_zones;
16631674
pool_size = max(lim.max_open_zones, lim.max_active_zones);
16641675
if (!pool_size)
16651676
pool_size = min(BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE, nr_seq_zones);
@@ -1673,6 +1684,7 @@ static int disk_update_zone_resources(struct gendisk *disk,
16731684
lim.max_open_zones = 0;
16741685
}
16751686

1687+
commit:
16761688
return queue_limits_commit_update(q, &lim);
16771689
}
16781690

0 commit comments

Comments
 (0)