- Fix memory ordering problem in wake_futex()
Quoted 10 lines · Jack
On IA64, locks are released using a "st.rel" instruction. This ensures that preceding "stores" are visible before the lock is released but does NOT prevent a "store" that follows the "st.rel" from becoming visible before the "st.rel". The result is that the task that owns the
futex_qcontinues prematurely.The failure I saw is the task that owned the
futex_qresumed prematurely and was context-switch off of the cpu. The task'sswitch_stackoccupied the same space of thefutex_q. The store toq->lock_ptroverwrote the ar.bspstore in theswitch_stack.
Bad race.
Unfortuantely the scenario that you describe is quite frequent:
- autoremove_wake_function()
- ipc/sem.c (search for IN_WAKEUP)
- ipc/msg.c appears to be correct, there are smp_wmb() calls.
--
Manfred
Quoted 11 lines · Manfred Spraul
Quoted 9 lines · Jack
On IA64, locks are released using a "st.rel" instruction. This ensures that preceding "stores" are visible before the lock is released but does NOT prevent a "store" that follows the "st.rel" from becoming visible before the "st.rel". The result is that the task that owns the
futex_qcontinues prematurely. The failure I saw is the task that owned thefutex_qresumed prematurely and was context-switch off of the cpu. The task'sswitch_stackoccupied the same space of thefutex_q. The store toq->lock_ptroverwrote the ar.bspstore in theswitch_stack.
I'm stupid - first I was certains that your description is wrong, I started a long mail, but the I confused myself and accepted your description.
Your description can't be correct: The store to q->lock_ptr can't overwrite ar.bspstore. As long as q->lock_ptr is not NULL, unqueue_me will spin and prevent a race. But the other race seems to be possible_ q->lock_ptr is set to NULL early, and then the spin_unlock_irqrestore() in __wake_up could overwrite ar.bspstore.
Quoted 17 lines · Manfred Spraul
Quoted 7 lines · Jack
On IA64, locks are released using a "st.rel" instruction. This ensures that preceding "stores" are visible before the lock is released but does NOT prevent
a "store" that follows the "st.rel" from becoming visible before the "st.rel".
The result is that the task that owns thefutex_qcontinues prematurely.Quoted 8 lines
The failure I saw is the task that owned the
futex_qresumed prematurely and
was context-switch off of the cpu. The task'sswitch_stackoccupied the same
space of thefutex_q. The store toq->lock_ptroverwrote the ar.bspstore in theswitch_stack.
Quoted 5 lines
Bad race.
Unfortuantely the scenario that you describe is quite frequent:
-autoremove_wake_function()
-ipc/sem.c(search forIN_WAKEUP)
-ipc/msg.cappears to be correct, there aresmp_wmb()calls.
Yuck. I agree - both of these look incorrect.
Also, I should have used smp_wmb(), not wmb(). Thanks for pointing that out.
I wonder how many other spots have the same problem. IIRC, we ran into similar problems in the tty driver a few years ago but I have not seen any problems recently.
Quoted 3 lines
--
Manfred
Signature · 4 lines
Thanks Jack Steiner ([email protected]) 651-683-5302 Principal Engineer SGI - Silicon Graphics, Inc.
Again replying to myself, sorry:
Quoted 8 lines · Jack Steiner
Quoted 5 lines · Manfred Spraul
Bad race.
Unfortuantely the scenario that you describe is quite frequent:
-autoremove_wake_function()
Not a bug, but for very subtile reasons:
There are no writes to the wait_queue structure except the list_del_init(), and for list_del_init() no memory barriers are required because finish_wait() uses list_empty_careful(), i.e. the spin_lock() is only bypassed if both write operations from list_del_init() have completed.
Quoted 3 lines
Quoted 3 lines
-
ipc/sem.c(search forIN_WAKEUP)
fixed in -rc7.
--
Manfred