arm: vfp: always clear vfp_current_hw_state when forcing reload
Subsystems (2)
PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
The current thread trying to clear the held vfp state may not be the owner of hw state. For example,
Core0 Core1
Thread1 uses VFP.
Thread1 vfpstate.hard.cpu = 1. vfp_current_hw_state[1] points to Thread1
vfpstate.
Going to suspend.
Freeze Thread1.
Thread1 is switched out.
VFP HW registers saved to Thread1 vfpstate.
Core0 disables Core1.
Stopper thread calls vfp_force_reload(). Stopper thread vfpstate.hard.cpu = NR_CPUS.
...
(No PM notifier for non-idle path. So
vfp_pm_suspend() is NOT called on Core1.)
...
Core1 is off and VFP HW registers are lost.
...
Core0 enables Core1.
Core0 thaw Thread1.
Thread1 migrate to Core1
before using VFP.
Thread1 starts using VFP.
Now we have vfp_current_hw_state[1] points
to Thread1 vfpstate. And Thread1 has vfpstate.hard.cpu = 1.
Thread1 does not need to reload saved vfpstate
to VFP HW.
Thread1 continues running using corrupted VFP HW register.
This change fixes above gap by always clearing vfp_current_hw_state when vfp_force_reload() is called.
--- arch/arm/vfp/vfpmodule.c | 1 + 1 file changed, 1 insertion(+)
arch/arm/vfp/vfpmodule.c +1 -0
@@ -84,6 +84,7 @@ static void vfp_force_reload(unsigned int cpu, struct thread_info *thread) }#ifdef CONFIG_SMP thread->vfpstate.hard.cpu =NR_CPUS ; + vfp_current_hw_state[cpu] =NULL ;#endif }
Signature · 1 line
1.7.10.4
PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
Quoted 11 lines · Yuanyuan Zhong
The current thread trying to clear the held vfp state may not be the owner of hw state. For example,
Core0 Core1
Thread1 uses VFP.
Thread1 vfpstate.hard.cpu = 1. vfp_current_hw_state[1] points to Thread1
vfpstate.
Going to suspend.
Freeze Thread1.
Thread1 is switched out.
VFP HW registers saved to Thread1 vfpstate.
Correct so far. At this point:
vfp_current_hw_state[1] = &thread1->vfpstate; thread1->vfpstate.hard.cpu = 1;
Quoted 3 lines
Core0 disables Core1.
Stopper thread callsvfp_force_reload(). Stopper thread vfpstate.hard.cpu =NR_CPUS.
Correct, except there's another part to this. vfp_state_in_hw() returns true here, since thread1->vfpstate.hard.cpu is the dying CPU (CPU 1), and vfp_current_hw_state[1] is &thread1->vfpstate. So we also do this:
clear FPEXC_EN vfp_current_hw_state[1] = NULL;
Quoted 6 lines
...
(No PM notifier for non-idle path. So
vfp_pm_suspend()is NOT called on Core1.)
...
Core1 is off and VFP HW registers are lost.
...
Quoted 8 lines
Core0 enables Core1.
Core0 thaw Thread1.
Thread1 migrate to Core1
before using VFP.
Thread1 starts using VFP.
Now we have vfp_current_hw_state[1] points
to Thread1 vfpstate. And Thread1 has vfpstate.hard.cpu = 1.
No. With my above correction:
vfp_current_hw_state[1] = NULL
and that forces a reload of the saved context.
PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
Quoted 22 lines · Russell King - ARM Linux
Quoted 11 lines · Yuanyuan Zhong
The current thread trying to clear the held vfp state may not be the owner of hw state. For example,
Core0 Core1
Thread1 uses VFP.
Thread1 vfpstate.hard.cpu = 1. vfp_current_hw_state[1] points to Thread1
vfpstate.
Going to suspend.
Freeze Thread1.
Thread1 is switched out.
VFP HW registers saved to Thread1 vfpstate.Correct so far. At this point:
vfp_current_hw_state[1] = &thread1->vfpstate; thread1->vfpstate.hard.cpu = 1;Quoted 3 lines
Core0 disables Core1.
Stopper thread callsvfp_force_reload(). Stopper thread vfpstate.hard.cpu =NR_CPUS.
Quoted 7 lines
Correct, except there's another part to this.
vfp_state_in_hw()returns true here, sincethread1->vfpstate.hard.cpuis the dying CPU (CPU 1), and vfp_current_hw_state[1] is&thread1->vfpstate. So we also do this:clear FPEXC_EN vfp_current_hw_state[1] = NULL;
vfp_state_in_hw() returns false. It's checking current_thread_info() which is the stopper thread migration/1, not thread1.
Quoted 19 lines
Quoted 6 lines
...
(No PM notifier for non-idle path. So
vfp_pm_suspend()is NOT called on Core1.)
...
Core1 is off and VFP HW registers are lost.
...Quoted 8 lines
Core0 enables Core1.
Core0 thaw Thread1.
Thread1 migrate to Core1
before using VFP.
Thread1 starts using VFP.
Now we have vfp_current_hw_state[1] points
to Thread1 vfpstate. And Thread1 has vfpstate.hard.cpu = 1.No. With my above correction:
vfp_current_hw_state[1] = NULLand that forces a reload of the saved context.
PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
Hi Russell, et al
If there is no further comments, I'll submit it to patch system. Thanks.
Quoted 52 lines · Yuanyuan ZHONG
Quoted 22 lines · Russell King - ARM Linux
Quoted 11 lines · Yuanyuan Zhong
The current thread trying to clear the held vfp state may not be the owner of hw state. For example,
Core0 Core1
Thread1 uses VFP.
Thread1 vfpstate.hard.cpu = 1. vfp_current_hw_state[1] points to Thread1
vfpstate.
Going to suspend.
Freeze Thread1.
Thread1 is switched out.
VFP HW registers saved to Thread1 vfpstate.Correct so far. At this point:
vfp_current_hw_state[1] = &thread1->vfpstate; thread1->vfpstate.hard.cpu = 1;Quoted 3 lines
Core0 disables Core1.
Stopper thread callsvfp_force_reload(). Stopper thread vfpstate.hard.cpu =NR_CPUS.Quoted 7 lines
Correct, except there's another part to this.
vfp_state_in_hw()returns true here, sincethread1->vfpstate.hard.cpuis the dying CPU (CPU 1), and vfp_current_hw_state[1] is&thread1->vfpstate. So we also do this:clear FPEXC_EN vfp_current_hw_state[1] = NULL;
vfp_state_in_hw()returns false. It's checkingcurrent_thread_info()which is the stopper thread migration/1, not thread1.Quoted 19 lines
Quoted 6 lines
...
(No PM notifier for non-idle path. So
vfp_pm_suspend()is NOT called on Core1.)
...
Core1 is off and VFP HW registers are lost.
...Quoted 8 lines
Core0 enables Core1.
Core0 thaw Thread1.
Thread1 migrate to Core1
before using VFP.
Thread1 starts using VFP.
Now we have vfp_current_hw_state[1] points
to Thread1 vfpstate. And Thread1 has vfpstate.hard.cpu = 1.No. With my above correction:
vfp_current_hw_state[1] = NULLand that forces a reload of the saved context.
PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
Quoted 4 lines · Yuanyuan ZHONG
Hi Russell, et al
If there is no further comments, I'll submit it to patch system. Thanks.
No, I still don't agree with your patch as being the correct fix. Look at the code that you're creating:
if (vfp_state_in_hw(cpu, thread)) {
fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
vfp_current_hw_state[cpu] = NULL;
}
#ifdef CONFIG_SMP
thread->vfpstate.hard.cpu = NR_CPUS;
vfp_current_hw_state[cpu] = NULL;#endif
So when SMP is enabled we unconditionally blat out the vfp_current_hw_state pointer for this CPU?
What actually needs fixing is the call to this function in the hotplug thread:
vfp_force_reload((long)hcpu, current_thread_info());
I'd suggest this becomes:
unsigned cpu = (long)hcpu; if (vfp_current_hw_state[cpu]) vfp_force_reload(cpu, vfp_current_hw_state[cpu]);
That will force the right hw_state to be forced to reload, rather than passing in the wrong thread state.
PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
Quoted 16 lines · Russell King - ARM Linux
Quoted 4 lines · Yuanyuan ZHONG
Hi Russell, et al
If there is no further comments, I'll submit it to patch system. Thanks.
No, I still don't agree with your patch as being the correct fix. Look at the code that you're creating:
if (vfp_state_in_hw(cpu, thread)) { fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN); vfp_current_hw_state[cpu] = NULL; } #ifdef CONFIG_SMP thread->vfpstate.hard.cpu = NR_CPUS; vfp_current_hw_state[cpu] = NULL;
Quoted 4 lines
#endif
So when SMP is enabled we unconditionally blat out the
vfp_current_hw_statepointer for this CPU?
I think ensuring local vfp_current_hw_state is invalidated is what vfp_force_reload() need to do when SMP is enabled.
Quoted 6 lines
What actually needs fixing is the call to this function in the hotplug thread:
vfp_force_reload((long)hcpu, current_thread_info());
Quoted 8 lines
I'd suggest this becomes:
unsigned cpu = (long)hcpu; if (vfp_current_hw_state[cpu]) vfp_force_reload(cpu, vfp_current_hw_state[cpu]);That will force the right
hw_stateto be forced to reload, rather than passing in the wrong thread state.
No. This is not right. Look at the other places vfp_force_reload() are called, they are all using current_thread_info(). I think only current_thread_info() is safe for vfp_force_reload().
With your suggestion:
(1) vfp_current_hw_state[cpu] is &thread->vfpstate, not thread.
(2) If the thread exited on another CPU and its stack has been reclaimed and reallocated, the "thread->vfpstate.hard.cpu = NR_CPUS;" in vfp_force_reload() will cause memory corruption.
Thanks.
PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
Quoted 20 lines · Yuanyuan ZHONG
Quoted 18 lines · Russell King - ARM Linux
Quoted 4 lines · Yuanyuan ZHONG
Hi Russell, et al
If there is no further comments, I'll submit it to patch system. Thanks.
No, I still don't agree with your patch as being the correct fix. Look at the code that you're creating:
if (vfp_state_in_hw(cpu, thread)) { fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN); vfp_current_hw_state[cpu] = NULL; } #ifdef CONFIG_SMP thread->vfpstate.hard.cpu = NR_CPUS; vfp_current_hw_state[cpu] = NULL;#endif
Quoted 5 lines
Quoted 2 lines
So when SMP is enabled we unconditionally blat out the
vfp_current_hw_statepointer for this CPU?I think ensuring local
vfp_current_hw_stateis invalidated is whatvfp_force_reload()need to do when SMP is enabled.
vfp_force_reload() is about asking for the state S on CPU N to be reloaded. It is not about merely asking for the state on CPU N to be reloaded.
PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
Quoted 24 lines · Russell King - ARM Linux
Quoted 23 lines · Yuanyuan ZHONG
Quoted 20 lines · Russell King - ARM Linux
Quoted 4 lines · Yuanyuan ZHONG
Hi Russell, et al
If there is no further comments, I'll submit it to patch system. Thanks.
No, I still don't agree with your patch as being the correct fix. Look at the code that you're creating:
if (vfp_state_in_hw(cpu, thread)) { fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN); vfp_current_hw_state[cpu] = NULL; } #ifdef CONFIG_SMP thread->vfpstate.hard.cpu = NR_CPUS; vfp_current_hw_state[cpu] = NULL;#endif
So when SMP is enabled we unconditionally blat out the
vfp_current_hw_statepointer for this CPU?
Quoted 6 lines
Quoted 2 lines
I think ensuring local
vfp_current_hw_stateis invalidated is whatvfp_force_reload()need to do when SMP is enabled.
vfp_force_reload()is about asking for the state S on CPU N to be reloaded. It is not about merely asking for the state on CPU N to be reloaded.
Then this function cannot do what we need for cpu hotplug. At that time we don't know if the state S on CPU N is valid, we can only ask for the state on CPU N to be reloaded. How about this:
arch/arm/vfp/vfpmodule.c +0 -0
@@ -644,6 +644,7 @@ static int vfp_hotplug(struct notifier_block *b,
unsigned long action,
{
if (action == CPU_DYING || action == CPU_DYING_FROZEN) {
vfp_force_reload((long)hcpu, current_thread_info());
+ vfp_current_hw_state[(long)hcpu] = NULL;
} else if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
vfp_enable(NULL);
return NOTIFY_OK;PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
Quoted 49 lines · Yuanyuan ZHONG
Quoted 24 lines · Russell King - ARM Linux
Quoted 23 lines · Yuanyuan ZHONG
Quoted 20 lines · Russell King - ARM Linux
Quoted 4 lines · Yuanyuan ZHONG
Hi Russell, et al
If there is no further comments, I'll submit it to patch system. Thanks.
No, I still don't agree with your patch as being the correct fix. Look at the code that you're creating:
if (vfp_state_in_hw(cpu, thread)) { fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN); vfp_current_hw_state[cpu] = NULL; } #ifdef CONFIG_SMP thread->vfpstate.hard.cpu = NR_CPUS; vfp_current_hw_state[cpu] = NULL;#endif
So when SMP is enabled we unconditionally blat out the
vfp_current_hw_statepointer for this CPU?Quoted 6 lines
Quoted 2 lines
I think ensuring local
vfp_current_hw_stateis invalidated is whatvfp_force_reload()need to do when SMP is enabled.
vfp_force_reload()is about asking for the state S on CPU N to be reloaded. It is not about merely asking for the state on CPU N to be reloaded.Then this function cannot do what we need for cpu hotplug. At that time we don't know if the state S on CPU N is valid, we can only ask for the state on CPU N to be reloaded. How about this:
arch/arm/vfp/vfpmodule.c +1
-0@@ -644,6 +644,7 @@ static int vfp_hotplug(struct notifier_block *b, unsigned long action, {if (action ==CPU_DYING || action ==CPU_DYING_FROZEN ) {vfp_force_reload ((long )hcpu,current_thread_info ()); + vfp_current_hw_state[(long )hcpu] =NULL ; }else if (action ==CPU_STARTING || action ==CPU_STARTING_FROZEN )vfp_enable (NULL );
Quoted 1 line
return NOTIFY_OK;
The vfp_force_reload() here does nothing. We can remove it and this this becomes
static int vfp_hotplug(struct notifier_block *b, unsigned long action,
void *hcpu)
{
if (action == CPU_DYING || action == CPU_DYING_FROZEN)
vfp_current_hw_state[(long)hcpu] = NULL;
else if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
vfp_enable(NULL);
return NOTIFY_OK;
}PATCH 1/1 arm: vfp: always clear vfp_current_hw_state when forcing reload
Quoted 56 lines · Yuanyuan ZHONG
Quoted 49 lines · Yuanyuan ZHONG
Quoted 24 lines · Russell King - ARM Linux
Quoted 23 lines · Yuanyuan ZHONG
Quoted 20 lines · Russell King - ARM Linux
Quoted 4 lines · Yuanyuan ZHONG
Hi Russell, et al
If there is no further comments, I'll submit it to patch system. Thanks.
No, I still don't agree with your patch as being the correct fix. Look at the code that you're creating:
if (vfp_state_in_hw(cpu, thread)) { fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN); vfp_current_hw_state[cpu] = NULL; } #ifdef CONFIG_SMP thread->vfpstate.hard.cpu = NR_CPUS; vfp_current_hw_state[cpu] = NULL;#endif
So when SMP is enabled we unconditionally blat out the
vfp_current_hw_statepointer for this CPU?Quoted 6 lines
Quoted 2 lines
I think ensuring local
vfp_current_hw_stateis invalidated is whatvfp_force_reload()need to do when SMP is enabled.
vfp_force_reload()is about asking for the state S on CPU N to be reloaded. It is not about merely asking for the state on CPU N to be reloaded.Then this function cannot do what we need for cpu hotplug. At that time we don't know if the state S on CPU N is valid, we can only ask for the state on CPU N to be reloaded. How about this:
arch/arm/vfp/vfpmodule.c +1
-0@@ -644,6 +644,7 @@ static int vfp_hotplug(struct notifier_block *b, unsigned long action, {if (action ==CPU_DYING || action ==CPU_DYING_FROZEN ) {vfp_force_reload ((long )hcpu,current_thread_info ()); + vfp_current_hw_state[(long )hcpu] =NULL ; }else if (action ==CPU_STARTING || action ==CPU_STARTING_FROZEN )vfp_enable (NULL );Quoted 1 line
return NOTIFY_OK;The
vfp_force_reload()here does nothing. We can remove it and this this becomesstatic int vfp_hotplug(struct
notifier_block*b, unsigned long action,
void *hcpu)
Quoted 8 lines
{
if (action == CPU_DYING || action == CPU_DYING_FROZEN)
vfp_current_hw_state[(long)hcpu] = NULL;
else if (action == CPU_STARTING || action == CPU_STARTING_FROZEN)
vfp_enable(NULL);
return NOTIFY_OK;
}What is the final path going to be?
As per Russell it seems setting the "vfp_current_hw_state[cpu] = NULL;" unconditionaly in "vfp_force_reload()" is wrong.
Signature · 2 lines
Regards, Murali N