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)
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

index 57e887bfa34cb70b3d829d13dbb80c3fc6bf7ba9..94b3d6930fc370526c105d14d666fd961762f491 100644 (file)
@@ -89,7 +89,7 @@ typedef struct page *pgtable_t;
 #define PTE_FMT "%08lx"
 #endif
 
-#ifdef CONFIG_64BIT
+#if defined(CONFIG_64BIT) && defined(CONFIG_MMU)
 /*
  * We override this value as its generic definition uses __pa too early in
  * the boot process (before kernel_map.va_pa_offset is set).
index 32cad6a65ccd23431d63097a0906ca5b8de485f8..b3e63dec3ab5cdc5c12035f593f3572b7b460699 100644 (file)
@@ -232,7 +232,7 @@ static void __init setup_bootmem(void)
         * In 64-bit, any use of __va/__pa before this point is wrong as we
         * did not know the start of DRAM before.
         */
-       if (IS_ENABLED(CONFIG_64BIT))
+       if (IS_ENABLED(CONFIG_64BIT) && IS_ENABLED(CONFIG_MMU))
                kernel_map.va_pa_offset = PAGE_OFFSET - phys_ram_base;
 
        /*