Re: [PATCH] pipe: keep per-write wakeups for EPOLLEXCLUSIVE consumers

From: Oleg Nesterov

Date: Wed Nov 18 2026 - 08:10:35 EST


On 11/17, Linus Torvalds wrote:
>
> That header isn't _horrible_, but some of it was uglier than needed,
> and adding WQ_FLAG_PRIORITY would have been a huge pain because the
> code unnecessarily special-cases WQ_FLAG_EXCLUSIVE.

Yes. See also below.

> NOTE! Entirely untested. Comments?

I tried to check it line-by-line, see nothing wrong. FWIW,

Reviewed-by: Oleg Nesterov <oleg@xxxxxxxxxx>

---------------------------------------------------------------------------
And this reminds me. Please look at __wait_event_interruptible_locked(),
it is buggy.

do_wait_intr() and do_wait_intr_irq() use __add_wait_queue_entry_tail()
regardless of WQ_FLAG_EXCLUSIVE (reported by Mani in another thread).

Plus another problem: exclusive waiter must not fail if it was selected
by wakeup, see the comment in prepare_to_wait_event().

What if we add, say, WQ_FLAG_LOCKED and change prepare_to_wait_event()

--- x/kernel/sched/wait.c
+++ x/kernel/sched/wait.c
@@ -274,7 +274,8 @@ long prepare_to_wait_event(struct wait_q
unsigned long flags;
long ret = 0;

- spin_lock_irqsave(&wq_head->lock, flags);
+ if (!(wq_entry->flags & WQ_FLAG_LOCKED))
+ spin_lock_irqsave(&wq_head->lock, flags);
if (signal_pending_state(state, current)) {
/*
* Exclusive waiter must not fail if it was selected by wakeup,
@@ -299,7 +300,8 @@ long prepare_to_wait_event(struct wait_q
}
set_current_state(state);
}
- spin_unlock_irqrestore(&wq_head->lock, flags);
+ if (!(wq_entry->flags & WQ_FLAG_LOCKED))
+ spin_unlock_irqrestore(&wq_head->lock, flags);

return ret;
}

?

Yes, finish_wait() needs to check WQ_FLAG_LOCKED too... perhaps just

if (WQ_FLAG_LOCKED) list_del_init(...);

at the start.

Then we can trivially redefine all users of __wait_event_interruptible_locked()
on top of ___wait_event/etc.

Say, wait_event_interruptible_exclusive_locked(wq, condition) can use
___wait_event(wq, condition, TASK_INTERRUPTIBLE,
WQ_FLAG_EXCLUSIVE | WQ_FLAG_LOCKED,
spin_unlock(&wq->lock); schedule(); spin_lock(&wq->lock))

Will you agree with this hack? If yes, I'll try to make the patch on top of
your cleanup.

Oleg.