Merge patch series "riscv: Introduce compat-mode helpers & improve arch_get_mmap_end()"
authorPalmer Dabbelt <palmer@rivosinc.com>
Wed, 20 Mar 2024 00:09:05 +0000 (17:09 -0700)
committerPalmer Dabbelt <palmer@rivosinc.com>
Wed, 20 Mar 2024 15:56:05 +0000 (08:56 -0700)
Leonardo Bras <leobras@redhat.com> says:

I just saw the opportunity of optimizing the helper is_compat_task() by
introducing a compile-time test, and it made possible to remove some
 #ifdef's without any loss of performance.

I also saw the possibility of removing the direct check of task flags from
general code, and concentrated it in asm/compat.h by creating a few more
helpers, which in the end helped optimize code.

arch_get_mmap_end() just got a simple improvement and some extra docs.

* b4-shazam-merge:
  riscv: Introduce set_compat_task() in asm/compat.h
  riscv: Introduce is_compat_thread() into compat.h
  riscv: add compile-time test into is_compat_task()
  riscv: Replace direct thread flag check with is_compat_task()
  riscv: Improve arch_get_mmap_end() macro

Link: https://lore.kernel.org/r/20240103160024.70305-2-leobras@redhat.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1  2 
arch/riscv/include/asm/pgtable.h
arch/riscv/include/asm/processor.h
arch/riscv/kernel/ptrace.c

Simple merge
index 0d13b4497b01745a467f580b6a2dd52b274de206,d2d7ce30baf3e32b0e58b9216dd311c4ec7286b3..0faf5f161f1e4957b4cbeac63cf4d69c4dbd55e6
  
  #include <asm/ptrace.h>
  
 -#ifdef CONFIG_64BIT
 -#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()) ||  \
 -      if ((_addr) == 0 || is_compat_task())                   \
++      if ((_addr) == 0 || is_compat_task() ||                 \
 +          ((_addr + len) > BIT(VA_BITS - 1)))                 \
                mmap_end = STACK_TOP_MAX;                       \
 -      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;                        \
 +              mmap_end = (_addr + len);                       \
        mmap_end;                                               \
  })
  
        typeof(addr) _addr = (addr);                            \
        typeof(base) _base = (base);                            \
        unsigned long rnd_gap = DEFAULT_MAP_WINDOW - (_base);   \
-       if ((_addr) == 0 ||                                     \
-           (IS_ENABLED(CONFIG_COMPAT) && is_compat_task()) ||  \
 -      if ((_addr) == 0 || is_compat_task())                   \
++      if ((_addr) == 0 || is_compat_task() ||                 \
 +          ((_addr + len) > BIT(VA_BITS - 1)))                 \
                mmap_base = (_base);                            \
 -      else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \
 -              mmap_base = VA_USER_SV57 - rnd_gap;             \
 -      else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= VA_BITS_SV48)) \
 -              mmap_base = VA_USER_SV48 - rnd_gap;             \
        else                                                    \
 -              mmap_base = VA_USER_SV39 - rnd_gap;             \
 +              mmap_base = (_addr + len) - rnd_gap;            \
        mmap_base;                                              \
  })
  
Simple merge