Skip to content

Commit 8db6f93

Browse files
geertupalmer-dabbelt
authored andcommitted
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: 2bfc6cd ("riscv: Move kernel mapping outside of linear mapping") Signed-off-by: Geert Uytterhoeven <[email protected]> Tested-by: Alexandre Ghiti <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 939b7cb commit 8db6f93

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

arch/riscv/mm/init.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,16 @@ void __init setup_bootmem(void)
135135

136136
/*
137137
* Reserve from the start of the kernel to the end of the kernel
138-
* and make sure we align the reservation on PMD_SIZE since we will
138+
*/
139+
#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)
140+
/*
141+
* Make sure we align the reservation on PMD_SIZE since we will
139142
* map the kernel in the linear mapping as read-only: we do not want
140143
* any allocation to happen between _end and the next pmd aligned page.
141144
*/
142-
memblock_reserve(vmlinux_start, (vmlinux_end - vmlinux_start + PMD_SIZE - 1) & PMD_MASK);
145+
vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK;
146+
#endif
147+
memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
143148

144149
/*
145150
* memblock allocator is not aware of the fact that last 4K bytes of

0 commit comments

Comments
 (0)