diff options
| author | Guobin Zhang <guobin.zhang@intel.com> | 2026-10-20 19:24:25 +0800 |
|---|---|---|
| committer | Paul Walmsley <pjw@kernel.org> | 2026-11-09 19:05:58 -0700 |
| commit | 018fe0700c569b50465b27d68deee7e9157e8e5f (patch) | |
| tree | f3e5b1791d5dd779abbc660e1bd9e08828722422 /tools/perf/scripts/python | |
| parent | 551bdd6fcaba4ffc98fd95c4d969d4470eae580f (diff) | |
riscv: signal: protect regs->status RMW from concurrent preemption
__fstate_clean() performs a non-atomic read-modify-write (RMW) on
task_pt_regs(current)->status to clear the FS bits. This RMW is
unprotected - it runs with preemption enabled and IRQs on during
signal delivery (setup_rt_frame -> fstate_save) and sigreturn
(restore_fp_state -> fstate_restore).
If a reschedule IPI or timer interrupt triggers preemption between
the load and store of this RMW, __switch_to_vector() calls
riscv_v_vstate_set_restore() which modifies the VS bits of the
same regs->status. When the preempted task resumes, it stores back
the stale value captured before preemption, overwriting the VS
update and restoring VS=DIRTY while TIF_RISCV_V_DEFER_RESTORE
remains set - a combination that should never occur and leads to
vector state corruption.
The race window:
__fstate_clean (signal path) set_restore (schedule path)
----------------------------- -----------------------------
ld a0, regs->status // VS=DIRTY, FS=DIRTY
<- preempted (reschedule IPI)
regs->status VS = INITIAL
set TIF_RISCV_V_DEFER_RESTORE
<- resumed
andi a0, ~FS
ori a0, FS_CLEAN // stale a0 still has VS=DIRTY
sd a0, regs->status // overwrites VS=INITIAL with VS=DIRTY
-> result: VS=DIRTY + DEFER -> ANOMALY
Fix by adding preempt_disable/enable in fstate_save() and
fstate_restore(), which covers the RMW in __fstate_clean(), and
around the RMW in fstate_off(). Add fstate_{save,restore}_preempt_off()
for code that already runs with preemption disabled (the scheduler and
kernel_mode_fpu).
riscv_v_vstate_set_restore() has the identical hazard: it is called
from __restore_v_state() (sigreturn path) with preemption enabled, and
it can race the same way against the scheduler's own call to
riscv_v_vstate_set_restore() for the same task in __switch_to_vector().
Wrap that call site with preempt_disable/enable as well.
Add WARN_ON_ONCE(preemptible()) to riscv_v_vstate_restore()
to catch any future unprotected callers at development time.
Suggested-by: Andy Chiu <tchiu@tenstorrent.com>
Signed-off-by: Guobin Zhang <guobin.zhang@intel.com>
Reviewed-by: Andy Chiu <tchiu@tenstorrent.com>
Link: https://patch.msgid.link/20261020-vector_fpu_regs_status_rmw_fix-v2-1-474a59155e96@intel.com
Cc: stable@vger.kernel.org
Signed-off-by: Paul Walmsley <pjw@kernel.org>
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions
