Skip to content

Commit 6be7ee4

Browse files
Leonardo Braspalmer-dabbelt
authored andcommitted
riscv: Improve arch_get_mmap_end() macro
This macro caused me some confusion, which took some reviewer's time to make it clear, so I propose adding a short comment in code to avoid confusion in the future. Also, added some improvements to the macro, such as removing the assumption of VA_USER_SV57 being the largest address space. Signed-off-by: Leonardo Bras <leobras@redhat.com> Reviewed-by: Guo Ren <guoren@kernel.org> Link: https://lore.kernel.org/r/20240103160024.70305-3-leobras@redhat.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent b85ea95 commit 6be7ee4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

arch/riscv/include/asm/processor.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,21 @@
1818
#define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1))
1919
#define STACK_TOP_MAX TASK_SIZE_64
2020

21+
/*
22+
* addr is a hint to the maximum userspace address that mmap should provide, so
23+
* this macro needs to return the largest address space available so that
24+
* mmap_end < addr, being mmap_end the top of that address space.
25+
* See Documentation/arch/riscv/vm-layout.rst for more details.
26+
*/
2127
#define arch_get_mmap_end(addr, len, flags) \
2228
({ \
2329
unsigned long mmap_end; \
2430
typeof(addr) _addr = (addr); \
2531
if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \
2632
mmap_end = STACK_TOP_MAX; \
27-
else if ((_addr) >= VA_USER_SV57) \
28-
mmap_end = STACK_TOP_MAX; \
29-
else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= VA_BITS_SV48)) \
33+
else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \
34+
mmap_end = VA_USER_SV57; \
35+
else if (((_addr) >= VA_USER_SV48) && (VA_BITS >= VA_BITS_SV48)) \
3036
mmap_end = VA_USER_SV48; \
3137
else \
3238
mmap_end = VA_USER_SV39; \

0 commit comments

Comments
 (0)