Skip to contentSkip to conversation

rust: configfs abstractions

PATCH Superseded Andreas Hindborg 1 participant 4 messages May 5, 2025

Subsystems (3)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Andreas Hindborg

author maintainer
#0 lore raw

v7 cover rust: configfs abstractions

Add a safe Rust API that allows Rust modules to interface the configfs machinery.

Add an example for the samples folder to demonstrate usage of the API.

Add a maintainer entry for the Rust configfs abstractions in the last patch, to make it absolutely clear that I will commit to maintain these abstractions, if 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

---
Changes in v7:
- Update documentation: Consistently apply code spans, add inter-doc links, fix typos and improve indentation.
- Use a const block to verify attribute index.
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- Use &raw const and &raw mut instead of addr_of! and addr_of_mut! macros.
- Drop use of ForeignOwnable.
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Remove as _ casts.
- Document ID type parameter of AttributeOperations.
- Add documentation at macro call sites in example.
- Add example expansion of configfs_attrs!.
- Move trait bound in AttributeList::add
- Improve safety requirement for AttributeList::new.
- Fix a copy/paste error in print in sample.
- Clarify use of {} for empty struct in sample.
- Improve documentation for AttributeList.
- Remove kernel:: prefix from container_of! invocation.
- Reword safety comment in get_group_data.
- Correct commit message in relation to unstable feature additions.
- Use imperative language in commit messages.
- Consistently capitalize the word "Rust" in commit messages.
- Explain that "drop" in GroupOperations::drop_item is not related to Rust drop.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Fix a build issue by depending on v18 of "rust: types: add ForeignOwnable::PointedTo"
- Link to v3: https://lore.kernel.org/r/[email protected]

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/[email protected]

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/[email protected]

---
Andreas Hindborg (3):
rust: configfs: introduce rust support for configfs
rust: configfs: add a sample demonstrating configfs usage
MAINTAINERS: add configfs Rust abstractions

 MAINTAINERS                     |    2 +
 rust/bindings/bindings_helper.h |    1 +
 rust/helpers/mutex.c            |    5 +
 rust/kernel/configfs.rs         | 1046 +++++++++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs              |    2 +
 samples/rust/Kconfig            |   11 +
 samples/rust/Makefile           |    1 +
 samples/rust/rust_configfs.rs   |  192 +++++++
 8 files changed, 1260 insertions(+)

---
base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e
change-id: 20250131-configfs-b888cd82d84a

Best regards,

Signature · 1 line
Andreas Hindborg <[email protected]>
author maintainer
#1 lore raw

PATCH v7 1/3 rust: configfs: introduce rust support for configfs

Add a Rust API for configfs, thus allowing Rust modules to use configfs for configuration. Make the implementation a shim on top of the C configfs implementation, allowing safe use of the C infrastructure from Rust.

---

This patch is a direct dependency for rnull, the rust null block driver.

---
 rust/bindings/bindings_helper.h |    1 +
 rust/helpers/mutex.c            |    5 +
 rust/kernel/configfs.rs         | 1046 +++++++++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs              |    2 +
 4 files changed, 1054 insertions(+)
rust/bindings/bindings_helper.h +1 -0
index ab37e1d35c70..1a532b83a9af 100644
@@ -10,6 +10,7 @@
 #include <linux/blk-mq.h>
 #include <linux/blk_types.h>
 #include <linux/blkdev.h>
+#include <linux/configfs.h>
 #include <linux/cpumask.h>
 #include <linux/cred.h>
 #include <linux/device/faux.h>
rust/helpers/mutex.c +5 -0
index 06575553eda5..3e9b910a88e9 100644
@@ -17,3 +17,8 @@ void rust_helper_mutex_assert_is_held(struct mutex *mutex)
 {
 	lockdep_assert_held(mutex);
 }
+
+void rust_helper_mutex_destroy(struct mutex *lock)
+{
+	mutex_destroy(lock);
+}
rust/kernel/configfs.rs new file +1046 -0

1,046 lines not on this page · raw message

rust/kernel/lib.rs +2 -0
index de07aadd1ff5..bcbf5026449d 100644
@@ -42,6 +42,8 @@
 pub mod block;
 #[doc(hidden)]
 pub mod build_assert;
+#[cfg(CONFIG_CONFIGFS_FS)]
+pub mod configfs;
 pub mod cred;
 pub mod device;
 pub mod device_id;
Signature · 1 line
2.47.2
author maintainer
#2 lore raw

PATCH v7 2/3 rust: configfs: add a sample demonstrating configfs usage

In reply to Andreas Hindborg

Add a sample to the samples folder, demonstrating the intended use of the Rust configfs API.

---
 samples/rust/Kconfig          |  11 +++
 samples/rust/Makefile         |   1 +
 samples/rust/rust_configfs.rs | 192 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
samples/rust/Kconfig +11 -0
index cad52b7120b5..be491ad9b3af 100644
@@ -10,6 +10,17 @@ menuconfig SAMPLES_RUST
 
 if SAMPLES_RUST
 
+config SAMPLE_RUST_CONFIGFS
+	tristate "Configfs sample"
+	depends on CONFIGFS_FS
+	help
+	  This option builds the Rust configfs sample.
+
+	  To compile this as a module, choose M here:
+	  the module will be called rust_configfs.
+
+	  If unsure, say N.
+
 config SAMPLE_RUST_MINIMAL
 	tristate "Minimal"
 	help
samples/rust/Makefile +1 -0
index c6a2479f7d9c..b3c9178d654a 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_SAMPLE_RUST_DMA)			+= rust_dma.o
 obj-$(CONFIG_SAMPLE_RUST_DRIVER_PCI)		+= rust_driver_pci.o
 obj-$(CONFIG_SAMPLE_RUST_DRIVER_PLATFORM)	+= rust_driver_platform.o
 obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX)		+= rust_driver_faux.o
+obj-$(CONFIG_SAMPLE_RUST_CONFIGFS)		+= rust_configfs.o
 
 rust_print-y := rust_print_main.o rust_print_events.o
 
samples/rust/rust_configfs.rs new file +192 -0

192 lines not on this page · raw message

Signature · 1 line
2.47.2
author maintainer
#3 lore raw

PATCH v7 3/3 MAINTAINERS: add configfs Rust abstractions

In reply to Andreas Hindborg

Add rust files to configfs MAINTAINERS entry.

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index 3cbf9ac0d83f..5ccf04e1eb1f 100644
@@ -5982,7 +5982,9 @@ S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/a.hindborg/linux.git configfs-next
 F:	fs/configfs/
 F:	include/linux/configfs.h
+F:	rust/kernel/configfs.rs
 F:	samples/configfs/
+F:	samples/rust/rust_configfs.rs
 
 CONGATEC BOARD CONTROLLER MFD DRIVER
 M:	Thomas Richard <[email protected]>
Signature · 1 line
2.47.2