[PATCH v2 1/2] riscv: signal: mark the FP state clean before restoring it from the frame
Nickolai Zeldovich
nickolai at csail.mit.edu
Sat Oct 31 09:18:25 PDT 2026
If rt_sigreturn() is preempted or sleeps on a page fault while it copies
the FP registers from the signal frame, the interrupted code resumes
with the signal handler's FP registers instead of its own.
restore_fp_state() copies the frame into current->thread.fstate and then
loads it with fstate_restore(). If the handler used the FPU, FS is still
Dirty during the copy, so a context switch makes fstate_save() store the
live registers, the handler's, over the partly copied image.
Mark the FP state clean before the copy, as commit c27fa53b858b ("riscv:
Fix vector state restore in rt_sigreturn()") did for the vector state.
Preemption is disabled around it because the scheduler also writes
regs->status.
Fixes: e2c0cdfba7f6 ("RISC-V: User-facing API")
Signed-off-by: Nickolai Zeldovich <nickolai at csail.mit.edu>
---
arch/riscv/kernel/signal.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 59784dc117e4..11edfc128ac3 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -47,6 +47,13 @@ static long restore_fp_state(struct pt_regs *regs,
long err;
struct __riscv_d_ext_state __user *state = &sc_fpregs->d;
+ /* Discard the handler's FP registers before the copy can sleep */
+ if ((regs->status & SR_FS) != SR_FS_OFF) {
+ preempt_disable();
+ __fstate_clean(regs);
+ preempt_enable();
+ }
+
err = __copy_from_user(¤t->thread.fstate, state, sizeof(*state));
if (unlikely(err))
return err;
--
2.53.0
More information about the linux-riscv
mailing list