From: sashiko-bot@kernel.org
To: "Andreas Hindborg" <a.hindborg@kernel.org>
Cc: linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org,
ojeda@kernel.org
Subject: Re: [PATCH v17 10/10] rust: page: add `from_raw()`
Date: Thu, 04 Jun 2026 20:27:59 +0000 [thread overview]
Message-ID: <20260604202759.630F81F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604-unique-ref-v17-10-7b4c3d2930b9@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The `Page::from_raw` method silently bypasses the documented type invariants of the `Page` struct and lacks an `// INVARIANT:` comment.
--
commit 224010a6541ae8f534f1577d76a1acd3e9bb5d34
Author: Andreas Hindborg <a.hindborg@kernel.org>
rust: page: add `from_raw()`
This commit adds a new from_raw() method to the Page struct. It enables the
creation of a shared &Page reference directly from a raw struct page C
pointer.
> diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
> index 844c75e541345..d56ae597f6926 100644
> --- a/rust/kernel/page.rs
> +++ b/rust/kernel/page.rs
[ ... ]
> @@ -214,6 +214,18 @@ 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 {
> + // SAFETY: By function safety requirements, `ptr` is not null and is convertible to a shared
> + // reference.
> + unsafe { &*ptr.cast() }
[Severity: Low]
This isn't a bug, but should this unsafe block include an `// INVARIANT:`
comment to justify the type invariants of the Page struct?
The Page struct has an `# Invariants` documentation section stating that it
has ownership over the page. While that ownership invariant might be an
obsolete leftover, creating a &Page reference here conceptually asserts that
the referenced memory satisfies this type invariant.
Could we add the required `// INVARIANT:` comment or update the outdated
type invariant documentation to clarify this?
> + }
> +
> /// Runs a piece of code with this page mapped to an address.
> ///
> /// The page is unmapped when this call returns.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604-unique-ref-v17-0-7b4c3d2930b9@kernel.org?part=10
prev parent reply other threads:[~2026-06-04 20:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 20:11 [PATCH v17 00/10] rust: add `Ownable` trait and `Owned` type Andreas Hindborg
2026-06-04 20:11 ` [PATCH v17 01/10] rust: alloc: add `KBox::into_non_null` Andreas Hindborg
2026-06-04 20:11 ` [PATCH v17 02/10] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-06-04 20:26 ` sashiko-bot
2026-06-04 20:11 ` [PATCH v17 03/10] rust: implement `ForeignOwnable` for `Owned` Andreas Hindborg
2026-06-04 20:23 ` sashiko-bot
2026-06-04 20:11 ` [PATCH v17 04/10] rust: page: update formatting of `use` statements Andreas Hindborg
2026-06-04 20:11 ` [PATCH v17 05/10] rust: page: convert to `Ownable` Andreas Hindborg
2026-06-04 20:29 ` sashiko-bot
2026-06-04 20:11 ` [PATCH v17 06/10] rust: rename `AlwaysRefCounted` to `RefCounted` Andreas Hindborg
2026-06-04 20:24 ` sashiko-bot
2026-06-04 20:11 ` [PATCH v17 07/10] rust: Add missing SAFETY documentation for `ARef` example Andreas Hindborg
2026-06-04 20:32 ` sashiko-bot
2026-06-04 20:11 ` [PATCH v17 08/10] rust: aref: update formatting of use statements Andreas Hindborg
2026-06-04 20:20 ` sashiko-bot
2026-06-04 20:11 ` [PATCH v17 09/10] rust: Add `OwnableRefCounted` Andreas Hindborg
2026-06-04 20:35 ` sashiko-bot
2026-06-04 20:11 ` [PATCH v17 10/10] rust: page: add `from_raw()` Andreas Hindborg
2026-06-04 20:27 ` sashiko-bot [this message]
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=20260604202759.630F81F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox