Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH 00/11] rust: page: improve access methods for racy memory regions
@ 2026-11-20 10:26 Andreas Hindborg
  2026-11-20 10:27 ` [PATCH 01/11] rust: page: tighten safety requirements of `SysMem` copy methods Andreas Hindborg
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Andreas Hindborg @ 2026-11-20 10:26 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, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Will Deacon, Peter Zijlstra,
	Mark Rutland, Lyude Paul, Greg Kroah-Hartman,
	Arve Hjønnevåg, Todd Kjos, Christian Brauner,
	Carlos Llamas, Zi Yan
  Cc: linux-mm, rust-for-linux, linux-kernel, driver-core,
	Andreas Hindborg

`Page` has a number of methods for manipulating the memory of the page.
These use `core::ptr::{copy_nonoverlapping,write_bytes}`, which are not
valid for use when one end of the operation may be subject to concurrent
reads or writes.

With recent patches that allow pages to be exposed as `SysMem` regions, we
can use the `SysMem` infrastructure to do the operations as byte-wise
atomic operations, thus making the operations well defined.

This series builds on the atomic memcpy series [1], the `Ownable` series
[2] and the `Page` refactor series [3] to prepare for handling the pages of
a `Bio` in a well defined way. As part of this work:

Remove the `core::ptr` memory operations from page.

Add a safe method to get a `SysMem` view of a page and use that when
copying into pages from `UserSliceReader`. Remove code paths in
`UserSliceReader` that would make a `&mut [MaybeUninit<u8>]` to page
contents.

As `SysMem` is `Send` and `Sync` but pages are mapped with `kmap_local`,
add a `SysMemLocal` variant that is neither `Send` nor `Sync` and use this
for the views of page data.

Finally, remove `Page::copy_from_user_slice_raw` as it is no longer used.

The three dependency series do not compose without conflicts, so I have
provided my b4 tree with all of them applied [4].

[1] https://lore.kernel.org/all/20261113-page-volatile-io-v6-0-5603e527c919@kernel.org
[2] https://lore.kernel.org/all/20261116-unique-ref-v22-0-12029383206d@kernel.org
[3] https://lore.kernel.org/all/20261118-page-ownable-v22-0-d63ff73f4075@kernel.org
[4] https://github.com/metaspace/linux/tree/page-shared

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
Andreas Hindborg (11):
      rust: page: tighten safety requirements of `SysMem` copy methods
      rust: sync: atomic: add memset
      rust: io: add `SysMem::fill_zero`
      rust: page: use byte-wise atomic operations in raw accessors
      rust: uaccess: take a raw pointer in `UserSliceReader::read_raw`
      rust: uaccess: add `UserSliceReader::read_sysmem`
      rust: page: add `Shared` page kind
      rust: io: add `SysMemLocal`
      rust: page: add `Page::with_page_as_sysmem_local`
      rust_binder: access page data through `SysMemLocal`
      rust: page: remove `Page::copy_from_user_slice_raw`

 drivers/android/binder/page_range.rs |  35 ++--
 rust/kernel/io.rs                    | 151 +++++++++++++--
 rust/kernel/page.rs                  | 355 +++++++++++++++++++++++++----------
 rust/kernel/sync/atomic.rs           |  25 +++
 rust/kernel/uaccess.rs               |  79 ++++++--
 5 files changed, 496 insertions(+), 149 deletions(-)
---
base-commit: fd9230005e85472b81c1c7c16afe93dd878996b1
change-id: 20261119-page-shared-9b748d499e3e
prerequisite-change-id: 20260130-page-volatile-io-05ff595507d3:v6
prerequisite-patch-id: 112f7ee8c101c766ba33128a08c053ff7dd1bd6f
prerequisite-patch-id: 4b725c8c4d3313096ea722ac2866bd5e36227b88
prerequisite-patch-id: bf25326b450044d86f2cc7392f67d17d674afe8a
prerequisite-patch-id: acbb5d7f331c45b8da915ea32bef91447ac0b234
prerequisite-change-id: 20250305-unique-ref-29fcd675f9e9:v22
prerequisite-patch-id: 4e3c7a1a2077aaa0ece2d557fa73486355903ae5
prerequisite-patch-id: d1073c5dcd6287fbcba7848a5d182108930230c1
prerequisite-patch-id: 3244def11bbdf2eabaa6e94e15ce06540b2f5814
prerequisite-patch-id: cef14c5bef5ba519ceaf0a0e7c9e93ef974db7b3
prerequisite-patch-id: 56410da35ed8dbe7b210adae0985af705cc0b5b0
prerequisite-change-id: 20261112-page-ownable-2e97941a83b2:v22
prerequisite-patch-id: 4e3c7a1a2077aaa0ece2d557fa73486355903ae5
prerequisite-patch-id: d1073c5dcd6287fbcba7848a5d182108930230c1
prerequisite-patch-id: 3244def11bbdf2eabaa6e94e15ce06540b2f5814
prerequisite-patch-id: cef14c5bef5ba519ceaf0a0e7c9e93ef974db7b3
prerequisite-patch-id: 56410da35ed8dbe7b210adae0985af705cc0b5b0
prerequisite-patch-id: 7454d72e9d18045c4b45c3be614c51288c7c437a
prerequisite-patch-id: edcc308e1ba9596e7939859cb50230ca56f0b265
prerequisite-patch-id: 90fcb80e26232818fea9472fa83871b6577bbddd
prerequisite-patch-id: 10e8ae82a9750cd76b42754393d3e39b9e849474
prerequisite-patch-id: 881055f06785a8df0ec9f8107065428900ca78d9
prerequisite-patch-id: e0759f2b41824d562a594c9e2452bf41ba514cbd

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



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

end of thread, other threads:[~2026-11-20 10:28 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 10:26 [PATCH 00/11] rust: page: improve access methods for racy memory regions Andreas Hindborg
2026-11-20 10:27 ` [PATCH 01/11] rust: page: tighten safety requirements of `SysMem` copy methods Andreas Hindborg
2026-11-20 10:27 ` [PATCH 02/11] rust: sync: atomic: add memset Andreas Hindborg
2026-11-20 10:27 ` [PATCH 03/11] rust: io: add `SysMem::fill_zero` Andreas Hindborg
2026-11-20 10:27 ` [PATCH 04/11] rust: page: use byte-wise atomic operations in raw accessors Andreas Hindborg
2026-11-20 10:27 ` [PATCH 05/11] rust: uaccess: take a raw pointer in `UserSliceReader::read_raw` Andreas Hindborg
2026-11-20 10:27 ` [PATCH 06/11] rust: uaccess: add `UserSliceReader::read_sysmem` Andreas Hindborg
2026-11-20 10:27 ` [PATCH 07/11] rust: page: add `Shared` page kind Andreas Hindborg
2026-11-20 10:27 ` [PATCH 08/11] rust: io: add `SysMemLocal` Andreas Hindborg
2026-11-20 10:27 ` [PATCH 09/11] rust: page: add `Page::with_page_as_sysmem_local` Andreas Hindborg
2026-11-20 10:27 ` [PATCH 10/11] rust_binder: access page data through `SysMemLocal` Andreas Hindborg
2026-11-20 10:27 ` [PATCH 11/11] rust: page: remove `Page::copy_from_user_slice_raw` Andreas Hindborg

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