riscv: Fix crash during early errata patching
authorSamuel Holland <samuel@sholland.org>
Sat, 26 Nov 2022 06:09:19 +0000 (00:09 -0600)
committerPalmer Dabbelt <palmer@rivosinc.com>
Fri, 9 Dec 2022 01:22:53 +0000 (17:22 -0800)
The patch function for the T-Head PBMT errata calls __pa_symbol() before
relocation. This crashes when CONFIG_DEBUG_VIRTUAL is enabled, because
__pa_symbol() forwards to __phys_addr_symbol(), and __phys_addr_symbol()
checks against the absolute kernel start/end address.

Fix this by checking against the kernel map instead of a symbol address.

Fixes: a35707c3d850 ("riscv: add memory-type errata for T-Head")
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Samuel Holland <samuel@sholland.org>
Link: https://lore.kernel.org/r/20221126060920.65009-1-samuel@sholland.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/mm/physaddr.c

index 19cf25a..9b18bda 100644 (file)
@@ -22,7 +22,7 @@ EXPORT_SYMBOL(__virt_to_phys);
 phys_addr_t __phys_addr_symbol(unsigned long x)
 {
        unsigned long kernel_start = kernel_map.virt_addr;
 phys_addr_t __phys_addr_symbol(unsigned long x)
 {
        unsigned long kernel_start = kernel_map.virt_addr;
-       unsigned long kernel_end = (unsigned long)_end;
+       unsigned long kernel_end = kernel_start + kernel_map.size;
 
        /*
         * Boundary checking aginst the kernel image mapping.
 
        /*
         * Boundary checking aginst the kernel image mapping.