Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr()
From: Peter Zijlstra
Date: Thu Oct 19 2023 - 04:55:04 EST
On Wed, Oct 18, 2023 at 03:40:05PM -0700, Linus Torvalds wrote:
> Look at the *REAL* sequence counter code in <linux/seqlock.h>. Notice
> how in raw_read_seqcount_begin() we have
>
> unsigned _seq = __read_seqcount_begin(s);
> smp_rmb();
>
> because it actually does the proper barriers. Notice how the garbage
> code in __cyc2ns_read() doesn't have them - and how it was buggy as a
> result.
>
> (Also notice how this all predates our "we should use load_acquire()
> instead of smb_rmb()", but whatever).
seqlock actually wants rmb even today, the pattern is:
do {
seq = load-seq
rmb
load-data
rmb
} while (seq != re-load-seq)
we specifically only care about loads, and the data loads must be
between the sequence number loads.
As such, load-acquire is not a natural match.