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

From: Peter Zijlstra

Date: Fri Feb 13 2026 - 09:26:29 EST


On Fri, Feb 13, 2026 at 03:13:01PM +0100, Andreas Hindborg wrote:

> C uses memcpy as seen in `bio_copy_data_iter` [1] and in the null_blk
> driver [2].

Right. And that is *fine*.

> Rust has `core::ptr::copy` and `core::ptr::copy_nonoverlapping`. I was
> informed these are not safe to use if source or destination may incur
> data races, and that we need an operation that is volatile or byte-wise
> atomic [3].

Safe how? It should just copy N bytes. Whatever it thinks those bytes
are.

Nothing can guard against concurrent modification. If there is, you get
to keep the pieces. Pretending anything else is delusional.

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.

No byte wise volatile barrier using nonsense is going to make this any
better.