mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs: add error injection support for checksum verification
@ 2026-07-02  2:36 Song Chen
  2026-07-02  2:36 ` [PATCH 1/2] error-injection: Introduce EI_ETYPE_FALSE for fail_function Song Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Song Chen @ 2026-07-02  2:36 UTC (permalink / raw)
  To: arnd, kees, clm, dsterba; +Cc: linux-arch, 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

 fs/btrfs/inode.c                      | 1 +
 include/asm-generic/error-injection.h | 1 +
 kernel/fail_function.c                | 2 ++
 3 files changed, 4 insertions(+)

-- 
2.43.0


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

* [PATCH 1/2] error-injection: Introduce EI_ETYPE_FALSE for fail_function
  2026-07-02  2:36 [PATCH 0/2] btrfs: add error injection support for checksum verification Song Chen
@ 2026-07-02  2:36 ` Song Chen
  2026-07-02  2:36 ` [PATCH 2/2] btrfs: Allow error injection on btrfs_data_csum_ok Song Chen
  2026-07-13  1:00 ` [PATCH 0/2] btrfs: add error injection support for checksum verification Song Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Song Chen @ 2026-07-02  2:36 UTC (permalink / raw)
  To: arnd, kees, clm, dsterba; +Cc: linux-arch, 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.

Signed-off-by: Song Chen <chensong_2000@126.com>
---
 include/asm-generic/error-injection.h | 1 +
 kernel/fail_function.c                | 2 ++
 2 files changed, 3 insertions(+)

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;
-- 
2.43.0


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

* [PATCH 2/2] btrfs: Allow error injection on btrfs_data_csum_ok
  2026-07-02  2:36 [PATCH 0/2] btrfs: add error injection support for checksum verification Song Chen
  2026-07-02  2:36 ` [PATCH 1/2] error-injection: Introduce EI_ETYPE_FALSE for fail_function Song Chen
@ 2026-07-02  2:36 ` Song Chen
  2026-07-13  1:00 ` [PATCH 0/2] btrfs: add error injection support for checksum verification Song Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Song Chen @ 2026-07-02  2:36 UTC (permalink / raw)
  To: arnd, kees, clm, dsterba; +Cc: linux-arch, 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, including any warning output and uspace
notification, 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

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 906d5c21ebc4..6be3e920b954 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3574,6 +3574,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] 4+ messages in thread

* Re: [PATCH 0/2] btrfs: add error injection support for checksum verification
  2026-07-02  2:36 [PATCH 0/2] btrfs: add error injection support for checksum verification Song Chen
  2026-07-02  2:36 ` [PATCH 1/2] error-injection: Introduce EI_ETYPE_FALSE for fail_function Song Chen
  2026-07-02  2:36 ` [PATCH 2/2] btrfs: Allow error injection on btrfs_data_csum_ok Song Chen
@ 2026-07-13  1:00 ` Song Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Song Chen @ 2026-07-13  1:00 UTC (permalink / raw)
  To: arnd, kees, clm, dsterba; +Cc: linux-arch, linux-kernel

Dear Maintainers and Reviewers,

This is friendly ping on this patchset.

The motive is rational and the implementation is simple and clear, 
what's more, no impact to any other function. I would appreciate it if 
you could have a look and leave comments.

Best regards,

Song

On 7/2/26 10:36, Song Chen wrote:
> 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
> 
>   fs/btrfs/inode.c                      | 1 +
>   include/asm-generic/error-injection.h | 1 +
>   kernel/fail_function.c                | 2 ++
>   3 files changed, 4 insertions(+)
> 


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

end of thread, other threads:[~2026-07-13  1:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-02  2:36 [PATCH 0/2] btrfs: add error injection support for checksum verification Song Chen
2026-07-02  2:36 ` [PATCH 1/2] error-injection: Introduce EI_ETYPE_FALSE for fail_function Song Chen
2026-07-02  2:36 ` [PATCH 2/2] btrfs: Allow error injection on btrfs_data_csum_ok Song Chen
2026-07-13  1:00 ` [PATCH 0/2] btrfs: add error injection support for checksum verification 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®