Skip to contentSkip to conversation

riscv: mm: check the SV39 rule

PATCH New Cheng Chao 1 participant 1 message Sep 28, 2024 RISC-V

lore
Share & tools
lore

Cheng Chao

author
#0 lore raw

PATCH 1/1 riscv: mm: check the SV39 rule

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.

---
 arch/riscv/mm/init.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/mm/init.c +6 -0
index bfa2dea95354..82d112c02662 100644
@@ -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();
 
Signature · 7 lines
2.26.3


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv