[PATCH v6 2/6] block: sanitize chunk_sectors for atomic write limits

John Garry posted 6 patches 2 months, 4 weeks ago
There is a newer version of this series
[PATCH v6 2/6] block: sanitize chunk_sectors for atomic write limits
Posted by John Garry 2 months, 4 weeks ago
Currently we just ensure that a non-zero value in chunk_sectors aligns
with any atomic write boundary, as the blk boundary functionality uses
both these values.

However it is also improper to have atomic write unit max > chunk_sectors
(for non-zero chunk_sectors), as this would lead to splitting of atomic
write bios (which is disallowed).

Sanitize atomic write unit max against chunk_sectors to avoid any
potential problems.

Fixes: d00eea91deaf3 ("block: Add extra checks in blk_validate_atomic_write_limits()")
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 block/blk-settings.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index a000daafbfb48..a2c089167174e 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -180,6 +180,7 @@ static void blk_atomic_writes_update_limits(struct queue_limits *lim)
 
 static void blk_validate_atomic_write_limits(struct queue_limits *lim)
 {
+	unsigned long long chunk_bytes = lim->chunk_sectors << SECTOR_SHIFT;
 	unsigned int boundary_sectors;
 
 	if (!(lim->features & BLK_FEAT_ATOMIC_WRITES))
@@ -202,6 +203,10 @@ static void blk_validate_atomic_write_limits(struct queue_limits *lim)
 			 lim->atomic_write_hw_max))
 		goto unsupported;
 
+	if (WARN_ON_ONCE(chunk_bytes &&
+			lim->atomic_write_hw_unit_max > chunk_bytes))
+		goto unsupported;
+
 	boundary_sectors = lim->atomic_write_hw_boundary >> SECTOR_SHIFT;
 
 	if (boundary_sectors) {
-- 
2.43.5
Re: [PATCH v6 2/6] block: sanitize chunk_sectors for atomic write limits
Posted by Damien Le Moal 2 months, 3 weeks ago
On 7/11/25 5:09 PM, John Garry wrote:
> Currently we just ensure that a non-zero value in chunk_sectors aligns
> with any atomic write boundary, as the blk boundary functionality uses
> both these values.
> 
> However it is also improper to have atomic write unit max > chunk_sectors
> (for non-zero chunk_sectors), as this would lead to splitting of atomic
> write bios (which is disallowed).
> 
> Sanitize atomic write unit max against chunk_sectors to avoid any
> potential problems.
> 
> Fixes: d00eea91deaf3 ("block: Add extra checks in blk_validate_atomic_write_limits()")
> Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
>  block/blk-settings.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index a000daafbfb48..a2c089167174e 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -180,6 +180,7 @@ static void blk_atomic_writes_update_limits(struct queue_limits *lim)
>  
>  static void blk_validate_atomic_write_limits(struct queue_limits *lim)
>  {
> +	unsigned long long chunk_bytes = lim->chunk_sectors << SECTOR_SHIFT;

Don't you need to cast to a 64-bits "lim->chunk_sectors" here ?

>  	unsigned int boundary_sectors;
>  
>  	if (!(lim->features & BLK_FEAT_ATOMIC_WRITES))
> @@ -202,6 +203,10 @@ static void blk_validate_atomic_write_limits(struct queue_limits *lim)
>  			 lim->atomic_write_hw_max))
>  		goto unsupported;
>  
> +	if (WARN_ON_ONCE(chunk_bytes &&
> +			lim->atomic_write_hw_unit_max > chunk_bytes))
> +		goto unsupported;
> +
>  	boundary_sectors = lim->atomic_write_hw_boundary >> SECTOR_SHIFT;
>  
>  	if (boundary_sectors) {


-- 
Damien Le Moal
Western Digital Research
Re: [PATCH v6 2/6] block: sanitize chunk_sectors for atomic write limits
Posted by John Garry 2 months, 3 weeks ago
On 11/07/2025 09:42, Damien Le Moal wrote:
>> diff --git a/block/blk-settings.c b/block/blk-settings.c
>> index a000daafbfb48..a2c089167174e 100644
>> --- a/block/blk-settings.c
>> +++ b/block/blk-settings.c
>> @@ -180,6 +180,7 @@ static void blk_atomic_writes_update_limits(struct queue_limits *lim)
>>   
>>   static void blk_validate_atomic_write_limits(struct queue_limits *lim)
>>   {
>> +	unsigned long long chunk_bytes = lim->chunk_sectors << SECTOR_SHIFT;
> Don't you need to cast to a 64-bits "lim->chunk_sectors" here ?

I thought that we automatically convert lim->chunk_sectors to unsigned 
long long, but I think that you are right...

At this point I think that it's easier to just convert 
atomic_write_hw_max to sectors and do that comparison

Thanks,
John