rcu: fix misplaced mb() in rcu_enter/exit_nohz()
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Thu, 20 Mar 2008 00:00:57 +0000 (17:00 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 20 Mar 2008 01:53:36 +0000 (18:53 -0700)
In the process of writing up the mechanical proof of correctness for the
dynticks/preemptable-RCU interface, I noticed misplaced memory barriers in
rcu_enter_nohz() and rcu_exit_nohz().

This patch puts them in the right place and adds a comment.  The key thing to
keep in mind is that rcu_enter_nohz() is -exiting- the mode that can legally
execute RCU read-side critical sections.

The memory barrier must be between any potential RCU read-side critical
sections and the increment of the per-CPU dynticks_progress_counter, and thus
must come -before- this increment.  And vice versa for rcu_exit_nohz().

The locking in the scheduler is probably saving us for the moment.

Also, switch to smp_mb() - we don't need a barrier for uniprocessor kernels.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Acked-by: Steven Rostedt <srostedt@redhat.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/rcupreempt.h

index 01152ed..d038aa6 100644 (file)
@@ -87,15 +87,15 @@ DECLARE_PER_CPU(long, dynticks_progress_counter);
 
 static inline void rcu_enter_nohz(void)
 {
+       smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */
        __get_cpu_var(dynticks_progress_counter)++;
        WARN_ON(__get_cpu_var(dynticks_progress_counter) & 0x1);
-       mb();
 }
 
 static inline void rcu_exit_nohz(void)
 {
-       mb();
        __get_cpu_var(dynticks_progress_counter)++;
+       smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
        WARN_ON(!(__get_cpu_var(dynticks_progress_counter) & 0x1));
 }