diff mbox series

[v2,1/2] block: Imporve checks on zone resource limits

Message ID 20240605022445.105747-2-dlemoal@kernel.org (mailing list archive)
State New, archived
Headers show
Series Fix DM zone resource limits stacking | expand

Commit Message

Damien Le Moal June 5, 2024, 2:24 a.m. UTC
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 a max open zones or a max active zones limit,
    check that the limits are lower than the number of sequential zones
    of the device.

For (a), a check is added to blk_validate_zoned_limits(). For (b), given
that we need to number of sequential zones of the device, this check is
added to disk_update_zone_resources(). This is safe to do as that
function is executed with the queue frozen and the check executed after
queue_limits_start_update() with the queue limits lock held.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 block/blk-settings.c | 4 ++++
 block/blk-zoned.c    | 5 +++++
 2 files changed, 9 insertions(+)

Comments

Christoph Hellwig June 5, 2024, 4:17 a.m. UTC | #1
improve is misspelled in the subject.

> @@ -80,6 +80,10 @@ static int blk_validate_zoned_limits(struct queue_limits *lim)
>  	if (WARN_ON_ONCE(!IS_ENABLED(CONFIG_BLK_DEV_ZONED)))
>  		return -EINVAL;
>  
> +	if (lim->max_active_zones &&
> +	    WARN_ON_ONCE(lim->max_open_zones > lim->max_active_zones))
> +		lim->max_open_zones = lim->max_active_zones;

Given how active zones are defined this is an error condition, and
should return -EINVAL.

> diff --git a/block/blk-zoned.c b/block/blk-zoned.c
> index 52abebf56027..2af4d5ca81d2 100644
> --- a/block/blk-zoned.c
> +++ b/block/blk-zoned.c
> @@ -1660,6 +1660,11 @@ static int disk_update_zone_resources(struct gendisk *disk,
>  	lim = queue_limits_start_update(q);
>  
>  	nr_seq_zones = disk->nr_zones - nr_conv_zones;
> +	if (WARN_ON_ONCE(lim.max_active_zones > nr_seq_zones))
> +		lim.max_active_zones = 0;
> +	if (WARN_ON_ONCE(lim.max_open_zones > nr_seq_zones))
> +		lim.max_open_zones = 0;

Why would you warn about this?  Offering an open/active limit larger
than the number of sequential zones is a pretty natural condition
for certain corner cases (e.g. create only a tiny namespace on a ZNS
SSD).  This could also use a code comment explaining why the limit
is adjusted.
Damien Le Moal June 5, 2024, 4:52 a.m. UTC | #2
On 6/5/24 13:17, Christoph Hellwig wrote:
> improve is misspelled in the subject.
> 
>> @@ -80,6 +80,10 @@ static int blk_validate_zoned_limits(struct queue_limits *lim)
>>  	if (WARN_ON_ONCE(!IS_ENABLED(CONFIG_BLK_DEV_ZONED)))
>>  		return -EINVAL;
>>  
>> +	if (lim->max_active_zones &&
>> +	    WARN_ON_ONCE(lim->max_open_zones > lim->max_active_zones))
>> +		lim->max_open_zones = lim->max_active_zones;
> 
> Given how active zones are defined this is an error condition, and
> should return -EINVAL.
> 
>> diff --git a/block/blk-zoned.c b/block/blk-zoned.c
>> index 52abebf56027..2af4d5ca81d2 100644
>> --- a/block/blk-zoned.c
>> +++ b/block/blk-zoned.c
>> @@ -1660,6 +1660,11 @@ static int disk_update_zone_resources(struct gendisk *disk,
>>  	lim = queue_limits_start_update(q);
>>  
>>  	nr_seq_zones = disk->nr_zones - nr_conv_zones;
>> +	if (WARN_ON_ONCE(lim.max_active_zones > nr_seq_zones))
>> +		lim.max_active_zones = 0;
>> +	if (WARN_ON_ONCE(lim.max_open_zones > nr_seq_zones))
>> +		lim.max_open_zones = 0;
> 
> Why would you warn about this?  Offering an open/active limit larger
> than the number of sequential zones is a pretty natural condition
> for certain corner cases (e.g. create only a tiny namespace on a ZNS
> SSD).  This could also use a code comment explaining why the limit
> is adjusted.

Right. I actually did not consider that case, which is indeed valid given that
for nvme, the limits are per controller, not namespace (which is a very
unfortunate design flaw...).

I will remove the warn and add a comment.
diff mbox series

Patch

diff --git a/block/blk-settings.c b/block/blk-settings.c
index effeb9a639bb..a79c57376ef7 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -80,6 +80,10 @@  static int blk_validate_zoned_limits(struct queue_limits *lim)
 	if (WARN_ON_ONCE(!IS_ENABLED(CONFIG_BLK_DEV_ZONED)))
 		return -EINVAL;
 
+	if (lim->max_active_zones &&
+	    WARN_ON_ONCE(lim->max_open_zones > lim->max_active_zones))
+		lim->max_open_zones = lim->max_active_zones;
+
 	if (lim->zone_write_granularity < lim->logical_block_size)
 		lim->zone_write_granularity = lim->logical_block_size;
 
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 52abebf56027..2af4d5ca81d2 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1660,6 +1660,11 @@  static int disk_update_zone_resources(struct gendisk *disk,
 	lim = queue_limits_start_update(q);
 
 	nr_seq_zones = disk->nr_zones - nr_conv_zones;
+	if (WARN_ON_ONCE(lim.max_active_zones > nr_seq_zones))
+		lim.max_active_zones = 0;
+	if (WARN_ON_ONCE(lim.max_open_zones > nr_seq_zones))
+		lim.max_open_zones = 0;
+
 	pool_size = max(lim.max_open_zones, lim.max_active_zones);
 	if (!pool_size)
 		pool_size = min(BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE, nr_seq_zones);