* [PATCH] riscv: vector: Fix data pointer constraints in context save/restore
@ 2026-09-08 13:03 Troy Mitchell
2026-09-11 6:56 ` Guo Ren
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Troy Mitchell @ 2026-09-08 13:03 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Guo Ren, Andy Chiu,
Vincent Chen, Björn Töpel
Cc: Alexandre Ghiti, linux-riscv, linux-kernel, Palmer Dabbelt,
Greentime Hu, Heiko Stuebner, Conor Dooley, Kevin Zhang,
Troy Mitchell
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@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"
"vse8.v v24, (%1)\n\t"
".option pop\n\t"
- : "=&r" (vl) : "r" (datap) : "memory");
+ : "=&r" (vl), "+r" (datap) : : "memory");
}
riscv_v_disable();
}
@@ -266,7 +266,7 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_
"add %1, %1, %0\n\t"
"vle8.v v24, (%1)\n\t"
".option pop\n\t"
- : "=&r" (vl) : "r" (datap) : "memory");
+ : "=&r" (vl), "+r" (datap) : : "memory");
}
__vstate_csr_restore(restore_from);
riscv_v_disable();
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260908-riscv-vector-asm-fix-27ed36623934
Best regards,
--
Troy Mitchell <troy.mitchell@linux.dev>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] riscv: vector: Fix data pointer constraints in context save/restore
2026-09-08 13:03 [PATCH] riscv: vector: Fix data pointer constraints in context save/restore Troy Mitchell
@ 2026-09-11 6:56 ` Guo Ren
2026-09-12 9:21 ` Troy Mitchell
2026-09-11 18:23 ` Aurelien Jarno
2026-09-11 19:01 ` Andy Chiu
2 siblings, 1 reply; 5+ messages in thread
From: Guo Ren @ 2026-09-11 6:56 UTC (permalink / raw)
To: Troy Mitchell
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Andy Chiu,
Vincent Chen, Björn Töpel, Alexandre Ghiti,
linux-riscv, linux-kernel, Palmer Dabbelt, Greentime Hu,
Heiko Stuebner, Conor Dooley, Kevin Zhang
On Tue, Sep 8, 2026 at 9:03 PM Troy Mitchell <troy.mitchell@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@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@kernel.org>
PS:
Don't forget "if (has_xtheadvector()) {" part, thx :)
> "vse8.v v24, (%1)\n\t"
> ".option pop\n\t"
> - : "=&r" (vl) : "r" (datap) : "memory");
> + : "=&r" (vl), "+r" (datap) : : "memory");
> }
> riscv_v_disable();
> }
> @@ -266,7 +266,7 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_
> "add %1, %1, %0\n\t"
> "vle8.v v24, (%1)\n\t"
> ".option pop\n\t"
> - : "=&r" (vl) : "r" (datap) : "memory");
> + : "=&r" (vl), "+r" (datap) : : "memory");
> }
> __vstate_csr_restore(restore_from);
> riscv_v_disable();
>
> ---
> base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
> change-id: 20260908-riscv-vector-asm-fix-27ed36623934
>
> Best regards,
> --
> Troy Mitchell <troy.mitchell@linux.dev>
>
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] riscv: vector: Fix data pointer constraints in context save/restore
2026-09-11 6:56 ` Guo Ren
@ 2026-09-12 9:21 ` Troy Mitchell
0 siblings, 0 replies; 5+ messages in thread
From: Troy Mitchell @ 2026-09-12 9:21 UTC (permalink / raw)
To: Guo Ren, Troy Mitchell
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Andy Chiu,
Vincent Chen, Björn Töpel, Alexandre Ghiti,
linux-riscv, linux-kernel, Palmer Dabbelt, Greentime Hu,
Heiko Stuebner, Conor Dooley, Kevin Zhang
[-- Attachment #1: Type: text/plain, Size: 1393 bytes --]
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@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@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@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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] riscv: vector: Fix data pointer constraints in context save/restore
2026-09-08 13:03 [PATCH] riscv: vector: Fix data pointer constraints in context save/restore Troy Mitchell
2026-09-11 6:56 ` Guo Ren
@ 2026-09-11 18:23 ` Aurelien Jarno
2026-09-11 19:01 ` Andy Chiu
2 siblings, 0 replies; 5+ messages in thread
From: Aurelien Jarno @ 2026-09-11 18:23 UTC (permalink / raw)
To: Troy Mitchell
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Guo Ren, Andy Chiu,
Vincent Chen, Björn Töpel, Alexandre Ghiti,
linux-riscv, linux-kernel, Palmer Dabbelt, Greentime Hu,
Heiko Stuebner, Conor Dooley, Kevin Zhang
On 2026-09-08 21:03, Troy Mitchell 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@linux.dev>
> ---
> arch/riscv/include/asm/vector.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
--
Aurelien Jarno GPG: 4096R/1DDD8C9B
aurelien@aurel32.net http://aurel32.net
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] riscv: vector: Fix data pointer constraints in context save/restore
2026-09-08 13:03 [PATCH] riscv: vector: Fix data pointer constraints in context save/restore Troy Mitchell
2026-09-11 6:56 ` Guo Ren
2026-09-11 18:23 ` Aurelien Jarno
@ 2026-09-11 19:01 ` Andy Chiu
2 siblings, 0 replies; 5+ messages in thread
From: Andy Chiu @ 2026-09-11 19:01 UTC (permalink / raw)
To: Troy Mitchell
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Guo Ren, Vincent Chen,
Björn Töpel, Alexandre Ghiti, linux-riscv,
linux-kernel, Palmer Dabbelt, Greentime Hu, Heiko Stuebner,
Conor Dooley, Kevin Zhang
Hi Troy,
On Tue, Sep 8, 2026 at 8:03 AM Troy Mitchell <troy.mitchell@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@linux.dev>
Reviewed-by: Andy Chiu <tchiu@tenstorrent.com>
Thank you,
Andy Chiu
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-12 9:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-08 13:03 [PATCH] riscv: vector: Fix data pointer constraints in context save/restore Troy Mitchell
2026-09-11 6:56 ` Guo Ren
2026-09-12 9:21 ` Troy Mitchell
2026-09-11 18:23 ` Aurelien Jarno
2026-09-11 19:01 ` Andy Chiu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®