riscv: Define TASK_SIZE_MAX for __access_ok()
authorSamuel Holland <samuel.holland@sifive.com>
Wed, 27 Mar 2024 14:38:13 +0000 (07:38 -0700)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 16 May 2024 19:59:58 +0000 (12:59 -0700)
TASK_SIZE_MAX should be set to a constant value, at least the largest
valid userspace address under any runtime configuration. This optimizes
the check in __access_ok(), which no longer needs to compute the runtime
value of TASK_SIZE. The check does not need to be exact, as long as it
accepts all valid userspace addresses and rejects all valid kernel
addresses; well-behaved programs will never fail the access_ok() check.

For RISC-V, which requires all virtual addresses to be sign extended,
the optimal choice is LONG_MAX because it simplifies the limit
comparison to a sign bit test.

This removes about half of the references to pgtable_l[45]_enabled.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20240327143858.711792-3-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/pgtable.h

index f5cc8bcc7f8d713f44fbad8d8e407e7c32c12d05..762a85551764973ff2f24f52214a817201c67319 100644 (file)
@@ -870,6 +870,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
  */
 #ifdef CONFIG_64BIT
 #define TASK_SIZE_64   (PGDIR_SIZE * PTRS_PER_PGD / 2)
+#define TASK_SIZE_MAX  LONG_MAX
 
 #ifdef CONFIG_COMPAT
 #define TASK_SIZE_32   (_AC(0x80000000, UL) - PAGE_SIZE)