[PATCH] riscv: Add sysctl to control discard of vstate during syscall

Drew Fustini pdp7pdp7 at gmail.com
Mon Jul 21 14:20:03 PDT 2025


On Mon, Jul 21, 2025 at 04:54:25PM +0200, Radim Krčmář wrote:
> 2025-07-21T14:35:38+02:00, Radim Krčmář <rkrcmar at ventanamicro.com>:
> > Shouldn't the RISC-V Linux syscall ABI be defined somewhere?
> 
> To clarify this point.  My issue is with the following part in
> Documentation/arch/riscv/vector.rst:
> 
> >>  As indicated by version 1.0 of the V extension [1], vector registers are
> >>  clobbered by system calls.
> >>  [...]
> >>  1: https://github.com/riscv/riscv-v-spec/blob/master/calling-convention.adoc
> 
> The ISA does not say that vector registers are clobbered by system
> calls.  All the ISA says is:
> 
>   "This Appendix is only a placeholder to help explain the conventions
>    used in the code examples, and is not considered frozen or
>    part of the ratification process.  The official RISC-V psABI document
>    is being expanded to specify the vector calling conventions."
> 
> while the RISC-V psABI says:
> 
>   "The calling convention for system calls does not fall within the
>    scope of this document. Please refer to the documentation of the
>    RISC-V execution environment interface (e.g OS kernel ABI, SBI)."
> 
> We made a circular dependency, misinterpreted the ISA, and probably
> implemented a suboptimal syscall ABI -- preserving vector registers
> seems strictly better.

Thanks for providing these references. It does seem like this is
something that an OS can decide and is not mandated by the ISA or psABI.

> > How come we could have broken it with 9657e9b7d253?
> 
> We changed the ABI once, so maybe we can change it back?

Reverting 9657e9b7d253 would solve the performance issue for some
implementations that I've highlighted in this patch. However, I am
interested to hear from others that feel the current mandatory
clobbering behavior is ideal for testing (and maybe security?).

Thanks,
Drew



More information about the linux-riscv mailing list