[PATCH] riscv: vector: Fix data pointer constraints in context save/restore
Troy Mitchell
troy.mitchell at linux.dev
Sat Sep 12 02:21:46 PDT 2026
On Fri Sep 11, 2026 at 2:56 PM +08, Guo Ren wrote:
> On Tue, Sep 8, 2026 at 9:03 PM Troy Mitchell <troy.mitchell at linux.dev> wrote:
>>
>> The standard vector save/restore asm advances datap but declares it as
>> input-only. An inlined caller reusing the original pointer may therefore
>> use the advanced address instead.
>>
>> Declare datap as read-write so the compiler can preserve the original
>> pointer when needed.
>>
>> Fixes: 03c3fcd9941a ("riscv: Introduce struct/helpers to save/restore per-task Vector state")
>> Signed-off-by: Troy Mitchell <troy.mitchell at linux.dev>
>> ---
>> arch/riscv/include/asm/vector.h | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h
>> index fffe72a772080..c7fd6d50a7a47 100644
>> --- a/arch/riscv/include/asm/vector.h
>> +++ b/arch/riscv/include/asm/vector.h
>> @@ -230,7 +230,7 @@ static inline void __riscv_v_vstate_save(struct __riscv_v_ext_state *save_to,
>> "add %1, %1, %0\n\t"
> Yes, %1 is modified. Good catch!
>
> Reviewed-by: GUO Ren (XuanTie) <guoren at kernel.org>
>
> PS:
> Don't forget "if (has_xtheadvector()) {" part, thx :)
The XTheadVector path copies datap into t0 and lists t0/t4 as
clobbers, so it doesn't have this issue. Thanks for the reminder!
--
Troy Mitchell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-riscv/attachments/20260912/12dcc9e4/attachment.sig>
More information about the linux-riscv
mailing list