mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/2] btrfs: add error injection support for checksum verification
@ 2026-10-12 21:29 Song Chen
  2026-10-12 21:29 ` [PATCH v3 1/2] error-injection: Introduce EI_ETYPE_FALSE for fail_function Song Chen
  2026-10-12 21:29 ` [PATCH v3 2/2] btrfs: Allow error injection on btrfs_data_csum_ok Song Chen
  0 siblings, 2 replies; 3+ messages in thread
From: Song Chen @ 2026-10-12 21:29 UTC (permalink / raw)
  To: dsterba, mason, akinobu.mita, corbet, skhan, rdunlap, arnd, akpm, ees
  Cc: linux-doc, linux-arch, linux-btrfs, linux-kernel, Song Chen

This patchset adds fault injection support for btrfs_data_csum_ok,
enabling controlled simulation of checksum mismatches to test btrfs
silent data corruption detection and reporting paths.

The first patch extends the error injection framework with a new type,
EI_ETYPE_FALSE, which allows bool-returning functions to be overridden
with a false return value directly.

The second patch marks btrfs_data_csum_ok with ALLOW_ERROR_INJECTION
using this new type.


Song Chen (2):
  error-injection: Introduce EI_ETYPE_FALSE for fail_function
  btrfs: Allow error injection on btrfs_data_csum_ok

 Documentation/fault-injection/fault-injection.rst | 3 +++
 fs/btrfs/inode.c                                  | 1 +
 include/asm-generic/error-injection.h             | 1 +
 kernel/fail_function.c                            | 2 ++
 lib/error-inject.c                                | 2 ++
 5 files changed, 9 insertions(+)

---
changelog:
v1 --- v2:
Add a parent field to struct fei_attr.

v2 --- v3
1, Withdraw adding parent field in fet_attr in v2.
2, Update commit message of second patch regarding sashiko-bot's
   suggestion in [1].
3, Add EI_ETYPE_FALSE in error_type_string regarding sashiko-bot's
   suggestion in [2].
4, Add EI_ETYPE_FALSE in Documentation/fault-injection/fault-injection.rst
   regarding sashiko-bot's suggestion in [2].

[1] https://lore.kernel.org/all/20260724022150.D2D811F000E9@smtp.kernel.org/
[2] https://lore.kernel.org/all/20260724022044.F31F11F000E9@smtp.kernel.org/
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3 1/2] error-injection: Introduce EI_ETYPE_FALSE for fail_function
  2026-10-12 21:29 [PATCH v3 0/2] btrfs: add error injection support for checksum verification Song Chen
@ 2026-10-12 21:29 ` Song Chen
  2026-10-12 21:29 ` [PATCH v3 2/2] btrfs: Allow error injection on btrfs_data_csum_ok Song Chen
  1 sibling, 0 replies; 3+ messages in thread
From: Song Chen @ 2026-10-12 21:29 UTC (permalink / raw)
  To: dsterba, mason, akinobu.mita, corbet, skhan, rdunlap, arnd, akpm, ees
  Cc: linux-doc, linux-arch, linux-btrfs, linux-kernel, Song Chen

Introduce EI_ETYPE_FALSE for functions which need false as return
value in their error-injections, like btrfs_data_csum_ok.

EI_ETYPE_NULL can return 0 too but its readability is not good
enough.

Acked-by: David Sterba  <dsterba@suse.com>
Signed-off-by: Song Chen <chensong_2000@126.com>
---
 Documentation/fault-injection/fault-injection.rst | 3 +++
 include/asm-generic/error-injection.h             | 1 +
 kernel/fail_function.c                            | 2 ++
 lib/error-inject.c                                | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/Documentation/fault-injection/fault-injection.rst b/Documentation/fault-injection/fault-injection.rst
index c2d3996b5b40..86431ad2b565 100644
--- a/Documentation/fault-injection/fault-injection.rst
+++ b/Documentation/fault-injection/fault-injection.rst
@@ -347,6 +347,9 @@ EI_ETYPE_ERRNO_NULL
 EI_ETYPE_TRUE
   This function will return `true` (non-zero positive value) if it fails.
 
+EI_ETYPE_FALSE
+  This function will return `false` if it fails.
+
 If you specifies a wrong type, for example, EI_TYPE_ERRNO for the function
 which returns an allocated object, it may cause a problem because the returned
 value is not an object address and the caller can not access to the address.
