Skip to content

Commit c51f926

Browse files
author
Ard Biesheuvel
committed
arm64: add abstractions for FPSIMD state manipulation
There are two tacit assumptions in the FPSIMD handling code that will no longer hold after the next patch that optimizes away some FPSIMD state restores: . the FPSIMD registers of this CPU contain the userland FPSIMD state of task 'current'; . when switching to a task, its FPSIMD state will always be restored from memory. This patch adds the following functions to abstract away from straight FPSIMD register file saves and restores: - fpsimd_preserve_current_state -> ensure current's FPSIMD state is saved - fpsimd_update_current_state -> replace current's FPSIMD state Where necessary, the signal handling and fork code are updated to use the above wrappers instead of poking into the FPSIMD registers directly. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
1 parent 0567f5f commit c51f926

5 files changed

Lines changed: 30 additions & 13 deletions

File tree

‎arch/arm64/include/asm/fpsimd.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ extern void fpsimd_load_state(struct fpsimd_state *state);
5858
extern void fpsimd_thread_switch(struct task_struct *next);
5959
extern void fpsimd_flush_thread(void);
6060

61+
extern void fpsimd_preserve_current_state(void);
62+
extern void fpsimd_update_current_state(struct fpsimd_state *state);
63+
6164
#endif
6265

6366
#endif

‎arch/arm64/kernel/fpsimd.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ void fpsimd_flush_thread(void)
8787
preempt_enable();
8888
}
8989

90+
/*
91+
* Save the userland FPSIMD state of 'current' to memory
92+
*/
93+
void fpsimd_preserve_current_state(void)
94+
{
95+
preempt_disable();
96+
fpsimd_save_state(&current->thread.fpsimd_state);
97+
preempt_enable();
98+
}
99+
100+
/*
101+
* Load an updated userland FPSIMD state for 'current' from memory
102+
*/
103+
void fpsimd_update_current_state(struct fpsimd_state *state)
104+
{
105+
preempt_disable();
106+
fpsimd_load_state(state);
107+
preempt_enable();
108+
}
109+
90110
#ifdef CONFIG_KERNEL_MODE_NEON
91111

92112
/*

‎arch/arm64/kernel/process.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void release_thread(struct task_struct *dead_task)
205205

206206
int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
207207
{
208-
fpsimd_save_state(&current->thread.fpsimd_state);
208+
fpsimd_preserve_current_state();
209209
*dst = *src;
210210
return 0;
211211
}

‎arch/arm64/kernel/signal.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
5151
int err;
5252

5353
/* dump the hardware registers to the fpsimd_state structure */
54-
fpsimd_save_state(fpsimd);
54+
fpsimd_preserve_current_state();
5555

5656
/* copy the FP and status/control registers */
5757
err = __copy_to_user(ctx->vregs, fpsimd->vregs, sizeof(fpsimd->vregs));
@@ -86,11 +86,8 @@ static int restore_fpsimd_context(struct fpsimd_context __user *ctx)
8686
__get_user_error(fpsimd.fpcr, &ctx->fpcr, err);
8787

8888
/* load the hardware registers from the fpsimd_state structure */
89-
if (!err) {
90-
preempt_disable();
91-
fpsimd_load_state(&fpsimd);
92-
preempt_enable();
93-
}
89+
if (!err)
90+
fpsimd_update_current_state(&fpsimd);
9491

9592
return err ? -EFAULT : 0;
9693
}

‎arch/arm64/kernel/signal32.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static int compat_preserve_vfp_context(struct compat_vfp_sigframe __user *frame)
219219
* Note that this also saves V16-31, which aren't visible
220220
* in AArch32.
221221
*/
222-
fpsimd_save_state(fpsimd);
222+
fpsimd_preserve_current_state();
223223

224224
/* Place structure header on the stack */
225225
__put_user_error(magic, &frame->magic, err);
@@ -282,11 +282,8 @@ static int compat_restore_vfp_context(struct compat_vfp_sigframe __user *frame)
282282
* We don't need to touch the exception register, so
283283
* reload the hardware state.
284284
*/
285-
if (!err) {
286-
preempt_disable();
287-
fpsimd_load_state(&fpsimd);
288-
preempt_enable();
289-
}
285+
if (!err)
286+
fpsimd_update_current_state(&fpsimd);
290287

291288
return err ? -EFAULT : 0;
292289
}

0 commit comments

Comments
 (0)