[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aFLb9CcL5W-y_TBl@pollux>
Date: Wed, 18 Jun 2025 17:32:04 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Matthew Maurer <mmaurer@...gle.com>
Cc: Alice Ryhl <aliceryhl@...gle.com>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Sami Tolvanen <samitolvanen@...gle.com>,
Timur Tabi <ttabi@...dia.com>, Benno Lossin <lossin@...nel.org>,
linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v6 3/5] rust: debugfs: Support arbitrary owned backing
for File
On Wed, Jun 18, 2025 at 08:00:51AM -0700, Matthew Maurer wrote:
> > We may want to consider using the ForeignOwnable trait here instead. The
>
> I was considering trying to switch over to `StableDeref`-like trait
> [1] in a follow-up patchset. The core property I need is that moving
> the `D` cannot result in the pointer it would `deref` to changing.
>
> The problem with `ForeignOwnable` is that it forbids the user from
> passing in a `Box<dyn Foo>`, because that doesn't fit in a `void*` A
> `StableDeref` version would not have this issue. I agree that
> `ForeignOwnable` would be a strict upgrade to what I have now, since a
> user can still pass in a `Box<Box<dyn Foo>>` and have it work with
> `ForeignOwnable`, and if we ever added `StableDeref`, then
> `ForeignOwnable` would have a blanket impl for it.
>
> I'll send a new version using `ForeignOwnable`, and we can consider
> the `StableDeref` version in the future.
Yes, please do that for now. It's rather common case that drivers want to expose
reference counted data, i.e. an Arc, through debugfs and having to go through
the indirection with an additional Box isn't quite nice.
> [1]: https://docs.rs/gimli/latest/gimli/trait.StableDeref.html
>
>
> > trait is implemented by anything that can be converted to/from a void
> > pointer, so you can:
> >
> > * When creating the file, convert it to a void pointer that you store in
> > File and pass to debugfs_create_file_full.
> > * When displaying the file, create a borrowed version of the void
> > pointer and display that.
> > * When freeing the File, convert the void pointer back into an owned
> > value and drop it.
> >
> > For cases where a box really is necessary, the user can create a box and
> > pass it themselves. But if the user already has a pointer type (e.g. and
> > Arc<T> or &'static T) then they can pass that pointer directly and the
> > pointer is stored as a void pointer without the Box indirection.
> >
> > Alice
Powered by blists - more mailing lists