public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Clobber V registers on syscalls
@ 2023-06-14 16:35 Palmer Dabbelt
  2023-06-15 17:36 ` Rémi Denis-Courmont
  2023-06-16 20:12 ` Björn Töpel
  0 siblings, 2 replies; 27+ messages in thread
From: Palmer Dabbelt @ 2023-06-14 16:35 UTC (permalink / raw)
  To: linux-riscv; +Cc: Palmer Dabbelt

The V registers are clobbered by standard ABI functions, so userspace
probably doesn't have anything useful in them by the time we get to the
kernel.  So let's just document that they're clobbered by syscalls and
proactively clobber them.

Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
---
IIRC we'd talked about doing this, but I didn't see anything in the
docs.  I figure it's better to just proactively clobber the registers on
syscalls, as that way userspace can't end up accidentally depending on
them.
---
 Documentation/riscv/vector.rst | 5 +++++
 arch/riscv/kernel/traps.c      | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/Documentation/riscv/vector.rst b/Documentation/riscv/vector.rst
index 48f189d79e41..a4dfa954215b 100644
--- a/Documentation/riscv/vector.rst
+++ b/Documentation/riscv/vector.rst
@@ -130,3 +130,8 @@ processes in form of sysctl knob:
 
     Modifying the system default enablement status does not affect the enablement
     status of any existing process of thread that do not make an execve() call.
+
+3.  Vector Register State Across System Calls
+---------------------------------------------
+
+Vector registers are clobbered by system calls.
diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index 05ffdcd1424e..bb99a6379b37 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -295,6 +295,8 @@ asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs)
 		regs->epc += 4;
 		regs->orig_a0 = regs->a0;
 
+		riscv_v_vstate_off(regs);
+
 		syscall = syscall_enter_from_user_mode(regs, syscall);
 
 		if (syscall < NR_syscalls)
-- 
2.40.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2025-06-16 22:49 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14 16:35 [PATCH] RISC-V: Clobber V registers on syscalls Palmer Dabbelt
2023-06-15 17:36 ` Rémi Denis-Courmont
2023-06-15 20:33   ` Palmer Dabbelt
2023-06-16 19:58     ` Rémi Denis-Courmont
2023-06-16 19:47   ` Björn Töpel
2023-06-16 20:12 ` Björn Töpel
2023-06-19 18:18   ` Palmer Dabbelt
2023-06-19 19:01     ` Björn Töpel
2023-06-19 19:05       ` Palmer Dabbelt
2023-06-21 14:26         ` Björn Töpel
2023-06-21 14:44           ` Darius Rad
2023-06-21 18:16             ` Palmer Dabbelt
2023-06-21 14:50           ` Andy Chiu
2023-06-21 21:40             ` Björn Töpel
2023-06-22 15:47               ` Andy Chiu
2023-06-22 16:38                 ` Björn Töpel
2023-06-24  6:54                   ` Andy Chiu
2023-06-26 15:36                     ` Björn Töpel
2023-06-27  1:07                       ` Andy Chiu
2023-06-27  6:33                         ` Björn Töpel
2023-06-24  8:41                   ` Andy Chiu
2023-06-26 14:54                     ` Björn Töpel
2023-06-21 16:47           ` Rémi Denis-Courmont
2023-06-21 18:16             ` Palmer Dabbelt
2023-06-21 21:42               ` Björn Töpel
2025-06-16 22:30         ` Drew Fustini
2025-06-16 22:48           ` Drew Fustini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox