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

From: Linus Torvalds
Date: Thu Oct 19 2023 - 13:00:06 EST


On Thu, 19 Oct 2023 at 00:04, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
>
> Let me explain how the compiler handles volatile.

We're talking past each other.

You are talking about the volatile *memory* ops, and the the
difference that "raw" vs "this" would cause with and without the
"volatile".

While *I* am now convinced that the memory ops aren't even an option,
because they will generate worse code, because pretty much all users
use the "this" version (which would have to use volatile),

Because if we just stick with inline asms, the need for "volatile"
simply goes away.

The existing volatile on those percpu inline asms is *wrong*. It's a
historical mistake.

And with just a plain non-volatile inline asm, the inline asm wins.

It doesn't have the (bad) read-once behavior of a volatile memory op.

And it also doesn't have the (horrible correctness issue)
rematerialization behavior of a non-volatile memory op.

A compiler that were to rematerializes an inline asm (instead of
spilling) would be a bad joke. That's not an optimization, that's just
a crazy bad compiler with a code generation bug.

Linus