linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Benno Lossin" <lossin@kernel.org>
To: "Danilo Krummrich" <dakr@kernel.org>
Cc: "Boqun Feng" <boqun.feng@gmail.com>, <gregkh@linuxfoundation.org>,
	<rafael@kernel.org>, <ojeda@kernel.org>, <alex.gaynor@gmail.com>,
	<gary@garyguo.net>, <bjorn3_gh@protonmail.com>,
	<a.hindborg@kernel.org>, <aliceryhl@google.com>,
	<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 v3 3/4] rust: devres: get rid of Devres' inner Arc
Date: Thu, 26 Jun 2025 15:09:30 +0200	[thread overview]
Message-ID: <DAWHMFWA2FZB.2III53VFXATS4@kernel.org> (raw)
In-Reply-To: <aF0xp4ZKP_a7cJsc@pollux>

On Thu Jun 26, 2025 at 1:40 PM CEST, Danilo Krummrich wrote:
> On Thu, Jun 26, 2025 at 01:07:25PM +0200, Danilo Krummrich wrote:
>> On Thu, Jun 26, 2025 at 12:27:18PM +0200, Benno Lossin wrote:
>> > On Thu Jun 26, 2025 at 12:01 PM CEST, Danilo Krummrich wrote:
>> > > On Wed, Jun 25, 2025 at 09:13:24PM -0700, Boqun Feng wrote:
>> > >> On Tue, Jun 24, 2025 at 11:54:01PM +0200, Danilo Krummrich wrote:
>> > >> [...]
>> > >> > +#[pin_data(PinnedDrop)]
>> > >> > +pub struct Devres<T> {
>> > >> 
>> > >> It makes me realize: I think we need to make `T` being `Send`? Because
>> > >> the devm callback can happen on a different thread other than
>> > >> `Devres::new()` and the callback may drop `T` because of revoke(), so we
>> > >> are essientially sending `T`. Alternatively we can make `Devres::new()`
>> > >> and its friend require `T` being `Send`.
>> > >> 
>> > >> If it's true, we need a separate patch that "Fixes" this.
>> > >
>> > > Indeed, that needs a fix.
>> > 
>> > Oh and we have no `'static` bound on `T` either... We should require
>> > that as well.
>> 
>> I don't think we actually need that, The Devres instance can't out-live a &T
>> passed into it. And the &T can't out-live the &Device<Bound>, hence we're
>> guaranteed that devres_callback() is never called because Devres::drop() will be
>> able successfully unregister the callback given that we're still in the
>> &Device<Bound> scope.
>> 
>> The only thing that could technically out-live the &Device<Bound> would be
>> &'static T, but that would obviously be fine.
>> 
>> Do I miss anything?
>
> Thinking a bit more about it, a similar argumentation is true for not needing
> T: Send. The only way to leave the &Device<Bound> scope and hence the thread
> would be to stuff the Devres into a ForeignOwnable container, no?

I think `T: Send` is required, since we drop the `T` in the other thread
when `devres_callback` is called from the device unbinding.

> Analogous to Benno asking for ForeignOwnable: 'static, should we also require
> ForeignOwnable: Send + Sync?

I don't think so, you could have a type that stores the pointer in C,
but only ever allows access from the same thread.

> Alternatively, the safety requirements of ForeignOwnable:::from_foreign() and
> ForeignOwnable::borrow() would need to cover this, which they currently they
> are not.

Oh right, yeah they should cover that.

---
Cheers,
Benno

  reply	other threads:[~2025-06-26 13:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-24 21:53 [PATCH v3 0/4] Improvements for Devres Danilo Krummrich
2025-06-24 21:53 ` [PATCH v3 1/4] rust: revocable: support fallible PinInit types Danilo Krummrich
2025-06-24 21:54 ` [PATCH v3 2/4] rust: devres: replace Devres::new_foreign_owned() Danilo Krummrich
2025-06-24 21:54 ` [PATCH v3 3/4] rust: devres: get rid of Devres' inner Arc Danilo Krummrich
2025-06-26  4:13   ` Boqun Feng
2025-06-26 10:01     ` Danilo Krummrich
2025-06-26 10:27       ` Benno Lossin
2025-06-26 11:07         ` Danilo Krummrich
2025-06-26 11:40           ` Danilo Krummrich
2025-06-26 13:09             ` Benno Lossin [this message]
2025-06-26 13:07           ` Benno Lossin
2025-06-26 19:47     ` Danilo Krummrich
2025-06-26 20:04       ` Boqun Feng
2025-06-24 21:54 ` [PATCH v3 4/4] rust: devres: implement register_release() Danilo Krummrich
2025-06-26 10:36   ` Benno Lossin
2025-06-26 11:15     ` Danilo Krummrich
2025-06-26 13:13       ` Benno Lossin
2025-06-26 14:02       ` Danilo Krummrich
2025-06-26 14:41         ` Benno Lossin
2025-06-26 15:32           ` Danilo Krummrich
2025-06-26 15:49             ` Danilo Krummrich
2025-06-26 23:13               ` 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=DAWHMFWA2FZB.2III53VFXATS4@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 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).