Linus rejects wait-queue reorder meant to unstick eventfd reads
A reader can sleep forever on a readable eventfd or timerfd if an exclusive epoll watcher was queued first; Torvalds wants the wakeup model changed instead.
A kernel hang that can leave a task blocked forever in read() on an eventfd or timerfd, even though the file is already readable, has a proposed fix, and Linus Torvalds does not want it.
Mani Tofigh reported that the stall happens when an epoll watcher using EPOLLEXCLUSIVE is already waiting on the same file. A later reader is queued behind that exclusive entry. A write wakes the epoll task and then stops. If that task is killed, or otherwise leaves without consuming the event, nobody wakes the reader. The descriptor stays readable and the read sleeps on. A periodic timerfd does not rescue the reader either: the timer is restarted only when someone actually reads it. The same helpers are used by the GPIO character device and Chrome OS's embedded-controller character device, so those poll paths can hang the same way.
The proposed change puts ordinary, non-exclusive waiters at the front of the queue, which is what the rest of the wait code already assumes, and what eventfd itself did before it moved onto the shared helpers. Exclusive waiters would still go to the tail. Every non-exclusive waiter would still see every wakeup; only the order would change. With that ordering, the write would wake the reader. Oleg Nesterov reviewed the change and signed off, suggesting a small shared helper could follow later.
Torvalds, writing on the kernel list, said this is the wrong place to fix it. "We need to fix the disaster area that is epoll, rather than work around more epoll bugs elsewhere and make other places more fragile and complex." He argued that exclusive waits exist to avoid a thundering herd, and that cutting the queue walk short was a premature optimization: the walk was never the expensive part. His preferred model is to always append new waiters, always walk the whole queue, and wake at most one exclusive waiter. He also wants the priority-exclusive flag out of the core wait logic. That flag, he wrote, is "literally just kvm eventfd that is being special," and "the 'my mom told me I'm special' kind of special, not the 'it's really important and fundamental' kind." Those users, he said, should walk the queue themselves. He further suggested wakeup functions return a bitmask, so a real exclusive consumer can claim every bit while epoll claims only its own, letting other waiters still run.