Skip to contentSkip to conversation

- Fix memory ordering problem in wake_futex()

PATCH Manfred Spraul 2 participants 4 messages Dec 23, 2005 – Dec 25, 2005

lore
Share & tools
lore
#0 lore raw
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_q continues prematurely.

The failure I saw is the task that owned the futex_q resumed prematurely and was context-switch off of the cpu. The task's switch_stack occupied the same space of the futex_q. The store to q->lock_ptr overwrote the ar.bspstore in the switch_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

#1 lore raw
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_q continues prematurely. The failure I saw is the task that owned the futex_q resumed prematurely and was context-switch off of the cpu. The task's switch_stack occupied the same space of the futex_q. The store to q->lock_ptr overwrote the ar.bspstore in the switch_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.

#2 lore raw
In reply to Manfred Spraul
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 the futex_q continues prematurely.

Quoted 8 lines

The failure I saw is the task that owned the futex_q resumed prematurely and
was context-switch off of the cpu. The task's switch_stack occupied the same
space of the futex_q. The store to q->lock_ptr overwrote the ar.bspstore in the
switch_stack.

Quoted 5 lines

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.

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.
#3 lore raw

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 for IN_WAKEUP)

fixed in -rc7.

--
Manfred