Re: [PATCH v2] rust: page: add byte-wise atomic memory copy methods

From: Peter Zijlstra

Date: Tue Feb 17 2026 - 04:34:11 EST


On Tue, Feb 17, 2026 at 10:17:23AM +0100, Peter Zijlstra wrote:
> On Fri, Feb 13, 2026 at 07:45:19AM -0800, Boqun Feng wrote:
>
> > > > Suppose the memory was 'AAAA' and while you're reading it, it is written
> > > > to be 'BBBB'. The resulting copy can be any combination of
> > > > '[AB][AB][AB][AB]'. Not one of them is better than the other.
> > > >
> >
> > The idea is if using Rust's own `core::ptr::copy()` or
> > `core::ptr::copy_nonoverlapping()`, you may get `CCCC`, because they are
> > not semantically guaranteed atomic per byte (i.e. tearing can happen at
> > bit level, because they are not designed for using in case of data
> > races, and there is no defined asm implementation of them, compilers can
> > do anything).
>
> How the heck would they do out-of-thin-air? Any memcpy() implementation
> that can cause that is insane and broken.
>
> Compilers are broken crap if they do this.

The only way I know for a compiler to cause out-of-thin-air is
speculative stores -- those MUST NOT happen. Just like hardware must not
do them.

We must all collectively say NO to a compiler that does these. Life is
too short to try and write concurrent programs with a compiler that does
this.