Linux PCI subsystem development
 help / color / mirror / Atom feed
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 v19 8/8] rust: page: add `from_raw()`
Date: Fri, 26 Jun 2026 12:06:29 +0000	[thread overview]
Message-ID: <20260626120630.C45EE1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260626-unique-ref-v19-8-2607ca88dfdf@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` fails to require that `ptr` points to a valid kernel `struct page`.
--

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

rust: page: add from_raw()

This commit adds a method to Page that allows construction of an instance
from a struct page pointer.

> diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
> --- a/rust/kernel/page.rs
> +++ b/rust/kernel/page.rs
[ ... ]
> +    /// 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]
Does the safety documentation for from_raw() need to explicitly require
that ptr points to a valid kernel struct page?

The current safety requirements only demand that ptr is convertible to a
shared reference (non-null, aligned, valid memory). However, the internal
INVARIANT comment explicitly relies on ptr being a valid struct page.

Could a caller technically satisfy the safety requirements with a
stack-allocated or dummy struct page, but break the type invariant
and cause issues when methods like page_to_nid() are called later?

> +        // INVARIANT: By the function safety requirements, ptr refers to a valid struct page, so
> +        // the returned reference upholds the type invariant of Page.
> +        // 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/20260626-unique-ref-v19-0-2607ca88dfdf@kernel.org?part=8

      reply	other threads:[~2026-06-26 12:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26 11:53 [PATCH v19 0/8] rust: add `Ownable` trait and `Owned` type Andreas Hindborg
2026-06-26 11:53 ` [PATCH v19 1/8] rust: alloc: add `KBox::into_non_null` Andreas Hindborg
2026-06-26 12:01   ` sashiko-bot
2026-06-26 11:53 ` [PATCH v19 2/8] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-06-26 12:06   ` sashiko-bot
2026-06-26 11:54 ` [PATCH v19 3/8] rust: implement `ForeignOwnable` for `Owned` Andreas Hindborg
2026-06-26 12:07   ` sashiko-bot
2026-06-26 11:54 ` [PATCH v19 4/8] rust: page: convert to `Ownable` Andreas Hindborg
2026-06-26 12:05   ` sashiko-bot
2026-06-26 11:54 ` [PATCH v19 5/8] rust: rename `AlwaysRefCounted` to `RefCounted` Andreas Hindborg
2026-06-26 12:06   ` sashiko-bot
2026-06-26 11:54 ` [PATCH v19 6/8] rust: Add missing SAFETY documentation for `ARef` example Andreas Hindborg
2026-06-26 12:02   ` sashiko-bot
2026-06-26 11:54 ` [PATCH v19 7/8] rust: Add `OwnableRefCounted` Andreas Hindborg
2026-06-26 12:06   ` sashiko-bot
2026-06-26 11:54 ` [PATCH v19 8/8] rust: page: add `from_raw()` Andreas Hindborg
2026-06-26 12:06   ` 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=20260626120630.C45EE1F00A3A@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