Skip to contentSkip to conversation

ARM: vfp: Always save VFP state in vfp_pm_suspend

PATCH Superseded Daniel Drake 4 participants 5 messages Jul 15, 2012 – Jul 16, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 ARM: vfp: Always save VFP state in vfp_pm_suspend

From: Colin Cross <[email protected]>

vfp_pm_suspend should save the VFP state any time there is a vfp_current_hw_state. 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 to allow lazy save and restore
Thread 2 initiates suspend
vfp_pm_suspend is called with the VFP disabled, but the
context has not been saved.

Modify vfp_pm_suspend to save the VFP context whenever vfp_current_hw_state is set.

---
 arch/arm/vfp/vfpmodule.c |    4 ++++
 1 file changed, 4 insertions(+)

Fixes a real-life issue found on OLPC laptops:
http://lists.arm.linux.org.uk/lurker/message/20120715.044946.c30fff2b.en.html

v4->v5: last_VFP_context has been renamed to vfp_current_hw_state.

arch/arm/vfp/vfpmodule.c +4 -0
index 58696192..c86fc52 100644
@@ -457,6 +457,10 @@ static int vfp_pm_suspend(void)
 
 		/* disable, just in case */
 		fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
+	} else if (vfp_current_hw_state[ti->cpu]) {
+		fmxr(FPEXC, fpexc | FPEXC_EN);
+		vfp_save_state(vfp_current_hw_state[ti->cpu], fpexc);
+		fmxr(FPEXC, fpexc);
 	}
 
 	/* clear any information we had about last context state */
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v5 1/1 ARM: vfp: Always save VFP state in vfp_pm_suspend

2012/7/16 Daniel Drake <[email protected]>:

Quoted 20 lines

From: Colin Cross <[email protected]>

vfp_pm_suspend should save the VFP state any time there is a vfp_current_hw_state. 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 to allow lazy save and restore
Thread 2 initiates suspend
vfp_pm_suspend is called with the VFP disabled, but the
context has not been saved.

Modify vfp_pm_suspend to save the VFP context whenever vfp_current_hw_state is set.

Quoted 6 lines
---
 arch/arm/vfp/vfpmodule.c |    4 ++++
 1 file changed, 4 insertions(+)

Fixes a real-life issue found on OLPC laptops:
http://lists.arm.linux.org.uk/lurker/message/20120715.044946.c30fff2b.en.html

we also found this kind of issue too, sometimes suspend/resume will fail with this bug.
so we refined this patch before. but i am really wondering why it has not been committed yet.

Quoted 19 lines

v4->v5: last_VFP_context has been renamed to vfp_current_hw_state.

arch/arm/vfp/vfpmodule.c +4 -1
index 58696192..c86fc52 100644
@@ -457,6 +457,10 @@ static int vfp_pm_suspend(void)
 
                /* disable, just in case */
                fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
+       } else if (vfp_current_hw_state[ti->cpu]) {
+               fmxr(FPEXC, fpexc | FPEXC_EN);
+               vfp_save_state(vfp_current_hw_state[ti->cpu], fpexc);
+               fmxr(FPEXC, fpexc);
        }
 
        /* clear any information we had about last context state */
--
Quoted 2 lines

1.7.10.4

-barry

#2 lore raw

PATCH v5 1/1 ARM: vfp: Always save VFP state in vfp_pm_suspend

Quoted 22 lines · Barry Song

2012/7/16 Daniel Drake <[email protected]>:

Quoted 12 lines

From: Colin Cross <[email protected]>

vfp_pm_suspend should save the VFP state any time there is a vfp_current_hw_state. 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 to allow lazy save and restore
Thread 2 initiates suspend
vfp_pm_suspend is called with the VFP disabled, but the
context has not been saved.

Quoted 8 lines

Modify vfp_pm_suspend to save the VFP context whenever vfp_current_hw_state is set.

Quoted 4 lines

we also found this kind of issue too, sometimes suspend/resume will fail with this bug.
so we refined this patch before. but i am really wondering why it has not been committed yet.

At a guess, it hasn't been applied because nobody has submitted it to the patch system.

Quoted 6 lines
Quoted 6 lines
arch/arm/vfp/vfpmodule.c +0 -0
index 58696192..c86fc52 100644
@@ -457,6 +457,10 @@ static int vfp_pm_suspend(void)
 
Quoted 6 lines

arch/arm/vfp/vfpmodule.c static int vfp_pm_suspend(void) · line 463

Quoted 6 lines
arch/arm/vfp/vfpmodule.c +4 -0
                /* disable, just in case */
                fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
+       } else if (vfp_current_hw_state[ti->cpu]) {
+               fmxr(FPEXC, fpexc | FPEXC_EN);
+               vfp_save_state(vfp_current_hw_state[ti->cpu], fpexc);
+               fmxr(FPEXC, fpexc);

Given that we don't do lazy saving on SMP systems, can we make this conditional on !SMP?

Will

#3 lore raw

PATCH v5 1/1 ARM: vfp: Always save VFP state in vfp_pm_suspend

Quoted 2 lines · Will Deacon

Given that we don't do lazy saving on SMP systems, can we make this conditional on !SMP?

Colin pointed out in private mail that there are some other patches in the android tree that fix this patch on SMP.

Colin, are you planning to roll them into one patch and posted a v6, or send the SMP fixes separately?

Thanks
Daniel

#4 lore raw

PATCH v5 1/1 ARM: vfp: Always save VFP state in vfp_pm_suspend

In reply to Will Deacon
Quoted 37 lines · Will Deacon
Quoted 22 lines · Barry Song

2012/7/16 Daniel Drake <[email protected]>:

Quoted 12 lines

From: Colin Cross <[email protected]>

vfp_pm_suspend should save the VFP state any time there is a vfp_current_hw_state. 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 to allow lazy save and restore
Thread 2 initiates suspend
vfp_pm_suspend is called with the VFP disabled, but the
context has not been saved.

Quoted 8 lines

Modify vfp_pm_suspend to save the VFP context whenever vfp_current_hw_state is set.

Quoted 4 lines

we also found this kind of issue too, sometimes suspend/resume will fail with this bug.
so we refined this patch before. but i am really wondering why it has not been committed yet.

At a guess, it hasn't been applied because nobody has submitted it to the patch system.

Quoted 6 lines
Quoted 6 lines
arch/arm/vfp/vfpmodule.c +0 -0
index 58696192..c86fc52 100644
@@ -457,6 +457,10 @@ static int vfp_pm_suspend(void)
 
Quoted 9 lines
Quoted 6 lines

arch/arm/vfp/vfpmodule.c static int vfp_pm_suspend(void) · line 463

Quoted 6 lines
arch/arm/vfp/vfpmodule.c +4 -0
                /* disable, just in case */
                fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
+       } else if (vfp_current_hw_state[ti->cpu]) {
+               fmxr(FPEXC, fpexc | FPEXC_EN);
+               vfp_save_state(vfp_current_hw_state[ti->cpu], fpexc);
+               fmxr(FPEXC, fpexc);

Given that we don't do lazy saving on SMP systems, can we make this conditional on !SMP?

Ido Yariv pointed out that this is actually unsafe on SMP systems, because vfp_current_hw_state can be a dangling pointer if a task exits on another cpu. I'll squash his fix into this one (#ifdef CONFIG_SMP around the contents of the new if clause) and post v6.