Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20261004024852.275144-1-alex@alexrp.com>
Date: Sun,  4 Oct 2026 04:48:52 +0200
From: Alex Rønne Petersen <alex@...xrp.com>
To: musl@...ts.openwall.com
Cc: Alex Rønne Petersen <alex@...xrp.com>
Subject: [PATCH] riscv: declare all vector registers as clobbers of syscalls

The kernel intentionally clobbers vector registers (by setting them to all 1s).
musl didn't declare this, so with a compiler targeting the V extension, this
could lead to all sorts of breakage that at first glance looks like
miscompilations.
---
 arch/riscv32/syscall_arch.h | 9 ++++++++-
 arch/riscv64/syscall_arch.h | 9 ++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/riscv32/syscall_arch.h b/arch/riscv32/syscall_arch.h
index 70d2773f..9149cb9e 100644
--- a/arch/riscv32/syscall_arch.h
+++ b/arch/riscv32/syscall_arch.h
@@ -3,9 +3,16 @@
 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
 #define __SYSCALL_LL_O(x) __SYSCALL_LL_E((x))
 
+#define SYSCALL_CLOBBERLIST \
+	"v0" , "v1",  "v2",  "v3",  "v4",  "v5",  "v6",  "v7", \
+	"v8",  "v9",  "v10", "v11", "v12", "v13", "v14", "v15", \
+	"v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", \
+	"v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", \
+	"vl", "vtype", "vxsat", "vxrm", "memory"
+
 #define __asm_syscall(...) \
 	__asm__ __volatile__ ("ecall\n\t" \
-	: "=r"(a0) : __VA_ARGS__ : "memory"); \
+	: "=r"(a0) : __VA_ARGS__ : SYSCALL_CLOBBERLIST); \
 	return a0; \
 
 static inline long __syscall0(long n)
diff --git a/arch/riscv64/syscall_arch.h b/arch/riscv64/syscall_arch.h
index 81993fc8..6e05c9b3 100644
--- a/arch/riscv64/syscall_arch.h
+++ b/arch/riscv64/syscall_arch.h
@@ -1,9 +1,16 @@
 #define __SYSCALL_LL_E(x) (x)
 #define __SYSCALL_LL_O(x) (x)
 
+#define SYSCALL_CLOBBERLIST \
+	"v0" , "v1",  "v2",  "v3",  "v4",  "v5",  "v6",  "v7", \
+	"v8",  "v9",  "v10", "v11", "v12", "v13", "v14", "v15", \
+	"v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", \
+	"v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", \
+	"vl", "vtype", "vxsat", "vxrm", "memory"
+
 #define __asm_syscall(...) \
 	__asm__ __volatile__ ("ecall\n\t" \
-	: "=r"(a0) : __VA_ARGS__ : "memory"); \
+	: "=r"(a0) : __VA_ARGS__ : SYSCALL_CLOBBERLIST); \
 	return a0; \
 
 static inline long __syscall0(long n)
-- 
2.53.0

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.