[PATCH v2 06/19] x86/efi: Defer sub-1M check from unmap to free stage
From: Ard Biesheuvel
Date: Thu Mar 19 2026 - 05:07:10 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 | 24 +++++++++-----------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 906e29754026..25f51d673ad6 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,17 @@ 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);
+
+ if (start >= range->end)
+ continue;
+
+ freed += efi_free_unreserved_subregions(start, range->end);
range++;
}
kfree(ranges_to_free);
--
2.53.0.851.ga537e3e6e9-goog