Re: [PATCH 1/1] x86: In x86-64 barrier_nospec can always be lfence

Andi Kleen <[email protected]> Sun, 9 Feb 2025 20:29:42 -0800
Newsgroups com.openwall.lists.kernel-hardening,org.kernel.vger.linux-arch,org.kernel.vger.linux-kernel
Message-ID <Z6mAtkG9DnDDNFvn@tassilo>
> So on x86, both read and write barriers are complete no-ops, because
> all reads are ordered, and all writes are ordered. So those only need
> compiler barriers to guarantee that the compiler itself doesn't
> re-order them.
> 
> (Side note: earlier reads are also guaranteed to happen before later
> writes, so it's really only writes that can be delayed past reads, but
> we don't haev a barrier for that situation anyway. Also note that all
> of this is not "real" ordering, but only a guarantee that the
> user-visible semantics are AS IF they were actually ordered - if
> things are local in cache, ordering doesn't matter because no external
> CPU can *see* what the ordering was).

However in the local case *FENCE still orders, so it's actually not a
nop. Just normally you can't tell the difference in ordering semantics,
but it's visible in side effects like RDTSC.

-Andi