mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 3/4] efi: loader: disk: don't require block-size aligned I/O buffers
Date: Wed, 26 Aug 2026 11:36:50 +0200	[thread overview]
Message-ID: <20260826093701.2486248-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260826093701.2486248-1-a.fatoum@pengutronix.de>

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@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




  parent reply	other threads:[~2026-08-26  9:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26  9:36 [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Ahmad Fatoum
2026-08-26  9:36 ` [PATCH master 2/4] efi: loader: fix sign of the error passed to ERR_PTR() Ahmad Fatoum
2026-08-26  9:36 ` Ahmad Fatoum [this message]
2026-08-26  9:36 ` [PATCH master 4/4] efi: loader: select PRINTF_WCHAR Ahmad Fatoum
2026-08-28 11:59 ` [PATCH master 1/4] efi: loader: don't truncate the status in efi_init_runtime_variable_supported() Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260826093701.2486248-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox