Re: [PATCH] locking/local_lock: Pretend to use the per-CPU variable if not needed.

From: Linus Torvalds
Date: Wed Mar 23 2022 - 13:17:33 EST


On Wed, Mar 23, 2022 at 4:09 AM Sebastian Andrzej Siewior
<bigeasy@xxxxxxxxxxxxx> wrote:
>
> Replace this_cpu_ptr() with __ll_cpu_ptr() which points to
> this_cpu_ptr() when it is used.

Ok, so that's just really ugly.

Is there really no way to just fixthis_cpu_ptr() to not generate crap
code when the result isn't used?

I get the feeling that the real problem is that on x86, we have this:

#define arch_raw_cpu_ptr(ptr) \
({ \
unsigned long tcp_ptr__; \
asm volatile("add " __percpu_arg(1) ", %0" \
: "=r" (tcp_ptr__) \
: "m" (this_cpu_off), "0" (ptr)); \
(typeof(*(ptr)) __kernel __force *)tcp_ptr__; \
})

and that "volatile" is just *WRONG*.

That volatile is what literally tells the compiler "you can't remove
this if it isn't used".

But there's no point to that.

So how about we

(a) just revert commit 9983a9d577db4

(b) remove that bogus 'volatile'

Doesn't that fix the problem?

Linus