Re: [PATCH] It may not be assumed that wake_up(), finish_wait() and co. imply a memory barrier

Oleg Nesterov
2009-04-24T17:34:34Z

On 04/24, David Howells wrote:
>
> (2) wake_up() interpolates a write memory barrier before clearing the task
> state - _if_ it wakes anything up - then there's no problem in the waker
> either.
>
[...snip...]
>
> +A write memory barrier is implied by wake_up() and co. if and only if they wake
> +something up. The barrier occurs before the task state is cleared, and so sits
> +between the STORE to indicate the event and the STORE to set TASK_RUNNING:

Very minor nit. Perhaps it makes sense to mention that we also need the
barrier before _reading_ the task->state as well. Or not, I am not sure ;)
Just in case...

event_indicated = 1;
wake_up_process(event_daemon);

Suppose that "event_indicated = 1" leaks into try_to_wake_up() after we
read p->state. In this case we have

try_to_wake_up:

if (!(p->state & state))
goto out; // do nothing

// WINDOW

event_indicated = 1; // leaked

In that case the whole

set_current_state(TASK_UNINTERRUPTIBLE);
if (event_indicated)
break;
schedule();

can happen in the WINDOW above.

But again, this is the real nitpick, and probably just the "implementation
details" which should not be documented.

Oleg.