Re: [PATCH v1 1/3] ublk: reject non-power-of-2 zone sizes in SET_PARAMS

Ming Lei <[email protected]>
Newsgroups org.kernel.vger.linux-block
Message-ID <CACVXFVP1gc3arTkP8eStdokYZCUU-KEFJ7dJ_VNiF8i0j1o1jA@mail.gmail.com>
On Thu, Aug 13, 2026 at 9:33 PM Yao Sang <[email protected]> wrote:
>
> UBLK_F_ZONED uses params.basic.chunk_sectors as zone size. ublk uses
> ilog2(chunk_sectors) to get number of zones, so the value must be power
> of 2.
>
> If chunk_sectors is 96 and dev_sectors is 96 * 16, userspace asks for
> 16 zones. But the shift calculation gets 24 zones.
>
> Block layer rejects such zone size when the disk is started. But
> SET_PARAMS has already returned success, which is confusing for
> userspace. Reject it in SET_PARAMS with other zoned parameter checks.
>
> Fixes: 29802d7ca33b ("ublk: enable zoned storage support")
> Signed-off-by: Yao Sang <[email protected]>
> ---
>  drivers/block/ublk_drv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 853cd40a3403..193f6ebc3b37 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -980,7 +980,7 @@ static int ublk_validate_params(const struct ublk_device *ub)
>                 if (p->max_sectors < PAGE_SECTORS)
>                         return -EINVAL;
>
> -               if (ublk_dev_is_zoned(ub) && !p->chunk_sectors)
> +               if (ublk_dev_is_zoned(ub) && !is_power_of_2(p->chunk_sectors))

Looks fine,  and is_power_of_2() returns false for 0.

Thanks,
Ming Lei
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.