From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Zorro Lang <zlang@kernel.org>,
fstests@vger.kernel.org,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Kanchan Joshi <joshi.k@samsung.com>,
Anuj Gupta <anuj20.g@samsung.com>,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH 5/5] generic: test corruption detection using T10 protection information
Date: Fri, 21 Aug 2026 16:38:36 -0700 [thread overview]
Message-ID: <20260821233836.GH839663@frogsfrogsfrogs> (raw)
In-Reply-To: <20260821051133.1817670-6-hch@lst.de>
On Fri, Aug 21, 2026 at 07:11:30AM +0200, Christoph Hellwig wrote:
> Add a test that simulates bit flips in data and misdirected writes and
> checks that file systems detect it when run on devices using protection
> information.
>
> This requires the new scsi_debug corruption injection.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Looks good to me (this patch and the previous one), so
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> tests/generic/2302 | 128 +++++++++++++++++++++++++++++++++++++++++
> tests/generic/2302.out | 21 +++++++
> 2 files changed, 149 insertions(+)
> create mode 100755 tests/generic/2302
> create mode 100644 tests/generic/2302.out
>
> diff --git a/tests/generic/2302 b/tests/generic/2302
> new file mode 100755
> index 000000000000..4a9d9165174b
> --- /dev/null
> +++ b/tests/generic/2302
> @@ -0,0 +1,128 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2026 Christoph Hellwig
> +#
> +# FS QA Test No. 2302
> +#
> +# Test that T10 DIF detects bitflips and misplaced writes.
> +#
> +. ./common/preamble
> +_begin_fstest auto rw pi
> +
> +_cleanup()
> +{
> + cd /
> + rm -r -f $tmp.*
> + [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
> + _put_scsi_debug_dev
> +}
> +
> +. ./common/scsi_debug
> +. ./common/filter
> +
> +_require_debugfs
> +_require_scsi_debug
> +# If TEST_DEV is block device, make sure current fs is a localfs which can be
> +# written on scsi_debug device
> +_require_test
> +_require_block_device $TEST_DEV
> +_require_xfs_io_command fiemap
> +_require_odirect
> +
> +# FIEMAP on Btrfs returns logical addresses within the filesystem's address
> +# space, not physical device offsets. Writing to these offsets on $SCRATCH_DEV
> +# would corrupt the filesystem in multi-device setups.
> +_exclude_fs btrfs
> +
> +size=$(_small_fs_size_mb 256)
> +
> +test_dif()
> +{
> + local pi_type=$1
> + local last=$2
> + local bit_errors=$3
> + local reftag_adjust=$4
> +
> + echo -n "Testing DIF type $pi_type "
> + if [ "$bit_errors" -gt "0" ]; then
> + echo -n "bit errors ($bit_errors) in "
> + fi
> + if [ "$reftag_adjust" -ne "0" ]; then
> + echo -n "reftag adjustment by $reftag_adjust in "
> + fi
> + if [ "$last" -eq 1 ]; then
> + echo "last sector"
> + else
> + echo "first sector"
> + fi
> +
> + scsi_debug_pi_opts="write_same_length=0 dif=${pi_type} dix=1"
> + SCSI_DEBUG_DEV=`_get_scsi_debug_dev 512 512 0 $size $scsi_debug_pi_opts`
> +
> + SCSI_DEBUG_MNT="$TEST_DIR/scsi_debug_$seq"
> + rm -rf $SCSI_DEBUG_MNT
> + mkdir $SCSI_DEBUG_MNT
> +
> + _mkfs_dev $SCSI_DEBUG_DEV || \
> + _fail "Can't make $FSTYP on DIF-enabled scsi_debug device"
> + run_check _mount $SCSI_DEBUG_DEV $SCSI_DEBUG_MNT
> +
> + local blksz=$(_get_block_size $SCSI_DEBUG_MNT)
> + local testfile="$SCSI_DEBUG_MNT/test"
> +
> + $XFS_IO_PROG -d -f \
> + -c "pwrite -S 0x66 0 $((128 * blksz))" \
> + -c fsync \
> + $testfile >> $seqres.full 2>&1
> +
> + local phys_blk=$(_get_file_extent_sector $testfile 0)
> + if [ -z "$phys_blk" ]; then
> + _fail "$test_name: failed to get physical block offset via fiemap"
> + fi
> +
> + local dev=$(_short_dev $SCSI_DEBUG_DEV)
> + local debugfs_dir=$(ls /sys/block/$dev/device/scsi_device/)
> + local debugfs_file="/sys/kernel/debug/scsi_debug/$debugfs_dir/corrupt"
> +
> + if [ ! -f "$debugfs_file" ]; then
> + _notrun "scsi_debug corruption injection not supported"
> + fi
> +
> + if [ "$last" -eq 1 ]; then
> + echo "adding to $phys_blk" >> $seqres.full
> + phys_blk=$((phys_blk + 127))
> + fi
> +
> + echo "lba=$phys_blk,num=1,bit_errors=$bit_errors,reftag_adjust=$reftag_adjust" \
> + > $debugfs_file
> +
> + $XFS_IO_PROG -d -f \
> + -c "pread 0 $((128 * blksz))" \
> + $testfile
> +
> + [ -d "$SCSI_DEBUG_MNT" ] && _unmount $SCSI_DEBUG_MNT 2>/dev/null
> + _put_scsi_debug_dev
> +}
> +
> +# test data corruption in first block
> +test_dif 1 0 2 0
> +test_dif 2 0 2 0
> +test_dif 3 0 2 0
> +
> +# test data corruption in last block
> +test_dif 1 1 2 0
> +test_dif 2 1 2 0
> +test_dif 3 1 2 0
> +
> +
> +# Note: Type 3 doesn't have a refrag, so don't test it
> +
> +# reftag mismatch in first block
> +test_dif 1 0 0 8
> +test_dif 2 0 0 8
> +
> +# reftag mismatch in last block
> +test_dif 1 1 0 8
> +test_dif 2 1 0 8
> +
> +_exit 0
> diff --git a/tests/generic/2302.out b/tests/generic/2302.out
> new file mode 100644
> index 000000000000..03b68d904943
> --- /dev/null
> +++ b/tests/generic/2302.out
> @@ -0,0 +1,21 @@
> +QA output created by 2302
> +Testing DIF type 1 bit errors (2) in first sector
> +pread: Invalid or incomplete multibyte or wide character
> +Testing DIF type 2 bit errors (2) in first sector
> +pread: Invalid or incomplete multibyte or wide character
> +Testing DIF type 3 bit errors (2) in first sector
> +pread: Invalid or incomplete multibyte or wide character
> +Testing DIF type 1 bit errors (2) in last sector
> +pread: Invalid or incomplete multibyte or wide character
> +Testing DIF type 2 bit errors (2) in last sector
> +pread: Invalid or incomplete multibyte or wide character
> +Testing DIF type 3 bit errors (2) in last sector
> +pread: Invalid or incomplete multibyte or wide character
> +Testing DIF type 1 reftag adjustment by 8 in first sector
> +pread: Invalid or incomplete multibyte or wide character
> +Testing DIF type 2 reftag adjustment by 8 in first sector
> +pread: Invalid or incomplete multibyte or wide character
> +Testing DIF type 1 reftag adjustment by 8 in last sector
> +pread: Invalid or incomplete multibyte or wide character
> +Testing DIF type 2 reftag adjustment by 8 in last sector
> +pread: Invalid or incomplete multibyte or wide character
> --
> 2.53.0
>
>
prev parent reply other threads:[~2026-08-21 23:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 5:11 add tests for file system on devices using protection information v2 Christoph Hellwig
2026-08-21 5:11 ` [PATCH 1/5] common/scsi_debug: don't slow down I/O Christoph Hellwig
2026-08-21 7:41 ` John Garry
2026-08-21 16:14 ` Bart Van Assche
2026-08-21 23:27 ` Darrick J. Wong
2026-08-21 5:11 ` [PATCH 2/5] common: add a _sysfs_block_integrity_path helper Christoph Hellwig
2026-08-21 23:29 ` Darrick J. Wong
2026-08-21 5:11 ` [PATCH 3/5] add a "pi" group Christoph Hellwig
2026-08-21 23:30 ` Darrick J. Wong
2026-08-21 5:11 ` [PATCH 4/5] generic: test I/O on devices with T10 protection information Christoph Hellwig
2026-08-21 23:37 ` Darrick J. Wong
2026-08-21 5:11 ` [PATCH 5/5] generic: test corruption detection using " Christoph Hellwig
2026-08-21 23:38 ` Darrick J. Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260821233836.GH839663@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=anuj20.g@samsung.com \
--cc=fstests@vger.kernel.org \
--cc=hch@lst.de \
--cc=joshi.k@samsung.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=zlang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox