block: Enforce power-of-2 physical block size

The merging/splitting code and other queue limits checking depends on the
physical block size being a power-of-2, so enforce it.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20250729091448.1691334-3-john.g.garry@oracle.com
[axboe: add missing braces]
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
John Garry 2025-07-29 09:14:48 +00:00 committed by Jens Axboe
parent 448dfecc7f
commit 1da67b5b17

View File

@ -320,8 +320,12 @@ int blk_validate_limits(struct queue_limits *lim)
pr_warn("Invalid logical block size (%d)\n", lim->logical_block_size);
return -EINVAL;
}
if (lim->physical_block_size < lim->logical_block_size)
if (lim->physical_block_size < lim->logical_block_size) {
lim->physical_block_size = lim->logical_block_size;
} else if (!is_power_of_2(lim->physical_block_size)) {
pr_warn("Invalid physical block size (%d)\n", lim->physical_block_size);
return -EINVAL;
}
/*
* The minimum I/O size defaults to the physical block size unless