| From ffb03799308c5af624b4b5d1b683c59fb328511c Mon Sep 17 00:00:00 2001 | |
| From: Sasha Levin <sashal@kernel.org> | |
| Date: Mon, 5 Oct 2026 19:02:37 -0600 | |
| Subject: riscv: vector: Fix data pointer constraints in context save/restore | |
| From: Troy Mitchell <troy.mitchell@linux.dev> | |
| [ Upstream commit 572b25f3a6453d8e7fc28cc0cefe41ed15be166c ] | |
| 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: GUO Ren (XuanTie) <guoren@kernel.org> | |
| Reviewed-by: Aurelien Jarno <aurelien@aurel32.net> | |
| Reviewed-by: Andy Chiu <tchiu@tenstorrent.com> | |
| Link: https://patch.msgid.link/20260908-riscv-vector-asm-fix-v1-1-147f314efb2b@linux.dev | |
| Signed-off-by: Paul Walmsley <pjw@kernel.org> | |
| Signed-off-by: Sasha Levin <sashal@kernel.org> | |
| --- | |
| 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 00cb9c0982b1a..e94f81cedda56 100644 | |
| --- a/arch/riscv/include/asm/vector.h | |
| +++ b/arch/riscv/include/asm/vector.h | |
| @@ -225,7 +225,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(); | |
| } | |
| @@ -261,7 +261,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(); | |
| -- | |
| 2.53.0 | |