All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Holland <samuel.holland@sifive.com>
To: Palmer Dabbelt <palmer@dabbelt.com>, linux-riscv@lists.infradead.org
Cc: Mark Rutland <mark.rutland@arm.com>,
	David Laight <David.Laight@ACULAB.COM>,
	Arnd Bergmann <arnd@arndb.de>,
	Alexandre Ghiti <alexghiti@rivosinc.com>,
	Samuel Holland <samuel.holland@sifive.com>
Subject: [PATCH v2 2/2] riscv: Define TASK_SIZE_MAX for __access_ok()
Date: Wed, 27 Mar 2024 07:38:13 -0700	[thread overview]
Message-ID: <20240327143858.711792-3-samuel.holland@sifive.com> (raw)
In-Reply-To: <20240327143858.711792-1-samuel.holland@sifive.com>

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)
-- 
2.43.1


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

  parent reply	other threads:[~2024-03-27 14:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 14:38 [PATCH v2 0/2] riscv: access_ok() optimization Samuel Holland
2024-03-27 14:38 ` [PATCH v2 1/2] riscv: Remove PGDIR_SIZE_L3 and TASK_SIZE_MIN Samuel Holland
2024-03-27 16:24   ` Arnd Bergmann
2024-04-04  7:33   ` Alexandre Ghiti
2024-03-27 14:38 ` Samuel Holland [this message]
2024-03-27 16:24   ` [PATCH v2 2/2] riscv: Define TASK_SIZE_MAX for __access_ok() Arnd Bergmann
2024-04-04  7:38   ` Alexandre Ghiti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240327143858.711792-3-samuel.holland@sifive.com \
    --to=samuel.holland@sifive.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=alexghiti@rivosinc.com \
    --cc=arnd@arndb.de \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=palmer@dabbelt.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.