Re: [PATCH v2] epoll: Use user_write_access_begin() and unsafe_put_user() in epoll_put_uevent().

From: Linus Torvalds

Date: Tue Oct 28 2025 - 15:45:06 EST


On Tue, 28 Oct 2025 at 12:27, Kuniyuki Iwashima <kuniyu@xxxxxxxxxx> wrote:
>
> Oh sorry, this was my copy-and-paste mistake, and it should have
> been can_do_masked_user_access() + masked_user_access_begin().

Ok.

> I used the diff below as the masked version.

That looks fine.

> I noticed user_access_begin() is used in "else if ()", but I
> think it should not matter as long as tested on x86_64 platform
> where can_do_masked_user_access() is true.

Correct. It's designed to be just optimized away statically based on
whether the architecture supports address masking or not.

> So, I think the diff is basically the same with the attached one.

Yes, looks fine.

> I had this with the masked version, taken from perf + 'a'.
>
> ---8<---
> │ movabs $0x7ffffffff000,%rcx
> 0.05 │ cmp %rcx,%r15
> 0.18 │ cmova %rcx,%r15
> 72.69 │ stac
> 0.08 │ lea 0x28(%rsp),%r12
> 0.09 │ mov %r14d,(%r15)
> 0.06 │ mov %rax,0x4(%r15)
> 6.42 │ clac
> ---8<---
>
> One possibility that Eric mentioned 2 weeks ago is that cmov
> might be expensive on the Zen 2 platform.

Hmm. I have a Zen 2 myself, and I haven't seen that being particularly
problematic, but admittedly I did most of my profiling with the
original address masking (back when it just used a plain 'or'
instruction to set all bits in the address).

Without the user address masking, you should be seeing a 'lfence'
(from the user_write_access_begin) instead, which has typically been
*much* more expensive.

I wonder if it's some random instruction scheduling thing.

Linus