Re: [PATCH v2 1/2] sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*()

From: Oleg Nesterov

Date: Tue Nov 24 2026 - 08:36:18 EST


On 11/23, Linus Torvalds wrote:
>
> Finally, I think we should make the return value from the wakeup
> function be a bitmask, and count "exclusive" as only "we haven't seen
> this bit returned yet". And then *real* exclusive users that actually
> guarantee that they react to the wakeup return all bits set, but the
> sh*t-for-brains garbage that is "epoll" only returns its own bit set -
> so we only wake up *one* epoll user, but we wake up other users anyway,
> because epoll clearl yis lying about its "exclusivity".

Ah, I don't think this can work... Suppose that ep_poll_callback()
returns its own EP_XXX bit set. Should __wake_up_common() wake up
the next waiter? It can't know until it calls ->wake_up_fn() which
can wakeup another epoll waiter.

Well. It is not that I like this idea (and I bet neither you ;) but
we can add WQ_FLAG_EPOLLEXCLUSIVE set by ep_ptable_queue_proc() and
__io_queue_proc(), and change __wake_up_common() to check it

static int __wake_up_common(struct wait_queue_head *wq_head, unsigned int mode,
int nr_exclusive, int wake_flags, void *key)
{
wait_queue_entry_t *curr, *next;
bool seen_epoll = false;

lockdep_assert_held(&wq_head->lock);

list_for_each_entry_safe(curr, next, &wq_head->head, entry) {
unsigned flags = curr->flags;
int ret;

if ((flags & WQ_FLAG_EPOLLEXCLUSIVE) && seen_epoll)
continue;

ret = curr->func(curr, mode, wake_flags, key);
if (ret < 0)
break;
if (ret && (flags & WQ_FLAG_EXCLUSIVE)) {
if (flags & WQ_FLAG_EPOLLEXCLUSIVE)
seen_epoll = true;
else if (!--nr_exclusive)
break;
}
}

return nr_exclusive;
}

for the start.

Oleg.