riscv: Fix loading 64-bit NOMMU kernels past the start of RAM
authorSamuel Holland <samuel.holland@sifive.com>
Tue, 27 Feb 2024 00:34:47 +0000 (16:34 -0800)
committerPalmer Dabbelt <palmer@rivosinc.com>
Tue, 9 Apr 2024 18:39:38 +0000 (11:39 -0700)
commitaea702dde7e9876fb00571a2602f25130847bf0f
tree37824f36f95979f408689fe75f3a7c78abdf07b3
parent6065e736f82c817c9a597a31ee67f0ce4628e948
riscv: Fix loading 64-bit NOMMU kernels past the start of RAM

commit 3335068f8721 ("riscv: Use PUD/P4D/PGD pages for the linear
mapping") added logic to allow using RAM below the kernel load address.
However, this does not work for NOMMU, where PAGE_OFFSET is fixed to the
kernel load address. Since that range of memory corresponds to PFNs
below ARCH_PFN_OFFSET, mm initialization runs off the beginning of
mem_map and corrupts adjacent kernel memory. Fix this by restoring the
previous behavior for NOMMU kernels.

Fixes: 3335068f8721 ("riscv: Use PUD/P4D/PGD pages for the linear mapping")
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240227003630.3634533-3-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/page.h
arch/riscv/mm/init.c