[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DB7US8G7ISG0.20430M3P7I0K0@kernel.org>
Date: Wed, 09 Jul 2025 23:47:38 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Matthew Maurer" <mmaurer@...gle.com>
Cc: "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>,
"Alice Ryhl" <aliceryhl@...gle.com>, "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 v9 0/5] rust: DebugFS Bindings
On Wed Jul 9, 2025 at 9:09 PM CEST, Matthew Maurer wrote:
> This series provides safe DebugFS bindings for Rust, with a sample
> module using them.
>
> Example interaction with the sample driver:
I understand what you're trying to do here, i.e. showcase that values exported
via debugfs can be altered.
The problem is that the current abstractions only implement read(), but not
write().
So, to work around this you create multiple files for a single value: one that
only prints the value on read() and one that modifies the value on read().
For instance, you have a value counter (AtomicUsize), which is exported as:
$(DEBUGFS_ROOT)/counter
$(DEBUGFS_ROOT)/inc_counter
where
$ cat $(DEBUGFS_ROOT)/counter
prints the value and
$ cat $(DEBUGFS_ROOT)/inc_counter
increments the counter.
While this is technically not wrong it's providing bad guidance to people.
Instead this should be something along the lines of:
$ cat $(DEBUGFS_ROOT)/counter
0
$ echo "++" > $(DEBUGFS_ROOT)/counter
$ cat $(DEBUGFS_ROOT)/counter
1
$ echo "42" > $(DEBUGFS_ROOT)/counter
$ cat $(DEBUGFS_ROOT)/counter
42
Given that the abstraction doesn't support write() yet, just don't try to work
around it.
If you really want to showcase changing values, you can, for instance, create a
workqueue inside the sample driver and modify the counter periodically.
We really should not teach people to modify values by read() instead of write().
Also, without this workaround there shouldn't be a reason to export the exact
same value twice, i.e. no need for File<File<AtomicUsize>>.
- Danilo
Powered by blists - more mailing lists