[PATCH v1 1/2] efi/libstub: Install memreserve table on x86
From: Jasmeet (Jazz) Bhatia
Date: Tue Sep 01 2026 - 07:34:43 EST
The generic EFI stub installs the Linux EFI memreserve configuration
table from efi_stub_common(), but x86 uses a separate EFI stub path.
Consequently, efi_mem_reserve_persistent() cannot be used on x86 when
no memreserve root has been installed.
Move install_memreserve_table() to the common stub helper code, expose
it through efistub.h, and invoke it from the x86 stub before exiting
boot services.
This allows x86 kernels to add persistent EFI memory reservations that
are carried across kexec.
Signed-off-by: Jasmeet (Jazz) Bhatia <jasmeet.bhatia.us@xxxxxxxxx>
---
.../firmware/efi/libstub/efi-stub-helper.c | 23 +++++++++++++++++++
drivers/firmware/efi/libstub/efi-stub.c | 23 -------------------
drivers/firmware/efi/libstub/efistub.h | 1 +
drivers/firmware/efi/libstub/x86-stub.c | 2 ++
4 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index f27f2e1f0019..9ea0ed0ed7d1 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -27,6 +27,29 @@ static bool efi_disable_pci_dma = IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA);
int efi_mem_encrypt;
+void install_memreserve_table(void)
+{
+ struct linux_efi_memreserve *rsv;
+ efi_guid_t memreserve_table_guid = LINUX_EFI_MEMRESERVE_TABLE_GUID;
+ efi_status_t status;
+
+ status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, sizeof(*rsv),
+ (void **)&rsv);
+ if (status != EFI_SUCCESS) {
+ efi_err("Failed to allocate memreserve entry!\n");
+ return;
+ }
+
+ rsv->next = 0;
+ rsv->size = 0;
+ atomic_set(&rsv->count, 0);
+
+ status = efi_bs_call(install_configuration_table,
+ &memreserve_table_guid, rsv);
+ if (status != EFI_SUCCESS)
+ efi_err("Failed to install memreserve config table!\n");
+}
+
bool __pure __efi_soft_reserve_enabled(void)
{
return !efi_nosoftreserve;
diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
index 42d6073bcd06..e378dd7db682 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -77,29 +77,6 @@ static struct sysfb_display_info *setup_primary_display(void)
return NULL;
}
-static void install_memreserve_table(void)
-{
- struct linux_efi_memreserve *rsv;
- efi_guid_t memreserve_table_guid = LINUX_EFI_MEMRESERVE_TABLE_GUID;
- efi_status_t status;
-
- status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, sizeof(*rsv),
- (void **)&rsv);
- if (status != EFI_SUCCESS) {
- efi_err("Failed to allocate memreserve entry!\n");
- return;
- }
-
- rsv->next = 0;
- rsv->size = 0;
- atomic_set(&rsv->count, 0);
-
- status = efi_bs_call(install_configuration_table,
- &memreserve_table_guid, rsv);
- if (status != EFI_SUCCESS)
- efi_err("Failed to install memreserve config table!\n");
-}
-
static u32 get_supported_rt_services(void)
{
const efi_rt_properties_table_t *rt_prop_table;
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index fd91fc15ec81..8656d6a545e5 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1168,6 +1168,7 @@ efi_enable_reset_attack_mitigation(void) { }
#endif
void efi_retrieve_eventlog(void);
+void install_memreserve_table(void);
struct sysfb_display_info *alloc_primary_display(void);
struct sysfb_display_info *__alloc_primary_display(void);
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index cef32e2c82d8..4a24126ccfd9 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -1015,6 +1015,8 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
efi_retrieve_eventlog();
+ install_memreserve_table();
+
setup_graphics(boot_params);
setup_efi_pci(boot_params);
--
2.55.0