[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e4d21516-23b5-404b-a7da-cf6ebfd02dbc@iscas.ac.cn>
Date: Sat, 9 Aug 2025 11:58:24 +0800
From: Vivian Wang <wangruikang@...as.ac.cn>
To: Drew Fustini <fustini@...nel.org>,
Paul Walmsley <paul.walmsley@...ive.com>, Palmer Dabbelt
<palmer@...belt.com>, Alexandre Ghiti <alex@...ti.fr>,
Samuel Holland <samuel.holland@...ive.com>, Björn Töpel
<bjorn@...osinc.com>, Andy Chiu <andybnac@...il.com>,
Conor Dooley <conor.dooley@...rochip.com>, linux-riscv@...ts.infradead.org,
linux-kernel@...r.kernel.org, Drew Fustini <dfustini@...storrent.com>
Subject: Re: [PATCH v2] riscv: Add sysctl to control discard of vstate during
syscall
My previous comment on v1 on prefering clobbering with VS = Initial
handling aside...
On 8/8/25 20:36, Darius Rad wrote:
> On Wed, Aug 06, 2025 at 07:03:28AM -0700, Drew Fustini wrote:
> [...]
>> diff --git a/Documentation/arch/riscv/vector.rst b/Documentation/arch/riscv/vector.rst
>> index 3987f5f76a9deb0824e53a72df4c3bf90ac2bee1..b702c00351617165a4d8897c7df68eadcd2d562e 100644
>> --- a/Documentation/arch/riscv/vector.rst
>> +++ b/Documentation/arch/riscv/vector.rst
>> @@ -134,7 +134,25 @@ processes in form of sysctl knob:
>> 3. Vector Register State Across System Calls
>> ---------------------------------------------
>>
>> -As indicated by version 1.0 of the V extension [1], vector registers are
>> -clobbered by system calls.
>> +Linux adopts the syscall ABI proposed by version 1.0 of the V extension [1],
>> +where vector registers are clobbered by system calls. Specifically:
>> +
>> + Executing a system call causes all caller-saved vector registers
>> + (v0-v31, vl, vtype) and vstart to become unspecied.
>> +
> Perhaps:
>
> Clobbering the vector registers may prevent leaking information to user
No... Not clobbering does not "leak" anything. If you find that it leaks
information, please report - that's a bug.
> space and aid in debugging, but can significantly increase system call
> latency for some implementations. [...]
>
>> +However, clobbering the vector registers can significantly increase system call
>> +latency for some implementations. To mitigate this performance impact, a sysctl
>> +knob is provided that controls whether vector state is always discarded in the
>> +syscall path:
>> +
>> +* /proc/sys/abi/riscv_v_vstate_discard
>> +
>> + Valid values are:
>> +
>> + * 0: Vector state is not always clobbered in all syscalls
>> + * 1: Mandatory clobbering of vector state in all syscalls
>> +
>> + Reading this file returns the current discard behavior. The initial state is
>> + controlled by CONFIG_RISCV_ISA_V_VSTATE_DISCARD.
>>
>> 1: https://github.com/riscv/riscv-v-spec/blob/master/calling-convention.adoc
>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
>> index 36061f4732b7496a9c68a9a10f9959849dc2a95c..7bb8a8513135cbc105bd94d273012486a886f724 100644
>> --- a/arch/riscv/Kconfig
>> +++ b/arch/riscv/Kconfig
>> @@ -656,6 +656,16 @@ config RISCV_ISA_V_DEFAULT_ENABLE
>>
>> If you don't know what to do here, say Y.
>>
>> +config RISCV_ISA_V_VSTATE_DISCARD
>> + bool "Enable Vector state discard by default"
>> + depends on RISCV_ISA_V
>> + default n
>> + help
> Perhaps add the following paragraph:
>
> Discarding vector state is more robust, but has negative performance
> implications in certain implementations.
"Robust" is too vague... I don't think this word is helpful for anyone
trying to understand what this does.
Vivian "dramforever" Wang
>
>> + Say Y here if you want to always discard vector state in syscalls.
>> + Otherwise, userspace has to enable it via the sysctl interface.
>> +
>> + If you don't know what to do here, say N.
>> +
>> config RISCV_ISA_V_UCOPY_THRESHOLD
>> int "Threshold size for vectorized user copies"
>> depends on RISCV_ISA_V
Powered by blists - more mailing lists