Skip to content

Commit f481bb3

Browse files
committed
Reapply "arm64: fpsimd: Implement lazy restore for kernel mode FPSIMD"
This reverts commit b8995a1. Ard managed to reproduce the dm-crypt corruption problem and got to the bottom of it, so re-apply the problematic patch in preparation for fixing things properly. Cc: [email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent ffbf4fb commit f481bb3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

arch/arm64/include/asm/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct thread_struct {
171171
struct debug_info debug; /* debugging */
172172

173173
struct user_fpsimd_state kernel_fpsimd_state;
174+
unsigned int kernel_fpsimd_cpu;
174175
#ifdef CONFIG_ARM64_PTR_AUTH
175176
struct ptrauth_keys_user keys_user;
176177
#ifdef CONFIG_ARM64_PTR_AUTH_KERNEL

arch/arm64/kernel/fpsimd.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,12 +1509,30 @@ void do_fpsimd_exc(unsigned long esr, struct pt_regs *regs)
15091509

15101510
static void fpsimd_load_kernel_state(struct task_struct *task)
15111511
{
1512+
struct cpu_fp_state *last = this_cpu_ptr(&fpsimd_last_state);
1513+
1514+
/*
1515+
* Elide the load if this CPU holds the most recent kernel mode
1516+
* FPSIMD context of the current task.
1517+
*/
1518+
if (last->st == &task->thread.kernel_fpsimd_state &&
1519+
task->thread.kernel_fpsimd_cpu == smp_processor_id())
1520+
return;
1521+
15121522
fpsimd_load_state(&task->thread.kernel_fpsimd_state);
15131523
}
15141524

15151525
static void fpsimd_save_kernel_state(struct task_struct *task)
15161526
{
1527+
struct cpu_fp_state cpu_fp_state = {
1528+
.st = &task->thread.kernel_fpsimd_state,
1529+
.to_save = FP_STATE_FPSIMD,
1530+
};
1531+
15171532
fpsimd_save_state(&task->thread.kernel_fpsimd_state);
1533+
fpsimd_bind_state_to_cpu(&cpu_fp_state);
1534+
1535+
task->thread.kernel_fpsimd_cpu = smp_processor_id();
15181536
}
15191537

15201538
void fpsimd_thread_switch(struct task_struct *next)

0 commit comments

Comments
 (0)