All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Benno Lossin" <lossin@kernel.org>
To: "Christian Schrefl" <chrisi.schrefl@gmail.com>,
	Sky <sky@sky9.dev>, "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Gerald Wisböck" <gerald.wisboeck@feather.ink>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <nick.desaulniers+lkml@gmail.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>
Cc: <linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>,
	<llvm@lists.linux.dev>, "Ralf Jung" <post@ralfj.de>
Subject: Re: [PATCH v4 1/3] rust: add UnsafePinned type
Date: Fri, 06 Jun 2025 10:12:42 +0200	[thread overview]
Message-ID: <DAFASAX0B837.1YDWHXPFR3JCT@kernel.org> (raw)
In-Reply-To: <63f92378-dde9-4bee-b2ae-b994052e8fd0@gmail.com>

On Thu Jun 5, 2025 at 7:57 PM CEST, Christian Schrefl wrote:
> On 05.06.25 7:30 PM, Benno Lossin wrote:
>> On Thu Jun 5, 2025 at 7:03 PM CEST, Christian Schrefl wrote:
>>> On 11.05.25 8:21 PM, Christian Schrefl wrote:
>>>> +/// This type provides a way to opt-out of typical aliasing rules;
>>>> +/// specifically, `&mut UnsafePinned<T>` is not guaranteed to be a unique pointer.
>>>> +///
>>>> +/// However, even if you define your type like `pub struct Wrapper(UnsafePinned<...>)`, it is still
>>>> +/// very risky to have an `&mut Wrapper` that aliases anything else. Many functions that work
>>>> +/// generically on `&mut T` assume that the memory that stores `T` is uniquely owned (such as
>>>> +/// `mem::swap`). In other words, while having aliasing with `&mut Wrapper` is not immediate
>>>> +/// Undefined Behavior, it is still unsound to expose such a mutable reference to code you do not
>>>> +/// control! Techniques such as pinning via [`Pin`](core::pin::Pin) are needed to ensure soundness.
>>>> +///
>>>> +/// Similar to [`UnsafeCell`], [`UnsafePinned`] will not usually show up in
>>>> +/// the public API of a library. It is an internal implementation detail of libraries that need to
>>>> +/// support aliasing mutable references.
>>>> +///
>>>> +/// Further note that this does *not* lift the requirement that shared references must be read-only!
>>>> +/// Use [`UnsafeCell`] for that.
>>>
>>> The upstream rust PR [0] that changes this was just merged. So now `UnsafePinned` includes
>>> `UnsafeCell` semantics. It's probably best to also change this in the kernel docs.
>>> Though it's still the case that removing the guarantee is simpler than adding it back later,
>>> so let me know what you all think.
>> 
>> Depends on how "stable" this decision is. I haven't followed the
>> discussion, but given that this once changed to the "non-backwards"
>> compatible case it feels permanent.
>
> It seems pretty permanent, from what I understand its hard to
> define the exact semantics `UnsafePinned` without `UnsafeCell`
> in a way that is sound and because of some interactions with
> `Pin::deref` it would have some backwards compatibility issues.
> See this comment by Ralf on github [1].

Oh yeah that seems like a done deal.

> [1]: https://github.com/rust-lang/rust/pull/137043#discussion_r1973978597
>
>> 
>> How close is it to stabilization?
>> 
>> If it's close-ish, then I'd suggest we change this to reflect the new
>> semantics. If not, then we should leave it as-is.
>
> It's pretty new, I'm not sure how long it's going to stay in nightly,
> but it's probably going to be quite some time.
>
> I wouldn't change it if it would already be in the kernel, but I think
> its probably good to add the current state of the feature. This
> would also reduce the difference between docs and implementation.

Makes sense, I agree with changing it. Thanks for your work!

---
Cheers,
Benno

  reply	other threads:[~2025-06-06  8:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-11 18:21 [PATCH v4 0/3] rust: add `UnsafePinned` type Christian Schrefl
2025-05-11 18:21 ` [PATCH v4 1/3] rust: add UnsafePinned type Christian Schrefl
2025-05-13 20:51   ` Benno Lossin
2025-05-17 11:36     ` Christian Schrefl
2025-05-17 19:11       ` Benno Lossin
2025-05-20 21:26   ` Miguel Ojeda
2025-05-30 20:22     ` Christian Schrefl
2025-05-30 21:01       ` Christian Schrefl
2025-05-31 10:30       ` Miguel Ojeda
2025-06-05 17:03   ` Christian Schrefl
2025-06-05 17:22     ` Miguel Ojeda
2025-06-05 17:30     ` Benno Lossin
2025-06-05 17:57       ` Christian Schrefl
2025-06-06  8:12         ` Benno Lossin [this message]
2025-05-11 18:21 ` [PATCH v4 2/3] rust: implement `Wrapper<T>` for `Opaque<T>` Christian Schrefl
2025-05-11 18:21 ` [PATCH v4 3/3] rust: use `UnsafePinned` in the implementation of `Opaque` Christian Schrefl
2025-05-19 18:26 ` [PATCH v4 0/3] rust: add `UnsafePinned` type Boqun Feng

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=DAFASAX0B837.1YDWHXPFR3JCT@kernel.org \
    --to=lossin@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=chrisi.schrefl@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=gerald.wisboeck@feather.ink \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=post@ralfj.de \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sky@sky9.dev \
    --cc=tmgross@umich.edu \
    /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.