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 08/15] efi/libstub: arm64: Use struct efi_image_info to access image properties
Date: Mon, 16 Nov 2026 15:26:27 +0100 [thread overview]
Message-ID: <20261116142618.1687025-25-ardb+git@google.com> (raw)
In-Reply-To: <20261116142618.1687025-17-ardb+git@google.com>
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 | 10 ------
drivers/firmware/efi/libstub/arm64-stub.c | 33 ++++++--------------
2 files changed, 9 insertions(+), 34 deletions(-)
diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
index 19d602e45523..329d5e214b36 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
@@ -32,14 +30,6 @@ PROVIDE(__efistub_primary_entry = primary_entry);
* position independent manner
*/
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
PROVIDE(__efistub__ctype = _ctype);
PROVIDE(__pi___memcpy = __pi_memcpy);
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index c93ab8b6e9d3..8ff8f8651504 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"
@@ -22,23 +21,23 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_handle_t image_handle,
const struct efi_image_info **image_info)
{
- unsigned long kernel_size, kernel_codesize, kernel_memsize;
+ 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;
- 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;
status = efi_kaslr_relocate_kernel(image_addr, reserve_addr,
reserve_size, kernel_size,
@@ -48,24 +47,10 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
if (status != EFI_SUCCESS)
return status;
- *(unsigned long *)image_info += *image_addr - (unsigned long)_text;
+ *(unsigned long *)image_info += *image_addr - kernel_base;
return EFI_SUCCESS;
}
-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);
--
2.56.0.611.g1030f0b940-goog
next prev parent reply other threads:[~2026-11-16 14:27 UTC|newest]
Thread overview: 21+ 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:33 ` sashiko-bot
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:59 ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 07/15] efi/libstub: Pass kernel entrypoint down to efi_enter_kernel() Ard Biesheuvel
2026-11-16 14:39 ` sashiko-bot
2026-11-16 14:26 ` Ard Biesheuvel [this message]
2026-11-16 14:26 ` [PATCH v3 09/15] efi/libstub: loongarch: Use struct efi_image_info to access image properties Ard Biesheuvel
2026-11-16 14:40 ` sashiko-bot
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:52 ` sashiko-bot
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-25-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