[PATCH] RISC-V: Add vector registers to __SYSCALL_CLOBBERS
Palmer Dabbelt
palmer@dabbelt.com
Wed Aug 20 00:22:21 GMT 2025
On Tue, 19 Aug 2025 14:48:13 PDT (-0700), bergner@tenstorrent.com wrote:
> The Linux kernel ABI specifies that the vector registers are not preserved
> across system calls, but the __SYSCALL_CLOBBERS macro doesn't mention them.
> This could possibly lead to compilers trying to keep data in the vector
> registers across the inline asm containing the syscall, leading to corruption.
> Add the vector registers to __SYSCALL_CLOBBERS when the vector extension is
> enabled.
>
> I tested this natively on a BananaPi and it showed no regressions in the
> build or testsuite. Ok for trunk?
>
> Is this "correctness" bug something we want backported to the release branch(es)
> after some burn-in time on trunk? If the answer is yes, then how far back?
It's only a correctness bug if you build GCC with V enabled globally.
For some reason I thought we'd forbidden that at configure time, but I
don't see it in preconfigure.ac so maybe I'm just misremembering?
That's why I'd punted on this earlier, but I guess I dropped the ball
there...
So ya, I think we should backport these basically forever. Seems like
the patch would just apply all the way back, so I guess it's just
Fixes: 36960f0c76 ("RISC-V: Linux Syscall Interface")
> The bug was discovered by Florian as part of the discussion from [1].
>
> [1] https://lore.kernel.org/linux-riscv/lhua545dl1i.fsf@oldenburg.str.redhat.com/
>
>
> Signed-off-by: Peter Bergner <bergner@tenstorrent.com>
>
> ---
> sysdeps/unix/sysv/linux/riscv/sysdep.h | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
> index 05e0e0523d..2548019c40 100644
> --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
> @@ -355,7 +355,14 @@
> _sys_result; \
> })
>
> +#ifdef __riscv_v
> +# define __SYSCALL_CLOBBERS "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", "memory"
There's a few more of these, GCC has "vl", "vtype", "vxrm", and
"vxsat". With those
Reviewed-by: Palmer Dabbelt <palmer@dabbelt.com>
Acked-by: Palmer Dabbelt <palmer@dabbelt.com>
IIRC we added the extra ones later, but maybe it's worth throwing
together some autoconf that forbids GCC versions before 15? Autovec is
pretty buggy in 14 and unlikely to be profitable, so I think users who
try would just be asking for trouble...
> +#else
> # define __SYSCALL_CLOBBERS "memory"
> +#endif
>
> extern long int __syscall_error (long int neg_errno);
More information about the Libc-alpha
mailing list