Thread (19 messages) flat view 19 messages, 4 authors, 13d ago

Re: [PATCH v21 9/9] rust: page: add `ExclusivePage` for race-free page access

From: Andreas Hindborg <a.hindborg@kernel.org>
Date: 2026-09-13 09:37:14
Also in: dri-devel, driver-core, linux-fsdevel, linux-mm, linux-pci, linux-pm, linux-pwm, linux-security-module, linux-usb, lkml, rust-for-linux

Matthew Wilcox [off-list ref] writes:
On Thu, Sep 10, 2026 at 11:00:13AM +0200, Andreas Hindborg wrote:
quoted
`ExclusivePage` wraps a regular page but adds an invariant that the
page data area does not incur data races. This means `ExclusivePage`
cannot be mapped to user space or shared with devices, and it
becomes simpler to directly reference the contents of the page.

Since `Page` implements `AlwaysRefCounted`, handing out a `&Page`
from an `ExclusivePage` would allow safe code to obtain an
`ARef<Page>` to the page and break the aliasing invariant of
`ExclusivePage`. Thus, do not implement `Deref<Target = Page>` for
`ExclusivePage`.
Given this description, I wonder if this shouldn't be implemented by
alloc_frozen_pages() / free_frozen_pages().  We'ree certainly trying
to move the C parts of the kernel away from thinking that pages have a
refcount (folios have a refcount; otheer memdescs may or may not have
a refcount).  Do your intended users of this actually have a need for a
refcount?
I'm not familiar with that API, but I will take a look. The
`ExclusivePage` would not need a refcount. The reference is intended to
be exclusive, giving mutable access to the page contents.

I could imagine a situation where someone might want to transition a
page reference from exclusive to shared, but I do not have a user for
that at the moment.
quoted
+++ b/rust/kernel/page.rs
@@ -17,7 +17,11 @@
         AlwaysRefCounted,
         RefCounted, //
     },
-    types::Opaque,
+    types::{
+        Opaque,
+        Ownable,
+        Owned, //
+    },
While I'm asking stupid questions, what's the significance of the //
after Owned?  I see it after RefCounted too.
It is a hack to get rustfmt to format the import statements in a Linus
compatible manner [1]. As far as I know, it will go away once rustfmt
learns to do this by itself.

Best regards,
Andreas Hindborg


[1] https://docs.kernel.org/rust/coding-guidelines.html#imports
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help