Skip to content

Commit d00eea9

Browse files
johnpgarryaxboe
authored andcommitted
block: Add extra checks in blk_validate_atomic_write_limits()
It is so far expected that the limits passed are valid. In future atomic writes will be supported for stacked block devices, and calculating the limits there will be complicated, so add extra sanity checks to ensure that the values are always valid. Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: John Garry <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 34c1227 commit d00eea9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

block/blk-settings.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,26 @@ static void blk_validate_atomic_write_limits(struct queue_limits *lim)
178178
if (!lim->atomic_write_hw_max)
179179
goto unsupported;
180180

181+
if (WARN_ON_ONCE(!is_power_of_2(lim->atomic_write_hw_unit_min)))
182+
goto unsupported;
183+
184+
if (WARN_ON_ONCE(!is_power_of_2(lim->atomic_write_hw_unit_max)))
185+
goto unsupported;
186+
187+
if (WARN_ON_ONCE(lim->atomic_write_hw_unit_min >
188+
lim->atomic_write_hw_unit_max))
189+
goto unsupported;
190+
191+
if (WARN_ON_ONCE(lim->atomic_write_hw_unit_max >
192+
lim->atomic_write_hw_max))
193+
goto unsupported;
194+
181195
boundary_sectors = lim->atomic_write_hw_boundary >> SECTOR_SHIFT;
182196

183197
if (boundary_sectors) {
198+
if (WARN_ON_ONCE(lim->atomic_write_hw_max >
199+
lim->atomic_write_hw_boundary))
200+
goto unsupported;
184201
/*
185202
* A feature of boundary support is that it disallows bios to
186203
* be merged which would result in a merged request which

0 commit comments

Comments
 (0)