[PATCH 1/1] virito: blk: fix logic to determine block sizes
Heinrich Schuchardt
heinrich.schuchardt at canonical.com
Thu Oct 9 18:44:35 CEST 2025
With commit c85b8071e7d3 ("virtio: blk: support block sizes exceeding 512
bytes") logic was added to detect the VIRTIO_BLK_F_BLK_SIZE capability and
to copy the block size reported by QEMU to the block device descriptor.
The logical block size can be set when invoking QEMU:
-drive if=none,file=4096.img,format=raw,id=vda \
-device virtio-blk-device,drive=vda,physical_block_size=4096,logical_block_size=4096
In U-Boot the logical block size is shown by command `virtio info`:
=> virtio info
Device 0: QEMU VirtIO Block Device
Type: Hard Disk
Capacity: 1024.0 MB = 1.0 GB (262144 x 4096)
There where two flaws which together hid that the logic was incorrect:
* VIRTIO_BLK_F_BLK_SIZE was missing in the driver capabilities and the bit
was filtered out.
* The result of the call to virtio_has_feature() was negated.
The problem became apparent when using ARM FVP as emulator which does not set
VIRTIO_BLK_F_BLK_SIZE.
Fixes: c85b8071e7d3 ("virtio: blk: support block sizes exceeding 512 bytes")
Reported-by: Debbie Horsfall <debbie.horsfall at arm.com>
Tested-by: Andre Przywara <andre.przywara at arm.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
drivers/virtio/virtio_blk.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/virtio/virtio_blk.c b/drivers/virtio/virtio_blk.c
index 4224e3c17f4..ec2e28b54f7 100644
--- a/drivers/virtio/virtio_blk.c
+++ b/drivers/virtio/virtio_blk.c
@@ -26,6 +26,7 @@ struct virtio_blk_priv {
};
static const u32 feature[] = {
+ VIRTIO_BLK_F_BLK_SIZE,
VIRTIO_BLK_F_WRITE_ZEROES
};
@@ -194,7 +195,7 @@ static int virtio_blk_probe(struct udevice *dev)
virtio_cread(dev, struct virtio_blk_config, capacity, &cap);
desc->lba = cap;
- if (!virtio_has_feature(dev, VIRTIO_BLK_F_BLK_SIZE)) {
+ if (virtio_has_feature(dev, VIRTIO_BLK_F_BLK_SIZE)) {
virtio_cread(dev, struct virtio_blk_config, blk_size, &blk_size);
desc->blksz = blk_size;
if (!is_power_of_2(blk_size) || desc->blksz < 512)
--
2.51.0
More information about the U-Boot
mailing list