Skip to content

Commit 0ceac9e

Browse files
mosalterMatt Fleming
authored and
Matt Fleming
committed
efi/arm64: Fix fdt-related memory reservation
Commit 86c8b27: "arm64: ignore DT memreserve entries when booting in UEFI mode prevents early_init_fdt_scan_reserved_mem() from being called for arm64 kernels booting via UEFI. This was done because the kernel will use the UEFI memory map to determine reserved memory regions. That approach has problems in that early_init_fdt_scan_reserved_mem() also reserves the FDT itself and any node-specific reserved memory. By chance of some kernel configs, the FDT may be overwritten before it can be unflattened and the kernel will fail to boot. More subtle problems will result if the FDT has node specific reserved memory which is not really reserved. This patch has the UEFI stub remove the memory reserve map entries from the FDT as it does with the memory nodes. This allows early_init_fdt_scan_reserved_mem() to be called unconditionally so that the other needed reservations are made. Signed-off-by: Mark Salter <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Acked-by: Mark Rutland <[email protected]> Signed-off-by: Matt Fleming <[email protected]>
1 parent 9cb0e39 commit 0ceac9e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

arch/arm64/mm/init.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ void __init arm64_memblock_init(void)
149149
memblock_reserve(__virt_to_phys(initrd_start), initrd_end - initrd_start);
150150
#endif
151151

152-
if (!efi_enabled(EFI_MEMMAP))
153-
early_init_fdt_scan_reserved_mem();
152+
early_init_fdt_scan_reserved_mem();
154153

155154
/* 4GB maximum for 32-bit only capable devices */
156155
if (IS_ENABLED(CONFIG_ZONE_DMA))

drivers/firmware/efi/libstub/fdt.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
2222
unsigned long map_size, unsigned long desc_size,
2323
u32 desc_ver)
2424
{
25-
int node, prev;
25+
int node, prev, num_rsv;
2626
int status;
2727
u32 fdt_val32;
2828
u64 fdt_val64;
@@ -73,6 +73,14 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
7373
prev = node;
7474
}
7575

76+
/*
77+
* Delete all memory reserve map entries. When booting via UEFI,
78+
* kernel will use the UEFI memory map to find reserved regions.
79+
*/
80+
num_rsv = fdt_num_mem_rsv(fdt);
81+
while (num_rsv-- > 0)
82+
fdt_del_mem_rsv(fdt, num_rsv);
83+
7684
node = fdt_subnode_offset(fdt, 0, "chosen");
7785
if (node < 0) {
7886
node = fdt_add_subnode(fdt, 0, "chosen");

0 commit comments

Comments
 (0)