Fix RCU race in access of nohz_cpu_mask
PATCH 1/1 Fix RCU race in access of nohz_cpu_mask
Accessing nohz_cpu_mask before incrementing rcp->cur is racy. It can cause tickless idle CPUs to be included in rsp->cpumask, which will extend graceperiods unnecessarily.
Patch below (against 2.6.15-rc5-mm1) fixes this race. It has been tested using extensions to RCU torture module that forces various CPUs to become idle.
Signed-off-by Srivatsa Vaddagiri <[email protected]>
---
linux-2.6.15-rc5-mm1-root/kernel/rcupdate.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/rcupdate.c renamed from kernel/rcupdate.c~rcu-lock +3 -3
@@ -244,15 +244,15 @@ static void rcu_start_batch(struct rcu_cif (rcp->next_pending && rcp->completed == rcp->cur) { -/* Can't change, since spin lock held. */ -cpus_andnot (rsp->cpumask, cpu_online_map, nohz_cpu_mask); - rcp->next_pending =0 ;/* next_pending == 0 must be visible in __rcu_process_callbacks() * before it can see new value of cur. */ smp_wmb (); rcp->cur++; +smp_mb (); +cpus_andnot (rsp->cpumask, cpu_online_map, nohz_cpu_mask); + } }
_
Thanks and Regards,
Srivatsa Vaddagiri,
Linux Technology Center,
IBM Software Labs,
Bangalore, INDIA - 560017
kernel/rcupdate.c static void rcu_start_batch(struct rcu_c · line 254
Quoted 3 lines · Srivatsa Vaddagiri
kernel/rcupdate.c renamed from kernel/rcupdate.c~rcu-lock +2
-0+smp_mb (); +cpus_andnot (rsp->cpumask, cpu_online_map, nohz_cpu_mask);
Please always include a comment when adding a barrier. Because it's often not obvious to the reader what that barrier is actually doing.