MAINTAINERS | 7 + rust/bindings/bindings_helper.h | 1 + rust/helpers/mutex.c | 5 + rust/kernel/configfs.rs | 938 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 2 + rust/kernel/sync/arc.rs | 21 +- samples/rust/Kconfig | 11 + samples/rust/Makefile | 1 + samples/rust/rust_configfs.rs | 179 ++++++++ 9 files changed, 1160 insertions(+), 5 deletions(-)
This series adds a safe Rust API that allows Rust modules to interface
the `configfs` machinery.
The series contains an example for the samples folder to demonstrate
usage of the API. As such, there is no inline example in the
documentation.
The last patch adds a maintainer entry for the Rust configfs
abstractions, to make it absolutely clear that I will commit to maintain
these abstractions, if required. Feel free to drop this patch if this is
not required.
The series is a dependency of `rnull`, the Rust null block driver.
Please see [1] for initial `configfs` support in `rnull`.
[1] https://github.com/metaspace/linux/tree/9ac53130f5fb05b9b3074fa261b445b8fde547dd/drivers/block/rnull
---
Joel, Christoph: please let me know how you would like to proceed with
maintenance and whether you would like to pick these patches through the
configfs tree or not.
To: Danilo Krummrich <dakr@kernel.org>
To: Miguel Ojeda <ojeda@kernel.org>
To: Alex Gaynor <alex.gaynor@gmail.com>
To: Boqun Feng <boqun.feng@gmail.com>
To: Gary Guo <gary@garyguo.net>
To: Björn Roy Baron <bjorn3_gh@protonmail.com>
To: Benno Lossin <benno.lossin@proton.me>
To: Alice Ryhl <aliceryhl@google.com>
To: Trevor Gross <tmgross@umich.edu>
To: Joel Becker <jlbec@evilplan.org>
To: Christoph Hellwig <hch@lst.de>
To: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@redhat.com>
To: Will Deacon <will@kernel.org>
To: Waiman Long <longman@redhat.com>
To: Fiona Behrens <me@kloenk.dev>
To: Charalampos Mitrodimas <charmitro@posteo.net>
Cc: rust-for-linux@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
Changes in v3:
- Allow trailing commas in invocation of `configfs_attrs!`.
- Use a more suitable C initialization function when initializing `Subsystem`.
- Split sample into separate patch.
- Add an inline example.
The remaining changes in this version are style fixes, documentation
improvements and typo fixes. They are enumerated below:
- Consolidate `paste` macro calls.
- Do not hard code page size in example.
- Remove prefix of `c_str!` in sample.
- Use a more descriptive variable name in `into_foreign`.
- Improve code formatting in macros invocations.
- Add comment related to null terminator in `configfs_attrs!`
- Move attributes below docstrings.
- Remove a rogue todo.
- Remove trait bound from struct definition `GroupOperationsVTable`.
- Remove `as _` casts.
- Remove `GroupOprations::Parent` associated type.
- General documentation improvements.
- Explicitly use `ArcBorrow` for `drop_item` parameter type.
- Add a comment describing expansion to a call to `Attribute::add`.
- Add a comment explaining bound check in `Attribute::add`.
- Link to v2: https://lore.kernel.org/r/20250207-configfs-v2-0-f7a60b24d38e@kernel.org
Changes in v2:
- Remove generalization over pointer type and enforce use of `Arc`.
- Use type system to enforce connection between `ItemType` and
`Subsystem` or `Group`. Differentiate construction of vtables on this
type difference.
- Move drop logic of child nodes from parent to child.
- Pick `ForeignOwnable::PointedTo` patch as dependency instead of
including it here.
- Fix some rustdoc warnings.
- Use CamelCase for generic type parameter declaration.
- Destroy mutex in `Subsystem::drop`.
- Move `GroupOperationsVTable` struct definition next to implementation.
- Rebase on v6.14-rc1.
- Link to v1: https://lore.kernel.org/r/20250131-configfs-v1-0-87947611401c@kernel.org
---
Andreas Hindborg (4):
rust: sync: change `<Arc<T> as ForeignOwnable>::PointedTo` to `T`
rust: configfs: introduce rust support for configfs
rust: configfs: add a sample demonstrating configfs usage
MAINTAINERS: add entry for configfs Rust abstractions
MAINTAINERS | 7 +
rust/bindings/bindings_helper.h | 1 +
rust/helpers/mutex.c | 5 +
rust/kernel/configfs.rs | 938 ++++++++++++++++++++++++++++++++++++++++
rust/kernel/lib.rs | 2 +
rust/kernel/sync/arc.rs | 21 +-
samples/rust/Kconfig | 11 +
samples/rust/Makefile | 1 +
samples/rust/rust_configfs.rs | 179 ++++++++
9 files changed, 1160 insertions(+), 5 deletions(-)
---
base-commit: 379487e17ca406b47392e7ab6cf35d1c3bacb371
change-id: 20250131-configfs-b888cd82d84a
prerequisite-patch-id: 275efe8e08839e3a0de28ed26e8de80be9852024
Best regards,
--
Andreas Hindborg <a.hindborg@kernel.org>
Hi Andreas,
> On 18 Feb 2025, at 09:57, Andreas Hindborg <a.hindborg@kernel.org> wrote:
>
> This series adds a safe Rust API that allows Rust modules to interface
> the `configfs` machinery.
>
> The series contains an example for the samples folder to demonstrate
> usage of the API. As such, there is no inline example in the
> documentation.
>
> The last patch adds a maintainer entry for the Rust configfs
> abstractions, to make it absolutely clear that I will commit to maintain
> these abstractions, if required. Feel free to drop this patch if this is
> not required.
>
> The series is a dependency of `rnull`, the Rust null block driver.
> Please see [1] for initial `configfs` support in `rnull`.
>
> [1] https://github.com/metaspace/linux/tree/9ac53130f5fb05b9b3074fa261b445b8fde547dd/drivers/block/rnull
>
I am trying to test this before reviewing, but I get this error:
```
error[E0308]: mismatched types
--> linux/rust/kernel/miscdevice.rs:300:62
|
300 | let device = unsafe { <T::Ptr as ForeignOwnable>::borrow(private) };
| ---------------------------------- ^^^^^^^ expected `*mut <... as ForeignOwnable>::PointedTo`, found `*mut c_void`
| |
| arguments to this function are incorrect
|
= note: expected raw pointer `*mut <<T as miscdevice::MiscDevice>::Ptr as types::ForeignOwnable>::PointedTo`
found raw pointer `*mut ffi::c_void`
= help: consider constraining the associated type `<<T as miscdevice::MiscDevice>::Ptr as types::ForeignOwnable>::PointedTo` to `ffi::c_void` or calling a method that returns `<<T as miscdevice::MiscDevice>::Ptr as types::ForeignOwnable>::PointedTo`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: associated function defined here
--> /home/dwls/dev/linux/rust/kernel/types.rs:98:15
|
98 | unsafe fn borrow<'a>(ptr: *mut Self::PointedTo) -> Self::Borrowed<'a>;
| ^^^^^^
error: aborting due to 1 previous error
```
— Daniel
"Daniel Almeida" <daniel.almeida@collabora.com> writes:
> Hi Andreas,
>
>> On 18 Feb 2025, at 09:57, Andreas Hindborg <a.hindborg@kernel.org> wrote:
>>
>> This series adds a safe Rust API that allows Rust modules to interface
>> the `configfs` machinery.
>>
>> The series contains an example for the samples folder to demonstrate
>> usage of the API. As such, there is no inline example in the
>> documentation.
>>
>> The last patch adds a maintainer entry for the Rust configfs
>> abstractions, to make it absolutely clear that I will commit to maintain
>> these abstractions, if required. Feel free to drop this patch if this is
>> not required.
>>
>> The series is a dependency of `rnull`, the Rust null block driver.
>> Please see [1] for initial `configfs` support in `rnull`.
>>
>> [1] https://github.com/metaspace/linux/tree/9ac53130f5fb05b9b3074fa261b445b8fde547dd/drivers/block/rnull
>>
>
> I am trying to test this before reviewing, but I get this error:
>
>
> ```
> error[E0308]: mismatched types
> --> linux/rust/kernel/miscdevice.rs:300:62
> |
> 300 | let device = unsafe { <T::Ptr as ForeignOwnable>::borrow(private) };
> | ---------------------------------- ^^^^^^^ expected `*mut <... as ForeignOwnable>::PointedTo`, found `*mut c_void`
> | |
> | arguments to this function are incorrect
> |
> = note: expected raw pointer `*mut <<T as miscdevice::MiscDevice>::Ptr as types::ForeignOwnable>::PointedTo`
> found raw pointer `*mut ffi::c_void`
> = help: consider constraining the associated type `<<T as miscdevice::MiscDevice>::Ptr as types::ForeignOwnable>::PointedTo` to `ffi::c_void` or calling a method that returns `<<T as miscdevice::MiscDevice>::Ptr as types::ForeignOwnable>::PointedTo`
> = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
> note: associated function defined here
> --> /home/dwls/dev/linux/rust/kernel/types.rs:98:15
> |
> 98 | unsafe fn borrow<'a>(ptr: *mut Self::PointedTo) -> Self::Borrowed<'a>;
> | ^^^^^^
>
> error: aborting due to 1 previous error
> ```
Thanks for testing! It seems there is a bug in the patch "rust: sync:
change `<Arc<T> as ForeignOwnable>::PointedTo` to `T`". If you would
like to test now, could you either:
- add `.cast()` on `private` in miscdevice.rs:300
- or drop patch 1/4 and pick [1] as a dependency instead
- or build with `CONFIG_COMPAT=n`
Or wait for me to send a new version where I add a dependency on the
fixed patch.
Best regards,
Andreas Hindborg
[1] https://lore.kernel.org/all/20250218-rust-xarray-bindings-v17-0-f3a99196e538@gmail.com/
© 2016 - 2025 Red Hat, Inc.