Re: [PATCH v3] rust: page: add byte-wise atomic memory copy methods
From: Peter Zijlstra
Date: Wed Feb 18 2026 - 03:54:06 EST
On Tue, Feb 17, 2026 at 09:10:42AM -0800, Boqun Feng wrote:
> We are worried about two racing memcpy()s end up being data race and
> that's undefined behavior. And "atomic" is the key word in C (and Rust)
> to "lift" normal accesses to non-data-race, for example:
I hate people for calling that atomic. It has nothing to do with
atomics.
>
> thread 1 thread 2
> -------- --------
> *a = 1; r1 = *a;
>
> is data race, and
>
> thread 1 thread 2
> -------- --------
> atomic_store(a,1); r1 = atomic_load(a);
>
> is not.
At the end of the day, they're both the bloody same thing, no matter
what you call them :-( All this UB nonsense is just compiler people
being silly.
> In memcpy() case, since we don't need the whole copy to be a single
> atomic operation, so as long as the atomicity is guaranteed at byte
> level (larger is fine because 2byte atomic is still byte atomic), it
> should be sufficient as a concurrent-safe memcpy().
But this is every memcpy(), ever :/
> So either we want to live in a world where
>
> "concurrent normal accesses with at least one being write are data race
> therefore UBs, use the corresponding atomic API in this case and handle
> the data carefully with concurrent accesses in mind".
>
> or we want to live in a world where
>
> "concurrent normal accesses with at least one being write are data race
> therefore UBs, but there are 17 and more API which are technically UBs,
> but they are not considered as UBs in kernel, use them"
>
> To me, having a atomic_bytewise_memcpy() at least clear things out about
> what is actually needed (at the very minimal) to have a concurrent-safe
> memcpy().
I'm still not seeing what it does over any other memcpy(), except you
created one more API, so now we have 18 :-(
> Moving forward, since the concept has been already somehow
> proposed to C/C++, it's likely to be standardized (we can push it from
> the kernel end as well) so we don't need to implement a concurrent-safe
> memcpy() for all architectures on our own.
>
> Hope this makes some sense ;-)
I'm still not seeing it. All memcpy() implementations are already
meeting the criteria you want. There is nothing to implement. And I
really don't see the point in creating: magical_memcpy() that is
*identical* to every other memcpy() we already have.
AFAICT the only problem here is that from:
https://lkml.kernel.org/r/20260218083754.GB2995752@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx