Re: [PATCH v3] eventpoll: Convert epoll_put_uevent() to scoped user access

From: Linus Torvalds

Date: Sat Mar 07 2026 - 18:45:45 EST


On Sat, 7 Mar 2026 at 15:33, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> Oh well. This makes one little piece of the kernel better, even if
> other horrors lurk everywhere...

Side note: if you want to improve code generation just a *tiny* bit
more, you should make that epoll_put_uevent() return a success value
instead ot the updated pointer value.

Because right now the caller does this:

events = epoll_put_uevent(revents, epi->event.data, events);
if (!events) {

and that "if (!events)" test triggers even for the success case,
because the compiler doesn't know whether the "uevent+1" might
overflow (and we really *do* want to make sure the compiler doesn't
remove overflow checks even if it causes these kinds of issues).

If epoll_put_uevent() just returns a success/fail marker (or 0/-EFAULT
or whatever), we wouldn't have that issue.

HOWEVER - the same magical ARM case would need to be dealt with - the
real size of the user space notion of "struct epoll_event" isn't
actually known to generic code, because it ends up depending on
architecture-specific packing issues.

So you'd have to pass in 'events' by reference and epoll_put_uevent()
would still update it.

Probably not worth it - it would mainly get rid of a perfectly
predicted conditional branch, and might possibly help a tiny bit with
register liveness analysis. But it's unlikely to have any really
visible effects - it's not like the clac/stac overhead.

But since I looked at the generated code, I thought I'd mention it.

Linus