mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v6 0/4] rust: byte-wise atomic copies between `Page` and shared memory
@ 2026-11-13 13:15 Andreas Hindborg
  2026-11-13 13:15 ` [PATCH v6 1/4] rust: io: forbid plain accesses racing with `SysMem` Andreas Hindborg
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Andreas Hindborg @ 2026-11-13 13:15 UTC (permalink / raw)
  To: Alice Ryhl, Lorenzo Stoakes, Liam R. Howlett, Miguel Ojeda,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Trevor Gross, Danilo Krummrich, Will Deacon, Peter Zijlstra,
	Mark Rutland, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Lyude Paul, Abdiel Janulgue,
	Robin Murphy, David Airlie, Simona Vetter
  Cc: linux-mm, rust-for-linux, linux-kernel, driver-core, dri-devel,
	Andreas Hindborg

This series adds a way to copy data between a `Page` and memory that is
shared with actors outside the kernel, such as user space threads or
hardware, without introducing a data race.

The copy is built on `SysMem` from `kernel::io`, which already accesses
system memory with volatile or byte-wise atomic operations. The series
first makes the requirements of `SysMem` explicit by requiring freedom from
racing plain accesses. It then adds `kernel::sync::atomic::memcpy()`, a
wrapper around the kernel's `memcpy()` with explicit safety requirements,
and routes the `SysMem` copies through it. Finally, it adds
`Page::{read,write}_sysmem`, which take a `SysMem<'_, [u8]>` view of the
shared buffer.

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
Changes in v6:
- Require that plain accesses do not race with accesses through a `SysMem`
  view, instead of forbidding them for the lifetime of the view (Sashiko).
- Update the safety comments on the existing `SysMem::new` callers in
  `dma.rs` and `drm/gem/shmem.rs`.
- Rename `atomic_per_byte_memcpy()` to `memcpy()` (Peter, Boqun).
- Refer to `core::ptr::copy_nonoverlapping()` instead of
  `core::ptr::copy()` (Sashiko).
- Add `#[inline]` to `memcpy()` (Sashiko).
- Rename `Page::{read,write}_bytewise_atomic` to
  `Page::{read,write}_sysmem` (Boqun).
- Link to v5: https://msgid.link/20261110-page-volatile-io-v5-0-a91ef252c24b@kernel.org

Changes in v5:
- Rebase on v7.4-rc2.
- Build on `SysMem` from `kernel::io` instead of adding raw pointer
  based helpers to `Page` (Gary).
- Add a patch that requires freedom from plain accesses for `SysMem`
  views (Gary).
- Route the `SysMemBackend` copies through `atomic_per_byte_memcpy()`,
  so that the requirements of the `memcpy()` call are explicit.
- Let `Page::{read,write}_bytewise_atomic` take a `SysMem<'_, [u8]>`
  instead of a raw pointer and a length.
- Drop the claim that `atomic_per_byte_memcpy()` is volatile.
- Add a non-overlap requirement to `atomic_per_byte_memcpy()`.
- Add examples to `Page::{read,write}_bytewise_atomic` (Alice).
- Link to v4: https://msgid.link/20260605-page-volatile-io-v4-0-0e217d9bf11a@kernel.org

Changes in v4:
- Split `atomic_per_byte_memcpy` out into its own patch (Boqun).
- Expand `atomic_per_byte_memcpy` documentation to explain the
  concurrent-safe semantics and to note that the kernel's `memcpy()`
  uses byte-wise atomic load/store instructions (Boqun).
- Clarify the src/dst asymmetry in the documentation of
  `Page::{read,write}_bytewise_atomic` (Boqun).
- Use the "valid for atomic {reads,writes}" shorthand in the safety
  lists of the new methods and of `atomic_per_byte_memcpy` (Benno).
- Drop the redundant data-race bullets that v3 added on
  `Page::{read,write}_raw` (Miguel).
- Link to v3: https://msgid.link/20260213-page-volatile-io-v3-1-d60487b04d40@kernel.org

Changes in v3:
- Update documentation adn safety requirements for `Page::{read,write}_bytewise_atomic`.
- Update safety comments in `Page::{read,write}_bytewise_atomic`.
- Call the correct copy function in `Page::{read,write}_bytewise_atomic`.
- Link to v2: https://msgid.link/20260212-page-volatile-io-v2-1-a36cb97d15c2@kernel.org

Changes in v2:
- Rewrite patch with byte-wise atomic operations as foundation of operation.
- Update subject and commit message.
- Link to v1: https://lore.kernel.org/r/20260130-page-volatile-io-v1-1-19f3d3e8f265@kernel.org

---
Andreas Hindborg (4):
      rust: io: forbid plain accesses racing with `SysMem`
      rust: sync: atomic: add memcpy
      rust: io: copy `SysMem` with `atomic::memcpy`
      rust: page: add byte-wise atomic copy methods for `SysMem`

 rust/kernel/dma.rs           |   8 ++-
 rust/kernel/drm/gem/shmem.rs |   2 +
 rust/kernel/io.rs            |  73 +++++++++++++++++---------
 rust/kernel/page.rs          | 121 +++++++++++++++++++++++++++++++++++++++++++
 rust/kernel/sync/atomic.rs   |  36 +++++++++++++
 5 files changed, 214 insertions(+), 26 deletions(-)
---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20260130-page-volatile-io-05ff595507d3

Best regards,
--  
Andreas Hindborg <a.hindborg@kernel.org>



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-13 13:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 13:15 [PATCH v6 0/4] rust: byte-wise atomic copies between `Page` and shared memory Andreas Hindborg
2026-11-13 13:15 ` [PATCH v6 1/4] rust: io: forbid plain accesses racing with `SysMem` Andreas Hindborg
2026-11-13 13:15 ` [PATCH v6 2/4] rust: sync: atomic: add memcpy Andreas Hindborg
2026-11-13 13:15 ` [PATCH v6 3/4] rust: io: copy `SysMem` with `atomic::memcpy` Andreas Hindborg
2026-11-13 13:15 ` [PATCH v6 4/4] rust: page: add byte-wise atomic copy methods for `SysMem` Andreas Hindborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®