linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Cheng Chao <cs.os.kernel@gmail.com>
To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu
Cc: linux-riscv@lists.infradead.org, Cheng Chao <cs.os.kernel@gmail.com>
Subject: [PATCH] riscv: mm: check the SV39 rule
Date: Sat, 28 Sep 2024 23:52:19 +0800	[thread overview]
Message-ID: <20240928155219.266866-1-cs.os.kernel@gmail.com> (raw)

SV39 rule: the address of bits[63..39] should be the same as bit[38],
it is easy to violate if configure PAGE_OFFSET too small.
for instance, PAGE_OFFSET=0xffffffc0_0000_0000,
the FIXADDR_START will be the 0xfffffffb0_xxxx_xxxx,
bit[39] == 0'b1, bit[38] == 0'b0, when access the FIXADDR,
which cause the page fault.
It's difficult to debug, check it when compile is necessary.

Signed-off-by: Cheng Chao <cs.os.kernel@gmail.com>
---
 arch/riscv/mm/init.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index bfa2dea95354..a5fb3fc2b2db 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -119,7 +119,7 @@ static inline void print_mlt(char *name, unsigned long b, unsigned long t)
 
 static inline void print_ml(char *name, unsigned long b, unsigned long t)
 {
-	unsigned long diff = t - b;
+	unsigned long diff = t - b + 1;
 
 	if (IS_ENABLED(CONFIG_64BIT) && (diff >> LOG2_SZ_1T) >= 10)
 		print_mlt(name, b, t);
@@ -1387,6 +1387,12 @@ static void __init arch_reserve_crashkernel(void)
 
 void __init paging_init(void)
 {
+#ifdef CONFIG_64BIT
+	BUILD_BUG_ON_MSG((VA_BITS == VA_BITS_SV39) &&
+			(((FIXADDR_START & BIT(39)) >> 39)
+			 != ((FIXADDR_START & BIT(38)) >> 38)),
+			"violate SV39 rule: bits[63..39] should be same as bit[38]");
+#endif
 	setup_bootmem();
 	setup_vm_final();
 
-- 
2.26.3


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

             reply	other threads:[~2024-09-28 15:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-28 15:52 Cheng Chao [this message]
2024-09-30  7:46 ` [PATCH] riscv: mm: check the SV39 rule Alexandre Ghiti
2024-10-07  9:44   ` Cheng Chao
  -- strict thread matches above, loose matches on Subject: below --
2024-09-28 15:56 Cheng Chao

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=20240928155219.266866-1-cs.os.kernel@gmail.com \
    --to=cs.os.kernel@gmail.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).