Skip to contentSkip to conversation

block: zero logical block size leads to infinite loop in set_init_blocksize()

DISCUSSION Maks 2 participants 5 messages Sep 3 – Sep 9 Block layer

lore
Share & tools
lore

Maks

author
#0 lore raw

Hi,

I hit a soft lockup in set_init_blocksize() with a block device whose logical_block_size was zero.

I understand that logical_block_size == 0 violates the block layer contract and that the driver which allowed this value needs to be fixed.

However, the generic block code currently turns this invariant violation into a non-terminating loop:

while (bsize < PAGE_SIZE) {
    if (size & bsize)
        break;
    bsize <<= 1;
}

With bsize == 0, the value never changes.

In my case this resulted in:

watchdog: BUG: soft lockup - CPU#0 stuck for 26s! [(udev-worker):...]
RIP: set_init_blocksize+0x28/0x60

Call Trace:
  blkdev_get_whole+...
  bdev_open+...

Is this considered acceptable behavior for a broken driver, or should the generic block layer defensively detect this case and fail the open instead of spinning indefinitely?

If adding such a check is considered worthwhile, I can prepare a patch.

Thanks,
Maks

#1 lore raw
Quoted 11 lines · Maks

Hi,

I hit a soft lockup in set_init_blocksize() with a block device whose logical_block_size was zero.

I understand that logical_block_size == 0 violates the block layer contract and that the driver which allowed this value needs to be fixed.

However, the generic block code currently turns this invariant violation into a non-terminating loop:

Quoted 7 lines
while (bsize < PAGE_SIZE) {
    if (size & bsize)
        break;
    bsize <<= 1;
}

With bsize == 0, the value never changes.

How did you manage to get a block_device created, but bypassed the check and override for a zero logical block size in blk_validate_limits()? Is your driver writing over the limits outside the API's update path?

#2 lore raw
Quoted 1 line

Is your driver writing over the limits outside the API's update path?

Yes, it does update the queue limits directly:

    volume->queue->limits = limits;

There is no blk_validate_limits() call on this path, so this bypasses the normal queue limits validation.

чт, 3 сент. 2026 г. в 20:55, Keith Busch <[email protected]>:

Quoted 24 lines · Maks
Quoted 11 lines

Hi,

I hit a soft lockup in set_init_blocksize() with a block device whose logical_block_size was zero.

I understand that logical_block_size == 0 violates the block layer contract and that the driver which allowed this value needs to be fixed.

However, the generic block code currently turns this invariant violation into a non-terminating loop:

Quoted 7 lines
while (bsize < PAGE_SIZE) {
    if (size & bsize)
        break;
    bsize <<= 1;
}

With bsize == 0, the value never changes.

How did you manage to get a block_device created, but bypassed the check and override for a zero logical block size in blk_validate_limits()? Is your driver writing over the limits outside the API's update path?

author
#3 lore raw
In reply to Keith Busch

Hi,

Quoted 3 lines

How did you manage to get a block_device created, but bypassed the check and override for a zero logical block size in blk_validate_limits()? Is your driver writing over the limits outside the API's update path?

Yes, it does update the queue limits directly:

    volume->queue->limits = limits;

There is no blk_validate_limits() call on this path, so this bypasses the normal queue limits validation.

Given that the driver is clearly bypassing the normal queue limits validation, would a defensive check in set_init_blocksize() still be considered worthwhile to avoid the infinite loop in this case?

If so, I can prepare and send a patch.

Thanks,
Maks

#4 lore raw
Quoted 8 lines · Maks

Hi,

Quoted 3 lines

How did you manage to get a block_device created, but bypassed the check and override for a zero logical block size in blk_validate_limits()? Is your driver writing over the limits outside the API's update path?

Yes, it does update the queue limits directly:

Quoted 8 lines
    volume->queue->limits = limits;

There is no blk_validate_limits() call on this path, so this bypasses the normal queue limits validation.

Given that the driver is clearly bypassing the normal queue limits validation, would a defensive check in set_init_blocksize() still be considered worthwhile to avoid the infinite loop in this case?

There's just a lot more places than set_init_blocksize() that assumes bdev_logical_block_size() returns a validated value. If you've a driver bypassing the API's that manage this field, then there's many other functions that also won't work correctly.