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

From: Benno Lossin
Date: Thu Jul 03 2025 - 08:35:08 EST


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?

---
Cheers,
Benno

> So how about a platform driver that exposes values read from a platform
> device (i.e. a soc info driver), that also includes a
> local-to-the-device data structure that can be locked and modified?
> That should cover all the use cases that I can think of at the moment.
>
> thanks,
>
> greg k-h