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 v4 09/19] efi/libstub: Pass kernel entrypoint down to efi_enter_kernel()
Date: Wed, 18 Nov 2026 19:21:15 +0100 [thread overview]
Message-ID: <20261118182105.1633603-30-ardb+git@google.com> (raw)
In-Reply-To: <20261118182105.1633603-21-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.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm/boot/compressed/head.S | 3 ++-
arch/arm64/include/asm/efi.h | 2 --
arch/riscv/include/asm/efi.h | 2 --
drivers/firmware/efi/libstub/arm64-stub.c | 15 ---------------
drivers/firmware/efi/libstub/arm64.c | 16 ++--------------
drivers/firmware/efi/libstub/efi-stub.c | 2 +-
drivers/firmware/efi/libstub/efistub.h | 13 +++++++------
drivers/firmware/efi/libstub/fdt.c | 5 +++--
drivers/firmware/efi/libstub/loongarch.c | 3 ++-
drivers/firmware/efi/libstub/riscv-stub.c | 13 -------------
drivers/firmware/efi/libstub/riscv.c | 16 +++-------------
11 files changed, 20 insertions(+), 70 deletions(-)
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 9f406e9c0ea6..6e4d8ce0efbb 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -1450,7 +1450,8 @@ __enter_kernel_from_hyp:
b __enter_kernel
ENTRY(efi_enter_kernel)
- mov r4, r0 @ preserve image base
+ ldr r4, [r0] @ preserve image base
+ add r4, r4, r0
mov r8, r1 @ preserve DT pointer
adr_l r0, call_cache_fn
diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index e8a9783235cb..d5775f38efea 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -103,8 +103,6 @@ static inline unsigned long efi_get_kimg_min_align(void)
#define EFI_ALLOC_ALIGN SZ_64K
#define EFI_ALLOC_LIMIT ((1UL << 48) - 1)
-extern unsigned long primary_entry_offset(void);
-
/*
* On ARM systems, virtually remapped UEFI runtime services are set up in two
* distinct stages:
diff --git a/arch/riscv/include/asm/efi.h b/arch/riscv/include/asm/efi.h
index 46a355913b27..ded51c656126 100644
--- a/arch/riscv/include/asm/efi.h
+++ b/arch/riscv/include/asm/efi.h
@@ -43,8 +43,6 @@ static inline unsigned long efi_get_kimg_min_align(void)
void arch_efi_call_virt_setup(void);
void arch_efi_call_virt_teardown(void);
-unsigned long stext_offset(void);
-
void efi_icache_sync(unsigned long start, unsigned long end);
#endif /* _ASM_EFI_H */
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index b57cccd75ab5..6140def24c69 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"
@@ -35,20 +34,6 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_kaslr_get_phys_seed(image_handle));
}
-asmlinkage void primary_entry(void);
-
-unsigned long primary_entry_offset(void)
-{
- /*
- * When built as part of the kernel, the EFI stub cannot branch to the
- * kernel proper via the image header, as the PE/COFF header is
- * strictly not part of the in-memory presentation of the image, only
- * 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;
-}
-
void efi_icache_sync(unsigned long start, unsigned long end)
{
caches_clean_inval_pou(start, end);
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 edc768a54473..e45d16095247 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,9 +1206,9 @@ 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,
- unsigned long fdt_addr,
- unsigned long fdt_size);
+void __noreturn efi_enter_kernel(const struct efi_image_info *image_info,
+ unsigned long fdt_addr,
+ unsigned long fdt_size);
void efi_handle_post_ebs_state(void);
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-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c
index e4f9723d5055..840fdd63dccf 100644
--- a/drivers/firmware/efi/libstub/riscv-stub.c
+++ b/drivers/firmware/efi/libstub/riscv-stub.c
@@ -6,23 +6,10 @@
#include <linux/efi.h>
#include <asm/efi.h>
-#include <asm/sections.h>
#include <linux/unaligned.h>
#include "efistub.h"
-unsigned long stext_offset(void)
-{
- /*
- * When built as part of the kernel, the EFI stub cannot branch to the
- * kernel proper via the image header, as the PE/COFF header is
- * strictly not part of the in-memory presentation of the image, only
- * 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;
-}
-
efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *image_size,
unsigned long *reserve_addr,
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.1.708.g77570a6a1d-goog
next prev parent reply other threads:[~2026-11-18 18:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 01/19] efi/zboot: arm64: Add missing barrier after cache maintenance Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 02/19] riscv: Use _stext not _text to denote the start of kernel code Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 03/19] riscv: Make _text point to the start of the kernel image Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 04/19] efi/riscv: Rename __init_text_end to __inittext_end like other archs Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 05/19] efi/libstub: Avoid _end section marker in library code Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 06/19] efi/libstub: arm: Size the decompressed kernel allocation precisely Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 07/19] efi/libstub: Avoid reserve_addr/_size in efi_kaslr_relocate_kernel() Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 08/19] efi/libstub: Capture loaded image information in struct efi_image_info Ard Biesheuvel
2026-11-18 18:21 ` Ard Biesheuvel [this message]
2026-11-18 18:21 ` [PATCH v4 10/19] efi/libstub: arm: Simplify handle_kernel_image() Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 11/19] efi/libstub: Drop reserve_addr/_size params from handle_kernel_image() Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 12/19] efi/libstub: arm64: Use struct efi_image_info to access image properties Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 13/19] efi/libstub: loongarch: " Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 14/19] efi/libstub: riscv: " Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 15/19] efi/libstub: Make efi_remap_image() return efi_status_t Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 16/19] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image() Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 17/19] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 18/19] efi: Make config table based primary display handover ARM-only again Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 19/19] 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=20261118182105.1633603-30-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