[RFC PATCH 4/9] x86/efi: Defer sub-1M check from unmap to free stage
From: Ard Biesheuvel
Date: Fri Mar 06 2026 - 10:59:06 EST
From: Ard Biesheuvel <ardb@xxxxxxxxxx>
As a first step towards moving the free logic to a later stage
altogether, and only keeping the unmap and the realmode trampoline hack
during the early stage of freeing the boot service code and data
regions, move the logic that avoids freeing memory below 1M to the later
stage.
Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
---
arch/x86/platform/efi/quirks.c | 21 ++++++++------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index f896930cecda..58d00ffb1d59 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -475,18 +475,6 @@ void __init efi_unmap_boot_services(void)
size -= rm_size;
}
- /*
- * Don't free memory under 1M for two reasons:
- * - BIOS might clobber it
- * - Crash kernel needs it to be reserved
- */
- if (start + size < SZ_1M)
- continue;
- if (start < SZ_1M) {
- size -= (SZ_1M - start);
- start = SZ_1M;
- }
-
/*
* With CONFIG_DEFERRED_STRUCT_PAGE_INIT parts of the memory
* map are still not initialized and we can't reliably free
@@ -579,7 +567,14 @@ static int __init efi_free_boot_services(void)
return 0;
while (range->start) {
- freed += efi_free_unreserved_subregions(range->start, range->end);
+ /*
+ * Don't free memory under 1M for two reasons:
+ * - BIOS might clobber it
+ * - Crash kernel needs it to be reserved
+ */
+ u64 start = max(range->start, SZ_1M);
+
+ freed += efi_free_unreserved_subregions(start, range->end);
range++;
}
kfree(ranges_to_free);
--
2.53.0.473.g4a7958ca14-goog