Re: [PATCH] poll: allow f_op->poll to sleep, take#5

From: Oleg Nesterov
Date: Thu Nov 27 2008 - 15:16:00 EST


On 11/26, Davide Libenzi wrote:
>
> w1) WR dev->events
> w2) WR triggered (1)
> w3) WMB
> w4) WR task->state (RUNNING)
> ...
> That is, an MB before w3 (triggered=1) and a set_mb(triggered,0) at
> s5+s6. The spinlock on the queue taken before entering pollwake() is not
> enough to guarantee the required ordering, since a LOCK is no guarantee
> that operations before it are visible after the LOCK.
> Without the MB at w2, it could happen [w3, s5, s7, w1] that will make us
> miss the event *and* sleep.

I think you are very right. Actually, this is just like

W:
fill_data(&DATA);
wmb();
DATA_is_ready = 1; // triggered
wake_up(wq);

S:
set_current_state(state);
if (DATA_is_ready)
ret = poll(&DATA);
else
schedule();

without wmb() above poll(&DATA) can obviously return the wrong value.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/