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

From: Peter Zijlstra
Date: Thu Oct 19 2023 - 04:46:02 EST


On Wed, Oct 18, 2023 at 03:40:05PM -0700, Linus Torvalds wrote:

> Side note: the code that caused that problem is this:
>
> __always_inline void __cyc2ns_read(struct cyc2ns_data *data)
> {
> int seq, idx;
>
> do {
> seq = this_cpu_read(cyc2ns.seq.seqcount.sequence);
> ...
> } while (unlikely(seq != this_cpu_read(cyc2ns.seq.seqcount.sequence)));
> }
>
> where the issue is that the this_cpu_read() of that sequence number
> needs to be ordered.

I have very vague memories of other code also relying on this_cpu_read()
implying READ_ONCE().

And that code really only is buggy if you do not have that. Since it is
cpu local, the smp_rmb() would be confusing, as would smp_load_acquire()
be -- there is no cross-cpu data ordering.

The other option is of couse adding explicit barrier(), but that's
entirely superfluous when all the loads are READ_ONCE().


If you want to make this_cpu_read() not imply READ_ONCE(), then we
should go audit all users :/ Can be done ofc.