fault-inject: rust: add a Rust API for fault-injection
Andreas Hindborg
reviewerPATCH v4 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 v4:
- Initialize the embedded struct fault_attr in FaultConfig::new() to the values of C FAULT_ATTR_INITIALIZER, and initialize its ratelimit state with ratelimit_state_init(). The attributes were left zeroed, so the ratelimit lock was never initialized, and with CONFIG_FAULT_INJECTION_STACKTRACE_FILTER enabled should_fail() returned false until userspace wrote require-end (Sashiko).
- Use the vertical import style (Sashiko).
- Mark FaultConfig::new(), the PinnedDrop implementation and CDefaultGroup::group_ptr() as #[inline] (Sashiko).
- Link to v3: https://msgid.link/[email protected]
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 | 186 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 2 + 3 files changed, 189 insertions(+)
rust/bindings/bindings_helper.h +1 -0
@@ -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 +186 -0
186 lines not on this page · raw message
rust/kernel/lib.rs +2 -0
@@ -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: bc71431221f5ba8bb33918399552636e059c2c45
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]>