Re: [PATCH] eventpoll: check the event mask before taking ep->lock
From: Christian Brauner
Date: Fri Nov 20 2026 - 03:53:19 EST
On Fri, Nov 06, 2026 at 12:46:23PM +0800, Jiayuan Chen wrote:
> Check the mask first and return early if the event is not wanted. The
> comment in ep_modify() counts on ep_poll_callback() taking ep->lock, so
> do smp_mb() and read the mask again before dropping the event. Wanted
> events take the lock as before.
Then this should update the comment too:
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 133a764..8a564d1 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -2029,9 +2029,8 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi,
* 1) Flush epi changes above to other CPUs. This ensures
* we do not miss events from ep_poll_callback if an
* event occurs immediately after we call f_op->poll().
- * We need this because we did not take ep->lock while
- * changing epi above (but ep_poll_callback does take
- * ep->lock).
+ * Pairs with the smp_mb() in ep_poll_callback() before it
+ * drops an event that isn't in epi->event.events.
*
* 2) We also need to ensure we do not miss _past_ events
* when calling f_op->poll(). This barrier also
> + if (!(pollflags & events))
> + return !(events & EPOLLEXCLUSIVE);
> + }
> +
> spin_lock_irqsave(&ep->lock, flags);
>
> ep_set_busy_poll_napi_id(epi);
This also skips ep_set_busy_poll_napi_id() for unwanted events now.
So with busy polling an EPOLLOUT wakeup from sock_wfree() for a socket
that only asked for EPOLLIN won't update ep->napi_id anymore, e.g.,
after ep_busy_loop() reset it on timeout.
Is that intended?
--