virito: blk: fix logic to determine block sizes
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 9 Oct 2025 16:44:35 +0000 (18:44 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 17 Oct 2025 00:01:42 +0000 (18:01 -0600)
commit7e65d29b6618603a51053d5fa9f4ef585e5b8959
tree5b105517d1e341ba9aa40759d6cec0fd1a724940
parentf6c01ec1510b95a623eb6d60647275a974582415
virito: blk: fix logic to determine block sizes

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@arm.com>
Tested-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
drivers/virtio/virtio_blk.c