diff mbox series

[v2,2/2] riscv: Define TASK_SIZE_MAX for __access_ok()

Message ID 20240327143858.711792-3-samuel.holland@sifive.com (mailing list archive)
State Accepted
Commit ad5643cf2f699989daa85d909403febd6712fccb
Headers show
Series riscv: access_ok() optimization | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR success PR summary
conchuod/patch-2-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh
conchuod/patch-2-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh
conchuod/patch-2-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh
conchuod/patch-2-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh
conchuod/patch-2-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh
conchuod/patch-2-test-6 success .github/scripts/patches/tests/checkpatch.sh
conchuod/patch-2-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh
conchuod/patch-2-test-8 success .github/scripts/patches/tests/header_inline.sh
conchuod/patch-2-test-9 success .github/scripts/patches/tests/kdoc.sh
conchuod/patch-2-test-10 success .github/scripts/patches/tests/module_param.sh
conchuod/patch-2-test-11 success .github/scripts/patches/tests/verify_fixes.sh
conchuod/patch-2-test-12 success .github/scripts/patches/tests/verify_signedoff.sh

Commit Message

Samuel Holland March 27, 2024, 2:38 p.m. UTC
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>
---

Changes in v2:
 - Set TASK_SIZE_MAX to LONG_MAX to optimize the comparison
 - Reword the commit message

 arch/riscv/include/asm/pgtable.h | 1 +
 1 file changed, 1 insertion(+)

Comments

Arnd Bergmann March 27, 2024, 4:24 p.m. UTC | #1
On Wed, Mar 27, 2024, at 15:38, Samuel Holland wrote:
> 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>
Alexandre Ghiti April 4, 2024, 7:38 a.m. UTC | #2
On 27/03/2024 15:38, Samuel Holland wrote:
> 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>
> ---
>
> Changes in v2:
>   - Set TASK_SIZE_MAX to LONG_MAX to optimize the comparison
>   - Reword the commit message
>
>   arch/riscv/include/asm/pgtable.h | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index f5cc8bcc7f8d..762a85551764 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -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)


You can add:

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Thanks,

Alex
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index f5cc8bcc7f8d..762a85551764 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -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)