Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr()

From: Uros Bizjak
Date: Thu Oct 19 2023 - 14:37:55 EST


On Thu, Oct 19, 2023 at 8:22 PM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Thu, 19 Oct 2023 at 11:14, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> >
> > But are you really saying this_cpu_read() should not imply READ_ONCE()?
>
> Well, Uros is saying that we may be *forced* to have that implication,
> much as I really hate it (and wonder at the competence of a compiler
> that forces the code-pessimizing 'volatile').

Please note that my patch mitigates exactly this. The propagation of
volatile(!) arguments allows huge instruction and code savings. By
using non-volatile asm, a very limited BB CSE can perhaps remove a few
asms. However, if there is no READ_ONCE requirement, then we can
simply remove "volatile" qualification for this_cpu_read from the
memory-ops patch. It will be like a field trip for the compiler,
because *then* it will be able to optimize everything without
limitations.

Uros.

> And the "it's not volatile" is actually our historical behavior. The
> volatile really is new, and didn't exist before your commit
> b59167ac7baf ("x86/percpu: Fix this_cpu_read()").
>
> So the whole "implies READ_ONCE()" really seems to be due to that
> *one* mistake in our percpu sequence locking code.
>
> Yes, it's been that way for 5 years now, but it was the other way
> around for the preceding decade....
>
> Linus