Re: poll() in 2.6 and beyond

From: Richard B. Johnson
Date: Tue Mar 02 2004 - 15:25:33 EST

On Tue, 2 Mar 2004, Roland Dreier wrote:

> Richard> Poll in 2.6.0; when a driver routine calls poll_wait() it
> Richard> returns <<immediately>> to somewhere in the kernel, then
> Richard> waits for my wake_up_interuptible(), before returning
> Richard> control to a user sleeping in poll(). This means that the
> Richard> user gets the wrong poll return value! It doesn't get the
> Richard> value it was given as a result of the interrupt, but the
> Richard> value that existed (0) before the interrupt occurred.
> Nothing has changed in 2.6 that I know of. poll_wait() always
> returned immediately to the driver. The driver's poll method is
> supposed to call poll_wait() on the wait queues that indicate a change
> in poll status, and then return with the current status.
> Read the description of "poll and select" in LDD:
> <>
> - Roland

I'm talking about the driver! When a open fd called poll() or select(),
in user-mode code, the driver's poll() was called, and the driver's poll()
would call poll_wait(). Poll_wait() used to NOT return until the driver
executed wake_up_interruptible() on that wait-queue. When poll_wait()
returned, the driver would return to the caller with the new poll-

Now, when the driver calls poll_wait(), it returns immediately to
the driver. The driver then returns with the wrong poll status because
nothing changed yet. This return, doesn't go back to the user-mode
caller, but remains within the kernel until a wake_up_interruptible()
has been received. Then it returns to the original caller, with the
(wrong) status that existed before the wake_up_interruptible().

When the cycle repeats, the status from the previous event gets
returned, so if the events are all the same (POLLIN), only the
first one is wrong and nobody is the wiser. However, when there
are multiple events, they appear to the user out-of-sequence
and muck up user-mode code.

Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at