From: Geert Uytterhoeven Date: Thu, 29 Apr 2021 15:05:00 +0000 (+0200) Subject: riscv: Only extend kernel reservation if mapped read-only X-Git-Tag: microblaze-v5.14~11^2~3 X-Git-Url: http://git.monstr.eu/?a=commitdiff_plain;h=8db6f937f4e76d9dd23795311fc14f0a5c0ac119;p=linux-2.6-microblaze.git riscv: Only extend kernel reservation if mapped read-only When the kernel mapping was moved outside of the linear mapping, the kernel memory reservation was increased, to take into account mapping granularity. However, this is done unconditionally, regardless of whether the kernel memory is mapped read-only or not. If this extension is not needed, up to 2 MiB may be lost, which has a big impact on e.g. Canaan K210 (64-bit nommu) platforms with only 8 MiB of RAM. Reclaim the lost memory by only extending the reserved region when needed, i.e. depending on a simplified version of the conditional logic around the call to protect_kernel_linear_mapping_text_rodata(). Fixes: 2bfc6cd81bd17e43 ("riscv: Move kernel mapping outside of linear mapping") Signed-off-by: Geert Uytterhoeven Tested-by: Alexandre Ghiti Signed-off-by: Palmer Dabbelt --- diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index dfb5e4f7a670..1ec98d97b67f 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -135,11 +135,16 @@ void __init setup_bootmem(void) /* * Reserve from the start of the kernel to the end of the kernel - * and make sure we align the reservation on PMD_SIZE since we will + */ +#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX) + /* + * Make sure we align the reservation on PMD_SIZE since we will * map the kernel in the linear mapping as read-only: we do not want * any allocation to happen between _end and the next pmd aligned page. */ - memblock_reserve(vmlinux_start, (vmlinux_end - vmlinux_start + PMD_SIZE - 1) & PMD_MASK); + vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK; +#endif + memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); /* * memblock allocator is not aware of the fact that last 4K bytes of