Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Alice Ryhl" <aliceryhl@google.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Will Deacon" <will@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Lyude Paul" <lyude@redhat.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Carlos Llamas" <cmllamas@google.com>, "Zi Yan" <ziy@nvidia.com>
Cc: linux-mm@kvack.org, rust-for-linux@vger.kernel.org,
	 linux-kernel@vger.kernel.org, driver-core@lists.linux.dev,
	 Andreas Hindborg <a.hindborg@kernel.org>
Subject: [PATCH 10/11] rust_binder: access page data through `SysMemLocal`
Date: Fri, 20 Nov 2026 11:27:09 +0100	[thread overview]
Message-ID: <20261120-page-shared-v1-10-66f8c4c62822@kernel.org> (raw)
In-Reply-To: <20261120-page-shared-v1-0-66f8c4c62822@kernel.org>

The pages of a binder page range are `Page<RefCounted>` pages, which
dereference to `Page<Shared>`. Thus, their data can be accessed through
the safe `Page::with_page_as_sysmem_local()`.

Use the view in `ShrinkablePageRange::copy_from_user_slice()` and
`ShrinkablePageRange::fill_zero()`. This removes the reliance on the
safety requirements of `Page::copy_from_user_slice_raw()` and
`Page::fill_zero_raw()` in these functions.

`ShrinkablePageRange::read()` and `ShrinkablePageRange::write()` copy to
and from raw pointers, so they keep using the raw accessors.

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
 drivers/android/binder/page_range.rs | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
index bddc4538745e..2d360c32202e 100644
--- a/drivers/android/binder/page_range.rs
+++ b/drivers/android/binder/page_range.rs
@@ -538,14 +538,12 @@ pub(crate) unsafe fn copy_from_user_slice(
         offset: usize,
         size: usize,
     ) -> Result {
-        // SAFETY: `self.iterate` has the same safety requirements as `copy_from_user_slice`. The
-        // pages of this range are `Page<RefCounted>` pages, and this driver never creates a
-        // reference to their data, so no reference to the data that is written exists.
-        unsafe {
-            self.iterate(offset, size, |page, offset, to_copy| {
-                page.copy_from_user_slice_raw(reader, offset, to_copy)
-            })
-        }
+        let copy = |page: &Page, offset: usize, to_copy: usize| {
+            page.with_page_as_sysmem_local(offset, to_copy, |view| reader.read_sysmem(view))
+        };
+
+        // SAFETY: `self.iterate` has the same safety requirements as `copy_from_user_slice`.
+        unsafe { self.iterate(offset, size, copy) }
     }
 
     /// Copy from this page range into kernel space.
@@ -605,14 +603,15 @@ pub(crate) unsafe fn write<T: ?Sized>(&self, offset: usize, obj: &T) -> Result {
     ///
     /// All pages touched by this operation must be in use for the duration of this call.
     pub(crate) unsafe fn fill_zero(&self, offset: usize, size: usize) -> Result {
-        // SAFETY: `self.iterate` has the same safety requirements as `fill_zero`. The pages of
-        // this range are `Page<RefCounted>` pages, and this driver never creates a reference to
-        // their data, so no reference to the data that is written exists.
-        unsafe {
-            self.iterate(offset, size, |page, offset, len| {
-                page.fill_zero_raw(offset, len)
+        let fill = |page: &Page, offset: usize, len: usize| {
+            page.with_page_as_sysmem_local(offset, len, |view| {
+                view.fill_zero();
+                Ok(())
             })
-        }
+        };
+
+        // SAFETY: `self.iterate` has the same safety requirements as `fill_zero`.
+        unsafe { self.iterate(offset, size, fill) }
     }
 }
 

-- 
2.54.0




  parent reply	other threads:[~2026-11-20 10:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Andreas Hindborg [this message]
2026-11-20 10:27 ` [PATCH 11/11] rust: page: remove `Page::copy_from_user_slice_raw` Andreas Hindborg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120-page-shared-v1-10-66f8c4c62822@kernel.org \
    --to=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=brauner@kernel.org \
    --cc=cmllamas@google.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=mark.rutland@arm.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tkjos@android.com \
    --cc=tmgross@umich.edu \
    --cc=will@kernel.org \
    --cc=work@onurozkan.dev \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox