[PATCH v2 19/19] x86/efi: Free unused tail of the EFI memory map

Ard Biesheuvel posted 19 patches 2 weeks, 4 days ago
[PATCH v2 19/19] x86/efi: Free unused tail of the EFI memory map
Posted by Ard Biesheuvel 2 weeks, 4 days ago
From: Ard Biesheuvel <ardb@kernel.org>

After moving the relevant entries to the start of the map, the remainder
can be handed back to the page allocator.

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

diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 8f2dc477eee0..3b3652c4b90e 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -443,6 +443,10 @@ static int __init efi_free_boot_services(void)
 
 	efi.memmap.num_valid_entries = (new_md - efi.memmap.map) / efi.memmap.desc_size;
 
+	/* Free the part of the memory map allocation that has become unused */
+	free_reserved_area(new_md, efi.memmap.map_end, -1, NULL);
+	freed += (void *)efi.memmap.map_end - new_md;
+
 	if (freed)
 		pr_info("Freeing EFI boot services memory: %ldK\n", freed / SZ_1K);
 
-- 
2.53.0.851.ga537e3e6e9-goog