From: Ard Biesheuvel <ardb+git@google.com>
To: linux-efi@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
Ard Biesheuvel <ardb@kernel.org>,
Jason Gunthorpe <jgg@nvidia.com>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Huacai Chen <chenhuacai@kernel.org>,
loongarch@lists.linux.dev, linux-riscv@lists.infradead.org
Subject: [PATCH v3 07/15] efi/libstub: Pass kernel entrypoint down to efi_enter_kernel()
Date: Mon, 16 Nov 2026 15:26:26 +0100 [thread overview]
Message-ID: <20261116142618.1687025-24-ardb+git@google.com> (raw)
In-Reply-To: <20261116142618.1687025-17-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
Update the EFI stub code shared by arm64 and RISC-V so that the kernel
entry point is taken from struct efi_image_info rather than from opaque
arithmetic performed on linker symbols.
Notably, this results in EFI zboot to enter via the actual kernel
entrypoint rather than byte 0x0 of the loaded image on these
architectures. Beyond that, it is mostly a cleanup that will allow
special linker exports for global symbols to be dropped in subsequent
patches.
ARM is a special case here, as it combines the EFI stub with its legacy
decompressor, and so the generic image_info carrying direct references
to vmlinux symbols cannot be used there. Instead, it provides an empty
struct efi_image_info, which is passed directly to its implementation of
efi_enter_kernel(). So on ARM, populate this efi_image_info with the
base address that the callee expects.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm/boot/compressed/head.S | 2 +-
drivers/firmware/efi/libstub/arm32-stub.c | 2 +-
drivers/firmware/efi/libstub/arm64.c | 16 ++--------------
drivers/firmware/efi/libstub/efi-stub.c | 2 +-
drivers/firmware/efi/libstub/efistub.h | 9 +++++----
drivers/firmware/efi/libstub/fdt.c | 5 +++--
drivers/firmware/efi/libstub/loongarch.c | 3 ++-
drivers/firmware/efi/libstub/riscv.c | 16 +++-------------
8 files changed, 18 insertions(+), 37 deletions(-)
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 9f406e9c0ea6..a7f58dfe41bc 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -1450,7 +1450,7 @@ __enter_kernel_from_hyp:
b __enter_kernel
ENTRY(efi_enter_kernel)
- mov r4, r0 @ preserve image base
+ ldr r4, [r0] @ preserve image base
mov r8, r1 @ preserve DT pointer
adr_l r0, call_cache_fn
diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c
index f7151a4915ba..b73a0b4fcd10 100644
--- a/drivers/firmware/efi/libstub/arm32-stub.c
+++ b/drivers/firmware/efi/libstub/arm32-stub.c
@@ -127,7 +127,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_bs_call(free_pages, *reserve_addr + MAX_UNCOMP_KERNEL_SIZE,
(alloc_size - MAX_UNCOMP_KERNEL_SIZE) / EFI_PAGE_SIZE);
- *image_addr = kernel_base + TEXT_OFFSET;
+ *image_addr = efistub_image_info._text_offset = kernel_base + TEXT_OFFSET;
*image_size = 0;
efi_debug("image addr == 0x%lx, reserve_addr == 0x%lx\n",
diff --git a/drivers/firmware/efi/libstub/arm64.c b/drivers/firmware/efi/libstub/arm64.c
index d35c6dd76601..e892302f4189 100644
--- a/drivers/firmware/efi/libstub/arm64.c
+++ b/drivers/firmware/efi/libstub/arm64.c
@@ -117,24 +117,12 @@ void efi_cache_sync_image(unsigned long image_base,
efi_remap_image(image_base, alloc_size, code_size);
}
-unsigned long __weak primary_entry_offset(void)
-{
- /*
- * By default, we can invoke the kernel via the branch instruction in
- * the image header, so offset #0. This will be overridden by the EFI
- * stub build that is linked into the core kernel, as in that case, the
- * image header may not have been loaded into memory, or may be mapped
- * with non-executable permissions.
- */
- return 0;
-}
-
-void __noreturn efi_enter_kernel(unsigned long entrypoint,
+void __noreturn efi_enter_kernel(const struct efi_image_info *image_info,
unsigned long fdt_addr,
unsigned long fdt_size)
{
void (* __noreturn enter_kernel)(u64, u64, u64, u64);
- enter_kernel = (void *)entrypoint + primary_entry_offset();
+ enter_kernel = efistub_kernel_entry(image_info);
enter_kernel(fdt_addr, 0, 0, 0);
}
diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
index bf9a9f53a95c..55bf7ed50c81 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -191,7 +191,7 @@ efi_status_t efi_stub_common(efi_handle_t handle,
install_memreserve_table();
- status = efi_boot_kernel(handle, image, image_addr, cmdline_ptr);
+ status = efi_boot_kernel(handle, image, image_info, cmdline_ptr);
free_primary_display(dpy);
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index bb8e360fee7b..b985ababbe66 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1054,9 +1054,6 @@ typedef efi_status_t (*efi_exit_boot_map_processing)(
efi_status_t efi_exit_boot_services(void *handle, void *priv,
efi_exit_boot_map_processing priv_func);
-efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
- unsigned long kernel_addr, char *cmdline_ptr);
-
void *get_fdt(unsigned long *fdt_size);
efi_status_t efi_alloc_virtmap(efi_memory_desc_t **virtmap,
@@ -1189,6 +1186,10 @@ void *efistub_kernel_entry(const struct efi_image_info *image_info)
return offset_to_ptr(&image_info->entry_offset);
}
+efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
+ const struct efi_image_info *image_info,
+ char *cmdline_ptr);
+
static inline
void *efistub_sysfb_display_info(const struct efi_image_info *image_info)
{
@@ -1205,7 +1206,7 @@ efi_status_t efi_stub_common(efi_handle_t handle,
efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr);
-asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint,
+asmlinkage void __noreturn efi_enter_kernel(const struct efi_image_info *image_info,
unsigned long fdt_addr,
unsigned long fdt_size);
diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c
index f01450b49975..09e9e5bc831e 100644
--- a/drivers/firmware/efi/libstub/fdt.c
+++ b/drivers/firmware/efi/libstub/fdt.c
@@ -344,7 +344,8 @@ efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
}
efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
- unsigned long kernel_addr, char *cmdline_ptr)
+ const struct efi_image_info *image_info,
+ char *cmdline_ptr)
{
unsigned long fdt_addr;
efi_status_t status;
@@ -359,7 +360,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
if (IS_ENABLED(CONFIG_ARM))
efi_handle_post_ebs_state();
- efi_enter_kernel(kernel_addr, fdt_addr, fdt_totalsize((void *)fdt_addr));
+ efi_enter_kernel(image_info, fdt_addr, fdt_totalsize((void *)fdt_addr));
/* not reached */
}
diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
index 2b0c87dc9908..7f21e79384d3 100644
--- a/drivers/firmware/efi/libstub/loongarch.c
+++ b/drivers/firmware/efi/libstub/loongarch.c
@@ -66,8 +66,9 @@ unsigned long __weak kernel_entry_address(unsigned long kernel_addr,
}
efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
- unsigned long kernel_addr, char *cmdline_ptr)
+ const struct efi_image_info *image_info, char *cmdline_ptr)
{
+ unsigned long kernel_addr = efistub_kernel_base(image_info);
kernel_entry_t real_kernel_entry;
struct exit_boot_struct priv;
unsigned long desc_size;
diff --git a/drivers/firmware/efi/libstub/riscv.c b/drivers/firmware/efi/libstub/riscv.c
index 49db47c05bfe..7be2774dea90 100644
--- a/drivers/firmware/efi/libstub/riscv.c
+++ b/drivers/firmware/efi/libstub/riscv.c
@@ -72,20 +72,10 @@ efi_status_t check_platform_features(void)
return EFI_SUCCESS;
}
-unsigned long __weak stext_offset(void)
+void __noreturn efi_enter_kernel(const struct efi_image_info *image_info,
+ unsigned long fdt, unsigned long fdt_size)
{
- /*
- * This fallback definition is used by the EFI zboot stub, which loads
- * the entire image so it can branch via the image header at offset #0.
- */
- return 0;
-}
-
-void __noreturn efi_enter_kernel(unsigned long entrypoint, unsigned long fdt,
- unsigned long fdt_size)
-{
- unsigned long kernel_entry = entrypoint + stext_offset();
- jump_kernel_func jump_kernel = (jump_kernel_func)kernel_entry;
+ jump_kernel_func jump_kernel = efistub_kernel_entry(image_info);
/*
* Jump to real kernel here with following constraints.
--
2.56.0.611.g1030f0b940-goog
next prev parent reply other threads:[~2026-11-16 14:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 14:26 [PATCH v3 00/15] efi: Expose loaded image properties via info struct Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 01/15] efi/zboot: arm64: Add missing barrier after cache maintenance Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 02/15] riscv: Use _stext not _text to denote the start of kernel code Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 03/15] riscv: Make _text point to the start of the kernel image Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 04/15] efi/riscv: Rename __init_text_end to __inittext_end like other archs Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 05/15] efi/libstub: Avoid _end section marker in library code Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 06/15] efi/libstub: Capture loaded image information in struct efi_image_info Ard Biesheuvel
2026-11-16 14:26 ` Ard Biesheuvel [this message]
2026-11-16 14:26 ` [PATCH v3 08/15] efi/libstub: arm64: Use struct efi_image_info to access image properties Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 09/15] efi/libstub: loongarch: " Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 10/15] efi/libstub: riscv: " Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 11/15] efi/libstub: Make efi_remap_image() return efi_status_t Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 12/15] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image() Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 13/15] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 14/15] efi: Make config table based primary display handover ARM-only again Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 15/15] Revert "efi: earlycon: Reprobe after parsing config tables" Ard Biesheuvel
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=20261116142618.1687025-24-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=jgg@nvidia.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=loongarch@lists.linux.dev \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.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