[PATCH 3/5] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image()
Ard Biesheuvel
ardb+git at google.com
Fri Nov 6 06:19:40 PST 2026
From: Ard Biesheuvel <ardb at kernel.org>
Refactor efi_cache_sync_image() so that it is not in charge of calling
efi_remap_image(), which is really the wrong way around.
Instead, call efi_remap_image() from the primary zboot procedure, where
it is more straight-forward to obtain the code size from the loaded
image.
Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
---
arch/arm64/include/asm/efi.h | 3 +++
drivers/firmware/efi/libstub/arm64.c | 2 --
drivers/firmware/efi/libstub/efistub.h | 4 ++++
drivers/firmware/efi/libstub/zboot.c | 23 +++++++++++++++++++-
4 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index e8a9783235cb..da6afd4a7a27 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -151,4 +151,7 @@ efi_status_t efi_handle_corrupted_x18(efi_status_t s, const char *f);
void efi_icache_sync(unsigned long start, unsigned long end);
+// temporary resolution for efistub_get_code_size()
+#define efistub_get_code_size(image_info) ({ extern u32 code_size; code_size; })
+
#endif /* _ASM_EFI_H */
diff --git a/drivers/firmware/efi/libstub/arm64.c b/drivers/firmware/efi/libstub/arm64.c
index e57cd3de0a00..7ab634e37cf1 100644
--- a/drivers/firmware/efi/libstub/arm64.c
+++ b/drivers/firmware/efi/libstub/arm64.c
@@ -112,8 +112,6 @@ void efi_cache_sync_image(unsigned long image_base,
asm("ic ialluis");
dsb(ish);
isb();
-
- efi_remap_image(image_base, alloc_size, code_size);
}
unsigned long __weak primary_entry_offset(void)
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 1955cdb5139a..89cd2ae57a3c 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1270,4 +1270,8 @@ void arch_accept_memory(phys_addr_t start, phys_addr_t end);
efi_status_t efi_zboot_decompress_init(unsigned long *alloc_size);
efi_status_t efi_zboot_decompress(u8 *out, unsigned long outlen);
+#ifndef efistub_get_code_size
+#define efistub_get_code_size(image_info) 0
+#endif
+
#endif
diff --git a/drivers/firmware/efi/libstub/zboot.c b/drivers/firmware/efi/libstub/zboot.c
index 97ae706c034a..27f6661253c0 100644
--- a/drivers/firmware/efi/libstub/zboot.c
+++ b/drivers/firmware/efi/libstub/zboot.c
@@ -36,6 +36,26 @@ const struct efi_image_info * __weak zboot_get_image_info(unsigned long image_ba
return NULL;
}
+static efi_status_t efi_zboot_remap_image(const struct efi_image_info *image_info,
+ unsigned long image_base,
+ unsigned long image_size)
+{
+ unsigned long code_size = efistub_get_code_size(image_info);
+ efi_status_t status;
+
+ if (code_size) {
+ efi_cache_sync_image(image_base, code_size);
+
+ status = efi_remap_image(image_base, image_size, code_size);
+ if (status != EFI_SUCCESS)
+ return status;
+ } else {
+ efi_cache_sync_image(image_base, image_size);
+ }
+
+ return EFI_SUCCESS;
+}
+
asmlinkage efi_status_t __efiapi
efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)
{
@@ -103,7 +123,8 @@ efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)
goto error;
auto image_info = zboot_get_image_info(image_base);
- status = efi_stub_common(handle, image, image_base, cmdline_ptr,
+ status = efi_zboot_remap_image(image_info, image_base, alloc_size) ?:
+ efi_stub_common(handle, image, image_base, cmdline_ptr,
image_info);
error:
--
2.56.0.455.g6c5a503b38-goog
More information about the linux-arm-kernel
mailing list