ARM: vfp: Always save VFP state in vfp_pm_suspend on UP
Subsystems (2)
PATCH v6 1/1 ARM: vfp: Always save VFP state in vfp_pm_suspend on UP
vfp_pm_suspend should save the VFP state in suspend after any lazy context switch. If it only saves when the VFP is enabled, the state can get lost when, on a UP system:
Thread 1 uses the VFP
Context switch occurs to thread 2, VFP is disabled but the
VFP context is not saved
Thread 2 initiates suspend
vfp_pm_suspend is called with the VFP disabled, and the unsaved
VFP context of Thread 1 in the registers
Modify vfp_pm_suspend to save the VFP context whenever vfp_current_hw_state is not NULL.
Includes a fix from Ido Yariv <[email protected]>, who pointed out that on SMP systems, the state pointer can be pointing to a freed task struct if a task exited on another cpu, fixed by using #ifdef CONFIG_SMP in the new if clause.
--- arch/arm/vfp/vfpmodule.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
arch/arm/vfp/vfpmodule.c +6 -0
@@ -457,6 +457,12 @@ static int vfp_pm_suspend(void)/* disable, just in case */ fmxr (FPEXC ,fmrx (FPEXC ) & ~FPEXC_EN ); + }else if (vfp_current_hw_state[ti->cpu]) { +#ifndef CONFIG_SMP +fmxr (FPEXC , fpexc |FPEXC_EN ); +vfp_save_state (vfp_current_hw_state[ti->cpu], fpexc); +fmxr (FPEXC , fpexc); +#endif }/* clear any information we had about last context state */
Signature · 1 line
1.7.7.3
Quoted 34 lines · Colin Cross
vfp_pm_suspendshould save the VFP state in suspend after any lazy context switch. If it only saves when the VFP is enabled, the state can get lost when, on a UP system:
Thread 1 uses the VFP
Context switch occurs to thread 2, VFP is disabled but the
VFP context is not saved
Thread 2 initiates suspend
vfp_pm_suspendis called with the VFP disabled, and the unsaved
VFP context of Thread 1 in the registersModify
vfp_pm_suspendto save the VFP context whenevervfp_current_hw_stateis not NULL.Includes a fix from Ido Yariv <[email protected]>, who pointed out that on SMP systems, the state pointer can be pointing to a freed task struct if a task exited on another cpu, fixed by using #ifdef
CONFIG_SMPin the new if clause.Cc Russell King <[email protected]>Cc Barry Song <[email protected]>Cc Catalin Marinas <[email protected]>Cc Ido Yariv <[email protected]>Cc Daniel Drake <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Colin Cross <[email protected]>--- arch/arm/vfp/vfpmodule.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)arch/arm/vfp/vfpmodule.c +0
-0
arch/arm/vfp/vfpmodule.c static int vfp_pm_suspend(void) · line 466
Quoted 10 lines
arch/arm/vfp/vfpmodule.c +6
-0@@ -457,6 +457,12 @@ static int vfp_pm_suspend(void)/* disable, just in case */ fmxr (FPEXC ,fmrx (FPEXC ) & ~FPEXC_EN ); + }else if (vfp_current_hw_state[ti->cpu]) { +#ifndef CONFIG_SMP +fmxr (FPEXC , fpexc |FPEXC_EN ); +vfp_save_state (vfp_current_hw_state[ti->cpu], fpexc); +fmxr (FPEXC , fpexc); +#endif }
Couldn't vfp_sync_hwstate() be used here instead?
Nicolas
Quoted 37 lines · Nicolas Pitre
Quoted 35 lines · Colin Cross
vfp_pm_suspendshould save the VFP state in suspend after any lazy context switch. If it only saves when the VFP is enabled, the state can get lost when, on a UP system:
Thread 1 uses the VFP
Context switch occurs to thread 2, VFP is disabled but the
VFP context is not saved
Thread 2 initiates suspend
vfp_pm_suspendis called with the VFP disabled, and the unsaved
VFP context of Thread 1 in the registersModify
vfp_pm_suspendto save the VFP context whenevervfp_current_hw_stateis not NULL.Includes a fix from Ido Yariv <[email protected]>, who pointed out that on SMP systems, the state pointer can be pointing to a freed task struct if a task exited on another cpu, fixed by using #ifdef
CONFIG_SMPin the new if clause.Cc Russell King <[email protected]>Cc Barry Song <[email protected]>Cc Catalin Marinas <[email protected]>Cc Ido Yariv <[email protected]>Cc Daniel Drake <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Colin Cross <[email protected]>--- arch/arm/vfp/vfpmodule.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)arch/arm/vfp/vfpmodule.c +0
-0@@ -457,6 +457,12 @@ static int vfp_pm_suspend(void)
Quoted 11 lines
arch/arm/vfp/vfpmodule.c static int vfp_pm_suspend(void) · line 466
Quoted 9 lines
arch/arm/vfp/vfpmodule.c +6
-0/* disable, just in case */ fmxr (FPEXC ,fmrx (FPEXC ) & ~FPEXC_EN ); + }else if (vfp_current_hw_state[ti->cpu]) { +#ifndef CONFIG_SMP +fmxr (FPEXC , fpexc |FPEXC_EN ); +vfp_save_state (vfp_current_hw_state[ti->cpu], fpexc); +fmxr (FPEXC , fpexc); +#endif }Couldn't
vfp_sync_hwstate()be used here instead?
Not easily, we don't have the thread struct of the thread that is in the vfp hardware. We would have to read vfp_current_hw_state for the current cpu and use container_of to get from struct vfpstate to struct thread_info, and then pass that back in to vfp_sync_hwstate.