[PATCH 6/7] x86/efi: Unmap kernel-reserved boot regions from EFI page tables

From: Ard Biesheuvel

Date: Fri Apr 10 2026 - 04:04:51 EST


From: Ard Biesheuvel <ardb@xxxxxxxxxx>

Currently, the logic that unmaps boot services code and data regions
that were mapped temporarily to work around firmware bugs disregards
regions that have been marked as EFI_MEMORY_RUNTIME. However, such
regions only have significance to the OS, and there is no reason to
retain the mapping in the EFI page tables, given that the runtime
firmware must never touch those regions.

So pull the unmap forward.

Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
---
arch/x86/platform/efi/quirks.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index ee906c0c46c1..929ee71a140c 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -438,12 +438,6 @@ void __init efi_unmap_boot_services(void)
continue;
}

- /* Do not free, someone else owns it: */
- if (md->attribute & EFI_MEMORY_RUNTIME) {
- num_entries++;
- continue;
- }
-
/*
* Before calling set_virtual_address_map(), EFI boot services
* code/data regions were mapped as a quirk for buggy firmware.
@@ -451,6 +445,12 @@ void __init efi_unmap_boot_services(void)
*/
efi_unmap_pages(md);

+ /* Do not free, someone else owns it: */
+ if (md->attribute & EFI_MEMORY_RUNTIME) {
+ num_entries++;
+ continue;
+ }
+
/*
* With CONFIG_DEFERRED_STRUCT_PAGE_INIT parts of the memory
* map are still not initialized and we can't reliably free
--
2.53.0.1213.gd9a14994de-goog