Skip to content

Commit 3aa4d74

Browse files
mrutland-armctmarinas
authored andcommitted
arm64/fpsimd: signal32: Always save+flush state early
There are several issues with the way the native signal handling code manipulates FPSIMD/SVE/SME state. To fix those issues, subsequent patches will rework the native signal handling code to always save+flush the current task's FPSIMD/SVE/SME state before manipulating that state. In preparation for those changes, rework the compat signal handling code to save+flush the current task's FPSIMD state before manipulating it. Subsequent patches will remove fpsimd_signal_preserve_current_state() and fpsimd_update_current_state(). Compat tasks can only have FPSIMD state, and cannot have any SVE or SME state. Thus, the SVE state manipulation present in fpsimd_signal_preserve_current_state() and fpsimd_update_current_state() is not necessary, and it is safe to directly manipulate current->thread.uw.fpsimd_state once it has been saved+flushed. Use fpsimd_save_and_flush_current_state() to save+flush the state for both signal delivery and signal return, before the state is manipulated in any way. While it would be safe for compat_restore_vfp_context() to use fpsimd_flush_task_state(current), there are several extant issues in the native signal code resulting from incorrect use of fpsimd_flush_task_state(), and for consistency it is preferable to use fpsimd_save_and_flush_current_state(). Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Mark Brown <broonie@kernel.org> Cc: Will Deacon <will@kernel.org> Reviewed-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20250409164010.3480271-12-mark.rutland@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent d3a1815 commit 3aa4d74

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/arm64/kernel/signal32.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static int compat_preserve_vfp_context(struct compat_vfp_sigframe __user *frame)
103103
* Note that this also saves V16-31, which aren't visible
104104
* in AArch32.
105105
*/
106-
fpsimd_signal_preserve_current_state();
106+
fpsimd_save_and_flush_current_state();
107107

108108
/* Place structure header on the stack */
109109
__put_user_error(magic, &frame->magic, err);
@@ -169,14 +169,17 @@ static int compat_restore_vfp_context(struct compat_vfp_sigframe __user *frame)
169169
fpsimd.fpsr = fpscr & VFP_FPSCR_STAT_MASK;
170170
fpsimd.fpcr = fpscr & VFP_FPSCR_CTRL_MASK;
171171

172+
if (err)
173+
return -EFAULT;
174+
172175
/*
173176
* We don't need to touch the exception register, so
174177
* reload the hardware state.
175178
*/
176-
if (!err)
177-
fpsimd_update_current_state(&fpsimd);
179+
fpsimd_save_and_flush_current_state();
180+
current->thread.uw.fpsimd_state = fpsimd;
178181

179-
return err ? -EFAULT : 0;
182+
return 0;
180183
}
181184

182185
static int compat_restore_sigframe(struct pt_regs *regs,

0 commit comments

Comments
 (0)