From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] eventpoll: check the event mask before taking ep->lock
Date: Fri, 20 Nov 2026 17:28:43 +0800 [thread overview]
Message-ID: <01e8710d-0eb3-4c82-ae52-682458a279e6@linux.dev> (raw)
In-Reply-To: <20261120-dazukommen-ruhen-fahnden-32e0d2201db9@brauner>
On 11/20/26 4:53 PM, Christian Brauner wrote:
> 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:
>
Thanks Christian. You are right.
> 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?
>
I missed that. I have no data showing that skipping it is fine, We should keep
old behaviour and calls ep_set_busy_poll_napi_id() before the early return.
It then runs without ep->lock, so the read and the write of ep->napi_id
in it become READ_ONCE()/WRITE_ONCE(). The other readers already use
READ_ONCE() outside the lock.
prev parent reply other threads:[~2026-11-20 9:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 4:46 [PATCH] eventpoll: check the event mask before taking ep->lock Jiayuan Chen
2026-11-20 8:53 ` Christian Brauner
2026-11-20 9:28 ` Jiayuan Chen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=01e8710d-0eb3-4c82-ae52-682458a279e6@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.