* [PATCH v2 00/10] efi: Expose loaded image properties via info struct
@ 2026-11-10 12:17 Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 01/10] efi/zboot: arm64: Add missing barrier after cache maintenance Ard Biesheuvel
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@kernel.org>
Clean up the arm64 build script and linker hacks that zboot uses to
obtain properties of the loaded image (which it cannot access directly
via a relative reference like the ordinary EFI stub).
Instead, define a generic struct efi_image_info, and expose its offset
in the loaded image in a similar manner, but without relying on explicit
linker script exports.
Populate the struct with section markers that all architecture use for
loading the kernel image at boot, so that all the linker exports can be
dropped for them.
Changes since v1:
- drop arm64 image header changes
- move efi_image_info out of __efistub_ scope so it can access vmlinux
symbols directly
- implement in a generic manner for all architectures that support zboot
- address Sashiko comments
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: loongarch@lists.linux.dev
Cc: linux-riscv@lists.infradead.org
Link: https://lore.kernel.org/all/0-v2-989a18390eb1+486-arm64_drtm_jgg@nvidia.com/
Ard Biesheuvel (10):
efi/zboot: arm64: Add missing barrier after cache maintenance
efi/riscv: Rename __init_text_end to __inittext_end like other archs
efi/libstub: Avoid _end section marker in library code
efi/libstub: Capture loaded image information in struct efi_image_info
efi/libstub: arm64: Use struct efi_image_info to access image
properties
efi/libstub: loongarch: Use struct efi_image_info to access image
properties
efi/libstub: riscv: Use struct efi_image_info to access image
properties
efi/libstub: Make efi_remap_image() return efi_status_t
efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image()
efi/libstub: arm64: Drop zboot code_size hack
arch/arm64/boot/Makefile | 3 --
arch/arm64/kernel/efi-header.S | 2 +
arch/arm64/kernel/image-vars.h | 10 ----
arch/loongarch/kernel/head.S | 1 +
arch/loongarch/kernel/image-vars.h | 1 -
arch/riscv/include/asm/sections.h | 2 +-
arch/riscv/kernel/head.S | 1 +
arch/riscv/kernel/image-vars.h | 5 --
arch/riscv/kernel/vmlinux.lds.S | 4 +-
drivers/firmware/efi/libstub/Makefile | 1 +
drivers/firmware/efi/libstub/Makefile.zboot | 11 ++++-
drivers/firmware/efi/libstub/arm32-stub.c | 3 ++
drivers/firmware/efi/libstub/arm64-stub.c | 20 ++++----
drivers/firmware/efi/libstub/arm64.c | 8 ++--
drivers/firmware/efi/libstub/efi-stub-entry.c | 10 +++-
drivers/firmware/efi/libstub/efi-stub-helper.c | 15 ++++--
drivers/firmware/efi/libstub/efi-stub.c | 3 +-
drivers/firmware/efi/libstub/efistub.h | 48 ++++++++++++++++++--
drivers/firmware/efi/libstub/image_info.S | 12 +++++
drivers/firmware/efi/libstub/kaslr.c | 2 +-
drivers/firmware/efi/libstub/loongarch-stub.c | 4 +-
drivers/firmware/efi/libstub/riscv-stub.c | 14 +++---
drivers/firmware/efi/libstub/zboot-decompress-gzip.c | 2 -
drivers/firmware/efi/libstub/zboot-decompress-zstd.c | 2 -
drivers/firmware/efi/libstub/zboot.c | 29 +++++++++++-
drivers/firmware/efi/libstub/zboot.lds | 6 +--
26 files changed, 150 insertions(+), 69 deletions(-)
create mode 100644 drivers/firmware/efi/libstub/image_info.S
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 01/10] efi/zboot: arm64: Add missing barrier after cache maintenance
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 02/10] efi/riscv: Rename __init_text_end to __inittext_end like other archs Ard Biesheuvel
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv,
stable
From: Ard Biesheuvel <ardb@kernel.org>
Prevent the I-cache from fetching stale data by issuing a barrier after
the data cache maintenance completes but before performing the I-cache
maintenance.
Cc: <stable@vger.kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/arm64.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/firmware/efi/libstub/arm64.c b/drivers/firmware/efi/libstub/arm64.c
index e57cd3de0a00..62fc8e53c8a0 100644
--- a/drivers/firmware/efi/libstub/arm64.c
+++ b/drivers/firmware/efi/libstub/arm64.c
@@ -107,6 +107,8 @@ void efi_cache_sync_image(unsigned long image_base,
base += lsize;
size -= lsize;
} while (size >= lsize);
+
+ dsb(ish);
}
asm("ic ialluis");
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 02/10] efi/riscv: Rename __init_text_end to __inittext_end like other archs
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 01/10] efi/zboot: arm64: Add missing barrier after cache maintenance Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 03/10] efi/libstub: Avoid _end section marker in library code Ard Biesheuvel
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@kernel.org>
Align RISC-V with arm64, LoongArch and x86, and drop the underscore
between 'init' and 'text' in the section markers. This allows the value
to be captured by generic EFI stub code that can be shared between all
those architectures.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/riscv/include/asm/sections.h | 2 +-
arch/riscv/kernel/image-vars.h | 2 +-
arch/riscv/kernel/vmlinux.lds.S | 4 ++--
drivers/firmware/efi/libstub/riscv-stub.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/include/asm/sections.h b/arch/riscv/include/asm/sections.h
index a393d5035c54..4a882a28f414 100644
--- a/arch/riscv/include/asm/sections.h
+++ b/arch/riscv/include/asm/sections.h
@@ -11,7 +11,7 @@
extern char _start[];
extern char _start_kernel[];
extern char __init_data_begin[], __init_data_end[];
-extern char __init_text_begin[], __init_text_end[];
+extern char __inittext_begin[], __inittext_end[];
extern char __alt_start[], __alt_end[];
extern char __exittext_begin[], __exittext_end[];
diff --git a/arch/riscv/kernel/image-vars.h b/arch/riscv/kernel/image-vars.h
index 7b44b94f1283..bf703eba3fa5 100644
--- a/arch/riscv/kernel/image-vars.h
+++ b/arch/riscv/kernel/image-vars.h
@@ -27,7 +27,7 @@ __efistub__start = _start;
__efistub__start_kernel = _start_kernel;
__efistub__end = _end;
__efistub__edata = _edata;
-__efistub___init_text_end = __init_text_end;
+__efistub___inittext_end = __inittext_end;
#if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
__efistub_sysfb_primary_display = sysfb_primary_display;
#endif
diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
index 1f4f8496941a..08ada0591f3a 100644
--- a/arch/riscv/kernel/vmlinux.lds.S
+++ b/arch/riscv/kernel/vmlinux.lds.S
@@ -46,7 +46,7 @@ SECTIONS
. = ALIGN(SECTION_ALIGN);
__init_begin = .;
- __init_text_begin = .;
+ __inittext_begin = .;
.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) ALIGN(SECTION_ALIGN) { \
_sinittext = .; \
INIT_TEXT \
@@ -72,7 +72,7 @@ SECTIONS
}
__exittext_end = .;
- __init_text_end = .;
+ __inittext_end = .;
. = ALIGN(SECTION_ALIGN);
#ifdef CONFIG_EFI
. = ALIGN(PECOFF_SECTION_ALIGNMENT);
diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c
index 725b634c5179..5cbc50a814e1 100644
--- a/drivers/firmware/efi/libstub/riscv-stub.c
+++ b/drivers/firmware/efi/libstub/riscv-stub.c
@@ -34,7 +34,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_status_t status;
kernel_size = _edata - _start;
- kernel_codesize = __init_text_end - _start;
+ kernel_codesize = __inittext_end - _start;
kernel_memsize = kernel_size + (_end - _edata);
*image_addr = (unsigned long)_start;
*reserve_size = kernel_memsize;
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 03/10] efi/libstub: Avoid _end section marker in library code
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 01/10] efi/zboot: arm64: Add missing barrier after cache maintenance Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 02/10] efi/riscv: Rename __init_text_end to __inittext_end like other archs Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 04/10] efi/libstub: Capture loaded image information in struct efi_image_info Ard Biesheuvel
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@kernel.org>
The _end marker could point to the end of the kernel image being loaded,
or to the _end of the zboot decompressor image, and so it should only be
used in code that is obviously only intended for the former case.
So instead, use kernel_memsize and the image address to obtain the same
quantity.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/kaslr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/firmware/efi/libstub/kaslr.c b/drivers/firmware/efi/libstub/kaslr.c
index 8f8dc335b3b3..b34e4599f0f6 100644
--- a/drivers/firmware/efi/libstub/kaslr.c
+++ b/drivers/firmware/efi/libstub/kaslr.c
@@ -125,7 +125,7 @@ efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
if (!check_image_region(*image_addr, kernel_memsize)) {
efi_err("FIRMWARE BUG: Image BSS overlaps adjacent EFI memory region\n");
} else if (IS_ALIGNED(*image_addr, min_kimg_align) &&
- (unsigned long)_end < EFI_ALLOC_LIMIT) {
+ (*image_addr + kernel_memsize) < EFI_ALLOC_LIMIT) {
/*
* Just execute from wherever we were loaded by the
* UEFI PE/COFF loader if the placement is suitable.
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 04/10] efi/libstub: Capture loaded image information in struct efi_image_info
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (2 preceding siblings ...)
2026-11-10 12:17 ` [PATCH v2 03/10] efi/libstub: Avoid _end section marker in library code Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 05/10] efi/libstub: arm64: Use struct efi_image_info to access image properties Ard Biesheuvel
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@kernel.org>
Define a struct efi_image_info that carries properties of the loaded
kernel image, and pass a pointer to it to efi_stub_common() so that EFI
stub code can access there properties in a consistent manner for both
the uncompressed kernel and the EFI zboot image.
Note that zboot can only access this information after decompressing the
image, whereas code that is part of the EFI stub that gets integrated
into Linux can just grab the efi_image_info pointer as needed.
ARM implements neither, but -like x86- incorporates the EFI stub into
its own decompressor. It has no need for this functionality, so emit a
dummy struct to satisfy the linker.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
| 2 +
arch/loongarch/kernel/head.S | 1 +
arch/riscv/kernel/head.S | 1 +
drivers/firmware/efi/libstub/Makefile | 1 +
drivers/firmware/efi/libstub/Makefile.zboot | 11 ++++-
drivers/firmware/efi/libstub/arm32-stub.c | 3 ++
drivers/firmware/efi/libstub/efi-stub-entry.c | 10 ++++-
drivers/firmware/efi/libstub/efi-stub.c | 3 +-
drivers/firmware/efi/libstub/efistub.h | 44 +++++++++++++++++++-
drivers/firmware/efi/libstub/image_info.S | 12 ++++++
drivers/firmware/efi/libstub/zboot.c | 17 +++++++-
drivers/firmware/efi/libstub/zboot.lds | 2 +
12 files changed, 101 insertions(+), 6 deletions(-)
--git a/arch/arm64/kernel/efi-header.S b/arch/arm64/kernel/efi-header.S
index 329e8df9215f..54ca61d03403 100644
--- a/arch/arm64/kernel/efi-header.S
+++ b/arch/arm64/kernel/efi-header.S
@@ -7,6 +7,8 @@
#include <linux/pe.h>
#include <linux/sizes.h>
+SYM_FUNC_ALIAS(efi_primary_entry, primary_entry)
+
.macro efi_signature_nop
#ifdef CONFIG_EFI
.L_head:
diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S
index 601ddd78b233..69c31b0b65c5 100644
--- a/arch/loongarch/kernel/head.S
+++ b/arch/loongarch/kernel/head.S
@@ -35,6 +35,7 @@ pe_header:
SYM_DATA(kernel_asize, .long _kernel_asize);
SYM_DATA(kernel_fsize, .long _kernel_fsize);
+SYM_FUNC_ALIAS(efi_primary_entry, kernel_entry)
#endif
__REF
diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index 1631fd6bc786..6c81f32be70b 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -28,6 +28,7 @@ SYM_CODE_START(_start)
* that expects this header format!!
*/
#ifdef CONFIG_EFI
+SYM_FUNC_ALIAS(efi_primary_entry, _start_kernel)
/*
* This instruction decodes to "MZ" ASCII required by UEFI.
*/
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index bbab12b8eb4b..9dc6a707fd79 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -107,6 +107,7 @@ lib-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o bitmap.o find.o
targets := $(lib-y)
lib-y := $(patsubst %.o,%.stub.o,$(lib-y))
+lib-$(CONFIG_EFI_GENERIC_STUB) += image_info.o
# Even when -mbranch-protection=none is set, Clang will generate a
# .note.gnu.property for code-less object files (like lib/ctype.c),
diff --git a/drivers/firmware/efi/libstub/Makefile.zboot b/drivers/firmware/efi/libstub/Makefile.zboot
index 52baacf3e9d9..e2769bbec963 100644
--- a/drivers/firmware/efi/libstub/Makefile.zboot
+++ b/drivers/firmware/efi/libstub/Makefile.zboot
@@ -26,9 +26,18 @@ zboot-size-len-$(CONFIG_KERNEL_ZSTD) := 4
$(obj)/vmlinuz: $(obj)/vmlinux.bin FORCE
+$(call if_changed,$(zboot-method-y))
+# subtract the two symbol values to obtain the offset of struct efi_image_info
+get_image_info_offset = $(shell $(NM) -n $(objtree)/vmlinux |\
+ grep -E ' _text$$| __efistub_efistub_image_info$$' |\
+ awk 'NR == 1 { a = toupper($$1) } \
+ NR == 2 { print "obase=16; ibase=16; " toupper($$1) "-" a }' |\
+ bc)
+
# avoid eager evaluation to prevent references to non-existent build artifacts
OBJCOPYFLAGS_vmlinuz.o = -I binary -O $(EFI_ZBOOT_BFD_TARGET) $(EFI_ZBOOT_OBJCOPY_FLAGS) \
- --rename-section .data=.gzdata,load,alloc,readonly,contents
+ --rename-section .data=.gzdata,load,alloc,readonly,contents \
+ --add-symbol efistub_image_info_offset=0x$(get_image_info_offset)
+
$(obj)/vmlinuz.o: $(obj)/vmlinuz FORCE
$(call if_changed,objcopy)
diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c
index 1073dd947516..53ade94f4bdb 100644
--- a/drivers/firmware/efi/libstub/arm32-stub.c
+++ b/drivers/firmware/efi/libstub/arm32-stub.c
@@ -132,3 +132,6 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
return EFI_SUCCESS;
}
+
+/* expose a dummy struct - ARM does not use this anyway */
+struct efi_image_info efistub_image_info = {};
diff --git a/drivers/firmware/efi/libstub/efi-stub-entry.c b/drivers/firmware/efi/libstub/efi-stub-entry.c
index efa3ab8ad1c6..c173c0dd8454 100644
--- a/drivers/firmware/efi/libstub/efi-stub-entry.c
+++ b/drivers/firmware/efi/libstub/efi-stub-entry.c
@@ -27,6 +27,13 @@ struct sysfb_display_info *alloc_primary_display(void)
return NULL;
}
+const struct efi_image_info *efistub_get_image_info(void)
+{
+ extern const struct efi_image_info efistub_image_info;
+
+ return &efistub_image_info;
+}
+
/*
* EFI entry point for the generic EFI stub used by ARM, arm64, RISC-V and
* LoongArch. This is the entrypoint that is described in the PE/COFF header
@@ -80,7 +87,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
kernel_image_offset = image_addr - (unsigned long)image->image_base;
- status = efi_stub_common(handle, image, image_addr, cmdline_ptr);
+ status = efi_stub_common(handle, image, image_addr, cmdline_ptr,
+ efistub_get_image_info());
efi_free(image_size, image_addr);
efi_free(reserve_size, reserve_addr);
diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
index 6db10590f89b..ee5931eed59c 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -161,7 +161,8 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr)
efi_status_t efi_stub_common(efi_handle_t handle,
efi_loaded_image_t *image,
unsigned long image_addr,
- char *cmdline_ptr)
+ char *cmdline_ptr,
+ const struct efi_image_info *image_info)
{
struct sysfb_display_info *dpy;
efi_status_t status;
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index f5eec8c12894..394796472cc0 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1148,11 +1148,53 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_loaded_image_t *image,
efi_handle_t image_handle);
+struct efi_image_info {
+ s32 _text_offset;
+ s32 __inittext_end_offset;
+ s32 _edata_offset;
+ s32 _end_offset;
+ s32 entry_offset;
+};
+
+const struct efi_image_info *efistub_get_image_info(void);
+const struct efi_image_info *zboot_get_image_info(unsigned long image_base);
+
+static inline
+unsigned long efistub_kernel_base(const struct efi_image_info *image_info)
+{
+ return (unsigned long)offset_to_ptr(&image_info->_text_offset);
+}
+
+static inline
+unsigned long efistub_kernel_size(const struct efi_image_info *image_info)
+{
+ return image_info->_edata_offset - image_info->_text_offset;
+}
+
+static inline
+unsigned long efistub_kernel_memsize(const struct efi_image_info *image_info)
+{
+ return image_info->_end_offset - image_info->_text_offset;
+}
+
+static inline
+unsigned long efistub_kernel_codesize(const struct efi_image_info *image_info)
+{
+ return image_info->__inittext_end_offset - image_info->_text_offset;
+}
+
+static inline
+unsigned long efistub_kernel_entry_offset(const struct efi_image_info *image_info)
+{
+ return image_info->entry_offset - image_info->_text_offset;
+}
+
/* shared entrypoint between the normal stub and the zboot stub */
efi_status_t efi_stub_common(efi_handle_t handle,
efi_loaded_image_t *image,
unsigned long image_addr,
- char *cmdline_ptr);
+ char *cmdline_ptr,
+ const struct efi_image_info *image_info);
efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr);
diff --git a/drivers/firmware/efi/libstub/image_info.S b/drivers/firmware/efi/libstub/image_info.S
new file mode 100644
index 000000000000..3d3dded0f451
--- /dev/null
+++ b/drivers/firmware/efi/libstub/image_info.S
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#define REL_REF(sym) .long sym - 0b
+
+ .globl __efistub_efistub_image_info
+ .p2align 3
+__efistub_efistub_image_info:
+0: REL_REF(_text)
+ REL_REF(__inittext_end)
+ REL_REF(_edata)
+ REL_REF(_end)
+ REL_REF(efi_primary_entry)
diff --git a/drivers/firmware/efi/libstub/zboot.c b/drivers/firmware/efi/libstub/zboot.c
index 4a5ffe164873..c6071b0e8f1a 100644
--- a/drivers/firmware/efi/libstub/zboot.c
+++ b/drivers/firmware/efi/libstub/zboot.c
@@ -31,6 +31,13 @@ struct sysfb_display_info *alloc_primary_display(void)
return __alloc_primary_display();
}
+const struct efi_image_info *zboot_get_image_info(unsigned long image_base)
+{
+ extern const u32 efistub_image_info_offset;
+
+ return (void *)image_base + efistub_image_info_offset;
+}
+
asmlinkage efi_status_t __efiapi
efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)
{
@@ -93,9 +100,15 @@ efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)
}
// Decompress the payload into the newly allocated buffer
- status = efi_zboot_decompress((void *)image_base, alloc_size) ?:
- efi_stub_common(handle, image, image_base, cmdline_ptr);
+ status = efi_zboot_decompress((void *)image_base, alloc_size);
+ if (status != EFI_SUCCESS)
+ goto error;
+
+ auto image_info = zboot_get_image_info(image_base);
+ status = efi_stub_common(handle, image, image_base, cmdline_ptr,
+ image_info);
+error:
efi_free(alloc_size, image_base);
return status;
}
diff --git a/drivers/firmware/efi/libstub/zboot.lds b/drivers/firmware/efi/libstub/zboot.lds
index 367907eb7d86..e1365907f805 100644
--- a/drivers/firmware/efi/libstub/zboot.lds
+++ b/drivers/firmware/efi/libstub/zboot.lds
@@ -24,6 +24,8 @@ SECTIONS
. = ALIGN(4);
__efistub_code_size = .;
LONG(zboot_code_size);
+ __efistub_efistub_image_info_offset = .;
+ LONG(efistub_image_info_offset);
_etext = ALIGN(4096);
. = _etext;
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 05/10] efi/libstub: arm64: Use struct efi_image_info to access image properties
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (3 preceding siblings ...)
2026-11-10 12:17 ` [PATCH v2 04/10] efi/libstub: Capture loaded image information in struct efi_image_info Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 06/10] efi/libstub: loongarch: " Ard Biesheuvel
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@kernel.org>
Instead of exposing individual symbols to the EFI stub explicitly via
the linker script, use the generic struct efi_image_info, which accesses
the original symbols via PC-relative references from the stub itself.
This improves code reuse across architectures, and makes it easier to
add new references in a generic manner.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm64/kernel/image-vars.h | 6 ------
drivers/firmware/efi/libstub/arm64-stub.c | 20 ++++++++++----------
2 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
index 19d602e45523..9ab71d103f64 100644
--- a/arch/arm64/kernel/image-vars.h
+++ b/arch/arm64/kernel/image-vars.h
@@ -20,8 +20,6 @@
PROVIDE(pisym = sym); \
ASSERT((sym - KIMAGE_VADDR) < (__bss_start - KIMAGE_VADDR), #msg)
-PROVIDE(__efistub_primary_entry = primary_entry);
-
/*
* The EFI stub has its own symbol namespace prefixed by __efistub_, to
* isolate it from the kernel proper. The following symbols are legally
@@ -33,10 +31,6 @@ PROVIDE(__efistub_primary_entry = primary_entry);
*/
PROVIDE(__efistub_caches_clean_inval_pou = __pi_caches_clean_inval_pou);
-PROVIDE(__efistub__text = _text);
-PROVIDE(__efistub__end = _end);
-PROVIDE(__efistub___inittext_end = __inittext_end);
-PROVIDE(__efistub__edata = _edata);
#if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
PROVIDE(__efistub_sysfb_primary_display = sysfb_primary_display);
#endif
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index 2c3869356147..8184b345af69 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -10,7 +10,6 @@
#include <linux/efi.h>
#include <asm/efi.h>
#include <asm/memory.h>
-#include <asm/sections.h>
#include "efistub.h"
@@ -21,22 +20,23 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_loaded_image_t *image,
efi_handle_t image_handle)
{
- unsigned long kernel_size, kernel_codesize, kernel_memsize;
+ auto image_info = efistub_get_image_info();
+ unsigned long kernel_base = efistub_kernel_base(image_info);
+ unsigned long kernel_size = efistub_kernel_size(image_info);
+ unsigned long kernel_codesize = efistub_kernel_codesize(image_info);
+ unsigned long kernel_memsize = efistub_kernel_memsize(image_info);
- if (image->image_base != _text) {
+ if (image->image_base != (void *)kernel_base) {
efi_err("FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value\n");
- image->image_base = _text;
+ image->image_base = (void *)kernel_base;
}
- if (!IS_ALIGNED((u64)_text, SEGMENT_ALIGN))
+ if (!IS_ALIGNED(kernel_base, SEGMENT_ALIGN))
efi_err("FIRMWARE BUG: kernel image not aligned on %dk boundary\n",
SEGMENT_ALIGN >> 10);
- kernel_size = _edata - _text;
- kernel_codesize = __inittext_end - _text;
- kernel_memsize = kernel_size + (_end - _edata);
*reserve_size = kernel_memsize;
- *image_addr = (unsigned long)_text;
+ *image_addr = kernel_base;
return efi_kaslr_relocate_kernel(image_addr, reserve_addr, reserve_size,
kernel_size, kernel_codesize, kernel_memsize,
@@ -54,7 +54,7 @@ unsigned long primary_entry_offset(void)
* of the file representation. So instead, we need to jump to the
* actual entrypoint in the .text region of the image.
*/
- return (char *)primary_entry - _text;
+ return efistub_kernel_entry_offset(efistub_get_image_info());
}
void efi_icache_sync(unsigned long start, unsigned long end)
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 06/10] efi/libstub: loongarch: Use struct efi_image_info to access image properties
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (4 preceding siblings ...)
2026-11-10 12:17 ` [PATCH v2 05/10] efi/libstub: arm64: Use struct efi_image_info to access image properties Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 07/10] efi/libstub: riscv: " Ard Biesheuvel
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@kernel.org>
Instead of exposing individual symbols to the EFI stub explicitly via
the linker script, use the generic struct efi_image_info, which accesses
the original symbols via PC-relative references from the stub itself.
This improves code reuse across architectures, and makes it easier to
add new references in a generic manner.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/loongarch/kernel/image-vars.h | 1 -
drivers/firmware/efi/libstub/loongarch-stub.c | 4 +---
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/arch/loongarch/kernel/image-vars.h b/arch/loongarch/kernel/image-vars.h
index e557ebd46c2b..d8676cea754a 100644
--- a/arch/loongarch/kernel/image-vars.h
+++ b/arch/loongarch/kernel/image-vars.h
@@ -8,7 +8,6 @@
#ifdef CONFIG_EFI_STUB
__efistub_strcmp = strcmp;
-__efistub_kernel_entry = kernel_entry;
__efistub_kernel_asize = kernel_asize;
__efistub_kernel_fsize = kernel_fsize;
#if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c
index c87ac7025107..ab7e73e38334 100644
--- a/drivers/firmware/efi/libstub/loongarch-stub.c
+++ b/drivers/firmware/efi/libstub/loongarch-stub.c
@@ -118,7 +118,5 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long kernel_entry_address(unsigned long kernel_addr,
efi_loaded_image_t *image)
{
- unsigned long base = (unsigned long)image->image_base;
-
- return (unsigned long)&kernel_entry - base + kernel_addr;
+ return kernel_addr + efistub_kernel_entry_offset(efistub_get_image_info());
}
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 07/10] efi/libstub: riscv: Use struct efi_image_info to access image properties
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (5 preceding siblings ...)
2026-11-10 12:17 ` [PATCH v2 06/10] efi/libstub: loongarch: " Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 08/10] efi/libstub: Make efi_remap_image() return efi_status_t Ard Biesheuvel
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@kernel.org>
Instead of exposing individual symbols to the EFI stub explicitly via
the linker script, use the generic struct efi_image_info, which accesses
the original symbols via PC-relative references from the stub itself.
This improves code reuse across architectures, and makes it easier to
add new references in a generic manner.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/riscv/kernel/image-vars.h | 5 -----
drivers/firmware/efi/libstub/riscv-stub.c | 14 +++++++-------
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/arch/riscv/kernel/image-vars.h b/arch/riscv/kernel/image-vars.h
index bf703eba3fa5..27efb990da43 100644
--- a/arch/riscv/kernel/image-vars.h
+++ b/arch/riscv/kernel/image-vars.h
@@ -23,11 +23,6 @@
* linked at. The routines below are all implemented in assembler in a
* position independent manner
*/
-__efistub__start = _start;
-__efistub__start_kernel = _start_kernel;
-__efistub__end = _end;
-__efistub__edata = _edata;
-__efistub___inittext_end = __inittext_end;
#if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
__efistub_sysfb_primary_display = sysfb_primary_display;
#endif
diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c
index 5cbc50a814e1..e8d66f6fe8e0 100644
--- a/drivers/firmware/efi/libstub/riscv-stub.c
+++ b/drivers/firmware/efi/libstub/riscv-stub.c
@@ -6,7 +6,6 @@
#include <linux/efi.h>
#include <asm/efi.h>
-#include <asm/sections.h>
#include <linux/unaligned.h>
#include "efistub.h"
@@ -20,7 +19,7 @@ unsigned long stext_offset(void)
* of the file representation. So instead, we need to jump to the
* actual entrypoint in the .text region of the image.
*/
- return _start_kernel - _start;
+ return efistub_kernel_entry_offset(efistub_get_image_info());
}
efi_status_t handle_kernel_image(unsigned long *image_addr,
@@ -30,13 +29,14 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_loaded_image_t *image,
efi_handle_t image_handle)
{
- unsigned long kernel_size, kernel_codesize, kernel_memsize;
+ auto image_info = efistub_get_image_info();
+ unsigned long kernel_base = efistub_kernel_base(image_info);
+ unsigned long kernel_size = efistub_kernel_size(image_info);
+ unsigned long kernel_codesize = efistub_kernel_codesize(image_info);
+ unsigned long kernel_memsize = efistub_kernel_memsize(image_info);
efi_status_t status;
- kernel_size = _edata - _start;
- kernel_codesize = __inittext_end - _start;
- kernel_memsize = kernel_size + (_end - _edata);
- *image_addr = (unsigned long)_start;
+ *image_addr = kernel_base;
*reserve_size = kernel_memsize;
status = efi_kaslr_relocate_kernel(image_addr,
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 08/10] efi/libstub: Make efi_remap_image() return efi_status_t
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (6 preceding siblings ...)
2026-11-10 12:17 ` [PATCH v2 07/10] efi/libstub: riscv: " Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 09/10] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image() Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 10/10] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@kernel.org>
efi_remap_image() uses the EFI Memory Attributes Protocol to remap code
and data regions with the appropriate permissions. This could fail for a
variety of regions, all of which are currently ignored.
So relay the failure status code if any occur when invoking the
protocol. Locating the protocol itself is allowed to fail, as remapping
the image is likely unnecessary in the first place if the protocol does
not exist.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/efi-stub-helper.c | 15 ++++++++++-----
drivers/firmware/efi/libstub/efistub.h | 4 ++--
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index 8e43eb3f418b..e50deec99686 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -697,9 +697,11 @@ efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key)
* region of the loaded image read-only/executable, and the remainder
* read-write/non-executable. The code region is assumed to start at the base
* of the image, and will therefore cover the PE/COFF header as well.
+ *
+ * Return: EFI_SUCCESS on success, other EFI status codes on failure.
*/
-void efi_remap_image(unsigned long image_base, unsigned alloc_size,
- unsigned long code_size)
+efi_status_t efi_remap_image(unsigned long image_base, unsigned alloc_size,
+ unsigned long code_size)
{
static efi_guid_t guid = EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID;
efi_memory_attribute_protocol_t *memattr;
@@ -710,10 +712,12 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
* If the firmware implements the EFI_MEMORY_ATTRIBUTE_PROTOCOL, let's
* invoke it to remap the text/rodata region of the decompressed image
* as read-only and the data/bss region as non-executable.
+ * Don't bother if the protocol does not exist: it means all memory is
+ * read-write-exec anyway.
*/
status = efi_bs_call(locate_protocol, &guid, NULL, (void **)&memattr);
if (status != EFI_SUCCESS)
- return;
+ return EFI_SUCCESS;
// Get the current attributes for the entire region
status = memattr->get_memory_attributes(memattr, image_base,
@@ -721,7 +725,7 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
if (status != EFI_SUCCESS) {
efi_warn("Failed to retrieve memory attributes for image region: 0x%lx\n",
status);
- return;
+ return status;
}
// Mark the code region as read-only
@@ -729,7 +733,7 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
EFI_MEMORY_RO);
if (status != EFI_SUCCESS) {
efi_warn("Failed to remap code region read-only\n");
- return;
+ return status;
}
// If the entire region was already mapped as non-exec, clear the
@@ -749,4 +753,5 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
if (status != EFI_SUCCESS)
efi_warn("Failed to remap data region non-executable\n");
}
+ return status;
}
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 394796472cc0..e2a9339f3e2c 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1283,8 +1283,8 @@ struct efi_smbios_type4_record {
const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,
const u8 *offset);
-void efi_remap_image(unsigned long image_base, unsigned alloc_size,
- unsigned long code_size);
+efi_status_t efi_remap_image(unsigned long image_base, unsigned alloc_size,
+ unsigned long code_size);
efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
unsigned long *reserve_addr,
unsigned long *reserve_size,
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 09/10] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image()
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (7 preceding siblings ...)
2026-11-10 12:17 ` [PATCH v2 08/10] efi/libstub: Make efi_remap_image() return efi_status_t Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 10/10] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@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@kernel.org>
---
drivers/firmware/efi/libstub/arm64.c | 2 --
drivers/firmware/efi/libstub/zboot-decompress-gzip.c | 2 --
drivers/firmware/efi/libstub/zboot-decompress-zstd.c | 2 --
drivers/firmware/efi/libstub/zboot.c | 14 +++++++++++++-
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/firmware/efi/libstub/arm64.c b/drivers/firmware/efi/libstub/arm64.c
index 62fc8e53c8a0..fdd48ba0f9f1 100644
--- a/drivers/firmware/efi/libstub/arm64.c
+++ b/drivers/firmware/efi/libstub/arm64.c
@@ -114,8 +114,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/zboot-decompress-gzip.c b/drivers/firmware/efi/libstub/zboot-decompress-gzip.c
index e97a7e9d3c98..79cf8c48b033 100644
--- a/drivers/firmware/efi/libstub/zboot-decompress-gzip.c
+++ b/drivers/firmware/efi/libstub/zboot-decompress-gzip.c
@@ -62,7 +62,5 @@ efi_status_t efi_zboot_decompress(u8 *out, unsigned long outlen)
return EFI_LOAD_ERROR;
}
- efi_cache_sync_image((unsigned long)out, outlen);
-
return EFI_SUCCESS;
}
diff --git a/drivers/firmware/efi/libstub/zboot-decompress-zstd.c b/drivers/firmware/efi/libstub/zboot-decompress-zstd.c
index bde9d94dd2e3..dd7f11238154 100644
--- a/drivers/firmware/efi/libstub/zboot-decompress-zstd.c
+++ b/drivers/firmware/efi/libstub/zboot-decompress-zstd.c
@@ -43,7 +43,5 @@ efi_status_t efi_zboot_decompress(u8 *out, unsigned long outlen)
return EFI_LOAD_ERROR;
}
- efi_cache_sync_image((unsigned long)out, outlen);
-
return EFI_SUCCESS;
}
diff --git a/drivers/firmware/efi/libstub/zboot.c b/drivers/firmware/efi/libstub/zboot.c
index c6071b0e8f1a..25ff5960771c 100644
--- a/drivers/firmware/efi/libstub/zboot.c
+++ b/drivers/firmware/efi/libstub/zboot.c
@@ -38,6 +38,17 @@ const struct efi_image_info *zboot_get_image_info(unsigned long image_base)
return (void *)image_base + efistub_image_info_offset;
}
+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_kernel_codesize(image_info);
+
+ efi_cache_sync_image(image_base, code_size);
+
+ return efi_remap_image(image_base, image_size, code_size);
+}
+
asmlinkage efi_status_t __efiapi
efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)
{
@@ -105,7 +116,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.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 10/10] efi/libstub: arm64: Drop zboot code_size hack
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (8 preceding siblings ...)
2026-11-10 12:17 ` [PATCH v2 09/10] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image() Ard Biesheuvel
@ 2026-11-10 12:17 ` Ard Biesheuvel
9 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2026-11-10 12:17 UTC (permalink / raw)
To: linux-efi
Cc: linux-arm-kernel, Ard Biesheuvel, Jason Gunthorpe, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Huacai Chen, loongarch, linux-riscv
From: Ard Biesheuvel <ardb@kernel.org>
Now that the code size can be obtained via the generic image_info
struct, there is no longer a need to inject it explicitly during the
build.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm64/boot/Makefile | 3 ---
arch/arm64/kernel/image-vars.h | 4 ----
drivers/firmware/efi/libstub/arm64.c | 4 +---
drivers/firmware/efi/libstub/zboot.lds | 4 ----
4 files changed, 1 insertion(+), 14 deletions(-)
diff --git a/arch/arm64/boot/Makefile b/arch/arm64/boot/Makefile
index d42d07667822..509b59518818 100644
--- a/arch/arm64/boot/Makefile
+++ b/arch/arm64/boot/Makefile
@@ -51,7 +51,4 @@ EFI_ZBOOT_BFD_TARGET := elf64-littleaarch64
EFI_ZBOOT_MACH_TYPE := ARM64
EFI_ZBOOT_FORWARD_CFI := $(CONFIG_ARM64_BTI_KERNEL)
-EFI_ZBOOT_OBJCOPY_FLAGS = --add-symbol zboot_code_size=0x$$( \
- $(NM) vmlinux|grep _kernel_codesize|cut -d' ' -f1)
-
include $(srctree)/drivers/firmware/efi/libstub/Makefile.zboot
diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
index 9ab71d103f64..22b242a7a21b 100644
--- a/arch/arm64/kernel/image-vars.h
+++ b/arch/arm64/kernel/image-vars.h
@@ -144,10 +144,6 @@ KVM_NVHE_ALIAS(kvm_protected_mode_initialized);
#endif /* CONFIG_KVM */
-#ifdef CONFIG_EFI_ZBOOT
-_kernel_codesize = ABSOLUTE(__inittext_end - _text);
-#endif
-
/*
* LLD will occasionally error out with a '__init_end does not converge' error
* if INIT_IDMAP_DIR_SIZE is defined in terms of _end, as this results in a
diff --git a/drivers/firmware/efi/libstub/arm64.c b/drivers/firmware/efi/libstub/arm64.c
index fdd48ba0f9f1..4399b23fa237 100644
--- a/drivers/firmware/efi/libstub/arm64.c
+++ b/drivers/firmware/efi/libstub/arm64.c
@@ -88,8 +88,6 @@ efi_status_t check_platform_features(void)
#define DCTYPE "cvau"
#endif
-u32 __weak code_size;
-
void efi_cache_sync_image(unsigned long image_base,
unsigned long alloc_size)
{
@@ -100,7 +98,7 @@ void efi_cache_sync_image(unsigned long image_base,
/* only perform the cache maintenance if needed for I/D coherency */
if (!(ctr & BIT(CTR_EL0_IDC_SHIFT))) {
unsigned long base = image_base;
- unsigned long size = code_size;
+ unsigned long size = alloc_size;
do {
asm("dc " DCTYPE ", %0" :: "r"(base));
diff --git a/drivers/firmware/efi/libstub/zboot.lds b/drivers/firmware/efi/libstub/zboot.lds
index e1365907f805..e0f0bf005854 100644
--- a/drivers/firmware/efi/libstub/zboot.lds
+++ b/drivers/firmware/efi/libstub/zboot.lds
@@ -2,8 +2,6 @@
ENTRY(__efistub_efi_zboot_header);
-PROVIDE(zboot_code_size = ABSOLUTE(0));
-
SECTIONS
{
.head : ALIGN(4096) {
@@ -22,8 +20,6 @@ SECTIONS
*(.rodata* .init.rodata* .srodata*)
. = ALIGN(4);
- __efistub_code_size = .;
- LONG(zboot_code_size);
__efistub_efistub_image_info_offset = .;
LONG(efistub_image_info_offset);
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-11-10 12:18 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10 12:17 [PATCH v2 00/10] efi: Expose loaded image properties via info struct Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 01/10] efi/zboot: arm64: Add missing barrier after cache maintenance Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 02/10] efi/riscv: Rename __init_text_end to __inittext_end like other archs Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 03/10] efi/libstub: Avoid _end section marker in library code Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 04/10] efi/libstub: Capture loaded image information in struct efi_image_info Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 05/10] efi/libstub: arm64: Use struct efi_image_info to access image properties Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 06/10] efi/libstub: loongarch: " Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 07/10] efi/libstub: riscv: " Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 08/10] efi/libstub: Make efi_remap_image() return efi_status_t Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 09/10] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image() Ard Biesheuvel
2026-11-10 12:17 ` [PATCH v2 10/10] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox