[PATCH] Fix memory ordering problem in wake_futex()
authorAndrew Morton <akpm@osdl.org>
Sat, 24 Dec 2005 03:54:46 +0000 (19:54 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sat, 24 Dec 2005 20:13:27 +0000 (12:13 -0800)
Fix a memory ordering problem that occurs on IA64. The "store" to q->lock_ptr
in wake_futex() can become visible before wake_up_all() clears the lock in the
futex_q.

Signed-off-by: Jack Steiner <steiner@sgi.com>
Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
kernel/futex.c

index 5872e3507f356bc61c71fa65c7e58d7866df316c..5e71a6bf6f6b47fb9b93cc1540e0632b5dd5b4e7 100644 (file)
@@ -270,7 +270,13 @@ static void wake_futex(struct futex_q *q)
        /*
         * The waiting task can free the futex_q as soon as this is written,
         * without taking any locks.  This must come last.
+        *
+        * A memory barrier is required here to prevent the following store
+        * to lock_ptr from getting ahead of the wakeup. Clearing the lock
+        * at the end of wake_up_all() does not prevent this store from
+        * moving.
         */
+       wmb();
        q->lock_ptr = NULL;
 }