rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Tamir Duberstein" <tamird@gmail.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
	"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>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Joel Becker" <jlbec@evilplan.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
	"Waiman Long" <longman@redhat.com>,
	"Fiona Behrens" <me@kloenk.dev>,
	"Charalampos Mitrodimas" <charmitro@posteo.net>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/4] rust: sync: change `<Arc<T> as ForeignOwnable>::PointedTo` to `T`
Date: Thu, 27 Feb 2025 19:26:28 +0100	[thread overview]
Message-ID: <87ikovp7l7.fsf@kernel.org> (raw)
In-Reply-To: <87o6ynp7nr.fsf@kernel.org> (Andreas Hindborg's message of "Thu, 27 Feb 2025 19:24:56 +0100")

Andreas Hindborg <a.hindborg@kernel.org> writes:

> "Tamir Duberstein" <tamird@gmail.com> writes:
>
>> On Thu, Feb 27, 2025 at 7:37 AM Andreas Hindborg <a.hindborg@kernel.org> wrote:
>>>
>>> Using `ArcInner` as `PoinedTo` in the `ForeignOwnable` implementation for
>>> `Arc` is a bit unfortunate. Using `T` as `PointedTo` does not remove any
>>> functionality, but allows `ArcInner` to be private. Further, it allows
>>> downstream users to write code that is generic over `Box` and `Arc`, when
>>> downstream users need access to `T` after calling `into_foreign`.
>>>
>>> Reviewed-by: Fiona Behrens <me@kloenk.dev>
>>> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
>>> Tested-by: Daniel Almeida <daniel.almeida@collabora.com>
>>> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
>>> ---
>>>
>>> This patch is a dependency for Rust `configfs` abstractions. It allows both
>>> `Box` and `Arc` to be used as pointer types in the `configfs` hierarchy.
>>> ---
>>>  rust/kernel/sync/arc.rs | 21 ++++++++++++++++-----
>>>  1 file changed, 16 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
>>> index dfe4abf82c25..3d77a31e116f 100644
>>> --- a/rust/kernel/sync/arc.rs
>>> +++ b/rust/kernel/sync/arc.rs
>>> @@ -143,7 +143,7 @@ pub struct Arc<T: ?Sized> {
>>>  #[doc(hidden)]
>>>  #[pin_data]
>>>  #[repr(C)]
>>> -pub struct ArcInner<T: ?Sized> {
>>> +struct ArcInner<T: ?Sized> {
>>>      refcount: Opaque<bindings::refcount_t>,
>>>      data: T,
>>>  }
>>> @@ -345,18 +345,25 @@ pub fn into_unique_or_drop(self) -> Option<Pin<UniqueArc<T>>> {
>>>
>>>  // SAFETY: The `into_foreign` function returns a pointer that is well-aligned.
>>>  unsafe impl<T: 'static> ForeignOwnable for Arc<T> {
>>> -    type PointedTo = ArcInner<T>;
>>> +    type PointedTo = T;
>>>      type Borrowed<'a> = ArcBorrow<'a, T>;
>>>      type BorrowedMut<'a> = Self::Borrowed<'a>;
>>>
>>>      fn into_foreign(self) -> *mut Self::PointedTo {
>>> -        ManuallyDrop::new(self).ptr.as_ptr()
>>> +        let this = ManuallyDrop::new(self).ptr.as_ptr();
>>> +        // SAFETY: `x` is a valid pointer to `Self` so the projection below is
>>> +        // in bounds of the allocation.
>>
>> Isn't the unsafe bit `*this`, which is what this comment should
>> justify?
>
> Yes, not sure what the origin of that name is. Good catch.

Referring to the `x` part here.


Best regards,
Andreas Hindborg



  reply	other threads:[~2025-02-27 18:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <41ZevHqZJoE8_8iyJejt99BGZVDfljWV3ycSSRkSxqBOEz-876GX03-R0Ca2z0SsGNhE4mIIV-6EegJL3ETAVw==@protonmail.internalid>
2025-02-27 12:35 ` [PATCH v5 0/4] rust: configfs abstractions Andreas Hindborg
2025-02-27 12:35   ` [PATCH v5 1/4] rust: sync: change `<Arc<T> as ForeignOwnable>::PointedTo` to `T` Andreas Hindborg
2025-02-27 13:48     ` Tamir Duberstein
2025-02-27 16:34       ` Miguel Ojeda
2025-02-27 16:36         ` Tamir Duberstein
2025-02-27 18:24       ` Andreas Hindborg
2025-02-27 18:26         ` Andreas Hindborg [this message]
2025-05-01  7:13     ` Alice Ryhl
2025-02-27 12:35   ` [PATCH v5 2/4] rust: configfs: introduce rust support for configfs Andreas Hindborg
2025-02-27 12:35   ` [PATCH v5 3/4] rust: configfs: add a sample demonstrating configfs usage Andreas Hindborg
2025-02-27 12:35   ` [PATCH v5 4/4] MAINTAINERS: add entry for configfs Rust abstractions Andreas Hindborg
2025-03-18 11:14   ` [PATCH v5 0/4] rust: configfs abstractions 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=87ikovp7l7.fsf@kernel.org \
    --to=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=charmitro@posteo.net \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=jlbec@evilplan.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=me@kloenk.dev \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@gmail.com \
    --cc=tmgross@umich.edu \
    --cc=will@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).