From: "Gary Guo" <gary@garyguo.net>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Alice Ryhl" <aliceryhl@google.com>,
"Lyude Paul" <lyude@redhat.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>
Cc: <linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH] rust: sync: fix safety comment for `Arc::from_raw`
Date: Wed, 23 Sep 2026 19:41:45 +0100 [thread overview]
Message-ID: <DLMX05RAZD0S.1EZ4L85L0T2HS@garyguo.net> (raw)
In-Reply-To: <20260923-aref-from-raw-safety-v1-1-e34f0da04145@kernel.org>
On Wed Sep 23, 2026 at 7:32 PM BST, Andreas Hindborg wrote:
> `Arc::from_raw` does not require `T: Send`. But if `Arc::from_raw` was
> executed on a different thread than `Arc::into_raw`, `T` must implement
> `Send` for the API to be sound. If this is not the case, ownership of `T`
> may be sent across a thread boundary even if `T: !Send`.
>
> Augment safety comment for `Arc::from_raw` to close this gap.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
> ---
> rust/kernel/sync/arc.rs | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index 8ae0fe6f19ec..06838ecf633c 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -276,6 +276,9 @@ pub fn as_ptr(this: &Self) -> *const T {
> ///
> /// `ptr` must have been returned by a previous call to [`Arc::into_raw`]. Additionally, it
> /// must not be called more than once for each previous call to [`Arc::into_raw`].
> + ///
> + /// If [`Arc::into_raw`] was executed on a different thread than the one executing
> + /// [`Arc::from_raw`], `T` must implement [`Send`].
This needs to be `Send + Sync`?
That said, I am not sure if we want to enumerate all cases where things can go
wrong. For example, would `Box::from_raw` need to mention that the type is
`Send` too? `ARef::from_raw`? `ForeignOwnable::from_foreign/borrow/borrow_mut`
all have to mention about this, too?
Best,
Gary
> pub unsafe fn from_raw(ptr: *const T) -> Self {
> // SAFETY: The caller promises that this pointer originates from a call to `into_raw` on an
> // `Arc` that is still valid.
>
> ---
> base-commit: df2908090cda368b01ff43709f51890076c56157
> change-id: 20260923-aref-from-raw-safety-78a7283627fa
>
> Best regards,
> --
> Andreas Hindborg <a.hindborg@kernel.org>
next prev parent reply other threads:[~2026-09-23 18:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 18:32 Andreas Hindborg
2026-09-23 18:41 ` Gary Guo [this message]
2026-09-23 20:34 ` Andreas Hindborg
2026-09-23 20:38 ` 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=DLMX05RAZD0S.1EZ4L85L0T2HS@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.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
all inboxes | Powered by JetHome®