From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
To: "Darrick J. Wong" <djwong@kernel.org>,
willy@infradead.org, linux-fsdevel@vger.kernel.org,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 3/2] fstests: test FALLOC_FL_UNSHARE when pagecache is not loaded
Date: Tue, 19 Sep 2023 11:21:43 +0530 [thread overview]
Message-ID: <87led27lsg.fsf@doe.com> (raw)
In-Reply-To: <20230918231945.GC348018@frogsfrogsfrogs>
"Darrick J. Wong" <djwong@kernel.org> writes:
> Add a regression test for funsharing uncached files to ensure that we
> actually manage the pagecache state correctly.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
> tests/xfs/1936 | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> tests/xfs/1936.out | 4 ++
> 2 files changed, 92 insertions(+)
> create mode 100755 tests/xfs/1936
> create mode 100644 tests/xfs/1936.out
1936? I am not sure how that works though.
./new I guess automatically gives the testcase no. for a new testcase right.
>
> diff --git a/tests/xfs/1936 b/tests/xfs/1936
> new file mode 100755
> index 0000000000..bcf9b6b478
> --- /dev/null
> +++ b/tests/xfs/1936
> @@ -0,0 +1,88 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2023 Oracle. All Rights Reserved.
> +#
> +# FS QA Test 1936
> +#
> +# This is a regression test for the kernel commit noted below. The stale
> +# memory exposure can be exploited by creating a file with shared blocks,
> +# evicting the page cache for that file, and then funshareing at least one
> +# memory page's worth of data. iomap will mark the page uptodate and dirty
> +# without ever reading the ondisk contents.
> +#
> +. ./common/preamble
> +_begin_fstest auto quick unshare clone
> +
> +_cleanup()
> +{
> + cd /
> + rm -r -f $tmp.* $testdir
> +}
> +
> +# real QA test starts here
> +
> +# Import common functions.
> +. ./common/filter
> +. ./common/attr
> +. ./common/reflink
> +
> +_fixed_by_git_commit kernel XXXXXXXXXXXXX \
> + "iomap: don't skip reading in !uptodate folios when unsharing a range"
> +
> +# real QA test starts here
> +_require_test_reflink
> +_require_cp_reflink
> +_require_xfs_io_command "funshare"
> +
> +testdir=$TEST_DIR/test-$seq
> +rm -rf $testdir
> +mkdir $testdir
> +
> +# Create a file that is at least four pages in size and aligned to the
> +# file allocation unit size so that we don't trigger any unnecessary zeroing.
> +pagesz=$(_get_page_size)
> +alloc_unit=$(_get_file_block_size $TEST_DIR)
> +filesz=$(( ( (4 * pagesz) + alloc_unit - 1) / alloc_unit * alloc_unit))
> +
> +echo "Create the original file and a clone"
> +_pwrite_byte 0x61 0 $filesz $testdir/file2.chk >> $seqres.full
> +_pwrite_byte 0x61 0 $filesz $testdir/file1 >> $seqres.full
> +_cp_reflink $testdir/file1 $testdir/file2
> +_cp_reflink $testdir/file1 $testdir/file3
> +
> +_test_cycle_mount
> +
> +cat $testdir/file3 > /dev/null
> +
> +echo "Funshare at least one pagecache page"
> +$XFS_IO_PROG -c "funshare 0 $filesz" $testdir/file2
> +$XFS_IO_PROG -c "funshare 0 $filesz" $testdir/file3
> +_pwrite_byte 0x61 0 $filesz $testdir/file2.chk >> $seqres.full
We don't need to write the bytes again to file2.chk. We already wrote above.
Otherwise looks right to me. Nice testcase indeed.
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> +
> +echo "Check contents"
> +
> +# file2 wasn't cached when it was unshared, but it should match
> +if ! cmp -s $testdir/file2.chk $testdir/file2; then
> + echo "file2.chk does not match file2"
> +
> + echo "file2.chk contents" >> $seqres.full
> + od -tx1 -Ad -c $testdir/file2.chk >> $seqres.full
> + echo "file2 contents" >> $seqres.full
> + od -tx1 -Ad -c $testdir/file2 >> $seqres.full
> + echo "end bad contents" >> $seqres.full
> +fi
> +
> +# file3 was cached when it was unshared, and it should match
> +if ! cmp -s $testdir/file2.chk $testdir/file3; then
> + echo "file2.chk does not match file3"
> +
> + echo "file2.chk contents" >> $seqres.full
> + od -tx1 -Ad -c $testdir/file2.chk >> $seqres.full
> + echo "file3 contents" >> $seqres.full
> + od -tx1 -Ad -c $testdir/file3 >> $seqres.full
> + echo "end bad contents" >> $seqres.full
> +fi
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/xfs/1936.out b/tests/xfs/1936.out
> new file mode 100644
> index 0000000000..c7c820ced5
> --- /dev/null
> +++ b/tests/xfs/1936.out
> @@ -0,0 +1,4 @@
> +QA output created by 1936
> +Create the original file and a clone
> +Funshare at least one pagecache page
> +Check contents
prev parent reply other threads:[~2023-09-19 5:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-18 23:11 [PATCHSET 0/2] iomap: fix unshare data corruption bug Darrick J. Wong
2023-09-18 23:12 ` [PATCH 1/2] iomap: don't skip reading in !uptodate folios when unsharing a range Darrick J. Wong
2023-09-19 4:42 ` Ritesh Harjani
2023-09-19 9:24 ` Ritesh Harjani
2023-09-19 5:14 ` Ritesh Harjani
2023-09-19 5:24 ` Darrick J. Wong
2023-09-19 5:32 ` Darrick J. Wong
2023-09-18 23:12 ` [PATCH 2/2] iomap: convert iomap_unshare_iter to use large folios Darrick J. Wong
2023-09-19 8:03 ` Ritesh Harjani
2023-09-18 23:19 ` [PATCH 3/2] fstests: test FALLOC_FL_UNSHARE when pagecache is not loaded Darrick J. Wong
2023-09-19 5:51 ` Ritesh Harjani [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=87led27lsg.fsf@doe.com \
--to=ritesh.list@gmail.com \
--cc=djwong@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=willy@infradead.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