Skip to content

Commit 5b86af1

Browse files
vpetrogakpm00
authored andcommitted
efi: support booting with kexec handover (KHO)
When KHO (Kexec HandOver) is enabled, it sets up scratch memory regions early during device tree scanning. After kexec, the new kernel exclusively uses this region for memory allocations during boot up to the initialization of the page allocator However, when booting with EFI, EFI's reserve_regions() uses memblock_remove(0, PHYS_ADDR_MAX) to clear all memory regions before rebuilding them from EFI data. This destroys KHO scratch regions and their flags, thus causing a kernel panic, as there are no scratch memory regions. Instead of wholesale removal, iterate through memory regions and only remove non-KHO ones. This preserves KHO scratch regions, which are good known memory, while still allowing EFI to rebuild its memory map. Link: https://lkml.kernel.org/r/b34da9fd50c89644cd4204136cfa6f5533445c56.1755721529.git.epetron@amazon.de Signed-off-by: Evangelos Petrongonas <epetron@amazon.de> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Acked-by: Pratyush Yadav <pratyush@kernel.org> Cc: Alexander Graf <graf@amazon.com> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Baoquan He <bhe@redhat.com> Cc: Changyuan Lyu <changyuanl@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent d6d5116 commit 5b86af1

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

drivers/firmware/efi/efi-init.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/efi.h>
1313
#include <linux/fwnode.h>
1414
#include <linux/init.h>
15+
#include <linux/kexec_handover.h>
1516
#include <linux/memblock.h>
1617
#include <linux/mm_types.h>
1718
#include <linux/of.h>
@@ -164,12 +165,32 @@ static __init void reserve_regions(void)
164165
pr_info("Processing EFI memory map:\n");
165166

166167
/*
167-
* Discard memblocks discovered so far: if there are any at this
168-
* point, they originate from memory nodes in the DT, and UEFI
169-
* uses its own memory map instead.
168+
* Discard memblocks discovered so far except for KHO scratch
169+
* regions. Most memblocks at this point originate from memory nodes
170+
* in the DT and UEFI uses its own memory map instead. However, if
171+
* KHO is enabled, scratch regions, which are good known memory
172+
* must be preserved.
170173
*/
171174
memblock_dump_all();
172-
memblock_remove(0, PHYS_ADDR_MAX);
175+
176+
if (is_kho_boot()) {
177+
struct memblock_region *r;
178+
179+
/* Remove all non-KHO regions */
180+
for_each_mem_region(r) {
181+
if (!memblock_is_kho_scratch(r)) {
182+
memblock_remove(r->base, r->size);
183+
r--;
184+
}
185+
}
186+
} else {
187+
/*
188+
* KHO is disabled. Discard memblocks discovered so far:
189+
* if there are any at this point, they originate from memory
190+
* nodes in the DT, and UEFI uses its own memory map instead.
191+
*/
192+
memblock_remove(0, PHYS_ADDR_MAX);
193+
}
173194

174195
for_each_efi_memory_desc(md) {
175196
paddr = md->phys_addr;

0 commit comments

Comments
 (0)