On Fri, Jun 02, 2017 at 05:12:52PM +0200, Andrew Jones wrote: > on_cpu() and friends are a bit risky when implemented without IPIs > (no preemption), because we can easily get deadlocks. Luckily, it's > also easy to detect those deadlocks, and assert, to at least make > them easier to debug. > > Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx> > --- > lib/arm/smp.c | 31 ++++++++++++++++++++++++++----- > 1 file changed, 26 insertions(+), 5 deletions(-) > > diff --git a/lib/arm/smp.c b/lib/arm/smp.c > index b4b43237e32e..34204955a549 100644 > --- a/lib/arm/smp.c > +++ b/lib/arm/smp.c > @@ -76,9 +76,25 @@ typedef void (*on_cpu_func)(void *); > struct on_cpu_info { > on_cpu_func func; > void *data; > + cpumask_t waiters; > }; > static struct on_cpu_info on_cpu_info[NR_CPUS]; > > +static void cpu_wait(int cpu) > +{ > + int me = smp_processor_id(); > + > + if (cpu == me) > + return; > + > + assert_msg(!cpumask_test_cpu(cpu, &on_cpu_info[me].waiters), "CPU%d <=> CPU%d deadlock detected", me, cpu); > + > + cpumask_set_cpu(me, &on_cpu_info[cpu].waiters); Doh, this bit set should come before the assert, otherwise there's a small race here. v2 coming up. drew