[PATCH 2/5] x86/efi: Gather initial memory reservation and table handling logic

Ard Biesheuvel posted 5 patches 1 week ago
There is a newer version of this series
[PATCH 2/5] x86/efi: Gather initial memory reservation and table handling logic
Posted by Ard Biesheuvel 1 week ago
From: Ard Biesheuvel <ardb@kernel.org>

Move the back-to-back calls to various EFI routines related to
processing of firmware tables and reserving the associated memory into a
helper function. This is tidier, and will avoid the need to add yet
another function call there in a subsequent patch.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/include/asm/efi.h  |  5 ++---
 arch/x86/kernel/setup.c     | 11 ++---------
 arch/x86/platform/efi/efi.c | 13 +++++++++++++
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 51b4cdbea061..3dcb137a49ed 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -387,11 +387,10 @@ static inline  bool efi_is_table_address(unsigned long phys_addr)
 {
 	return false;
 }
-static inline void efi_reserve_boot_services(void)
-{
-}
 #endif /* CONFIG_EFI */
 
+void efi_init_reservations(void);
+
 extern int __init efi_memmap_alloc(unsigned int num_entries,
 				   struct efi_memory_map_data *data);
 
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index eebcc9db1a1b..9f5f50bff16d 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1083,15 +1083,8 @@ void __init setup_arch(char **cmdline_p)
 	mem_encrypt_setup_arch();
 	cc_random_init();
 
-	efi_find_mirror();
-	efi_esrt_init();
-	efi_mokvar_table_init();
-
-	/*
-	 * The EFI specification says that boot service code won't be
-	 * called after ExitBootServices(). This is, in fact, a lie.
-	 */
-	efi_reserve_boot_services();
+	if (efi_enabled(EFI_BOOT))
+		efi_init_reservations();
 
 	/* preallocate 4k for mptable mpc */
 	e820__memblock_alloc_reserved_mpc_new();
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index d84c6020dda1..f32276bd8d4e 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -165,6 +165,19 @@ static void __init do_add_efi_memmap(void)
 	e820__update_table(e820_table);
 }
 
+void __init efi_init_reservations(void)
+{
+	efi_find_mirror();
+	efi_esrt_init();
+	efi_mokvar_table_init();
+
+	/*
+	 * The EFI specification says that boot service code won't be
+	 * called after ExitBootServices(). This is, in fact, a lie.
+	 */
+	efi_reserve_boot_services();
+}
+
 /*
  * Given add_efi_memmap defaults to 0 and there is no alternative
  * e820 mechanism for soft-reserved memory, import the full EFI memory
-- 
2.53.0.1018.g2bb0e51243-goog
Re: [PATCH 2/5] x86/efi: Gather initial memory reservation and table handling logic
Posted by Gregory Price 4 days, 2 hours ago
On Thu, Mar 26, 2026 at 02:26:58PM +0100, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
> 
> Move the back-to-back calls to various EFI routines related to
> processing of firmware tables and reserving the associated memory into a
> helper function. This is tidier, and will avoid the need to add yet
> another function call there in a subsequent patch.
> 
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

Reviewed-by: Gregory Price <gourry@gourry.net>