arm64: fix bug for reloading FPSIMD state after cpu power off
PATCH 1/1 arm64: fix bug for reloading FPSIMD state after cpu power off
Now arm64 defers reloading FPSIMD state, but this optimization also introduces the bug after cpu resume back from low power mode.
The reason is after the cpu has been powered off, s/w need set the cpu's fpsimd_last_state to NULL so that it will force to reload FPSIMD state for the thread, otherwise there has the chance to meet the condition for both the task's fpsimd_state.cpu field contains the id of the current cpu, and the cpu's fpsimd_last_state per-cpu variable points to the task's fpsimd_state, so finally kernel will skip to reload the context during it return back to userland.
Furthermore, this patch also removes the redundant operation for saving the state for idle thread; this operation is needless due kernel's idle thread will not use any VFP/NEON instruction. so that this also can benefit a bit for the latency during cpu's power off.
--- arch/arm64/kernel/fpsimd.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/arm64/kernel/fpsimd.c +1 -5
@@ -268,13 +268,9 @@ static int fpsimd_cpu_pm_notifier(struct notifier_block *self, {switch (cmd) {case CPU_PM_ENTER : -if (current->mm && !test_thread_flag (TIF_FOREIGN_FPSTATE )) -fpsimd_save_state (¤t->thread.fpsimd_state); +this_cpu_write (fpsimd_last_state,NULL );break ;case CPU_PM_EXIT : -if (current->mm) -set_thread_flag (TIF_FOREIGN_FPSTATE ); -break ;case CPU_PM_ENTER_FAILED :default :return NOTIFY_DONE ;
Signature · 1 line
1.9.1
Catalin Marinas
maintainerQuoted 2 lines · Leo Yan
Now arm64 defers reloading FPSIMD state, but this optimization also introduces the bug after cpu resume back from low power mode.
You are right, I can see a bug here.
arch/arm64/kernel/fpsimd.c static int fpsimd_cpu_pm_notifier(struct notifier_block *self, · line 272
Quoted 10 lines
arch/arm64/kernel/fpsimd.c +0
-2@@ -268,13 +268,9 @@ static int fpsimd_cpu_pm_notifier(struct notifier_block *self, {switch (cmd) {case CPU_PM_ENTER : -if (current->mm && !test_thread_flag (TIF_FOREIGN_FPSTATE )) -fpsimd_save_state (¤t->thread.fpsimd_state);
That?s needed if we enter a low power state directly from a task with a valid mm (user). I?m not sure that?s possible, but just in case.
arch/arm64/kernel/fpsimd.c static int fpsimd_cpu_pm_notifier(struct notifier_block *self, · line 271
Quoted 1 line
arch/arm64/kernel/fpsimd.c +1
-0+this_cpu_write (fpsimd_last_state,NULL );
That?s correct. In most cases, we enter low power state from the idle thread which does not have an mm, so the CPU_PM_EXIT case wouldn?t set a TIF_FOREIGN_FPSTATE, so thread switching would not detect the change.
arch/arm64/kernel/fpsimd.c static int fpsimd_cpu_pm_notifier(struct notifier_block *self, · line 276
Quoted 4 lines
arch/arm64/kernel/fpsimd.c +0
-2break ;case CPU_PM_EXIT : -if (current->mm) -set_thread_flag (TIF_FOREIGN_FPSTATE );
See above for why this may still be needed (it case it returns to user directly without fpsimd_thread_switch() to detect fpsimd_last_state).
Catalin
Quoted 6 lines · Catalin Marinas
Quoted 2 lines · Leo Yan
Now arm64 defers reloading FPSIMD state, but this optimization also introduces the bug after cpu resume back from low power mode.
You are right, I can see a bug here.
Quoted 13 lines
arch/arm64/kernel/fpsimd.c static int fpsimd_cpu_pm_notifier(struct notifier_block *self, · line 272
Quoted 10 lines
arch/arm64/kernel/fpsimd.c +0
-2@@ -268,13 +268,9 @@ static int fpsimd_cpu_pm_notifier(struct notifier_block *self, {switch (cmd) {case CPU_PM_ENTER : -if (current->mm && !test_thread_flag (TIF_FOREIGN_FPSTATE )) -fpsimd_save_state (¤t->thread.fpsimd_state);That?s needed if we enter a low power state directly from a task with a valid mm (user). I?m not sure that?s possible, but just in case.
u are right, in some special cases (such like IKS, etc) a normal thread also may call cpu_suspend() function so that it will run here; i will commit another patch to reserve this part.
Quoted 6 lines
arch/arm64/kernel/fpsimd.c static int fpsimd_cpu_pm_notifier(struct notifier_block *self, · line 271
Quoted 1 line
arch/arm64/kernel/fpsimd.c +1
-0+this_cpu_write (fpsimd_last_state,NULL );That?s correct. In most cases, we enter low power state from the idle thread which does not have an mm, so the
CPU_PM_EXITcase wouldn?t set aTIF_FOREIGN_FPSTATE, so thread switching would not detect the change.
Quoted 7 lines
arch/arm64/kernel/fpsimd.c static int fpsimd_cpu_pm_notifier(struct notifier_block *self, · line 276
Quoted 4 lines
arch/arm64/kernel/fpsimd.c +0
-2break ;case CPU_PM_EXIT : -if (current->mm) -set_thread_flag (TIF_FOREIGN_FPSTATE );See above for why this may still be needed (it case it returns to user directly without
fpsimd_thread_switch()to detectfpsimd_last_state).
Will reserve this part as well.
Thanks,
Leo Yan