From: Benno Lossin <benno.lossin@proton.me>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] rust: sync: add `ArcBorrow::from_raw`
Date: Mon, 11 Mar 2024 15:04:27 +0000 [thread overview]
Message-ID: <4aef25d7-5135-4444-a461-fdef02f969e0@proton.me> (raw)
In-Reply-To: <CAH5fLggWwOLR0c-MR_p=Tw4vS8RHAEhJZsMLyx9rhYo=eVu+9g@mail.gmail.com>
On 3/11/24 09:58, Alice Ryhl wrote:
> On Sat, Mar 9, 2024 at 1:56 PM Benno Lossin <benno.lossin@proton.me> wrote:
>>> + /// Creates an [`ArcBorrow`] to an [`Arc`] that has previously been deconstructed with
>>> + /// [`Arc::into_raw`].
>>> + ///
>>> + /// # Safety
>>> + ///
>>> + /// * The provided pointer must originate from a call to [`Arc::into_raw`].
>>> + /// * For the duration of the lifetime annotated on this `ArcBorrow`, the reference count must
>>> + /// not hit zero.
>>> + /// * For the duration of the lifetime annotated on this `ArcBorrow`, there must not be a
>>> + /// [`UniqueArc`] reference to this value.
>>
>> I am a bit confused, this feels to me like it should be guaranteed by
>> `UniqueArc` and not by this function. Currently there is not even a way
>> of getting a `*const T` from a `UniqueArc`.
>> So I think we can remove this requirement and instead have the
>> requirement for creating `UniqueArc` that not only the refcount is
>> exactly 1, but also that no `ArcBorrow` exists.
>
> If you combine this with `into_unique_or_drop` that is introduced in
> the next patch of this series, then you could perform these
> operations:
>
> * Arc::into_raw
> * ArcBorrow::from_raw
> * Arc::from_raw
> * Arc::into_unique_or_drop
> * And then use the ArcBorrow
>
> If we drop the final safety requirement from `ArcBorrow::from_raw`,
> then the above would be allowed. The refcount does not hit zero at any
> point during these operations. The only unsafe functions are
> Arc::into_raw, Arc::from_raw, and ArcBorrow::from_raw, so this safety
> requirement must go on one of them. It seems to me that, out of these,
> ArcBorrow::from_raw is the most appropriate choice.
>
> Thoughts?
I see, it is a bit unfortunate that we have to put the constraint onto
`ArcBorrow::from_raw`, but I also do not see a better place. Thus:
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
--
Cheers,
Benno
next prev parent reply other threads:[~2024-03-11 15:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 13:00 [PATCH v2 0/2] Arc methods for linked list Alice Ryhl
2024-02-28 13:00 ` [PATCH v2 1/2] rust: sync: add `ArcBorrow::from_raw` Alice Ryhl
2024-03-09 12:55 ` Benno Lossin
2024-03-11 8:58 ` Alice Ryhl
2024-03-11 15:04 ` Benno Lossin [this message]
2024-02-28 13:00 ` [PATCH v2 2/2] rust: sync: add `Arc::into_unique_or_drop` Alice Ryhl
2024-03-09 13:02 ` Benno Lossin
2024-03-11 9:03 ` Alice Ryhl
2024-03-11 15:15 ` Benno Lossin
2024-03-11 15:35 ` Alice Ryhl
2024-03-11 15:45 ` Alice Ryhl
2024-03-11 15:47 ` Benno Lossin
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=4aef25d7-5135-4444-a461-fdef02f969e0@proton.me \
--to=benno.lossin@proton.me \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
/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).