[PATCH v2 2/2] riscv: more accurate check for CPU atomics support

Vladimir Kondratiev vladimir.kondratiev at mobileye.com
Tue Jan 20 06:26:24 PST 2026


CPU reports extensions supported in "riscv,isa-extensions" property
of the CPU node, for atomic operations it is
- "a" extension meaning both AMO and LR/SC supported
- "zaamo" extension meaning AMO instructions supported
- "zalrsc" extension meaning LR/SC supported

Code can also be compiled with subset of atomics support

Relax requirements for CPU extension support from full "a"
to subset compatible with software configuration

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

diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c
index 3dbc8cc557dd1d71101959a003ea7195af3c92a0..84d4a549b6136e0c97a35025a18ce710afbedad5 100644
--- a/arch/riscv/kernel/cpu.c
+++ b/arch/riscv/kernel/cpu.c
@@ -82,12 +82,26 @@ 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;
 	}
-
+	/* any atomic supported? */
+#if defined(__riscv_atomic) || defined(__riscv_zaamo)
+	if (of_property_match_string(node, "riscv,isa-extensions", "a") < 0 &&
+	    of_property_match_string(node, "riscv,isa-extensions", "zaamo") < 0) {
+		pr_warn("CPU with hartid=%lu does not support AMO atomics", *hart);
+		return -ENODEV;
+	}
+#elif defined(__riscv_zalrsc)
+	if (of_property_match_string(node, "riscv,isa-extensions", "a") < 0 &&
+	    of_property_match_string(node, "riscv,isa-extensions", "zalrsc") < 0) {
+		pr_warn("CPU with hartid=%lu does not support LS/SC atomics", *hart);
+		return -ENODEV;
+	}
+#else
+#error "need atomic or zalrsc extension"
+#endif
 	return 0;
 
 old_interface:

-- 
2.43.0




More information about the linux-riscv mailing list