Re: [PATCH v2] rust: page: add byte-wise atomic memory copy methods
From: Jens Axboe
Date: Tue Feb 17 2026 - 15:32:22 EST
On 2/17/26 11:43 AM, Andreas Hindborg wrote:
> "Peter Zijlstra" <peterz@xxxxxxxxxxxxx> writes:
>
>> On Tue, Feb 17, 2026 at 02:56:40PM +0100, Andreas Hindborg wrote:
>>
>>> I'm processing disk IO in the Rust null block driver. The pages backing
>>> the IO requests may be simultaneously mapped to user space, so there is
>>> no way to guarantee that there is no concurrent memory operation to/from
>>> the memory area. User space programs can do whatever.
>>>
>>> I don't have any control flow depending on the data I copy. I just store
>>> it somewhere and return it if a read IO for the same sector arrive.
>>
>> Right, so IIRC the old DIO code used to have this problem. We'd end up
>> writing whatever random state to disk if you did DIO of an mmap().
>>
>> And if IIRC the current state of things is better in that we ensure the
>> mapping becomes RO and we have writes fault and wait until the writeback
>> is complete, ensuring things are somewhat more consistent.
>>
>> But you'd better ask Jens or someone that has looked at the various IO
>> paths in the past 10 years or so :-)
>
> Oh, this is a really important detail that I did not find while trying
> to follow the code path from user space.
>
> Cc: Jens Axboe <axboe@xxxxxxxxx>
>
> @Jens is this so, are pages from user space that are part of a write
> request mapped RO during the IO operation?
No, there's no such thing. It'd make O_DIRECT writes much slower.
Also see the recent stable pages merge that went into upstream this
merge window:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4adc13ed7c281c16152a700e47b65d17de07321a
which only really deals with the checksumming problem, but regardless
it's in the same area of "userspace modifies page(s) while IO is
in-flight". If you don't do checksums, and you rely on bufferA ending up
on stable storage while having it in-flight and also modifying bufferA
simultaneously from your application, you get to keep both broken pieces
--
Jens Axboe