Skip to content

Commit 497fe3b

Browse files
committed
Merge tag 'riscv-for-linus-5.18-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fix from Palmer Dabbelt: - A fix to relocate the DTB early in boot, in cases where the bootloader doesn't put the DTB in a region that will end up mapped by the kernel. This manifests as a crash early in boot on a handful of configurations. * tag 'riscv-for-linus-5.18-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: RISC-V: relocate DTB if it's outside memory region
2 parents 4df22ca + c6fe811 commit 497fe3b

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

arch/riscv/mm/init.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,25 @@ static void __init setup_bootmem(void)
208208
* early_init_fdt_reserve_self() since __pa() does
209209
* not work for DTB pointers that are fixmap addresses
210210
*/
211-
if (!IS_ENABLED(CONFIG_BUILTIN_DTB))
212-
memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
211+
if (!IS_ENABLED(CONFIG_BUILTIN_DTB)) {
212+
/*
213+
* In case the DTB is not located in a memory region we won't
214+
* be able to locate it later on via the linear mapping and
215+
* get a segfault when accessing it via __va(dtb_early_pa).
216+
* To avoid this situation copy DTB to a memory region.
217+
* Note that memblock_phys_alloc will also reserve DTB region.
218+
*/
219+
if (!memblock_is_memory(dtb_early_pa)) {
220+
size_t fdt_size = fdt_totalsize(dtb_early_va);
221+
phys_addr_t new_dtb_early_pa = memblock_phys_alloc(fdt_size, PAGE_SIZE);
222+
void *new_dtb_early_va = early_memremap(new_dtb_early_pa, fdt_size);
223+
224+
memcpy(new_dtb_early_va, dtb_early_va, fdt_size);
225+
early_memunmap(new_dtb_early_va, fdt_size);
226+
_dtb_early_pa = new_dtb_early_pa;
227+
} else
228+
memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
229+
}
213230

214231
early_init_fdt_scan_reserved_mem();
215232
dma_contiguous_reserve(dma32_phys_limit);

0 commit comments

Comments
 (0)