Re: [PATCH v3] rust: page: add byte-wise atomic memory copy methods
From: Andreas Hindborg
Date: Fri Feb 13 2026 - 07:45:46 EST
"Peter Zijlstra" <peterz@xxxxxxxxxxxxx> writes:
> On Fri, Feb 13, 2026 at 07:42:53AM +0100, Andreas Hindborg wrote:
>> When copying data from buffers that are mapped to user space, it is
>> impossible to guarantee absence of concurrent memory operations on those
>> buffers. Copying data to/from `Page` from/to these buffers would be
>> undefined behavior if no special considerations are made.
>>
>> Add methods on `Page` to read and write the contents using byte-wise atomic
>> operations.
>>
>> Also improve clarity by specifying additional requirements on
>> `read_raw`/`write_raw` methods regarding concurrent operations on involved
>> buffers.
>
>
>> + /// - Callers must ensure that this call does not race with a write to the source page that
>> + /// overlaps with this read.
>
> Yeah, but per the bit above, its user mapped, you *CANNOT* ensure this.
Not all pages are user mapped. If `self` is user mapped, you cannot use
this function. As you say, it would not be possible to satisfy the
safety precondition.
If `self` is only mapped in the kernel and if you can guarantee that
there are no other concurrent writes to it, you can use this function.
>
> And same comment as for v2, none of this makes sense. Byte loads are not
> magically atomic. And they don't actually fix anything.
I am curious about on what architectures byte loads can tear?
Best regards,
Andreas Hindborg