[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aF0aiHhCuHjLFIij@pollux>
Date: Thu, 26 Jun 2025 12:01:44 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Boqun Feng <boqun.feng@...il.com>
Cc: gregkh@...uxfoundation.org, rafael@...nel.org, ojeda@...nel.org,
alex.gaynor@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
lossin@...nel.org, a.hindborg@...nel.org, aliceryhl@...gle.com,
tmgross@...ch.edu, david.m.ertman@...el.com, ira.weiny@...el.com,
leon@...nel.org, kwilczynski@...nel.org, bhelgaas@...gle.com,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-pci@...r.kernel.org
Subject: Re: [PATCH v3 3/4] rust: devres: get rid of Devres' inner Arc
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.
> (Imagine a Devres<MutexGuard>)
>
> > + dev: ARef<Device>,
> > + /// Pointer to [`Self::devres_callback`].
> > + ///
> > + /// Has to be stored, since Rust does not guarantee to always return the same address for a
> > + /// function. However, the C API uses the address as a key.
> > + callback: unsafe extern "C" fn(*mut c_void),
> > + /// Contains all the fields shared with [`Self::callback`].
> > + // TODO: Replace with `UnsafePinned`, once available.
>
> nit: Maybe also reference the `drop_in_place()` in Devres::drop() as
> well, because once we use `UnsafePinned`, we don't need that
> `drop_in_place()`. But not a big deal, just trying to help the people
> who would handle that "TODO" ;-)
Makes sense, the same is true for the Send and Sync impls, I think. AFAIK,
UnsafePinned should cover them automatically.
Powered by blists - more mailing lists