Skip to contentSkip to conversation

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

PATCH Superseded Andreas Hindborg 2 participants 3 messages Jun 5 – Jun 6 Rust

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Andreas Hindborg

author reviewer
#0 lore raw

PATCH 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
index 446dbeaf0866..bfa5153d2ce8 100644
@@ -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
index b72b2fbe046d..8ba0083139b6 100644
@@ -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]>
#1 lore raw

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 true if the operation should fail.

[true]

Quoted 1 line

+ // INVARIANT: self.inner is initialized in ffi_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

author reviewer
#2 lore raw
Quoted 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.

self

Quoted 1 line

+ /// Returns true if the operation should fail.

[true]

Thanks, I'll correct these for next version.

Quoted 6 lines
Quoted 2 lines

+ // INVARIANT: self.inner is initialized in ffi_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