All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andreas Hindborg" <a.hindborg@kernel.org>
Cc: linux-pci@vger.kernel.org, ojeda@kernel.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v18 8/8] rust: page: add `from_raw()`
Date: Thu, 25 Jun 2026 10:25:49 +0000	[thread overview]
Message-ID: <20260625102549.B56171F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260625-unique-ref-v18-8-4e06b5896d47@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The `# Safety` documentation for `Page::from_raw` is missing the precondition that `ptr` must point to a valid `struct page`.
--

commit f6aeebdd661d4004190de07e9d991442f793517a
Author: Andreas Hindborg <a.hindborg@kernel.org>

rust: page: add `from_raw()`

This commit adds a from_raw() method to the Page abstraction. It allows
the construction of a shared reference to a Page instance directly from a 
raw struct page pointer.

> diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
> index 6dc1c2395acaf..c88fda09ead5a 100644
> --- a/rust/kernel/page.rs
> +++ b/rust/kernel/page.rs

[ ... ]

> @@ -143,6 +143,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 {

[Severity: Medium]
Is the safety documentation missing a requirement here? 

The # Safety section only requires that ptr is convertible to a shared 
reference. Under Rust's rules, an uninitialized or dummy pointer could 
technically be converted to a shared reference if properly aligned.

> +        // INVARIANT: By the function safety requirements, `ptr` refers to a valid `struct page`, so
> +        // the returned reference upholds the type invariant of `Page`.

The invariant justification inside the function explicitly relies on the 
caller guaranteeing that ptr refers to a valid struct page. Could the 
# Safety documentation be updated to explicitly require that ptr points 
to a valid, initialized struct page so that callers do not inadvertently 
violate the Page type invariant?

> +        // 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/20260625-unique-ref-v18-0-4e06b5896d47@kernel.org?part=8

  reply	other threads:[~2026-06-25 10:25 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 10:15 [PATCH v18 0/8] rust: add `Ownable` trait and `Owned` type Andreas Hindborg
2026-06-25 10:15 ` [PATCH v18 1/8] rust: alloc: add `KBox::into_non_null` Andreas Hindborg
2026-06-25 10:22   ` sashiko-bot
2026-06-25 10:15 ` [PATCH v18 2/8] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-06-25 10:24   ` sashiko-bot
2026-06-25 12:24     ` Andreas Hindborg
2026-06-25 10:15 ` [PATCH v18 3/8] rust: implement `ForeignOwnable` for `Owned` Andreas Hindborg
2026-06-25 10:23   ` sashiko-bot
2026-06-25 13:29   ` Gary Guo
2026-06-25 19:47     ` Andreas Hindborg
2026-06-25 10:15 ` [PATCH v18 4/8] rust: page: convert to `Ownable` Andreas Hindborg
2026-06-25 10:25   ` sashiko-bot
2026-06-25 13:32   ` Gary Guo
2026-06-25 10:15 ` [PATCH v18 5/8] rust: rename `AlwaysRefCounted` to `RefCounted` Andreas Hindborg
2026-06-25 10:28   ` sashiko-bot
2026-06-25 12:26     ` Andreas Hindborg
2026-06-25 10:15 ` [PATCH v18 6/8] rust: Add missing SAFETY documentation for `ARef` example Andreas Hindborg
2026-06-25 10:21   ` sashiko-bot
2026-06-25 10:15 ` [PATCH v18 7/8] rust: Add `OwnableRefCounted` Andreas Hindborg
2026-06-25 10:26   ` sashiko-bot
2026-06-25 12:37     ` Andreas Hindborg
2026-06-25 10:15 ` [PATCH v18 8/8] rust: page: add `from_raw()` Andreas Hindborg
2026-06-25 10:25   ` sashiko-bot [this message]
2026-06-25 13:02     ` 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=20260625102549.B56171F00A3E@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 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.