call_function_many: fix list delete vs add race
authorMilton Miller <miltonm@bga.com>
Tue, 15 Mar 2011 19:27:16 +0000 (13:27 -0600)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 23 Mar 2011 20:04:07 +0000 (13:04 -0700)
commitcb8385e61fb736ef6748d305d868b28a9f649ef1
tree86e0c7c4fb345b5aa91dd37f19c9f2fc639a8fa3
parent7f59045ccf26f8ead7947a29eb1cc91a1776cbf1
call_function_many: fix list delete vs add race

commit e6cd1e07a185d5f9b0aa75e020df02d3c1c44940 upstream.

Peter pointed out there was nothing preventing the list_del_rcu in
smp_call_function_interrupt from running before the list_add_rcu in
smp_call_function_many.

Fix this by not setting refs until we have gotten the lock for the list.
Take advantage of the wmb in list_add_rcu to save an explicit additional
one.

I tried to force this race with a udelay before the lock & list_add and
by mixing all 64 online cpus with just 3 random cpus in the mask, but
was unsuccessful.  Still, inspection shows a valid race, and the fix is
a extension of the existing protection window in the current code.

Reported-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Milton Miller <miltonm@bga.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
kernel/smp.c