Skip to content

Commit 4400231

Browse files
atishp04palmer-dabbelt
authored andcommitted
RISC-V: Do not rely on initrd_start/end computed during early dt parsing
Currently, initrd_start/end are computed during early_init_dt_scan but used during arch_setup. We will get the following panic if initrd is used and CONFIG_DEBUG_VIRTUAL is turned on. [ 0.000000] ------------[ cut here ]------------ [ 0.000000] kernel BUG at arch/riscv/mm/physaddr.c:33! [ 0.000000] Kernel BUG [#1] [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.8.0-rc4-00015-ged0b226fed02 #886 [ 0.000000] epc: ffffffe0002058d2 ra : ffffffe0000053f0 sp : ffffffe001001f40 [ 0.000000] gp : ffffffe00106e250 tp : ffffffe001009d40 t0 : ffffffe00107ee28 [ 0.000000] t1 : 0000000000000000 t2 : ffffffe000a2e880 s0 : ffffffe001001f50 [ 0.000000] s1 : ffffffe0001383e8 a0 : ffffffe00c087e00 a1 : 0000000080200000 [ 0.000000] a2 : 00000000010bf000 a3 : ffffffe00106f3c8 a4 : ffffffe0010bf000 [ 0.000000] a5 : ffffffe000000000 a6 : 0000000000000006 a7 : 0000000000000001 [ 0.000000] s2 : ffffffe00106f068 s3 : ffffffe00106f070 s4 : 0000000080200000 [ 0.000000] s5 : 0000000082200000 s6 : 0000000000000000 s7 : 0000000000000000 [ 0.000000] s8 : 0000000080011010 s9 : 0000000080012700 s10: 0000000000000000 [ 0.000000] s11: 0000000000000000 t3 : 000000000001fe30 t4 : 000000000001fe30 [ 0.000000] t5 : 0000000000000000 t6 : ffffffe00107c471 [ 0.000000] status: 0000000000000100 badaddr: 0000000000000000 cause: 0000000000000003 [ 0.000000] random: get_random_bytes called from print_oops_end_marker+0x22/0x46 with crng_init=0 To avoid the error, initrd_start/end can be computed from phys_initrd_start/size in setup itself. It also improves the initrd placement by aligning the start and size with the page size. Fixes: 76d2a04 ("RISC-V: Init and Halt Code") Signed-off-by: Atish Patra <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent d0d8aae commit 4400231

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

arch/riscv/mm/init.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,40 @@ void __init mem_init(void)
9595
#ifdef CONFIG_BLK_DEV_INITRD
9696
static void __init setup_initrd(void)
9797
{
98+
phys_addr_t start;
9899
unsigned long size;
99100

100-
if (initrd_start >= initrd_end) {
101-
pr_info("initrd not found or empty");
101+
/* Ignore the virtul address computed during device tree parsing */
102+
initrd_start = initrd_end = 0;
103+
104+
if (!phys_initrd_size)
105+
return;
106+
/*
107+
* Round the memory region to page boundaries as per free_initrd_mem()
108+
* This allows us to detect whether the pages overlapping the initrd
109+
* are in use, but more importantly, reserves the entire set of pages
110+
* as we don't want these pages allocated for other purposes.
111+
*/
112+
start = round_down(phys_initrd_start, PAGE_SIZE);
113+
size = phys_initrd_size + (phys_initrd_start - start);
114+
size = round_up(size, PAGE_SIZE);
115+
116+
if (!memblock_is_region_memory(start, size)) {
117+
pr_err("INITRD: 0x%08llx+0x%08lx is not a memory region",
118+
(u64)start, size);
102119
goto disable;
103120
}
104-
if (__pa_symbol(initrd_end) > PFN_PHYS(max_low_pfn)) {
105-
pr_err("initrd extends beyond end of memory");
121+
122+
if (memblock_is_region_reserved(start, size)) {
123+
pr_err("INITRD: 0x%08llx+0x%08lx overlaps in-use memory region\n",
124+
(u64)start, size);
106125
goto disable;
107126
}
108127

109-
size = initrd_end - initrd_start;
110-
memblock_reserve(__pa_symbol(initrd_start), size);
128+
memblock_reserve(start, size);
129+
/* Now convert initrd to virtual addresses */
130+
initrd_start = (unsigned long)__va(phys_initrd_start);
131+
initrd_end = initrd_start + phys_initrd_size;
111132
initrd_below_start_ok = 1;
112133

113134
pr_info("Initial ramdisk at: 0x%p (%lu bytes)\n",

0 commit comments

Comments
 (0)