diff --git a/include/asm-generic/error-injection.h b/include/asm-generic/error-injection.h
index b05253f68eaa..6c399121ab7a 100644
--- a/include/asm-generic/error-injection.h
+++ b/include/asm-generic/error-injection.h
@@ -8,6 +8,7 @@ enum {
 	EI_ETYPE_ERRNO,		/* Return -ERRNO if failure */
 	EI_ETYPE_ERRNO_NULL,	/* Return -ERRNO or NULL if failure */
 	EI_ETYPE_TRUE,		/* Return true if failure */
+	EI_ETYPE_FALSE,		/* Return false if failure */
 };
 
 struct error_injection_entry {
diff --git a/kernel/fail_function.c b/kernel/fail_function.c
index 2eaf55005f49..90cdad0412cd 100644
--- a/kernel/fail_function.c
+++ b/kernel/fail_function.c
@@ -48,6 +48,8 @@ static unsigned long adjust_error_retval(unsigned long addr, unsigned long retv)
 		break;
 	case EI_ETYPE_TRUE:
 		return 1;
+	case EI_ETYPE_FALSE:
+		return 0;
 	}
 
 	return retv;
diff --git a/lib/error-inject.c b/lib/error-inject.c
index 32f3d1ca9ea2..115b10dbf9aa 100644
--- a/lib/error-inject.c
+++ b/lib/error-inject.c
@@ -189,6 +189,8 @@ static const char *error_type_string(int etype)
 		return "ERRNO_NULL";
 	case EI_ETYPE_TRUE:
 		return "TRUE";
+	case EI_ETYPE_FALSE:
+		return "FALSE";
 	default:
 		return "(unknown)";
 	}
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3 2/2] btrfs: Allow error injection on btrfs_data_csum_ok
  2026-10-12 21:29 [PATCH v3 0/2] btrfs: add error injection support for checksum verification Song Chen
  2026-10-12 21:29 ` [PATCH v3 1/2] error-injection: Introduce EI_ETYPE_FALSE for fail_function Song Chen
@ 2026-10-12 21:29 ` Song Chen
  1 sibling, 0 replies; 3+ messages in thread
From: Song Chen @ 2026-10-12 21:29 UTC (permalink / raw)
  To: dsterba, mason, akinobu.mita, corbet, skhan, rdunlap, arnd, akpm, ees
  Cc: linux-doc, linux-arch, linux-btrfs, linux-kernel, Song Chen

btrfs_data_csum_ok validates the checksum of a data block
after a read I/O completes. A mismatch between the on-disk
checksum and the one computed from the read data indicates
silent data corruption, which can be caused by bit flips due
to DRAM errors, storage media degradation, or bus transmission
faults.

Testing the error handling path that responds to such
corruption, normally requires reproducing the hardware
fault, which is not always feasible.

Mark btrfs_data_csum_ok with ALLOW_ERROR_INJECTION so that
the fail_function infrastructure can override its return value
to false, simulating a checksum mismatch without requiring
actual data corruption. This enables validation of the full
error detection and reporting path in a controlled environment.

Usage:
        cd /sys/kernel/debug/fail_function
        echo btrfs_data_csum_ok > inject
        echo 0 > btrfs_data_csum_ok/retval
        echo 100 > probability
        echo N > times

Acked-by: David Sterba  <dsterba@suse.com>
Signed-off-by: Song Chen <chensong_2000@126.com>
---
 fs/btrfs/inode.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 93ef3cec191e..73c801197934 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3586,6 +3586,7 @@ bool btrfs_data_csum_ok(struct btrfs_bio *bbio, struct btrfs_device *dev,
 		memzero_page(phys_to_page(paddrs[i]), offset_in_page(paddrs[i]), step);
 	return false;
 }
+ALLOW_ERROR_INJECTION(btrfs_data_csum_ok, FALSE);
 
 /*
  * Perform a delayed iput on @inode.
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-12 13:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-12 21:29 [PATCH v3 0/2] btrfs: add error injection support for checksum verification Song Chen
2026-10-12 21:29 ` [PATCH v3 1/2] error-injection: Introduce EI_ETYPE_FALSE for fail_function Song Chen
2026-10-12 21:29 ` [PATCH v3 2/2] btrfs: Allow error injection on btrfs_data_csum_ok Song Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®