From: "Benno Lossin" <lossin@kernel.org>
To: "Boqun Feng" <boqun.feng@gmail.com>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
<rafael@kernel.org>, "Miguel Ojeda" <ojeda@kernel.org>,
<alex.gaynor@gmail.com>, "Gary Guo" <gary@garyguo.net>,
<bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>, <david.m.ertman@intel.com>,
<ira.weiny@intel.com>, <leon@kernel.org>,
<kwilczynski@kernel.org>, <bhelgaas@google.com>,
<rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-pci@vger.kernel.org>
Subject: Re: [PATCH v4 4/5] rust: types: ForeignOwnable: Add type Target
Date: Fri, 27 Jun 2025 11:05:44 +0200 [thread overview]
Message-ID: <DAX72CI4S0JF.1GCUWSOEO3H7W@kernel.org> (raw)
In-Reply-To: <44579f29-a8a4-41cb-97ea-5ab7711e4d2a@app.fastmail.com>
On Fri Jun 27, 2025 at 1:55 AM CEST, Boqun Feng wrote:
> On Thu, Jun 26, 2025, at 4:45 PM, Boqun Feng wrote:
>> On Thu, Jun 26, 2025, at 4:36 PM, Benno Lossin wrote:
>>> On Fri Jun 27, 2025 at 1:21 AM CEST, Boqun Feng wrote:
>>>> On Thu, Jun 26, 2025, at 4:17 PM, Benno Lossin wrote:
>>>>> On Thu Jun 26, 2025 at 10:20 PM CEST, Boqun Feng wrote:
>>>>>> On Thu, Jun 26, 2025 at 10:00:42PM +0200, Danilo Krummrich wrote:
>>>>>>> diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
>>>>>>> index 3958a5f44d56..74c787b352a9 100644
>>>>>>> --- a/rust/kernel/types.rs
>>>>>>> +++ b/rust/kernel/types.rs
>>>>>>> @@ -27,6 +27,9 @@
>>>>>>> /// [`into_foreign`]: Self::into_foreign
>>>>>>> /// [`PointedTo`]: Self::PointedTo
>>>>>>> pub unsafe trait ForeignOwnable: Sized {
>>>>>>> + /// The payload type of the foreign-owned value.
>>>>>>> + type Target;
>>>>>>
>>>>>> I think `ForeignOwnable` also implies a `T` maybe get dropped via a
>>>>>> pointer from `into_foreign()`. Not sure it's worth mentioning though.
>>>>>
>>>>> What? How would that happen?
>>>>
>>>> The owner of the pointer can do from_foreign() and eventually drop
>>>> the ForeignOwnable, hence dropping T.
>>>
>>> I'm confused, you said `into_foreign` above. I don't think any sensible
>>> ForeignOwnable implementation will drop a T in any of its functions.
>>>
>>
>> A KBox<T> would drop T when it gets dropped, no?
>> A Arc<T> would drop T when it gets dropped if it’s the last refcount.
>>
>> I was trying to say “ForeignOwnable::drop() may implies Target::drop()”,
>> that’s what a “payload” means. Maybe that I used “T” instead of “Target”
>> in the original message caused confusion?
Ah now I understand what you are saying. Your mentioning of
`into_foreign` and `from_foreign` confused me. Yes a `ForeignOwnable`
may drop a `T`/`Target` in its own drop function. But I don't think we
need to document that.
> The point is whichever receives the pointer from a into_foreign()
> would owns the Target, because it can from_foreign() and
> drop the ForeignOwnable. So for example, if the pointer can
> be passed across threads, that means Target needs to be Send.
We should solve this in a different manner. Document the `Send` & `Sync`
requirements on `into_foreign`. So when you turn a `P: ForeignOwnable`
that is `!Send` into a raw pointer, you are not allowed to call
`from_foreign` on a different thread.
If `P: !Sync` then you're not allowed to call `borrow[_mut]` on the
pointer from two different threads (ie only the one that is currently
owning the value is allowed to call that).
---
Cheers,
Benno
next prev parent reply other threads:[~2025-06-27 9:05 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-26 20:00 [PATCH v4 0/5] Improvements for Devres Danilo Krummrich
2025-06-26 20:00 ` [PATCH v4 1/5] rust: revocable: support fallible PinInit types Danilo Krummrich
2025-06-26 20:00 ` [PATCH v4 2/5] rust: devres: replace Devres::new_foreign_owned() Danilo Krummrich
2025-06-26 20:00 ` [PATCH v4 3/5] rust: devres: get rid of Devres' inner Arc Danilo Krummrich
2025-06-26 20:14 ` Boqun Feng
2025-06-26 23:33 ` Benno Lossin
2025-06-26 23:53 ` Danilo Krummrich
2025-06-27 9:01 ` Benno Lossin
2025-06-27 19:59 ` Benno Lossin
2025-06-26 20:00 ` [PATCH v4 4/5] rust: types: ForeignOwnable: Add type Target Danilo Krummrich
2025-06-26 20:20 ` Boqun Feng
2025-06-26 23:17 ` Benno Lossin
2025-06-26 23:21 ` Boqun Feng
2025-06-26 23:36 ` Benno Lossin
2025-06-26 23:45 ` Boqun Feng
2025-06-26 23:55 ` Boqun Feng
2025-06-27 9:05 ` Benno Lossin [this message]
2025-06-26 23:22 ` Benno Lossin
2025-06-27 19:53 ` Miguel Ojeda
2025-07-01 11:49 ` Alice Ryhl
2025-06-26 20:00 ` [PATCH v4 5/5] rust: devres: implement register_release() Danilo Krummrich
2025-06-26 20:37 ` Boqun Feng
2025-06-26 20:48 ` Danilo Krummrich
2025-06-26 21:16 ` Boqun Feng
2025-06-26 21:20 ` Danilo Krummrich
2025-06-26 21:21 ` Boqun Feng
2025-06-26 23:19 ` Benno Lossin
2025-06-27 22:06 ` Boqun Feng
2025-06-28 6:06 ` Benno Lossin
2025-06-28 6:38 ` Boqun Feng
2025-06-28 7:53 ` Benno Lossin
2025-06-28 9:58 ` Danilo Krummrich
2025-06-28 12:13 ` Benno Lossin
2025-06-28 12:32 ` Danilo Krummrich
2025-06-29 15:11 ` [PATCH v4 0/5] Improvements for Devres Danilo Krummrich
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=DAX72CI4S0JF.1GCUWSOEO3H7W@kernel.org \
--to=lossin@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=david.m.ertman@intel.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=ira.weiny@intel.com \
--cc=kwilczynski@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--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.