[PATCH 2/7] sched/wait: add WQ_FLAG_POLL_EXCLUSIVE for user space waiters
From: Linus Torvalds
Date: Tue Nov 24 2026 - 12:44:11 EST
From: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 23 Nov 2026 16:47:33 -0800
Subject: [PATCH 2/7] sched/wait: add WQ_FLAG_POLL_EXCLUSIVE for user space
waiters
An exclusive waiter whose wake function returns a positive return value
to indicate that it has successfully been woken up stops the wakeup
walk, on the understanding that it will handle the event.
However, user space consumers - like eventpoll or io_uring - want to be
woken up, and want to avoid the thundering herd issue. So they used an
exclusive wait - but without any actual guarantee that they will then
meaningfully handle the event.
So the wakeup could be lost, and real waiters would be left pending.
Add a separate flag for these kind of "exclusive poll" cases, which is
effectively what these user space waiters are. Only the first such
entry that accepts a wakeup is woken, as now, but they don't count
against nr_exclusive and it doesn't stop the walk.
Wake-all (nr_exclusive == 0, including POLLFREE) still calls every entry.
Reported-by: Mani Tofigh <mt4022@xxxxxxxxxxxx>
Cc: Jens Axboe <axboe@xxxxxxxxx>
Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
---
include/linux/wait.h | 1 +
kernel/sched/wait.c | 14 +++++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/include/linux/wait.h b/include/linux/wait.h
index b3e94c71cd3e..09518f8ff10c 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -21,6 +21,7 @@ int default_wake_function(struct wait_queue_entry
*wq_entry, unsigned mode, int
#define WQ_FLAG_CUSTOM 0x04
#define WQ_FLAG_DONE 0x08
#define WQ_FLAG_PRIORITY 0x10
+#define WQ_FLAG_POLL_EXCLUSIVE 0x20
/*
* A single wait-queue entry structure:
diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
index f8d6d8b9d03e..9f126cc5c338 100644
--- a/kernel/sched/wait.c
+++ b/kernel/sched/wait.c
@@ -85,6 +85,11 @@ EXPORT_SYMBOL(remove_wait_queue);
* may be at the head of the list, and can consume the event without any other
* tasks being woken if it's also an exclusive task.
*
+ * An exclusive waiter that returns >0 promises to handle the event. Pollers
+ * (EPOLLEXCLUSIVE) can't promise that, since userspace may never consume it.
+ * They use WQ_FLAG_POLL_EXCLUSIVE instead: only one of them is woken, but they
+ * never count against nr_exclusive or stop the walk.
+ *
* There are circumstances in which we can try to wake a task which has already
* started to run but is not in state TASK_RUNNING. try_to_wake_up() returns
* zero in this (rare) case, and we handle it by continuing to scan the queue.
@@ -93,6 +98,7 @@ 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 poll_woken = false;
lockdep_assert_held(&wq_head->lock);
@@ -105,10 +111,16 @@ static int __wake_up_common(struct
wait_queue_head *wq_head, unsigned int mode,
unsigned flags = curr->flags;
int ret;
+ if ((flags & WQ_FLAG_POLL_EXCLUSIVE) && poll_woken)
+ continue;
ret = curr->func(curr, mode, wake_flags, key);
if (ret < 0)
break;
- if (ret && (flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
+ if (!ret)
+ continue;
+ if (flags & WQ_FLAG_POLL_EXCLUSIVE)
+ poll_woken = nr_exclusive > 0;
+ else if ((flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
break;
}
--
2.56.0.313.g975a75ca90