powerpc: icswx: fix race condition where threads do not get their ACOP register updated in time.
PATCH 1/1 powerpc: icswx: fix race condition where threads do not get their ACOP register updated in time.
There is a race where a thread causes a coprocessor type to be valid in its own ACOP _and_ in the current context, but it does not propagate to the ACOP register of other threads in time for them to use it. The original code tries to solve this by sending an IPI to all threads on the system, which is heavy handed, but unfortunately still provides a window where the icswx is issued by other threads and the ACOP is not up to date.
This patch detects that the ACOP DSI fault was a "false positive" and syncs the ACOP and causes the icswx to be replayed.
--- arch/powerpc/mm/icswx.c | 29 +++++++++++++++++++++++++++-- arch/powerpc/mm/icswx.h | 6 ++++++ 2 files changed, 33 insertions(+), 2 deletions(-)
arch/powerpc/mm/icswx.c +27 -2
@@ -163,7 +163,7 @@ EXPORT_SYMBOL_GPL(drop_cop);static int acop_use_cop (int ct) { -/* todo */ +/* There is no alternate policy, yet */ return -1 ; }
@@ -227,11 +227,36 @@ int acop_handle_fault(struct pt_regs *regs, unsigned long address, ct = (ccw >>16 ) &0x3f ; } +/* +* We could be here because another thread has enabled acop +* but the ACOP register has yet to be updated. +* +* This should have been taken care of by the IPI to sync all +* the threads (see smp_call_function(sync_cop, mm, 1)), but +* that could take forever if there are a significant amount +* of threads. +* +* Given the number of threads on some of these systems, +* perhaps this is the best way to sync ACOP rather than whack +* every thread with an IPI. +*/ +if (acop_copro_type_bit (ct) && current->active_mm->context.acop) { +pr_debug ("%s[%d]: Spurrious ACOP Fault, CT: %d, bit: 0x%llx " +"SPR: 0x%lx, mm->acop: 0x%lx\n" , + current->comm, current->pid, + ct,acop_copro_type_bit (ct),mfspr (SPRN_ACOP ), + current->active_mm->context.acop); + +sync_cop (current->active_mm); +return 0 ; + } + +/* check for alternate policy */ if (!acop_use_cop (ct))return 0 ;/* at this point the CT is unknown to the system */ -pr_warn ("%s[%d]: Coprocessor %d is unavailable" , +pr_warn ("%s[%d]: Coprocessor %d is unavailable\n" , current->comm, current->pid, ct);/* get inst if we don't already have it */
arch/powerpc/mm/icswx.h +6 -0
@@ -59,4 +59,10 @@ extern void free_cop_pid(int free_pid);extern int acop_handle_fault (struct pt_regs *regs,unsigned long address,unsigned long error_code); + +static inline u64 acop_copro_type_bit (unsigned int type) +{ +return 1ULL << (63 - type); +} +#endif /* !_ARCH_POWERPC_MM_ICSWX_H_ */
Signature · 1 line
1.7.0.4
Quoted 5 lines
arch/powerpc/mm/icswx.c +3
-0+/* +* We could be here because another thread has enabled acop +* but the ACOP register has yet to be updated.
arch/powerpc/mm/icswx.c int acop_handle_fault(struct pt_regs *regs, unsigned long address, · line 242
Quoted 10 lines
arch/powerpc/mm/icswx.c +10
-0+* +* This should have been taken care of by the IPI to sync all +* the threads (see smp_call_function(sync_cop, mm, 1)), but +* that could take forever if there are a significant amount +* of threads. +* +* Given the number of threads on some of these systems, +* perhaps this is the best way to sync ACOP rather than whack +* every thread with an IPI. +*/
This is actually pretty standard stuff... If it was me I would make it all lazy and avoid the IPI completely but it doesn't necessarily hurt that much. In any case the "recovery" is indeed needed and you should probably also remove the pr_debug, it's really just spam.
arch/powerpc/mm/icswx.c int acop_handle_fault(struct pt_regs *regs, unsigned long address, · line 243
Quoted 1 line
arch/powerpc/mm/icswx.c +1
-0+if (acop_copro_type_bit (ct) && current->active_mm->context.acop) {
Shouldn't that be "&" ? In fact, gcc would even warn so either make it acop_check_copro(acop, ct) or do a (x & y) != 0
Cheers,
Ben.
Quoted 35 lines
arch/powerpc/mm/icswx.c +12
-1+pr_debug ("%s[%d]: Spurrious ACOP Fault, CT: %d, bit: 0x%llx " +"SPR: 0x%lx, mm->acop: 0x%lx\n" , + current->comm, current->pid, + ct,acop_copro_type_bit (ct),mfspr (SPRN_ACOP ), + current->active_mm->context.acop); + +sync_cop (current->active_mm); +return 0 ; + } + +/* check for alternate policy */ if (!acop_use_cop (ct))return 0 ;/* at this point the CT is unknown to the system */ -pr_warn ("%s[%d]: Coprocessor %d is unavailable" , +pr_warn ("%s[%d]: Coprocessor %d is unavailable\n" , current->comm, current->pid, ct);/* get inst if we don't already have it */ arch/powerpc/mm/icswx.h +6
-0@@ -59,4 +59,10 @@ extern void free_cop_pid(int free_pid);extern int acop_handle_fault (struct pt_regs *regs,unsigned long address,unsigned long error_code); + +static inline u64 acop_copro_type_bit (unsigned int type) +{ +return 1ULL << (63 - type); +} +#endif /* !_ARCH_POWERPC_MM_ICSWX_H_ */
Quoted 11 lines · Benjamin Herrenschmidt
=20
Quoted 10 lines
=20
arch/powerpc/mm/icswx.c +9
-0+/* +* We could be here because another thread has enabled acop +* but the ACOP register has yet to be updated. +* +* This should have been taken care of by the IPI to sync all +* the threads (see smp_call_function(sync_cop, mm, 1)), but +* that could take forever if there are a significant amount +* of threads. +*
Quoted 8 lines
arch/powerpc/mm/icswx.c int acop_handle_fault(struct pt_regs *regs, unsigned long address, · line 242
Quoted 4 lines
arch/powerpc/mm/icswx.c +4
-0+* Given the number of threads on some of these systems, +* perhaps this is the best way to sync ACOP rather than whack +* every thread with an IPI. +*/ =20
This is actually pretty standard stuff... If it was me I would make it all lazy and avoid the IPI completely but it doesn't necessarily hurt that much.
I'm happy to get rid of the IPI completely if Anton (or someone else) = agrees to test on his end.
If not, do you want me to reduce the comment?
Quoted 2 lines
In any case the "recovery" is indeed needed and you should probably also remove the
pr_debug, it's really just spam.
ack
Quoted 2 lines
=20
Review
Quoted 1 line
(quoted diff) +1
-0+ if (acop_copro_type_bit(ct) && current->active_mm->context.acop) =
{
Quoted 3 lines
=20
Shouldn't that be "&" ? In fact, gcc would even warn so either make itacop_check_copro(acop, ct)or do a (x & y) !=3D 0
Ach!! nice catch!
-jx
Quoted 5 lines
=20
Cheers,
Ben.
=20Review
Quoted 1 line
(quoted diff) +1
-0+ pr_debug("%s[%d]: Spurrious ACOP Fault, CT: %d, bit: =
0x%llx "
Quoted 18 lines
Quoted 18 lines
arch/powerpc/mm/icswx.c +10
-0+"SPR: 0x%lx, mm->acop: 0x%lx\n" , + current->comm, current->pid, + ct,acop_copro_type_bit (ct),mfspr (SPRN_ACOP ), + current->active_mm->context.acop); + +sync_cop (current->active_mm); +return 0 ; + } + +/* check for alternate policy */ if (!acop_use_cop(ct)) return 0; =20 /* at this point the CT is unknown to the system */arch/powerpc/mm/icswx.c +1
-1- pr_warn("%s[%d]: Coprocessor %d is unavailable", + pr_warn("%s[%d]: Coprocessor %d is unavailable\n",current->comm, current->pid, ct);=20
Quoted 8 lines
Quoted 8 lines
/* get inst if we don't already have it */arch/powerpc/mm/icswx.h +0
-0@@ -59,4 +59,10 @@ extern void free_cop_pid(int free_pid);=20
extern int acop_handle_fault(structpt_regs*regs, unsigned long =
address,
Quoted 10 lines
Quoted 8 lines
unsigned long error_code);arch/powerpc/mm/icswx.h +6
-0+ +static inline u64 acop_copro_type_bit (unsigned int type) +{ +return 1ULL << (63 - type); +} +#endif /* !_ARCH_POWERPC_MM_ICSWX_H_ */
=20
=20