aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2004-11-21 03:05:05 -0800
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-11-21 03:05:05 -0800
commit8c2bfc5b38c5338472cac971230183de07bb11b9 (patch)
tree067a7dcc1c67d49250afb57b3742d92ce8ac5aed /kernel
parent6621ad71381d3eb9cc11e9176bd1be7829c5baff (diff)
downloadhistory-8c2bfc5b38c5338472cac971230183de07bb11b9.tar.gz
[PATCH] del_timer() vs. mod_timer() SMP race
We just spent some days fighting a rare race in one of the distro's who backported some of timer.c from 2.6 to 2.4 (though they missed a bit). The actual race we found didn't happen in 2.6 _but_ code inspection showed that a similar race is still present in 2.6, explanation below: Code removing a timer from a list (run_timers or del_timer) takes that CPU list lock, does list_del, then timer->base = NULL. It is mandatory that this timer->base = NULL is visible to other CPUs only after the list_del() is complete. If not, then mod timer could see it NULL, thus take it's own CPU list lock and not the one for the CPU the timer was beeing removed from the list, and thus the list_add in mod_timer() could race with the list_del() from run_timers() or del_timer(). Our race happened with run_timers(), which _DOES_ contain a proper smp_wmb() in the right spot in 2.6, but didn't in the "backport" we were fighting with. However, del_timer() doesn't have such a barrier, and thus is subject to this race in 2.6 as well. This patch fixes it. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/timer.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/timer.c b/kernel/timer.c
index 5a8fc3a4519cdd..d0eed9b563c48b 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -308,6 +308,8 @@ repeat:
goto repeat;
}
list_del(&timer->entry);
+ /* Need to make sure that anybody who sees a NULL base also sees the list ops */
+ smp_wmb();
timer->base = NULL;
spin_unlock_irqrestore(&base->lock, flags);