Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <71a003c7-ceac-478e-b85b-c49dc42e399f@app.fastmail.com>
Date: Sun, 18 Oct 2026 03:06:10 +0200
From: Alex Rønne Petersen <alex@...xrp.com>
To: "Rich Felker" <dalias@...ifal.cx>
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH v2] riscv: declare all vector registers as clobbers of
 syscalls

On Sun, Oct 18, 2026, at 02:35, Rich Felker wrote:
> On Sat, Oct 17, 2026 at 03:11:13PM +0200, Alex Rønne Petersen wrote:
>> 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.
>> 
>> Because the history of vector clobber support in compilers is messy,
>> we detect support for them at configure time. If the clobbers we need
>> are not supported, we instead declare the syscall functions noinline
>> and rely on the calling convention to mark the registers clobbered.
>> 
>> Co-authored-by: Rich Felker <dalias@...ifal.cx>
>> ---
>>  arch/riscv32/syscall_arch.h | 34 ++++++++++++++++++++++++++--------
>>  arch/riscv64/syscall_arch.h | 34 ++++++++++++++++++++++++++--------
>>  configure                   |  8 ++++++++
>>  3 files changed, 60 insertions(+), 16 deletions(-)
>> 
>> diff --git a/arch/riscv32/syscall_arch.h b/arch/riscv32/syscall_arch.h
>> index 70d2773f..2baa6e65 100644
>> --- a/arch/riscv32/syscall_arch.h
>> +++ b/arch/riscv32/syscall_arch.h
>> @@ -3,26 +3,44 @@
>>  ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
>>  #define __SYSCALL_LL_O(x) __SYSCALL_LL_E((x))
>>  
>> +#ifndef MISSING_RVV_CLOBBERS
>> +#define SYSCALL_CLOBBERLIST "memory", \
>> +	"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"
>> +#else
>> +#define SYSCALL_CLOBBERLIST "memory"
>> +#if defined(__riscv_v) || defined(__riscv_vector)
>> +#define SYSCALL_FUNCTION_ATTRS __attribute__((__noinline__, __unused__)) static
>> +#endif
>> +#endif
>> +
>> +#ifndef SYSCALL_FUNCTION_ATTRS
>> +#define SYSCALL_FUNCTION_ATTRS static inline
>> +#endif
>> +
>>  #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)
>> +SYSCALL_FUNCTION_ATTRS long __syscall0(long n)
>
> Could you keep the static out of the macro so that it's clear to
> someone reading it that it's there without looking up how the macro
> gets defined?
>
> -static inline long __syscall0(long n)
> +SYSCALL_FUNCTION_ATTRS
> +static long __syscall0(long n)

Sure.

> I'm guessing inline clashed (or you were worried a compiler might
> treat it as clashing?) with the noinline attribute, so moving it out
> like you did is fine if needed.

gcc -Wattributes (on by default) will warn if a function has both inline
and __attribute__((noinline)). So not strictly needed, but I'm assuming
we'd rather not have those warnings.

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.