From: sashiko-bot@kernel.org
To: "Andreas Hindborg" <a.hindborg@kernel.org>
Cc: ojeda@kernel.org, linux-pci@vger.kernel.org, gary@garyguo.net,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v21 8/9] rust: page: add `from_raw()`
Date: Thu, 10 Sep 2026 09:11:38 +0000 [thread overview]
Message-ID: <20260910091138.C6BDC1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910-unique-ref-v21-8-e83257373062@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Insufficient `# Safety` requirements for `Page::from_raw` leading to unsoundness.
--
commit e6799a35c42d6949e4edb57a0982fc37d7af34f7
Author: Andreas Hindborg <a.hindborg@kernel.org>
rust: page: add `from_raw()`
Add a method to `Page` that allows construction of an instance from `struct
page` pointer.
> diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
> index a2610774c7499..cd394b0656c0c 100644
> --- a/rust/kernel/page.rs
> +++ b/rust/kernel/page.rs
> @@ -146,6 +146,20 @@ pub fn nid(&self) -> i32 {
> unsafe { bindings::page_to_nid(self.as_ptr()) }
> }
>
> + /// Create a `&Page` from a raw `struct page` pointer.
> + ///
> + /// # Safety
> + ///
> + /// `ptr` must be convertible to a shared reference with a lifetime of `'a`.
> + #[inline]
> + pub unsafe fn from_raw<'a>(ptr: *const bindings::page) -> &'a Self {
> + // INVARIANT: By the function safety requirements, `ptr` refers to a valid `struct page`, so
> + // the returned reference upholds the type invariant of `Page`.
[Severity: High]
Are the safety requirements for Page::from_raw() sufficient?
The documented requirement allows passing a pointer to a valid struct page
that has a zero reference count or is unmanaged (e.g. stack allocated or
reserved).
If safe Rust code later casts this &Page to an ARef<Page> (via .into()
or .clone()), this invokes inc_ref() (get_page()) on an unmanaged or
0-refcount page.
Couldn't this cause memory corruption or trigger a VM_BUG_ON_PAGE? Should
the safety documentation and type invariant require that the page is managed
by the page reference count (i.e. has a non-zero refcount)?
> + // SAFETY: By function safety requirements, `ptr` is not null and is convertible to a shared
> + // reference.
> + unsafe { &*ptr.cast() }
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910-unique-ref-v21-0-e83257373062@kernel.org?part=8
next prev parent reply other threads:[~2026-09-10 9:11 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 9:00 [PATCH v21 0/9] rust: add `Ownable` trait and `Owned` type Andreas Hindborg
2026-09-10 9:00 ` [PATCH v21 1/9] rust: alloc: add `KBox::into_non_null` Andreas Hindborg
2026-09-10 9:05 ` sashiko-bot
2026-09-10 9:00 ` [PATCH v21 2/9] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-09-10 9:06 ` sashiko-bot
2026-09-10 9:00 ` [PATCH v21 3/9] rust: implement `ForeignOwnable` for `Owned` Andreas Hindborg
2026-09-10 9:08 ` sashiko-bot
2026-09-10 9:00 ` [PATCH v21 4/9] rust: rename `AlwaysRefCounted` to `RefCounted` Andreas Hindborg
2026-09-10 9:14 ` sashiko-bot
2026-09-11 9:08 ` Alice Ryhl
2026-09-11 12:29 ` Gary Guo
2026-09-13 9:49 ` Andreas Hindborg
2026-09-10 9:00 ` [PATCH v21 5/9] rust: Add missing SAFETY documentation for `ARef` example Andreas Hindborg
2026-09-10 9:07 ` sashiko-bot
2026-09-11 9:09 ` Alice Ryhl
2026-09-10 9:00 ` [PATCH v21 6/9] rust: Add `OwnableRefCounted` Andreas Hindborg
2026-09-10 9:09 ` sashiko-bot
2026-09-11 9:19 ` Alice Ryhl
2026-09-11 13:25 ` Andreas Hindborg
2026-09-10 9:00 ` [PATCH v21 7/9] rust: page: convert to `AlwaysRefCounted` Andreas Hindborg
2026-09-10 9:18 ` sashiko-bot
2026-09-11 13:43 ` Alice Ryhl
2026-09-10 9:00 ` [PATCH v21 8/9] rust: page: add `from_raw()` Andreas Hindborg
2026-09-10 9:11 ` sashiko-bot [this message]
2026-09-10 9:00 ` [PATCH v21 9/9] rust: page: add `ExclusivePage` for race-free page access Andreas Hindborg
2026-09-10 9:14 ` sashiko-bot
2026-09-13 3:11 ` Matthew Wilcox
2026-09-13 9:36 ` 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=20260910091138.C6BDC1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.