Skip to contentSkip to conversation

fault-inject: rust: add a Rust API for fault-injection

PATCH Superseded Andreas Hindborg 1 participant 1 message Nov 13 Rust

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Andreas Hindborg

author reviewer
#0 lore raw

PATCH v3 1/1 fault-inject: rust: add a Rust API for fault-injection

Add a way for Rust code to create fault-injection control points. The control points can be attached to a configfs tree as default groups and controlled from user space. On the kernel side, provide a should_fail method to query if an operation should fail.

---
This patch is a dependency for the rust null block driver fault
injection feature.
---
Changes in v3:
- Sort the fault-inject.h include in bindings_helper.h (Miguel).
- Use backticks for FaultConfig and self in code comments (Miguel).
- Link to [true] in the should_fail rustdoc (Miguel).
- Replace the stale INVARIANT comment that referred to a no longer existing ffi_init call (Miguel).
- Add a PinnedDrop for FaultConfig that releases the reference on the embedded struct config_item acquired by fault_config_init. Nothing released it before, so creating a FaultConfig and dropping it leaked the resources configfs associated with the item, including the name allocation for names of 20 bytes or more.
- Implement CDefaultGroup as an unsafe trait, following the configfs change, and document why FaultConfig meets the requirements.
- Document the remaining CDefaultGroup safety requirement, that
the implementer never attaches the group itself.
- Say what the Send and Sync impls rely on instead of claiming
that struct fault_attr applies internal synchronization.
- Add an example for the module.
- Link the module documentation to UnattachedGroup and
Group::new.
- Gate the module on FAULT_INJECTION_CONFIGFS alone, merge the
two impl FaultConfig blocks and drop a cast_mut.
- Link to v2: https://msgid.link/[email protected]

Changes in v2:
- Mark should_fail as #[inline] (Gary).
- Expand should_fail rustdoc to describe the size parameter,
including the negative-size replenish semantics, and link to the
fault injection documentation (Gary).
- Link to v1: https://msgid.link/[email protected]

---
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/fault_injection.rs  | 144 ++++++++++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs              |   2 +
 3 files changed, 147 insertions(+)
rust/bindings/bindings_helper.h +1 -0
index 3791af0aadc7..08a10a7214b0 100644
@@ -58,6 +58,7 @@
 #include <linux/dma-resv.h>
 #include <linux/errname.h>
 #include <linux/ethtool.h>
+#include <linux/fault-inject.h>
 #include <linux/fdtable.h>
 #include <linux/file.h>
 #include <linux/firmware.h>
rust/kernel/fault_injection.rs new file +144 -0

144 lines not on this page · raw message

rust/kernel/lib.rs +2 -0
index 1ab41129d557..156074709ed1 100644
@@ -73,6 +73,8 @@
 #[cfg(CONFIG_DRM = "y")]
 pub mod drm;
 pub mod error;
+#[cfg(CONFIG_FAULT_INJECTION_CONFIGFS)]
+pub mod fault_injection;
 pub mod faux;
 #[cfg(CONFIG_RUST_FW_LOADER_ABSTRACTIONS)]
 pub mod firmware;

---
base-commit: fd9230005e85472b81c1c7c16afe93dd878996b1
change-id: 20260215-rust-fault-inject-bc62f1083502
prerequisite-change-id: 20260215-configfs-c-default-groups-bdb0a44633a6:v4
prerequisite-patch-id: 54d13c089786f6c33633e3df846ae2a573542dd6

Best regards,

Signature · 1 line
Andreas Hindborg <[email protected]>