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

Ard Biesheuvel posted 5 patches 8 hours ago
[PATCH v2 2/5] x86/efi: Gather initial memory reservation and table handling logic
Posted by Ard Biesheuvel 8 hours 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.

Reviewed-by: Gregory Price <gourry@gourry.net>
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.1118.gaef5881109-goog
Re: [PATCH v2 2/5] x86/efi: Gather initial memory reservation and table handling logic
Posted by Breno Leitao 5 hours ago
On Wed, Apr 01, 2026 at 02:23:54PM +0200, 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.
> 
> Reviewed-by: Gregory Price <gourry@gourry.net>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

Reviewed-by: Breno Leitao <leitao@debian.org>

> +void efi_init_reservations(void);

Do you neeed __init here, as the declaration below? I know that "extern" is not
necessary, but isn't __init?

  extern int __init efi_memmap_alloc(unsigned int num_entries,
                                     struct efi_memory_map_data *data);

  extern int __init efi_memmap_install(struct efi_memory_map_data *data);
  extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
Re: [PATCH v2 2/5] x86/efi: Gather initial memory reservation and table handling logic
Posted by Ard Biesheuvel 5 hours ago
On Wed, 1 Apr 2026, at 16:49, Breno Leitao wrote:
> On Wed, Apr 01, 2026 at 02:23:54PM +0200, 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.
>>
>> Reviewed-by: Gregory Price <gourry@gourry.net>
>> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
>
> Reviewed-by: Breno Leitao <leitao@debian.org>
>

Thanks

>> +void efi_init_reservations(void);
>
> Do you neeed __init here, as the declaration below? I know that
> "extern" is not necessary, but isn't __init?
>

No, it's not. Initness is a property of the definition not the
declaration. It decides which ELF section the code is emitted into,
and a declaration does not produce any code.

The section attribute is permitted on declarations by most compilers,
and I can see how it may be informative, but it can also easily get
out of sync so I prefer to omit it.