* [PATCH v4 01/19] efi/zboot: arm64: Add missing barrier after cache maintenance
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
@ 2026-11-18 18:21 ` 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
` (17 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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 | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/firmware/efi/libstub/arm64.c b/drivers/firmware/efi/libstub/arm64.c
index e57cd3de0a00..d35c6dd76601 100644
--- a/drivers/firmware/efi/libstub/arm64.c
+++ b/drivers/firmware/efi/libstub/arm64.c
@@ -109,6 +109,7 @@ void efi_cache_sync_image(unsigned long image_base,
} while (size >= lsize);
}
+ dsb(ish);
asm("ic ialluis");
dsb(ish);
isb();
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 02/19] riscv: Use _stext not _text to denote the start of kernel code
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 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 03/19] riscv: Make _text point to the start of the kernel image Ard Biesheuvel
` (16 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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>
On RISC-V, _text and _stext currently refer to the same location, i.e.,
the start of the .text output section, which follows the image header
(.head.text) emitted by HEAD_TEXT_SECTION. _start is the symbol that
refers to the actual start of the image.
On other architectures such as arm64, _text refers to the start of the
image, and _stext to the start of the kernel code, and generic code
(such as the EFI stub) may start relying on this distinction.
So switch the only user of _text in arch/riscv, i.e., the "Kernel code"
resource that is exposed via /proc/iomem (and from which the "Kernel
image" resource inherits its start address), over to _stext. This is a
no-op given that both symbols currently resolve to the same address, but
it permits _text to be moved to the start of the image, making it an
alias of _start.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/riscv/kernel/setup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index d79f99b86033..e6112d424fde 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -91,7 +91,7 @@ static int __init add_kernel_resources(void)
* child nodes.
*/
- code_res.start = __pa_symbol(_text);
+ code_res.start = __pa_symbol(_stext);
code_res.end = __pa_symbol(_etext) - 1;
code_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 03/19] riscv: Make _text point to the start of the kernel image
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 ` 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
` (15 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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>
On RISC-V, _text currently refers to the start of the .text output
section, which is placed after the image header (.head.text), and is
therefore equal to _stext. On other architectures such as arm64, _text
refers to the start of the image, and is used as such by generic code,
e.g., to describe the kernel mapping in /proc/kcore and in the ELF
headers of the vmcore, and by the EFI stub.
Now that arch/riscv no longer uses _text to refer to the start of the
kernel code, move it to the start of the image so that it is equal to
_start, and the distinction between _text and _stext is the same as on
other architectures.
This also means that the image header is no longer omitted from the
/proc/kcore and vmcore kernel text mappings. Other users of _text, such
as kallsyms and ftrace, only use it as a reference point to calculate
relative offsets, and are not affected by this change.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/riscv/kernel/vmlinux.lds.S | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
index 1f4f8496941a..9849a3e4d102 100644
--- a/arch/riscv/kernel/vmlinux.lds.S
+++ b/arch/riscv/kernel/vmlinux.lds.S
@@ -28,11 +28,11 @@ SECTIONS
/* Beginning of code and text segment */
. = LOAD_OFFSET;
_start = .;
+ _text = .;
HEAD_TEXT_SECTION
. = ALIGN(PAGE_SIZE);
.text : {
- _text = .;
_stext = .;
TEXT_TEXT
SCHED_TEXT
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 04/19] efi/riscv: Rename __init_text_end to __inittext_end like other archs
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (2 preceding siblings ...)
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 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 05/19] efi/libstub: Avoid _end section marker in library code Ard Biesheuvel
` (14 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
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 9849a3e4d102..0ec1b4b55e41 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,12 +72,12 @@ SECTIONS
}
__exittext_end = .;
- __init_text_end = .;
. = ALIGN(SECTION_ALIGN);
#ifdef CONFIG_EFI
. = ALIGN(PECOFF_SECTION_ALIGNMENT);
__pecoff_text_end = .;
#endif
+ __inittext_end = .;
/* Start of init data section */
__init_data_begin = .;
INIT_DATA_SECTION(16)
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.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 05/19] efi/libstub: Avoid _end section marker in library code
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (3 preceding siblings ...)
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 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 06/19] efi/libstub: arm: Size the decompressed kernel allocation precisely Ard Biesheuvel
` (13 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
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.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 06/19] efi/libstub: arm: Size the decompressed kernel allocation precisely
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (4 preceding siblings ...)
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 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 07/19] efi/libstub: Avoid reserve_addr/_size in efi_kaslr_relocate_kernel() Ard Biesheuvel
` (12 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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 ARM EFI stub reserves a window for the decompressed kernel, as the
decompressor writes it to memory without regard for other allocations
made while running under the firmware. Currently, this window is
MAX_UNCOMP_KERNEL_SIZE (32 MiB) in size, but it starts 5 pages below the
kernel's start address, to cover the initial page tables. This leaves
32 MiB minus 5 pages for the kernel itself, and nothing checks whether
that is sufficient. Large kernels (e.g., multiplatform builds with debug
options enabled) can exceed this, in which case the decompressed image
and its BSS overrun the reservation into memory that the firmware
regards as free, and which may have been handed out for the FDT, the
initrd or the EFI memory map.
So instead, size the window based on the actual memory footprint of the
kernel: the uncompressed image size, which is stored in the last 4 bytes
of the compressed payload, plus the size of BSS, which is recorded in
the zImage tag table, plus the size of the initial page tables, which is
4 pages, or 5 pages when LPAE is enabled.
While at it, drop the requirement that the window is aligned to a power
of two that is at least TEXT_OFFSET, which means 4 MiB when TEXT_OFFSET
is 0x208000 or 0x308000. The only actual requirement is that the
physical start of the kernel minus TEXT_OFFSET, which becomes
PHYS_OFFSET, is a multiple of 2 MiB, as required by the phys-to-virt
patching code. The reason for the larger alignment was that the existing
logic breaks down when the slack below the kernel exceeds the alignment,
and so this is fixed by making the additional space that is allocated to
accommodate the alignment the larger of 2 MiB and the size of the slack.
This also ensures that PHYS_OFFSET never ends up below the 2 MiB aligned
block containing the start of the allocation, which only requires DRAM
to be 2 MiB aligned rather than 4 MiB aligned.
Finally, free the unused parts at either end of the allocation without
updating alloc_base and alloc_size in place, so that both frees are
derived directly from the original allocation, and return the reserved
window to the caller as is.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm/include/asm/efi.h | 15 ++--------
drivers/firmware/efi/libstub/arm32-stub.c | 31 ++++++++++++--------
2 files changed, 20 insertions(+), 26 deletions(-)
diff --git a/arch/arm/include/asm/efi.h b/arch/arm/include/asm/efi.h
index e408399d5f0e..c28508c6e107 100644
--- a/arch/arm/include/asm/efi.h
+++ b/arch/arm/include/asm/efi.h
@@ -56,22 +56,11 @@ void efi_virtmap_unload(void);
/* arch specific definitions used by the stub code */
-/*
- * A reasonable upper bound for the uncompressed kernel size is 32 MBytes,
- * so we will reserve that amount of memory. We have no easy way to tell what
- * the actuall size of code + data the uncompressed kernel will use.
- * If this is insufficient, the decompressor will relocate itself out of the
- * way before performing the decompression.
- */
-#define MAX_UNCOMP_KERNEL_SIZE SZ_32M
-
/*
* phys-to-virt patching requires that the physical to virtual offset is a
- * multiple of 2 MiB. However, using an alignment smaller than TEXT_OFFSET
- * here throws off the memory allocation logic, so let's use the lowest power
- * of two greater than 2 MiB and greater than TEXT_OFFSET.
+ * multiple of 2 MiB.
*/
-#define EFI_PHYS_ALIGN max(UL(SZ_2M), roundup_pow_of_two(TEXT_OFFSET))
+#define EFI_PHYS_ALIGN SZ_2M
/* on ARM, the initrd should be loaded in a lowmem region */
static inline unsigned long efi_get_max_initrd_addr(unsigned long image_addr)
diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c
index 1073dd947516..1ab15d66e709 100644
--- a/drivers/firmware/efi/libstub/arm32-stub.c
+++ b/drivers/firmware/efi/libstub/arm32-stub.c
@@ -76,6 +76,12 @@ void efi_handle_post_ebs_state(void)
&efi_entry_state->sctlr_after_ebs);
}
+/* last unaligned u32 in the image carries the uncompressed size */
+extern u32 input_data_end[] __aligned(1);
+
+/* entry #3 in the zimage magic table carries the kernel's BSS size */
+extern u32 zimage_magic_table[] asm("_table_start");
+
efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *image_size,
unsigned long *reserve_addr,
@@ -83,18 +89,22 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_loaded_image_t *image,
efi_handle_t image_handle)
{
- const int slack = TEXT_OFFSET - 5 * PAGE_SIZE;
- int alloc_size = MAX_UNCOMP_KERNEL_SIZE + EFI_PHYS_ALIGN;
+ unsigned long kernel_memsize = input_data_end[-1] + zimage_magic_table[3];
+ const int pgdir_size = (4 + IS_ENABLED(CONFIG_ARM_LPAE)) * PAGE_SIZE;
+ int alloc_size = pgdir_size + ALIGN(kernel_memsize, EFI_PAGE_SIZE);
+ const int slack = TEXT_OFFSET - pgdir_size;
+ const unsigned long margin = max(EFI_PHYS_ALIGN, slack);
unsigned long alloc_base, kernel_base;
efi_status_t status;
/*
* Allocate space for the decompressed kernel as low as possible.
- * The region should be 16 MiB aligned, but the first 'slack' bytes
+ * The region should be 2 MiB aligned, but the first 'slack' bytes
* are not used by Linux, so we allow those to be occupied by the
* firmware.
*/
- status = efi_low_alloc_above(alloc_size, EFI_PAGE_SIZE, &alloc_base, 0x0);
+ status = efi_low_alloc_above(alloc_size + margin, EFI_PAGE_SIZE,
+ &alloc_base, 0x0);
if (status != EFI_SUCCESS) {
efi_err("Unable to allocate memory for uncompressed kernel.\n");
return status;
@@ -103,7 +113,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
if ((alloc_base % EFI_PHYS_ALIGN) > slack) {
/*
* More than 'slack' bytes are already occupied at the base of
- * the allocation, so we need to advance to the next 16 MiB block.
+ * the allocation, so we need to advance to the next 2 MiB block.
*/
kernel_base = round_up(alloc_base, EFI_PHYS_ALIGN);
efi_info("Free memory starts at 0x%lx, setting kernel_base to 0x%lx\n",
@@ -113,16 +123,11 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
}
*reserve_addr = kernel_base + slack;
- *reserve_size = MAX_UNCOMP_KERNEL_SIZE;
+ *reserve_size = alloc_size;
/* now free the parts that we will not use */
- if (*reserve_addr > alloc_base) {
- efi_bs_call(free_pages, alloc_base,
- (*reserve_addr - alloc_base) / EFI_PAGE_SIZE);
- alloc_size -= *reserve_addr - alloc_base;
- }
- efi_bs_call(free_pages, *reserve_addr + MAX_UNCOMP_KERNEL_SIZE,
- (alloc_size - MAX_UNCOMP_KERNEL_SIZE) / EFI_PAGE_SIZE);
+ efi_free(*reserve_addr - alloc_base, alloc_base); /* no-op if 0 */
+ efi_free(alloc_base + margin - *reserve_addr, *reserve_addr + alloc_size);
*image_addr = kernel_base + TEXT_OFFSET;
*image_size = 0;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 07/19] efi/libstub: Avoid reserve_addr/_size in efi_kaslr_relocate_kernel()
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (5 preceding siblings ...)
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 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 08/19] efi/libstub: Capture loaded image information in struct efi_image_info Ard Biesheuvel
` (11 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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>
Avoid reserve_addr and reserve_size to carry the information about the
allocated space for the relocated kernel, and instead, use a single
alloc_size output parameter that is wired to image_size.
While at it, don't use the alloc_size as an in/out parameter, but only
use it to return the allocated size (and leave it as 0x0 if the image
is going to execute in place)
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/arm64-stub.c | 3 +-
drivers/firmware/efi/libstub/efistub.h | 3 +-
drivers/firmware/efi/libstub/kaslr.c | 30 +++++++++-----------
drivers/firmware/efi/libstub/riscv-stub.c | 4 +--
4 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index 2c3869356147..fe0deae78e5b 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -35,10 +35,9 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
kernel_size = _edata - _text;
kernel_codesize = __inittext_end - _text;
kernel_memsize = kernel_size + (_end - _edata);
- *reserve_size = kernel_memsize;
*image_addr = (unsigned long)_text;
- return efi_kaslr_relocate_kernel(image_addr, reserve_addr, reserve_size,
+ return efi_kaslr_relocate_kernel(image_addr, image_size,
kernel_size, kernel_codesize, kernel_memsize,
efi_kaslr_get_phys_seed(image_handle));
}
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index f5eec8c12894..5c10815d9172 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1244,8 +1244,7 @@ const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,
void 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,
+ unsigned long *alloc_size,
unsigned long kernel_size,
unsigned long kernel_codesize,
unsigned long kernel_memsize,
diff --git a/drivers/firmware/efi/libstub/kaslr.c b/drivers/firmware/efi/libstub/kaslr.c
index b34e4599f0f6..49b05d0c0003 100644
--- a/drivers/firmware/efi/libstub/kaslr.c
+++ b/drivers/firmware/efi/libstub/kaslr.c
@@ -82,9 +82,8 @@ static bool check_image_region(u64 base, u64 size)
/**
* efi_kaslr_relocate_kernel() - Relocate the kernel (random if KASLR enabled)
- * @image_addr: Pointer to the current kernel location
- * @reserve_addr: Pointer to the relocated kernel location
- * @reserve_size: Size of the relocated kernel
+ * @image_addr: Pointer to variable carrying the image base address
+ * @alloc_size: Pointer to variable carrying the allocated size
* @kernel_size: Size of the text + data
* @kernel_codesize: Size of the text
* @kernel_memsize: Size of the text + data + bss
@@ -97,13 +96,13 @@ static bool check_image_region(u64 base, u64 size)
* Return: status code, EFI_SUCCESS if relocation is successful
*/
efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
- unsigned long *reserve_addr,
- unsigned long *reserve_size,
+ unsigned long *alloc_size,
unsigned long kernel_size,
unsigned long kernel_codesize,
unsigned long kernel_memsize,
u32 phys_seed)
{
+ unsigned long kernel_base = *image_addr;
efi_status_t status;
u64 min_kimg_align = efi_get_kimg_min_align();
@@ -112,8 +111,8 @@ efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
* If KASLR is enabled, and we have some randomness available,
* locate the kernel at a randomized offset in physical memory.
*/
- status = efi_random_alloc(*reserve_size, min_kimg_align,
- reserve_addr, phys_seed,
+ status = efi_random_alloc(kernel_memsize, min_kimg_align,
+ image_addr, phys_seed,
EFI_LOADER_CODE, 0, EFI_ALLOC_LIMIT);
if (status != EFI_SUCCESS)
efi_warn("efi_random_alloc() failed: 0x%lx\n", status);
@@ -122,33 +121,32 @@ efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
}
if (status != EFI_SUCCESS) {
- if (!check_image_region(*image_addr, kernel_memsize)) {
+ if (!check_image_region(kernel_base, kernel_memsize)) {
efi_err("FIRMWARE BUG: Image BSS overlaps adjacent EFI memory region\n");
- } else if (IS_ALIGNED(*image_addr, min_kimg_align) &&
- (*image_addr + kernel_memsize) < EFI_ALLOC_LIMIT) {
+ } else if (IS_ALIGNED(kernel_base, min_kimg_align) &&
+ (kernel_base + kernel_memsize) < EFI_ALLOC_LIMIT) {
/*
* Just execute from wherever we were loaded by the
* UEFI PE/COFF loader if the placement is suitable.
*/
- *reserve_size = 0;
return EFI_SUCCESS;
}
- status = efi_allocate_pages_aligned(*reserve_size, reserve_addr,
+ status = efi_allocate_pages_aligned(kernel_memsize, image_addr,
ULONG_MAX, min_kimg_align,
EFI_LOADER_CODE);
if (status != EFI_SUCCESS) {
efi_err("Failed to relocate kernel\n");
- *reserve_size = 0;
return status;
}
}
- memcpy((void *)*reserve_addr, (void *)*image_addr, kernel_size);
- *image_addr = *reserve_addr;
+ memcpy((void *)*image_addr, (void *)kernel_base, kernel_size);
+ *alloc_size = kernel_memsize;
+
efi_icache_sync(*image_addr, *image_addr + kernel_codesize);
- efi_remap_image(*image_addr, *reserve_size, kernel_codesize);
+ efi_remap_image(*image_addr, kernel_memsize, kernel_codesize);
return status;
}
diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c
index 5cbc50a814e1..d0fc04d21b56 100644
--- a/drivers/firmware/efi/libstub/riscv-stub.c
+++ b/drivers/firmware/efi/libstub/riscv-stub.c
@@ -37,10 +37,8 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
kernel_codesize = __inittext_end - _start;
kernel_memsize = kernel_size + (_end - _edata);
*image_addr = (unsigned long)_start;
- *reserve_size = kernel_memsize;
- status = efi_kaslr_relocate_kernel(image_addr,
- reserve_addr, reserve_size,
+ status = efi_kaslr_relocate_kernel(image_addr, image_size,
kernel_size, kernel_codesize, kernel_memsize,
efi_kaslr_get_phys_seed(image_handle));
if (status != EFI_SUCCESS)
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 08/19] efi/libstub: Capture loaded image information in struct efi_image_info
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (6 preceding siblings ...)
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 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 09/19] efi/libstub: Pass kernel entrypoint down to efi_enter_kernel() Ard Biesheuvel
` (10 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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 these 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 could just grab the efi_image_info pointer as needed.
However, in order to avoid future surprises, pass the efi_image_info
pointer down via the calls into the shared stub code, replacing the
image base address field, whose value can be derived from image_info as
well as long as it is taken from the copy of the image that will
ultimately be used to boot the kernel.
ARM implements neither, but -like x86- incorporates the EFI stub into
its own decompressor and cannot incorporate struct efi_image_info as
defined here, as it refers to global symbols in vmlinux. Assign the
efi_image_info._text_offset field at runtime so that generic code can
use efi_image_info to derive the base address of the loaded image. Other
fields are not used on ARM so ignore those.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
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 | 8 ++-
drivers/firmware/efi/libstub/arm64-stub.c | 13 +----
drivers/firmware/efi/libstub/efi-stub-entry.c | 22 +++----
drivers/firmware/efi/libstub/efi-stub.c | 10 ++--
drivers/firmware/efi/libstub/efistub.h | 61 ++++++++++++++++++--
drivers/firmware/efi/libstub/image_info.S | 19 ++++++
drivers/firmware/efi/libstub/kaslr.c | 17 +++---
drivers/firmware/efi/libstub/loongarch-stub.c | 4 +-
drivers/firmware/efi/libstub/riscv-stub.c | 12 +---
drivers/firmware/efi/libstub/zboot.c | 22 +++++--
drivers/firmware/efi/libstub/zboot.lds | 2 +
16 files changed, 148 insertions(+), 58 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 1ab15d66e709..798b2ae3bb03 100644
--- a/drivers/firmware/efi/libstub/arm32-stub.c
+++ b/drivers/firmware/efi/libstub/arm32-stub.c
@@ -82,12 +82,15 @@ extern u32 input_data_end[] __aligned(1);
/* entry #3 in the zimage magic table carries the kernel's BSS size */
extern u32 zimage_magic_table[] asm("_table_start");
+struct efi_image_info efistub_image_info = {};
+
efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *image_size,
unsigned long *reserve_addr,
unsigned long *reserve_size,
efi_loaded_image_t *image,
- efi_handle_t image_handle)
+ efi_handle_t image_handle,
+ const struct efi_image_info **image_info)
{
unsigned long kernel_memsize = input_data_end[-1] + zimage_magic_table[3];
const int pgdir_size = (4 + IS_ENABLED(CONFIG_ARM_LPAE)) * PAGE_SIZE;
@@ -122,6 +125,9 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
kernel_base = round_down(alloc_base, EFI_PHYS_ALIGN);
}
+ efistub_image_info._text_offset =
+ kernel_base + TEXT_OFFSET - (u32)&efistub_image_info;
+
*reserve_addr = kernel_base + slack;
*reserve_size = alloc_size;
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index fe0deae78e5b..b57cccd75ab5 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -19,10 +19,9 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *reserve_addr,
unsigned long *reserve_size,
efi_loaded_image_t *image,
- efi_handle_t image_handle)
+ efi_handle_t image_handle,
+ const struct efi_image_info **image_info)
{
- unsigned long kernel_size, kernel_codesize, kernel_memsize;
-
if (image->image_base != _text) {
efi_err("FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value\n");
image->image_base = _text;
@@ -32,13 +31,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
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);
- *image_addr = (unsigned long)_text;
-
- return efi_kaslr_relocate_kernel(image_addr, image_size,
- kernel_size, kernel_codesize, kernel_memsize,
+ return efi_kaslr_relocate_kernel(image_addr, image_size, image_info,
efi_kaslr_get_phys_seed(image_handle));
}
diff --git a/drivers/firmware/efi/libstub/efi-stub-entry.c b/drivers/firmware/efi/libstub/efi-stub-entry.c
index efa3ab8ad1c6..36ea6aa2cfcc 100644
--- a/drivers/firmware/efi/libstub/efi-stub-entry.c
+++ b/drivers/firmware/efi/libstub/efi-stub-entry.c
@@ -7,22 +7,17 @@
#include "efistub.h"
-static unsigned long kernel_image_offset;
+extern const struct efi_image_info efistub_image_info;
-static void *kernel_image_addr(void *addr)
-{
- return addr + kernel_image_offset;
-}
-
-struct sysfb_display_info *alloc_primary_display(void)
+struct sysfb_display_info *
+alloc_primary_display(const struct efi_image_info *image_info)
{
if (IS_ENABLED(CONFIG_ARM))
return __alloc_primary_display();
- if (IS_ENABLED(CONFIG_X86) ||
- IS_ENABLED(CONFIG_EFI_EARLYCON) ||
+ if (IS_ENABLED(CONFIG_EFI_EARLYCON) ||
IS_ENABLED(CONFIG_SYSFB))
- return kernel_image_addr(&sysfb_primary_display);
+ return efistub_sysfb_display_info(image_info);
return NULL;
}
@@ -36,6 +31,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
efi_system_table_t *systab)
{
static efi_guid_t loaded_image_proto = LOADED_IMAGE_PROTOCOL_GUID;
+ const struct efi_image_info *image_info = &efistub_image_info;
efi_loaded_image_t *image;
efi_status_t status;
unsigned long image_addr;
@@ -72,15 +68,13 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
status = handle_kernel_image(&image_addr, &image_size,
&reserve_addr,
&reserve_size,
- image, handle);
+ image, handle, &image_info);
if (status != EFI_SUCCESS) {
efi_err("Failed to relocate kernel\n");
return status;
}
- 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_info, cmdline_ptr);
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..bf9a9f53a95c 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -51,14 +51,15 @@ static bool flat_va_mapping = (EFI_RT_VIRTUAL_OFFSET != 0);
void __weak free_primary_display(struct sysfb_display_info *dpy)
{ }
-static struct sysfb_display_info *setup_primary_display(void)
+static struct sysfb_display_info *
+setup_primary_display(const struct efi_image_info *image_info)
{
struct sysfb_display_info *dpy;
struct screen_info *screen = NULL;
struct edid_info *edid = NULL;
efi_status_t status;
- dpy = alloc_primary_display();
+ dpy = alloc_primary_display(image_info);
if (!dpy)
return NULL;
screen = &dpy->screen;
@@ -160,9 +161,10 @@ 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,
+ const struct efi_image_info *image_info,
char *cmdline_ptr)
{
+ unsigned long image_addr = efistub_kernel_base(image_info);
struct sysfb_display_info *dpy;
efi_status_t status;
@@ -170,7 +172,7 @@ efi_status_t efi_stub_common(efi_handle_t handle,
if (status != EFI_SUCCESS)
return status;
- dpy = setup_primary_display();
+ dpy = setup_primary_display(image_info);
efi_retrieve_eventlog();
efi_bli_set_variables(image);
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 5c10815d9172..edc768a54473 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1135,6 +1135,16 @@ efi_status_t efi_load_initrd(efi_loaded_image_t *image,
unsigned long soft_limit,
unsigned long hard_limit,
const struct linux_efi_initrd **out);
+
+struct efi_image_info {
+ s32 _text_offset;
+ s32 __inittext_end_offset;
+ s32 _edata_offset;
+ s32 _end_offset;
+ s32 entry_offset;
+ s32 sysfb_primary_display_offset;
+};
+
/*
* This function handles the architcture specific differences between arm and
* arm64 regarding where the kernel image must be loaded and any memory that
@@ -1146,12 +1156,51 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *reserve_addr,
unsigned long *reserve_size,
efi_loaded_image_t *image,
- efi_handle_t image_handle);
+ efi_handle_t image_handle,
+ const struct efi_image_info **image_info);
+
+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
+void *efistub_kernel_entry(const struct efi_image_info *image_info)
+{
+ return offset_to_ptr(&image_info->entry_offset);
+}
+
+static inline
+void *efistub_sysfb_display_info(const struct efi_image_info *image_info)
+{
+ auto offset = &image_info->sysfb_primary_display_offset;
+
+ return *offset ? offset_to_ptr(offset) : NULL;
+}
/* 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,
+ const struct efi_image_info *image_info,
char *cmdline_ptr);
efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr);
@@ -1173,7 +1222,9 @@ efi_enable_reset_attack_mitigation(void) { }
void efi_retrieve_eventlog(void);
-struct sysfb_display_info *alloc_primary_display(void);
+struct sysfb_display_info *
+alloc_primary_display(const struct efi_image_info *image_info);
+
struct sysfb_display_info *__alloc_primary_display(void);
void free_primary_display(struct sysfb_display_info *dpy);
@@ -1245,9 +1296,7 @@ void 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 *alloc_size,
- unsigned long kernel_size,
- unsigned long kernel_codesize,
- unsigned long kernel_memsize,
+ const struct efi_image_info **image_info,
u32 phys_seed);
u32 efi_kaslr_get_phys_seed(efi_handle_t image_handle);
diff --git a/drivers/firmware/efi/libstub/image_info.S b/drivers/firmware/efi/libstub/image_info.S
new file mode 100644
index 000000000000..587a3eaff1c3
--- /dev/null
+++ b/drivers/firmware/efi/libstub/image_info.S
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/init.h>
+
+ __INITRODATA
+
+ .p2align 3
+ .globl __efistub_efistub_image_info
+__efistub_efistub_image_info:
+0: .long _text - .
+ .long __inittext_end - 0b
+ .long _edata - 0b
+ .long _end - 0b
+ .long efi_primary_entry - .
+#if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
+ .long sysfb_primary_display - .
+#else
+ .long 0
+#endif
diff --git a/drivers/firmware/efi/libstub/kaslr.c b/drivers/firmware/efi/libstub/kaslr.c
index 49b05d0c0003..7cf68a612394 100644
--- a/drivers/firmware/efi/libstub/kaslr.c
+++ b/drivers/firmware/efi/libstub/kaslr.c
@@ -84,9 +84,7 @@ static bool check_image_region(u64 base, u64 size)
* efi_kaslr_relocate_kernel() - Relocate the kernel (random if KASLR enabled)
* @image_addr: Pointer to variable carrying the image base address
* @alloc_size: Pointer to variable carrying the allocated size
- * @kernel_size: Size of the text + data
- * @kernel_codesize: Size of the text
- * @kernel_memsize: Size of the text + data + bss
+ * @image_info: Pointer to struct efi_image_info pointer
* @phys_seed: Random seed used for the relocation
*
* If KASLR is not enabled, this function relocates the kernel to a fixed
@@ -97,14 +95,15 @@ static bool check_image_region(u64 base, u64 size)
*/
efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
unsigned long *alloc_size,
- unsigned long kernel_size,
- unsigned long kernel_codesize,
- unsigned long kernel_memsize,
+ const struct efi_image_info **image_info,
u32 phys_seed)
{
- unsigned long kernel_base = *image_addr;
+ 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);
+ u64 min_kimg_align = efi_get_kimg_min_align();
efi_status_t status;
- u64 min_kimg_align = efi_get_kimg_min_align();
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && phys_seed != 0) {
/*
@@ -148,5 +147,7 @@ efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
efi_icache_sync(*image_addr, *image_addr + kernel_codesize);
efi_remap_image(*image_addr, kernel_memsize, kernel_codesize);
+ *(unsigned long *)image_info += *image_addr - kernel_base;
+
return status;
}
diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c
index c87ac7025107..d57e3d3557a5 100644
--- a/drivers/firmware/efi/libstub/loongarch-stub.c
+++ b/drivers/firmware/efi/libstub/loongarch-stub.c
@@ -99,7 +99,8 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *reserve_addr,
unsigned long *reserve_size,
efi_loaded_image_t *image,
- efi_handle_t image_handle)
+ efi_handle_t image_handle,
+ const struct efi_image_info **image_info)
{
efi_status_t status;
unsigned long kernel_addr = 0;
@@ -112,6 +113,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
*image_addr = kernel_addr;
*image_size = kernel_asize;
+ *(unsigned long *)image_info += *image_addr - (unsigned long)image->image_base;
return status;
}
diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c
index d0fc04d21b56..e4f9723d5055 100644
--- a/drivers/firmware/efi/libstub/riscv-stub.c
+++ b/drivers/firmware/efi/libstub/riscv-stub.c
@@ -28,18 +28,12 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *reserve_addr,
unsigned long *reserve_size,
efi_loaded_image_t *image,
- efi_handle_t image_handle)
+ efi_handle_t image_handle,
+ const struct efi_image_info **image_info)
{
- unsigned long kernel_size, kernel_codesize, kernel_memsize;
efi_status_t status;
- kernel_size = _edata - _start;
- kernel_codesize = __inittext_end - _start;
- kernel_memsize = kernel_size + (_end - _edata);
- *image_addr = (unsigned long)_start;
-
- status = efi_kaslr_relocate_kernel(image_addr, image_size,
- kernel_size, kernel_codesize, kernel_memsize,
+ status = efi_kaslr_relocate_kernel(image_addr, image_size, image_info,
efi_kaslr_get_phys_seed(image_handle));
if (status != EFI_SUCCESS)
efi_err("Failed to relocate kernel\n");
diff --git a/drivers/firmware/efi/libstub/zboot.c b/drivers/firmware/efi/libstub/zboot.c
index 4a5ffe164873..4cff756902ad 100644
--- a/drivers/firmware/efi/libstub/zboot.c
+++ b/drivers/firmware/efi/libstub/zboot.c
@@ -26,9 +26,18 @@ void __weak efi_cache_sync_image(unsigned long image_base,
// executable code loaded into memory to be safe for execution.
}
-struct sysfb_display_info *alloc_primary_display(void)
+struct sysfb_display_info *
+alloc_primary_display(const struct efi_image_info *image_info)
{
- return __alloc_primary_display();
+ return efistub_sysfb_display_info(image_info);
+}
+
+static
+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
@@ -93,9 +102,14 @@ 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_info, cmdline_ptr);
+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.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 09/19] efi/libstub: Pass kernel entrypoint down to efi_enter_kernel()
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (7 preceding siblings ...)
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
2026-11-18 18:21 ` [PATCH v4 10/19] efi/libstub: arm: Simplify handle_kernel_image() Ard Biesheuvel
` (9 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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>
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
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 10/19] efi/libstub: arm: Simplify handle_kernel_image()
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (8 preceding siblings ...)
2026-11-18 18:21 ` [PATCH v4 09/19] efi/libstub: Pass kernel entrypoint down to efi_enter_kernel() Ard Biesheuvel
@ 2026-11-18 18:21 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 11/19] efi/libstub: Drop reserve_addr/_size params from handle_kernel_image() Ard Biesheuvel
` (8 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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 ARM moved to efi_image_info for obtaining the base of the
decompressed kernel image in efi_enter_kernel(), it no longer needs to
distinguish between the image address (which might point into an
unrelated allocation below the decompressed image) and the reservation
address (which is what can be freed upon an error).
So use image_addr/image_size rather than reserve_addr/reserve_size in
handle_kernel_image() to return the base and size of the allocated
region to the caller. This will allow those parameters to be dropped
entirely from the prototype in a subsequent patch.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/arm32-stub.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c
index 798b2ae3bb03..55d4fa3177a9 100644
--- a/drivers/firmware/efi/libstub/arm32-stub.c
+++ b/drivers/firmware/efi/libstub/arm32-stub.c
@@ -128,18 +128,14 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efistub_image_info._text_offset =
kernel_base + TEXT_OFFSET - (u32)&efistub_image_info;
- *reserve_addr = kernel_base + slack;
- *reserve_size = alloc_size;
+ kernel_base += slack;
/* now free the parts that we will not use */
- efi_free(*reserve_addr - alloc_base, alloc_base); /* no-op if 0 */
- efi_free(alloc_base + margin - *reserve_addr, *reserve_addr + alloc_size);
+ efi_free(kernel_base - alloc_base, alloc_base); /* no-op if 0 */
+ efi_free(alloc_base + margin - kernel_base, kernel_base + alloc_size);
- *image_addr = kernel_base + TEXT_OFFSET;
- *image_size = 0;
-
- efi_debug("image addr == 0x%lx, reserve_addr == 0x%lx\n",
- *image_addr, *reserve_addr);
+ *image_addr = kernel_base;
+ *image_size = alloc_size;
return EFI_SUCCESS;
}
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 11/19] efi/libstub: Drop reserve_addr/_size params from handle_kernel_image()
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (9 preceding siblings ...)
2026-11-18 18:21 ` [PATCH v4 10/19] efi/libstub: arm: Simplify handle_kernel_image() Ard Biesheuvel
@ 2026-11-18 18:21 ` 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
` (7 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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 reserve_addr and reserve_size variable pointers passed to
handle_kernel_image() are no longer used, so drop them from the caller
and from the prototype.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/arm32-stub.c | 2 --
drivers/firmware/efi/libstub/arm64-stub.c | 2 --
drivers/firmware/efi/libstub/efi-stub-entry.c | 6 ------
drivers/firmware/efi/libstub/efistub.h | 2 --
drivers/firmware/efi/libstub/loongarch-stub.c | 2 --
drivers/firmware/efi/libstub/riscv-stub.c | 2 --
6 files changed, 16 deletions(-)
diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c
index 55d4fa3177a9..3ca20d2dd4d2 100644
--- a/drivers/firmware/efi/libstub/arm32-stub.c
+++ b/drivers/firmware/efi/libstub/arm32-stub.c
@@ -86,8 +86,6 @@ struct efi_image_info efistub_image_info = {};
efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *image_size,
- unsigned long *reserve_addr,
- unsigned long *reserve_size,
efi_loaded_image_t *image,
efi_handle_t image_handle,
const struct efi_image_info **image_info)
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index 6140def24c69..af38cf73cf01 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -15,8 +15,6 @@
efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *image_size,
- unsigned long *reserve_addr,
- unsigned long *reserve_size,
efi_loaded_image_t *image,
efi_handle_t image_handle,
const struct efi_image_info **image_info)
diff --git a/drivers/firmware/efi/libstub/efi-stub-entry.c b/drivers/firmware/efi/libstub/efi-stub-entry.c
index 36ea6aa2cfcc..a2fefe1ded05 100644
--- a/drivers/firmware/efi/libstub/efi-stub-entry.c
+++ b/drivers/firmware/efi/libstub/efi-stub-entry.c
@@ -36,9 +36,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
efi_status_t status;
unsigned long image_addr;
unsigned long image_size = 0;
- /* addr/point and size pairs for memory management*/
- unsigned long reserve_addr = 0;
- unsigned long reserve_size = 0;
WRITE_ONCE(efi_system_table, systab);
@@ -66,8 +63,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
efi_info("Booting Linux Kernel...\n");
status = handle_kernel_image(&image_addr, &image_size,
- &reserve_addr,
- &reserve_size,
image, handle, &image_info);
if (status != EFI_SUCCESS) {
efi_err("Failed to relocate kernel\n");
@@ -77,7 +72,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
status = efi_stub_common(handle, image, image_info, cmdline_ptr);
efi_free(image_size, image_addr);
- efi_free(reserve_size, reserve_addr);
return status;
}
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index e45d16095247..4e6af37c4ecb 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1150,8 +1150,6 @@ struct efi_image_info {
*/
efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *image_size,
- unsigned long *reserve_addr,
- unsigned long *reserve_size,
efi_loaded_image_t *image,
efi_handle_t image_handle,
const struct efi_image_info **image_info);
diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c
index d57e3d3557a5..8f2145bd9ad2 100644
--- a/drivers/firmware/efi/libstub/loongarch-stub.c
+++ b/drivers/firmware/efi/libstub/loongarch-stub.c
@@ -96,8 +96,6 @@ efi_status_t efi_relocate_kernel(unsigned long *image_addr,
efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *image_size,
- unsigned long *reserve_addr,
- unsigned long *reserve_size,
efi_loaded_image_t *image,
efi_handle_t image_handle,
const struct efi_image_info **image_info)
diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c
index 840fdd63dccf..8cd0cd9b0048 100644
--- a/drivers/firmware/efi/libstub/riscv-stub.c
+++ b/drivers/firmware/efi/libstub/riscv-stub.c
@@ -12,8 +12,6 @@
efi_status_t handle_kernel_image(unsigned long *image_addr,
unsigned long *image_size,
- unsigned long *reserve_addr,
- unsigned long *reserve_size,
efi_loaded_image_t *image,
efi_handle_t image_handle,
const struct efi_image_info **image_info)
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 12/19] efi/libstub: arm64: Use struct efi_image_info to access image properties
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (10 preceding siblings ...)
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 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 13/19] efi/libstub: loongarch: " Ard Biesheuvel
` (6 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm64/kernel/image-vars.h | 10 ----------
drivers/firmware/efi/libstub/arm64-stub.c | 8 +++++---
2 files changed, 5 insertions(+), 13 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 af38cf73cf01..351fcb4493e1 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -19,12 +19,14 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_handle_t image_handle,
const struct efi_image_info **image_info)
{
- if (image->image_base != _text) {
+ unsigned long kernel_base = efistub_kernel_base(*image_info);
+
+ 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);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 13/19] efi/libstub: loongarch: Use struct efi_image_info to access image properties
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (11 preceding siblings ...)
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 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 14/19] efi/libstub: riscv: " Ard Biesheuvel
` (5 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/loongarch/kernel/head.S | 3 ---
arch/loongarch/kernel/image-vars.h | 6 ------
arch/loongarch/kernel/vmlinux.lds.S | 1 -
drivers/firmware/efi/libstub/loongarch-stub.c | 15 ++-------------
drivers/firmware/efi/libstub/loongarch-stub.h | 4 ----
drivers/firmware/efi/libstub/loongarch.c | 10 +---------
6 files changed, 3 insertions(+), 36 deletions(-)
diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S
index 69c31b0b65c5..93ffedad6aca 100644
--- a/arch/loongarch/kernel/head.S
+++ b/arch/loongarch/kernel/head.S
@@ -32,9 +32,6 @@ _head:
pe_header:
__EFI_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
diff --git a/arch/loongarch/kernel/image-vars.h b/arch/loongarch/kernel/image-vars.h
index e557ebd46c2b..6ace4993df57 100644
--- a/arch/loongarch/kernel/image-vars.h
+++ b/arch/loongarch/kernel/image-vars.h
@@ -8,12 +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)
-__efistub_sysfb_primary_display = sysfb_primary_display;
-#endif
#endif
diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vmlinux.lds.S
index ce097e25881f..f8723c1ba9a7 100644
--- a/arch/loongarch/kernel/vmlinux.lds.S
+++ b/arch/loongarch/kernel/vmlinux.lds.S
@@ -159,7 +159,6 @@ SECTIONS
/* header symbols */
_kernel_entry = ABSOLUTE(kernel_entry & PHYSADDR_MASK);
_kernel_asize = ABSOLUTE(_end - _text);
- _kernel_fsize = ABSOLUTE(_edata - _text);
_kernel_vsize = ABSOLUTE(_end - __initdata_begin);
_kernel_rsize = ABSOLUTE(_edata - __initdata_begin);
#endif
diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c
index 8f2145bd9ad2..df6749643bb8 100644
--- a/drivers/firmware/efi/libstub/loongarch-stub.c
+++ b/drivers/firmware/efi/libstub/loongarch-stub.c
@@ -8,11 +8,6 @@
#include <asm/efi.h>
#include <asm/addrspace.h>
#include "efistub.h"
-#include "loongarch-stub.h"
-
-extern int kernel_asize;
-extern int kernel_fsize;
-extern int kernel_entry;
/**
* efi_relocate_kernel() - copy memory area
@@ -100,6 +95,8 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_handle_t image_handle,
const struct efi_image_info **image_info)
{
+ int kernel_asize = efistub_kernel_memsize(*image_info);
+ int kernel_fsize = efistub_kernel_size(*image_info);
efi_status_t status;
unsigned long kernel_addr = 0;
@@ -114,11 +111,3 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
*(unsigned long *)image_info += *image_addr - (unsigned long)image->image_base;
return status;
}
-
-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;
-}
diff --git a/drivers/firmware/efi/libstub/loongarch-stub.h b/drivers/firmware/efi/libstub/loongarch-stub.h
deleted file mode 100644
index cd015955a015..000000000000
--- a/drivers/firmware/efi/libstub/loongarch-stub.h
+++ /dev/null
@@ -1,4 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-unsigned long kernel_entry_address(unsigned long kernel_addr,
- efi_loaded_image_t *image);
diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
index 7f21e79384d3..cd19f3b574fd 100644
--- a/drivers/firmware/efi/libstub/loongarch.c
+++ b/drivers/firmware/efi/libstub/loongarch.c
@@ -8,7 +8,6 @@
#include <asm/efi.h>
#include <asm/addrspace.h>
#include "efistub.h"
-#include "loongarch-stub.h"
typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,
unsigned long systab);
@@ -59,16 +58,9 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
return EFI_SUCCESS;
}
-unsigned long __weak kernel_entry_address(unsigned long kernel_addr,
- efi_loaded_image_t *image)
-{
- return *(unsigned long *)(kernel_addr + 8) - PHYSADDR(VMLINUX_LOAD_ADDRESS) + kernel_addr;
-}
-
efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
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;
@@ -99,7 +91,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
csr_write(CSR_DMW2_INIT, LOONGARCH_CSR_DMWIN2);
csr_write(CSR_DMW3_INIT, LOONGARCH_CSR_DMWIN3);
- real_kernel_entry = (void *)kernel_entry_address(kernel_addr, image);
+ real_kernel_entry = efistub_kernel_entry(image_info);
real_kernel_entry(true, (unsigned long)cmdline_ptr,
(unsigned long)efi_system_table);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 14/19] efi/libstub: riscv: Use struct efi_image_info to access image properties
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (12 preceding siblings ...)
2026-11-18 18:21 ` [PATCH v4 13/19] efi/libstub: loongarch: " Ard Biesheuvel
@ 2026-11-18 18:21 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 15/19] efi/libstub: Make efi_remap_image() return efi_status_t Ard Biesheuvel
` (4 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/riscv/kernel/image-vars.h | 8 --------
1 file changed, 8 deletions(-)
diff --git a/arch/riscv/kernel/image-vars.h b/arch/riscv/kernel/image-vars.h
index bf703eba3fa5..c18b24792a29 100644
--- a/arch/riscv/kernel/image-vars.h
+++ b/arch/riscv/kernel/image-vars.h
@@ -23,14 +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
/*
* These double-word integer shifts are used by the library code, and
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 15/19] efi/libstub: Make efi_remap_image() return efi_status_t
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (13 preceding siblings ...)
2026-11-18 18:21 ` [PATCH v4 14/19] efi/libstub: riscv: " Ard Biesheuvel
@ 2026-11-18 18:21 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 16/19] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image() Ard Biesheuvel
` (3 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
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 4e6af37c4ecb..27b60ad81264 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1291,8 +1291,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 *alloc_size,
const struct efi_image_info **image_info,
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 16/19] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image()
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (14 preceding siblings ...)
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 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 17/19] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
` (2 subsequent siblings)
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
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 e892302f4189..f8bb890b9631 100644
--- a/drivers/firmware/efi/libstub/arm64.c
+++ b/drivers/firmware/efi/libstub/arm64.c
@@ -113,8 +113,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);
}
void __noreturn efi_enter_kernel(const struct efi_image_info *image_info,
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 4cff756902ad..9c7de225b39e 100644
--- a/drivers/firmware/efi/libstub/zboot.c
+++ b/drivers/firmware/efi/libstub/zboot.c
@@ -40,6 +40,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)
{
@@ -107,7 +118,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_info, cmdline_ptr);
+ status = efi_zboot_remap_image(image_info, image_base, alloc_size) ?:
+ efi_stub_common(handle, image, image_info, cmdline_ptr);
error:
efi_free(alloc_size, image_base);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 17/19] efi/libstub: arm64: Drop zboot code_size hack
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (15 preceding siblings ...)
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 ` 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
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
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 329d5e214b36..ca634cedcf63 100644
--- a/arch/arm64/kernel/image-vars.h
+++ b/arch/arm64/kernel/image-vars.h
@@ -140,10 +140,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 f8bb890b9631..8a051412814d 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.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 18/19] efi: Make config table based primary display handover ARM-only again
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (16 preceding siblings ...)
2026-11-18 18:21 ` [PATCH v4 17/19] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
@ 2026-11-18 18:21 ` Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 19/19] Revert "efi: earlycon: Reprobe after parsing config tables" Ard Biesheuvel
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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>
This reverts the effect of commit 732ea9db9d8a ("efi: libstub: Move
screen_info handling to common code"), taking into account the changes
that were made to the code since.
That commit moved all architectures to the ARM approach of passing the
primary display information (formerly struct screen_info) from the EFI
stub to the core kernel via an EFI configuration table, so that the zboot
decompressor, which is not linked into the core kernel image, could pass
this information as well.
Now that the EFI stub and the zboot decompressor both have access to the
location of sysfb_primary_display inside the loaded kernel image via
struct efi_image_info, they can populate it directly, and the
configuration table is only needed on ARM, whose decompressor has no
such information.
So make the configuration table based handover ARM-only again:
- move the config table based alloc/free routines into the ARM stub,
and provide __weak defaults in the generic stub that return a pointer
to the kernel image's copy of sysfb_primary_display;
- drop the primary display table from the common config table list,
and move the code that copies it into sysfb_primary_display into the
ARM arch code;
- on the other architectures, revert to simply reserving the
framebuffer memory if the stub populated sysfb_primary_display.
This makes the EFI framebuffer earlycon available right away when booting
via zboot, rather than only after the EFI config tables have been parsed.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm/kernel/efi.c | 27 ++++++++++
arch/loongarch/kernel/efi.c | 20 ++-----
drivers/firmware/efi/efi-init.c | 24 ++-------
drivers/firmware/efi/efi.c | 5 --
drivers/firmware/efi/libstub/Makefile | 2 +-
drivers/firmware/efi/libstub/arm32-stub.c | 41 ++++++++++++++
drivers/firmware/efi/libstub/efi-stub-entry.c | 13 -----
drivers/firmware/efi/libstub/efi-stub.c | 14 +++++
drivers/firmware/efi/libstub/efistub.h | 1 -
drivers/firmware/efi/libstub/primary_display.c | 56 --------------------
drivers/firmware/efi/libstub/zboot.c | 6 ---
11 files changed, 90 insertions(+), 119 deletions(-)
diff --git a/arch/arm/kernel/efi.c b/arch/arm/kernel/efi.c
index c14275257a8a..84d516b84848 100644
--- a/arch/arm/kernel/efi.c
+++ b/arch/arm/kernel/efi.c
@@ -7,6 +7,7 @@
#include <linux/memblock.h>
#include <linux/screen_info.h>
#include <linux/sizes.h>
+#include <linux/sysfb.h>
#include <asm/efi.h>
#include <asm/mach/map.h>
@@ -91,13 +92,36 @@ int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
return 0;
}
+static unsigned long __initdata primary_display_table = EFI_INVALID_TABLE_ADDR;
static unsigned long __initdata cpu_state_table = EFI_INVALID_TABLE_ADDR;
const efi_config_table_type_t efi_arch_tables[] __initconst = {
+ {LINUX_EFI_PRIMARY_DISPLAY_TABLE_GUID, &primary_display_table},
{LINUX_EFI_ARM_CPU_STATE_TABLE_GUID, &cpu_state_table},
{}
};
+static void __init load_primary_display_table(void)
+{
+ struct sysfb_display_info *dpy;
+
+ if (primary_display_table == EFI_INVALID_TABLE_ADDR)
+ return;
+
+ dpy = early_memremap(primary_display_table, sizeof(*dpy));
+ if (!dpy) {
+ pr_err("Could not map primary_display config table\n");
+ return;
+ }
+ sysfb_primary_display = *dpy;
+ memset(dpy, 0, sizeof(*dpy));
+ early_memunmap(dpy, sizeof(*dpy));
+
+ if (memblock_is_map_memory(sysfb_primary_display.screen.lfb_base))
+ memblock_mark_nomap(sysfb_primary_display.screen.lfb_base,
+ sysfb_primary_display.screen.lfb_size);
+}
+
static void __init load_cpu_state_table(void)
{
if (cpu_state_table != EFI_INVALID_TABLE_ADDR) {
@@ -136,6 +160,9 @@ void __init arm_efi_init(void)
{
efi_init();
+ if (IS_ENABLED(CONFIG_SYSFB) || IS_ENABLED(CONFIG_FIRMWARE_EDID))
+ load_primary_display_table();
+
/* ARM does not permit early mappings to persist across paging_init() */
efi_memmap_unmap();
diff --git a/arch/loongarch/kernel/efi.c b/arch/loongarch/kernel/efi.c
index 69dd83f8082f..c914aabcd282 100644
--- a/arch/loongarch/kernel/efi.c
+++ b/arch/loongarch/kernel/efi.c
@@ -72,8 +72,6 @@ bool efi_poweroff_required(void)
(acpi_gbl_reduced_hardware || acpi_no_s5);
}
-unsigned long __initdata primary_display_table = EFI_INVALID_TABLE_ADDR;
-
#if defined(CONFIG_SYSFB) || defined(CONFIG_EFI_EARLYCON)
struct sysfb_display_info sysfb_primary_display __section(".data");
EXPORT_SYMBOL_GPL(sysfb_primary_display);
@@ -81,22 +79,10 @@ EXPORT_SYMBOL_GPL(sysfb_primary_display);
static void __init init_primary_display(void)
{
- struct sysfb_display_info *dpy;
-
- if (primary_display_table == EFI_INVALID_TABLE_ADDR)
- return;
-
- dpy = early_memremap(primary_display_table, sizeof(*dpy));
- if (!dpy) {
- pr_err("Could not map primary_display config table\n");
- return;
- }
- sysfb_primary_display = *dpy;
- memset(dpy, 0, sizeof(*dpy));
- early_memunmap(dpy, sizeof(*dpy));
+ struct screen_info *si = &sysfb_primary_display.screen;
- memblock_reserve(__screen_info_lfb_base(&sysfb_primary_display.screen),
- sysfb_primary_display.screen.lfb_size);
+ if (si->orig_video_isVGA == VIDEO_TYPE_EFI)
+ memblock_reserve(__screen_info_lfb_base(si), si->lfb_size);
}
void __init efi_init(void)
diff --git a/drivers/firmware/efi/efi-init.c b/drivers/firmware/efi/efi-init.c
index 9f09b0d2daa0..25a5497ebb2e 100644
--- a/drivers/firmware/efi/efi-init.c
+++ b/drivers/firmware/efi/efi-init.c
@@ -23,8 +23,6 @@
#include <asm/efi.h>
-unsigned long __initdata primary_display_table = EFI_INVALID_TABLE_ADDR;
-
static int __init is_memory(efi_memory_desc_t *md)
{
if (md->attribute & (EFI_MEMORY_WB|EFI_MEMORY_WT|EFI_MEMORY_WC))
@@ -67,25 +65,11 @@ EXPORT_SYMBOL_GPL(sysfb_primary_display);
static void __init init_primary_display(void)
{
- struct sysfb_display_info *dpy;
-
- if (primary_display_table != EFI_INVALID_TABLE_ADDR) {
- dpy = early_memremap(primary_display_table, sizeof(*dpy));
- if (!dpy) {
- pr_err("Could not map primary_display config table\n");
- return;
- }
- sysfb_primary_display = *dpy;
- memset(dpy, 0, sizeof(*dpy));
- early_memunmap(dpy, sizeof(*dpy));
+ struct screen_info *si = &sysfb_primary_display.screen;
- if (memblock_is_map_memory(sysfb_primary_display.screen.lfb_base))
- memblock_mark_nomap(sysfb_primary_display.screen.lfb_base,
- sysfb_primary_display.screen.lfb_size);
-
- if (IS_ENABLED(CONFIG_EFI_EARLYCON))
- efi_earlycon_reprobe();
- }
+ if (si->orig_video_isVGA == VIDEO_TYPE_EFI &&
+ memblock_is_map_memory(si->lfb_base))
+ memblock_mark_nomap(si->lfb_base, si->lfb_size);
}
static int __init uefi_init(u64 efi_system_table)
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 9bc22de0d67e..90c421211ddc 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -57,8 +57,6 @@ unsigned long __ro_after_init efi_rng_seed = EFI_INVALID_TABLE_ADDR;
static unsigned long __initdata rt_prop = EFI_INVALID_TABLE_ADDR;
static unsigned long __initdata initrd = EFI_INVALID_TABLE_ADDR;
-extern unsigned long primary_display_table;
-
struct mm_struct efi_mm = {
.mm_mt = MTREE_INIT_EXT(mm_mt, MM_MT_FLAGS, efi_mm.mmap_lock),
.mm_users = ATOMIC_INIT(2),
@@ -674,9 +672,6 @@ static const efi_config_table_type_t common_tables[] __initconst = {
#endif
#ifdef CONFIG_UNACCEPTED_MEMORY
{LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID, &efi.unaccepted, "Unaccepted" },
-#endif
-#ifdef CONFIG_EFI_GENERIC_STUB
- {LINUX_EFI_PRIMARY_DISPLAY_TABLE_GUID, &primary_display_table },
#endif
{},
};
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index 9dc6a707fd79..0c5fbc21d2a2 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -81,7 +81,7 @@ $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE
$(call if_changed_rule,cc_o_c)
lib-$(CONFIG_EFI_GENERIC_STUB) += efi-stub.o string.o intrinsics.o systable.o \
- primary_display.o efi-stub-entry.o
+ efi-stub-entry.o
lib-$(CONFIG_ARM) += arm32-stub.o
lib-$(CONFIG_ARM64) += kaslr.o arm64.o arm64-stub.o smbios.o
diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c
index 3ca20d2dd4d2..89e48ac0b7cb 100644
--- a/drivers/firmware/efi/libstub/arm32-stub.c
+++ b/drivers/firmware/efi/libstub/arm32-stub.c
@@ -3,6 +3,7 @@
* Copyright (C) 2013 Linaro Ltd; <roy.franz@linaro.org>
*/
#include <linux/efi.h>
+#include <linux/sysfb.h>
#include <asm/efi.h>
#include "efistub.h"
@@ -76,6 +77,46 @@ void efi_handle_post_ebs_state(void)
&efi_entry_state->sctlr_after_ebs);
}
+static efi_guid_t primary_display_guid = LINUX_EFI_PRIMARY_DISPLAY_TABLE_GUID;
+
+struct sysfb_display_info *
+alloc_primary_display(const struct efi_image_info *image_info)
+{
+ struct sysfb_display_info *dpy;
+ efi_status_t status;
+
+ /*
+ * Unlike on other architectures, where we can directly fill out the
+ * sysfb_primary_display structure in the loaded kernel image, we need
+ * to allocate a buffer to hold its contents while we hand over to the
+ * kernel proper from the decompressor.
+ */
+ status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY,
+ sizeof(*dpy), (void **)&dpy);
+
+ if (status != EFI_SUCCESS)
+ return NULL;
+
+ memset(dpy, 0, sizeof(*dpy));
+
+ status = efi_bs_call(install_configuration_table,
+ &primary_display_guid, dpy);
+ if (status == EFI_SUCCESS)
+ return dpy;
+
+ efi_bs_call(free_pool, dpy);
+ return NULL;
+}
+
+void free_primary_display(struct sysfb_display_info *dpy)
+{
+ if (!dpy)
+ return;
+
+ efi_bs_call(install_configuration_table, &primary_display_guid, NULL);
+ efi_bs_call(free_pool, dpy);
+}
+
/* last unaligned u32 in the image carries the uncompressed size */
extern u32 input_data_end[] __aligned(1);
diff --git a/drivers/firmware/efi/libstub/efi-stub-entry.c b/drivers/firmware/efi/libstub/efi-stub-entry.c
index a2fefe1ded05..dcf4442a16b0 100644
--- a/drivers/firmware/efi/libstub/efi-stub-entry.c
+++ b/drivers/firmware/efi/libstub/efi-stub-entry.c
@@ -9,19 +9,6 @@
extern const struct efi_image_info efistub_image_info;
-struct sysfb_display_info *
-alloc_primary_display(const struct efi_image_info *image_info)
-{
- if (IS_ENABLED(CONFIG_ARM))
- return __alloc_primary_display();
-
- if (IS_ENABLED(CONFIG_EFI_EARLYCON) ||
- IS_ENABLED(CONFIG_SYSFB))
- return efistub_sysfb_display_info(image_info);
-
- return NULL;
-}
-
/*
* 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
diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
index 55bf7ed50c81..a824b2ba3026 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -48,6 +48,20 @@
static u64 virtmap_base = EFI_RT_VIRTUAL_BASE;
static bool flat_va_mapping = (EFI_RT_VIRTUAL_OFFSET != 0);
+/*
+ * By default, populate the core kernel's copy of sysfb_primary_display
+ * directly. This works for both the EFI stub that is incorporated into the
+ * core kernel and for the zboot decompressor, as both have access to the
+ * location of the variable inside the loaded kernel image via image_info.
+ *
+ * ARM overrides these, as it uses a configuration table instead.
+ */
+struct sysfb_display_info * __weak
+alloc_primary_display(const struct efi_image_info *image_info)
+{
+ return efistub_sysfb_display_info(image_info);
+}
+
void __weak free_primary_display(struct sysfb_display_info *dpy)
{ }
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 27b60ad81264..df3f88f4786b 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1224,7 +1224,6 @@ void efi_retrieve_eventlog(void);
struct sysfb_display_info *
alloc_primary_display(const struct efi_image_info *image_info);
-struct sysfb_display_info *__alloc_primary_display(void);
void free_primary_display(struct sysfb_display_info *dpy);
void efi_cache_sync_image(unsigned long image_base,
diff --git a/drivers/firmware/efi/libstub/primary_display.c b/drivers/firmware/efi/libstub/primary_display.c
deleted file mode 100644
index cdaebab26514..000000000000
--- a/drivers/firmware/efi/libstub/primary_display.c
+++ /dev/null
@@ -1,56 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/efi.h>
-#include <linux/sysfb.h>
-
-#include <asm/efi.h>
-
-#include "efistub.h"
-
-/*
- * There are two ways of populating the core kernel's sysfb_primary_display
- * via the stub:
- *
- * - using a configuration table, which relies on the EFI init code to
- * locate the table and copy the contents; or
- *
- * - by linking directly to the core kernel's copy of the global symbol.
- *
- * The latter is preferred because it makes the EFIFB earlycon available very
- * early, but it only works if the EFI stub is part of the core kernel image
- * itself. The zboot decompressor can only use the configuration table
- * approach.
- */
-
-static efi_guid_t primary_display_guid = LINUX_EFI_PRIMARY_DISPLAY_TABLE_GUID;
-
-struct sysfb_display_info *__alloc_primary_display(void)
-{
- struct sysfb_display_info *dpy;
- efi_status_t status;
-
- status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY,
- sizeof(*dpy), (void **)&dpy);
-
- if (status != EFI_SUCCESS)
- return NULL;
-
- memset(dpy, 0, sizeof(*dpy));
-
- status = efi_bs_call(install_configuration_table,
- &primary_display_guid, dpy);
- if (status == EFI_SUCCESS)
- return dpy;
-
- efi_bs_call(free_pool, dpy);
- return NULL;
-}
-
-void free_primary_display(struct sysfb_display_info *dpy)
-{
- if (!dpy)
- return;
-
- efi_bs_call(install_configuration_table, &primary_display_guid, NULL);
- efi_bs_call(free_pool, dpy);
-}
diff --git a/drivers/firmware/efi/libstub/zboot.c b/drivers/firmware/efi/libstub/zboot.c
index 9c7de225b39e..4089a29068ca 100644
--- a/drivers/firmware/efi/libstub/zboot.c
+++ b/drivers/firmware/efi/libstub/zboot.c
@@ -26,12 +26,6 @@ void __weak efi_cache_sync_image(unsigned long image_base,
// executable code loaded into memory to be safe for execution.
}
-struct sysfb_display_info *
-alloc_primary_display(const struct efi_image_info *image_info)
-{
- return efistub_sysfb_display_info(image_info);
-}
-
static
const struct efi_image_info *zboot_get_image_info(unsigned long image_base)
{
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 19/19] Revert "efi: earlycon: Reprobe after parsing config tables"
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
` (17 preceding siblings ...)
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 ` Ard Biesheuvel
18 siblings, 0 replies; 20+ messages in thread
From: Ard Biesheuvel @ 2026-11-18 18:21 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>
This reverts commit 8b3a149db461d3286d1e211112de3b44ccaeaf71.
That commit added logic to probe the EFI framebuffer earlycon again after
the EFI configuration tables have been parsed, as the primary display
information may not have been available yet when the earlycon= early
parameter was processed.
Now that only ARM uses a configuration table to pass the primary display
information to the core kernel, and the EFI framebuffer earlycon is not
supported on ARM, the reprobe logic no longer has any callers. So revert
it.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/earlycon.c | 16 +++-------------
include/linux/efi.h | 1 -
2 files changed, 3 insertions(+), 14 deletions(-)
diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlycon.c
index 3d060d59968c..997f69ce46cb 100644
--- a/drivers/firmware/efi/earlycon.c
+++ b/drivers/firmware/efi/earlycon.c
@@ -216,14 +216,6 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num)
}
}
-static bool __initdata fb_probed;
-
-void __init efi_earlycon_reprobe(void)
-{
- if (fb_probed)
- setup_earlycon("efifb");
-}
-
static int __init efi_earlycon_setup(struct earlycon_device *device,
const char *opt)
{
@@ -231,17 +223,15 @@ static int __init efi_earlycon_setup(struct earlycon_device *device,
u16 xres, yres;
u32 i;
- fb_wb = opt && !strcmp(opt, "ram");
-
- if (si->orig_video_isVGA != VIDEO_TYPE_EFI) {
- fb_probed = true;
+ if (si->orig_video_isVGA != VIDEO_TYPE_EFI)
return -ENODEV;
- }
fb_base = si->lfb_base;
if (si->capabilities & VIDEO_CAPABILITY_64BIT_BASE)
fb_base |= (u64)si->ext_lfb_base << 32;
+ fb_wb = opt && !strcmp(opt, "ram");
+
xres = si->lfb_width;
yres = si->lfb_height;
diff --git a/include/linux/efi.h b/include/linux/efi.h
index cc1df1577d5f..4a809c6ae724 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -719,7 +719,6 @@ efi_guid_to_str(const efi_guid_t *guid, char *out)
}
extern void efi_init (void);
-extern void efi_earlycon_reprobe(void);
#ifdef CONFIG_EFI
extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
#else
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread