public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] riscv: Define TASK_SIZE_MAX for __access_ok()
@ 2024-03-13 17:59 Samuel Holland
  2024-03-18 20:50 ` Alexandre Ghiti
  2024-03-25 20:40 ` Arnd Bergmann
  0 siblings, 2 replies; 19+ messages in thread
From: Samuel Holland @ 2024-03-13 17:59 UTC (permalink / raw)
  To: Palmer Dabbelt, linux-riscv
  Cc: Samuel Holland, Albert Ou, Alexandre Ghiti, Andrew Morton,
	Charlie Jenkins, Guo Ren, Jisheng Zhang, Kemeng Shi,
	Matthew Wilcox (Oracle), Mike Rapoport (IBM), Paul Walmsley,
	Xiao Wang, Yangyu Chen, linux-kernel

TASK_SIZE_MAX should be set to the largest userspace address under any
runtime configuration. This optimizes the check in __access_ok(), which
no longer needs to compute the current value of TASK_SIZE. It is still
safe because addresses between TASK_SIZE and TASK_SIZE_MAX are invalid
at the hardware level.

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

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
---

 arch/riscv/include/asm/pgtable-64.h | 1 +
 arch/riscv/include/asm/pgtable.h    | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h
index b99bd66107a6..a677ef3c0fe2 100644
--- a/arch/riscv/include/asm/pgtable-64.h
+++ b/arch/riscv/include/asm/pgtable-64.h
@@ -17,6 +17,7 @@ extern bool pgtable_l5_enabled;
 #define PGDIR_SHIFT_L4  39
 #define PGDIR_SHIFT_L5  48
 #define PGDIR_SIZE_L3   (_AC(1, UL) << PGDIR_SHIFT_L3)
+#define PGDIR_SIZE_L5   (_AC(1, UL) << PGDIR_SHIFT_L5)
 
 #define PGDIR_SHIFT     (pgtable_l5_enabled ? PGDIR_SHIFT_L5 : \
 		(pgtable_l4_enabled ? PGDIR_SHIFT_L4 : PGDIR_SHIFT_L3))
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 6066822e7396..2032f8ac5fc5 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -867,6 +867,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_MIN	(PGDIR_SIZE_L3 * PTRS_PER_PGD / 2)
+#define TASK_SIZE_MAX	(PGDIR_SIZE_L5 * PTRS_PER_PGD / 2)
 
 #ifdef CONFIG_COMPAT
 #define TASK_SIZE_32	(_AC(0x80000000, UL))
-- 
2.43.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-03-26 16:02 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-13 17:59 [PATCH] riscv: Define TASK_SIZE_MAX for __access_ok() Samuel Holland
2024-03-18 20:50 ` Alexandre Ghiti
2024-03-18 21:29   ` Samuel Holland
2024-03-19 16:51     ` Alexandre Ghiti
2024-03-24 19:42       ` David Laight
2024-03-25  7:30         ` Alexandre Ghiti
2024-03-25  9:30           ` David Laight
2024-03-25 16:39           ` Mark Rutland
2024-03-25 18:02             ` Arnd Bergmann
2024-03-25 18:30               ` Mark Rutland
2024-03-25 19:20                 ` Samuel Holland
2024-03-25 20:38                 ` Arnd Bergmann
2024-03-26 10:19                   ` David Laight
2024-03-26 14:49                     ` Mark Rutland
2024-03-25 20:12             ` Alexandre Ghiti
2024-03-24 22:05       ` Arnd Bergmann
2024-03-25  7:25         ` Alexandre Ghiti
2024-03-25 11:15           ` Arnd Bergmann
2024-03-25 20:40 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox