[PATCH v6 3/6] riscv: accept the atomic extensions this kernel was built with

Vladimir Kondratiev vladimir.kondratiev at mobileye.com
Tue Nov 10 05:21:00 PST 2026


riscv_early_of_processor_hartid() rejects a hart unless its
riscv,isa-extensions property contains "a". A hart that lists "zaamo"
and "zalrsc" instead of "a" is rejected, and so is one that lists only
"zalrsc", even when the kernel was built to use only LR/SC.

Accept "a" as before. Without it, require "zalrsc", which every kernel
uses for cmpxchg, and "zaamo" when RISCV_ISA_ZAAMO is enabled. The
default build therefore needs "a", or "zaamo" together with "zalrsc";
a kernel built without Zaamo needs only "zalrsc".

The legacy "riscv,isa" fallback keeps its rv{32,64}ima check.

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev at mobileye.com>
---
 arch/riscv/kernel/cpu.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c
index 3dbc8cc557dd..9ba0d49c87bc 100644
--- a/arch/riscv/kernel/cpu.c
+++ b/arch/riscv/kernel/cpu.c
@@ -82,12 +82,29 @@ int __init riscv_early_of_processor_hartid(struct device_node *node, unsigned lo
 		return -ENODEV;
 
 	if (of_property_match_string(node, "riscv,isa-extensions", "i") < 0 ||
-	    of_property_match_string(node, "riscv,isa-extensions", "m") < 0 ||
-	    of_property_match_string(node, "riscv,isa-extensions", "a") < 0) {
-		pr_warn("CPU with hartid=%lu does not support ima", *hart);
+	    of_property_match_string(node, "riscv,isa-extensions", "m") < 0) {
+		pr_warn("CPU with hartid=%lu does not support im", *hart);
 		return -ENODEV;
 	}
 
+	/*
+	 * Require the atomic extensions this kernel was built with. "a"
+	 * covers both; otherwise LR/SC is always needed and AMO is needed
+	 * when the kernel uses it.
+	 */
+	if (of_property_match_string(node, "riscv,isa-extensions", "a") < 0) {
+		if (of_property_match_string(node, "riscv,isa-extensions", "zalrsc") < 0) {
+			pr_warn("CPU with hartid=%lu does not support zalrsc", *hart);
+			return -ENODEV;
+		}
+
+		if (IS_ENABLED(CONFIG_RISCV_ISA_ZAAMO) &&
+		    of_property_match_string(node, "riscv,isa-extensions", "zaamo") < 0) {
+			pr_warn("CPU with hartid=%lu does not support zaamo", *hart);
+			return -ENODEV;
+		}
+	}
+
 	return 0;
 
 old_interface:

-- 
2.43.0




More information about the linux-riscv mailing list