Re: [PATCH v8 4/6] rust: debugfs: Support arbitrary owned backing for File

From: Greg Kroah-Hartman
Date: Thu Jul 03 2025 - 08:45:18 EST


On Thu, Jul 03, 2025 at 02:34:13PM +0200, Benno Lossin wrote:
> On Thu Jul 3, 2025 at 1:41 PM CEST, Greg Kroah-Hartman wrote:
> > On Thu, Jul 03, 2025 at 12:54:18PM +0200, Alice Ryhl wrote:
> >> On Thu, Jul 3, 2025 at 12:33 PM Benno Lossin <lossin@xxxxxxxxxx> wrote:
> >> > How would your example look like with the current approach? IIUC, it
> >> > also wouldn't work, because the debugfs data can't be mutated?
> >>
> >> I would store a bunch of `File<Arc<Process>>` instances somewhere.
> >> Each one has a closure that takes the spinlock and prints the
> >> appropriate value.
>
> But you could also do that with the pin-init design?
>
> > Ok, I think we need to see some "real" examples here of the api in use
> > before figuring it out further as I'm totally confused :)
>
> Agreed :)
>
> > Yes, we need to be able to have a debugfs file callback handle a mutable
> > structure in order to lock things correctly.
>
> To me this seems orthogonal to storing the value in-place or in a
> `ForeignOwnable`.
>
> > We also need to have it be mutable so that it can MODIFY the value
> > (everyone seems to forget that debugfs allows that...)
>
> Well that changes things a lot IMO... How does the C side usually handle
> synchronization here? Does the driver decide that the structure exposed
> to debugfs is locked with eg a spinlock and then in the debugfs callback
> they just lock the same one?

It does whatever it feels like, so both are valid uses.

Sometimes a lock is involved, sometimes not. Remember this is debugfs,
the only rule for it is "there are no rules except it requires root
permissions to access".

thanks,

greg k-h