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

From: Linus Torvalds
Date: Thu Oct 12 2023 - 15:41:19 EST


On Thu, 12 Oct 2023 at 12:32, Nadav Amit <namit@xxxxxxxxxx> wrote:
>
> If you refer to the difference between DECLARE_PER_CPU_ALIGNED() and
> DECLARE_PER_CPU() - that’s just a silly mistake that I made porting my
> old patch (I also put “const” in the wrong place of the declaration, sorry).

Yes, the only difference is the ALIGNED and the 'const', but I think
also the alias attribute.

However, I'd be happier if we had just one place that declares them, not two.

Even if the two were identical, it seems wrong to have two
declarations for the same thing.

> The “trick” that the patch does is to expose a new const_pcpu_hot symbol that has
> a “const” qualifier. For compilation units from which the symbol is effectively
> constant, we use const_pcpu_hot. The compiler then knows that the value would not
> change.

Oh, I don't disagree with that part.

I just don't see why the 'asm' version would have any difference. For
that too, the compiler should see that the result of the asm doesn't
change.

So my confusion / worry is not about the const alias. I like that part.

My worry is literally "in other situations we _have_ to use asm(), and
it's not clear why gcc wouldn't do as well for it".

Linus