]> xenbits.xensource.com Git - people/aperard/linux.git/commitdiff
riscv: Improve arch_get_mmap_end() macro
authorLeonardo Bras <leobras@redhat.com>
Wed, 3 Jan 2024 16:00:19 +0000 (13:00 -0300)
committerPalmer Dabbelt <palmer@rivosinc.com>
Tue, 19 Mar 2024 23:39:36 +0000 (16:39 -0700)
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>
arch/riscv/include/asm/processor.h

index f19f861cda549014eee042efb651709f5da00475..2278e2a8362af06e4ef799b74af52ea459f59d62 100644 (file)
 #define DEFAULT_MAP_WINDOW     (UL(1) << (MMAP_VA_BITS - 1))
 #define STACK_TOP_MAX          TASK_SIZE_64
 
+/*
+ * addr is a hint to the maximum userspace address that mmap should provide, so
+ * this macro needs to return the largest address space available so that
+ * mmap_end < addr, being mmap_end the top of that address space.
+ * See Documentation/arch/riscv/vm-layout.rst for more details.
+ */
 #define arch_get_mmap_end(addr, len, flags)                    \
 ({                                                             \
        unsigned long mmap_end;                                 \
        typeof(addr) _addr = (addr);                            \
        if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \
                mmap_end = STACK_TOP_MAX;                       \
-       else if ((_addr) >= VA_USER_SV57)                       \
-               mmap_end = STACK_TOP_MAX;                       \
-       else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= VA_BITS_SV48)) \
+       else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \
+               mmap_end = VA_USER_SV57;                        \
+       else if (((_addr) >= VA_USER_SV48) && (VA_BITS >= VA_BITS_SV48)) \
                mmap_end = VA_USER_SV48;                        \
        else                                                    \
                mmap_end = VA_USER_SV39;                        \