riscv: vector: Fix data pointer constraints in context save/restore
PATCH 1/1 riscv: vector: Fix data pointer constraints in context save/restore
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.
--- arch/riscv/include/asm/vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/include/asm/vector.h +2 -2
@@ -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,
Signature · 1 line
Troy Mitchell <[email protected]>
Quoted 19 lines · 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 <[email protected]>--- arch/riscv/include/asm/vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/include/asm/vector.h +0
-0
arch/riscv/include/asm/vector.h static inline void __riscv_v_vstate_save(struct __riscv_v_ext_state *save_to, · line 230
Quoted 1 line
arch/riscv/include/asm/vector.h +0
-0@@ -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!
PS:
Don't forget "if (has_xtheadvector()) {" part, thx :)
Quoted 25 lines
arch/riscv/include/asm/vector.h +2
-3"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-27ed36623934Best regards,
--
Troy Mitchell <[email protected]>
Signature · 2 lines
Best Regards Guo Ren
Quoted 23 lines · Guo Ren
Quoted 19 lines · 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 <[email protected]>--- arch/riscv/include/asm/vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/include/asm/vector.h +0
-0arch/riscv/include/asm/vector.h static inline void __riscv_v_vstate_save(struct __riscv_v_ext_state *save_to, · line 230
Quoted 1 line
arch/riscv/include/asm/vector.h +0
-0@@ -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!
Quoted 4 lines
Reviewed-by GUO Ren (XuanTie) <[email protected]>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!
Signature · 1 line
Troy Mitchell
Quoted 4 lines · 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.
Quoted 8 lines
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 <[email protected]>--- arch/riscv/include/asm/vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://aurel32.net
Hi Troy,
Quoted 10 lines · 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 <[email protected]>
Thank you,
Andy Chiu
Paul Walmsley
maintainerQuoted 9 lines · 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 <[email protected]>
Thanks, queued for v7.3-rc.
- Paul