[PATCH master 3/4] efi: loader: disk: don't require block-size aligned I/O buffers

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Aug 26 02:36:50 PDT 2026


The Block I/O protocol's io_align member tells the consumer what
alignment the buffers passed to read_blocks()/write_blocks() need to
have. We set it to the block size, but our implementation services all
requests via cdev_read()/cdev_write(), which copy through the block
layer's cache chunks regardless of the caller's buffer alignment, so
there is no such requirement.

Report an io_align of 1 instead, which per UEFI specification, like 0,
means the buffer can be placed anywhere in memory. Prefer 1 over 0 as
a consumer computing the mask as io_align - 1 without checking for 0
first (as U-Boot's own producer side does) keeps working with 1, but
would reject every buffer with 0.

Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 efi/loader/protocols/disk.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/efi/loader/protocols/disk.c b/efi/loader/protocols/disk.c
index 5c5447acca20..5376c9ec9a14 100644
--- a/efi/loader/protocols/disk.c
+++ b/efi/loader/protocols/disk.c
@@ -253,7 +253,13 @@ static efi_status_t efi_disk_add_cdev(efi_handle_t parent,
 	diskobj->media.removable_media = removable;
 	diskobj->media.media_present = true;
 	diskobj->media.read_only = cdev->flags & DEVFS_PARTITION_READONLY;
-	diskobj->media.block_size = diskobj->media.io_align = 1u << blockbits;
+	diskobj->media.block_size = 1u << blockbits;
+	/*
+	 * Reads and writes go through cdev_read()/cdev_write(), which
+	 * always copy through the block layer cache, so any buffer
+	 * alignment is acceptable.
+	 */
+	diskobj->media.io_align = 1;
 	diskobj->media.last_block = (cdev->size >> blockbits) - 1;
 	diskobj->blockbits = blockbits;
 
-- 
2.47.3




More information about the barebox mailing list