All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andreas Hindborg" <a.hindborg@kernel.org>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org,
	linux-pci@vger.kernel.org
Subject: Re: [PATCH v20 2/8] rust: types: Add Ownable/Owned types
Date: Mon, 24 Aug 2026 11:27:34 +0000	[thread overview]
Message-ID: <20260824112734.7B1321F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260824-unique-ref-v20-2-490735672187@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The safety documentation for `Owned::from_raw` fails to require the caller to uphold the pinning invariant.
--

--- Patch [2]: [PATCH v20 2/8] rust: types: Add Ownable/Owned types ---
commit 82ccf756b593f4c76a8a6694855add1d65c27d53
Author: Asahi Lina <lina+kernel@asahilina.net>
rust: types: Add Ownable/Owned types

This commit introduces Ownable and Owned types for unique ownership of objects
with custom drop logic. It provides a mechanism for C-allocated objects to be 
owned by Rust without generic allocators, delegating resource management to 
the type itself.

Link: https://lore.kernel.org/all/20250202-rust-page-v1-1-e3170d7fe55e@asahilina.net/

> diff --git a/rust/kernel/owned.rs b/rust/kernel/owned.rs
> new file mode 100644
> index 0000000000000..7fe9ec3e55126
> --- /dev/null
> +++ b/rust/kernel/owned.rs
[ ... ]
> +    /// Creates a new instance of [`Owned`].
> +    ///
> +    /// This function takes over ownership of the underlying object.
> +    ///
> +    /// # Safety
> +    ///
> +    /// Callers must ensure that:
> +    /// - `ptr` points to a valid instance of `T`.
> +    /// - Until `T::release` is called, the returned `Owned<T>` exclusively owns the underlying `T`.
> +    #[inline]
> +    pub unsafe fn from_raw(ptr: NonNull<T>) -> Self {

[Severity: Medium]
Should the safety documentation for from_raw() explicitly require the caller
to uphold the pinning invariant?

Since as_pin_mut() returns a Pin<&mut T> and the internal comments note that
T is treated as pinned from now on, it seems the caller must guarantee this.

If a caller provides an unpinned allocation, retrieves the pointer later with
into_raw(), and safely moves the object, it could violate the pinning
assumptions established here. Could this lead to memory corruption if the
pinned object is self-referential or registered elsewhere?

> +        // INVARIANT: By function safety requirement we satisfy the first invariant of `Self`.
> +        // We treat `T` as pinned from now on.
> +        Self { ptr }
> +    }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260824-unique-ref-v20-0-490735672187@kernel.org?part=2

  reply	other threads:[~2026-08-24 11:27 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 11:17 [PATCH v20 0/8] rust: add `Ownable` trait and `Owned` type Andreas Hindborg
2026-08-24 11:17 ` [PATCH v20 1/8] rust: alloc: add `KBox::into_non_null` Andreas Hindborg
2026-08-24 11:22   ` sashiko-bot
2026-08-25 13:01   ` Danilo Krummrich
2026-08-24 11:17 ` [PATCH v20 2/8] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-08-24 11:27   ` sashiko-bot [this message]
2026-08-24 11:17 ` [PATCH v20 3/8] rust: implement `ForeignOwnable` for `Owned` Andreas Hindborg
2026-08-24 11:24   ` sashiko-bot
2026-08-24 11:17 ` [PATCH v20 4/8] rust: page: convert to `Ownable` Andreas Hindborg
2026-08-24 11:26   ` sashiko-bot
2026-08-25 13:20   ` [PATCH v20 4/8] rust: page: convert to `Ownable`' Alice Ryhl
2026-09-06 13:02     ` Gary Guo
2026-09-07  9:24       ` Alice Ryhl
2026-09-07 12:38         ` Andreas Hindborg
2026-09-07 13:31           ` Alice Ryhl
2026-09-07 13:58             ` Andreas Hindborg
2026-09-07 14:06               ` Alice Ryhl
2026-09-08  8:46                 ` Andreas Hindborg
2026-09-08  9:18                   ` Alice Ryhl
2026-09-08 12:10                     ` Andreas Hindborg
2026-08-25 13:34   ` [PATCH v20 4/8] rust: page: convert to `Ownable` Danilo Krummrich
2026-08-24 11:17 ` [PATCH v20 5/8] rust: rename `AlwaysRefCounted` to `RefCounted` Andreas Hindborg
2026-08-24 11:28   ` sashiko-bot
2026-08-24 12:26   ` Uwe Kleine-König
2026-08-24 11:17 ` [PATCH v20 6/8] rust: Add missing SAFETY documentation for `ARef` example Andreas Hindborg
2026-08-24 11:25   ` sashiko-bot
2026-08-24 11:36   ` Miguel Ojeda
2026-08-26  9:29     ` Andreas Hindborg
2026-09-03 13:28       ` Miguel Ojeda
2026-08-24 11:17 ` [PATCH v20 7/8] rust: Add `OwnableRefCounted` Andreas Hindborg
2026-08-24 11:28   ` sashiko-bot
2026-08-25 13:16   ` Danilo Krummrich
2026-08-25 13:37     ` Gary Guo
2026-08-24 11:18 ` [PATCH v20 8/8] rust: page: add `from_raw()` Andreas Hindborg
2026-08-24 11:25   ` sashiko-bot

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=20260824112734.7B1321F000E9@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.