public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: mm: Do not probe satp mode limit if known in FDT
@ 2026-04-24  3:03 Vivian Wang
  2026-04-25  2:02 ` Guo Ren
  0 siblings, 1 reply; 4+ messages in thread
From: Vivian Wang @ 2026-04-24  3:03 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Palmer Dabbelt, Alexandre Ghiti
  Cc: Han Gao, linux-riscv, linux-kernel, Vivian Wang

Some systems may only have memory at such a high address that an
identity mapping cannot be made in Sv48, or even Sv57. To avoid crashing
while probing satp mode support, trust the mmu-type property from FDT
and avoid probing if it is set.

For example, if a CPU supports (up to) Sv57 but the SoC it is on only
has memory starting at 128 TiB, an identity mapping cannot be made in
Sv48. If the user specifies "no5lvl" on the command line,
set_satp_mode() will attempt to test Sv48 support and crash, since the
virtual address is too high. Instead, given the correct FDT CPU node
property mmu-type = "riscv,sv57", set_satp_mode() can pick the maximum
allowed mode from command line and FDT, namely Sv48, without probing.

Handling of mmu-type "riscv,sv57" in set_satp_mode_from_fdt() is added
since it is now needed.

Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
---
Tested on QEMU 10.2.2 on all 3*3 combinations of Sv39/Sv48/Sv57 and
(none)/no4lvl/no5lvl.

In theory this could be a break if mmu-type is wrong, but so many other
things would break if the FDT is wrong anyway.

Also note that this doesn't apply on ACPI since it is difficult to use
ACPICA and read ACPI RHCT at this point, so that will just fall back to
probing. Hopefully UEFI/ACPI + this atrocious SoC design never happens,
since the high memory base address would prevent a lot of PCI(e) devices
from working without an IOMMU. (Fingers crossed.)
---
 arch/riscv/kernel/pi/fdt_early.c | 2 ++
 arch/riscv/mm/init.c             | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/pi/fdt_early.c b/arch/riscv/kernel/pi/fdt_early.c
index a12ff8090f19..702253287560 100644
--- a/arch/riscv/kernel/pi/fdt_early.c
+++ b/arch/riscv/kernel/pi/fdt_early.c
@@ -218,6 +218,8 @@ u64 set_satp_mode_from_fdt(uintptr_t dtb_pa)
 			return SATP_MODE_39;
 		else if (!strcmp(mmu_type, "riscv,sv48"))
 			return SATP_MODE_48;
+		else if (!strcmp(mmu_type, "riscv,sv57"))
+			return SATP_MODE_57;
 		break;
 	}
 
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 811e03786c56..c37578eaddd0 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -859,8 +859,9 @@ static __init void set_satp_mode(uintptr_t dtb_pa)
 {
 	u64 identity_satp, hw_satp;
 	uintptr_t set_satp_mode_pmd = ((unsigned long)set_satp_mode) & PMD_MASK;
+	u64 satp_mode_limit_fdt = __pi_set_satp_mode_from_fdt(dtb_pa);
 	u64 satp_mode_limit = min_not_zero(__pi_set_satp_mode_from_cmdline(dtb_pa),
-					   __pi_set_satp_mode_from_fdt(dtb_pa));
+					   satp_mode_limit_fdt);
 
 	kernel_map.page_offset = PAGE_OFFSET_L5;
 
@@ -872,6 +873,10 @@ static __init void set_satp_mode(uintptr_t dtb_pa)
 		return;
 	}
 
+	/* Skip probing if max SATP mode known from FDT */
+	if (satp_mode_limit_fdt)
+		return;
+
 	create_p4d_mapping(early_p4d,
 			set_satp_mode_pmd, (uintptr_t)early_pud,
 			P4D_SIZE, PAGE_TABLE);

---
base-commit: 028ef9c96e96197026887c0f092424679298aae8
change-id: 20260424-riscv-mm-trust-fdt-mmu-type-c874f7628178

Best regards,
--  
Vivian "dramforever" Wang


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

end of thread, other threads:[~2026-04-25  6:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-24  3:03 [PATCH] riscv: mm: Do not probe satp mode limit if known in FDT Vivian Wang
2026-04-25  2:02 ` Guo Ren
2026-04-25  5:23   ` Vivian Wang
2026-04-25  6:32     ` Guo Ren

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