fault-inject: rust: add a Rust API for fault-injection
Andreas Hindborg
reviewerPATCH v2 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 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]
To: Miguel Ojeda <[email protected]>
To: Boqun Feng <[email protected]>
To: Gary Guo <[email protected]>
To: Björn Roy Baron <[email protected]>
To: Benno Lossin <[email protected]>
To: Andreas Hindborg <[email protected]>
To: Alice Ryhl <[email protected]>
To: Trevor Gross <[email protected]>
To: Danilo Krummrich <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- rust/bindings/bindings_helper.h | 1 + rust/kernel/fault_injection.rs | 101 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 2 + 3 files changed, 104 insertions(+)
rust/bindings/bindings_helper.h +1 -0
@@ -57,6 +57,7 @@#include <linux/errname.h> #include <linux/ethtool.h> #include <linux/fdtable.h> +#include <linux/fault-inject.h> #include <linux/file.h> #include <linux/firmware.h> #include <linux/fs.h>
rust/kernel/fault_injection.rs new file +101 -0
101 lines not on this page · raw message
rust/kernel/lib.rs +2 -0
@@ -67,6 +67,8 @@#[cfg( CONFIG_DRM = "y" )] pub mod drm;pub mod error; +#[cfg(all( CONFIG_FAULT_INJECTION , CONFIG_FAULT_INJECTION_CONFIGFS ))] +pub mod fault_injection;pub mod faux;#[cfg( CONFIG_RUST_FW_LOADER_ABSTRACTIONS )] pub mod firmware;
---
base-commit: 9e0898f1c0f134c6bad146ca8578f73c3e40ac0a
change-id: 20260215-rust-fault-inject-bc62f1083502
prerequisite-change-id: 20260215-configfs-c-default-groups-bdb0a44633a6:v2
prerequisite-patch-id: 03b8e71b79be89a73946f3c1f7248671c28ccd42
Best regards,
Signature · 1 line
Andreas Hindborg <[email protected]>
Hi Andreas,
Some quick comments scanning your patch diagonally since I was here for something else.
Quoted 5 lines · Andreas Hindborg
#include <
linux/ethtool.h>
#include <linux/fdtable.h>
+#include <linux/fault-inject.h>
#include <linux/file.h>
Please keep them sorted :)
Quoted 1 line
+// SAFETY: FaultConfig can be used from any task.
FaultConfig
Quoted 1 line
+ // SAFETY: By type invariant, self is always valid.
self
Quoted 1 line
+ /// Returns
trueif the operation should fail.
[true]
Quoted 1 line
+ // INVARIANT:
self.inneris initialized inffi_init.
I was going to say ffi_init, but there is no such call here. Isn't it getting initialized by the C side? I guess this got copy-pasted from somewhere else?
Cheers,
Miguel
Andreas Hindborg
reviewerQuoted 18 lines · Miguel Ojeda
Hi Andreas,
Some quick comments scanning your patch diagonally since I was here for something else.
Quoted 5 lines · Andreas Hindborg
#include <
linux/ethtool.h>
#include <linux/fdtable.h>
+#include <linux/fault-inject.h>
#include <linux/file.h>Please keep them sorted :)
Quoted 1 line
+// SAFETY: FaultConfig can be used from any task.
FaultConfig
Quoted 7 lines
Quoted 1 line
+ // SAFETY: By type invariant, self is always valid.
selfQuoted 1 line
+ /// Returns
trueif the operation should fail.[
true]
Thanks, I'll correct these for next version.
Quoted 6 lines
Quoted 2 lines
+ // INVARIANT:
self.inneris initialized inffi_init.I was going to say
ffi_init, but there is no such call here. Isn't it getting initialized by the C side? I guess this got copy-pasted from somewhere else?
Thanks for catching this, it is a stale comment. I was using Opaque::ffi_init in an earlier version (pre v1, this was also present in v1).
Best regards,
Andreas Hindborg