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

From: Nadav Amit
Date: Wed Oct 18 2023 - 12:03:10 EST



> On Oct 18, 2023, at 6:17 PM, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
>
> I am more thinking of moving the ifdeffery to percpu.h, something like
> the attached part of the patch. This would handle all current and
> future stable percpu variables.

I think that for consistency this_cpu_read_stable() should always be an
rvalue, so instead of:

> #define this_cpu_read_stable(pcp) const_##pcp

You would use a statement expression:

#define this_cpu_read_stable(pcp) ({ const_##pcp; })

This would match the other (existing/fallback) definition of
this_cpu_read_stable.

Having said that, I am not sure what other usages you have in mind.
“current” is a pretty obvious straight forward case with considerable
impact on code generation. There may be additional variables, but it is
likely that there would be more functions/TU in which they would not be
constant and would require more refined techniques to avoid mistakes
such as the use of stale cached values.