generic: test small swapfile without page-aligned contiguous blocks
PATCH v2 1/1 generic: test small swapfile without page-aligned contiguous blocks
If a swapfile doesn't contain even a single page-aligned contiguous range of blocks, it's an invalid swapfile, and might cause kernel issue. This case covered commit 5808fecc5723 ("iomap: Fix negative assignment to unsigned sis->pages in iomap_swapfile_activate").
---
Hi,
Sorry for the late V2, I just back from a longtime sick leave. V2 accord to the review points from djwong:
https://lore.kernel.org/fstests/20210525160907.GB202095@locust/
But I didn't change the _scratch_mkfs_blocksized() helper in this patch.
CC Ritesh Harjani who's the original author of commit 5808fecc5723, and looks like he sent another test case.
Thanks,
Zorro
tests/generic/639 | 82 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/639.out | 2 ++ tests/generic/group | 1 + 3 files changed, 85 insertions(+) create mode 100755 tests/generic/639 create mode 100644 tests/generic/639.out
tests/generic/639 new file +82 -0
@@ -0,0 +1,82 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 Red Hat Inc. All Rights Reserved. +# +# FS QA Test No. 639 +# +# Test small swapfile which doesn't contain even a single page-aligned contiguous +# range of blocks. This case covered commit 5808fecc5723 ("iomap: Fix negative +# assignment to unsigned sis->pages in iomap_swapfile_activate"). +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_require_scratch +_require_scratch_swapfile +_require_test_program mkswap +_require_test_program swapon + +make_unaligned_swapfile() +{ + local fname=$1 + local n=$((psize / bsize - 1)) + + # Make sure the swapfile doesn't contain even a single page-aligned + # contiguous range of blocks. This's necessary to cover the bug + $XFS_IO_PROG -f -t -c "pwrite 0 $(((psize + bsize) * n))" $fname >> $seqres.full 2>&1 + for((i=1; i<=n; i++));do + $XFS_IO_PROG -c "fcollapse $(((psize - bsize) * i)) $bsize" $fname + done + chmod 0600 $fname + $CHATTR_PROG +C $fname > /dev/null 2>&1 + $here/src/mkswap $fname +} + +_scratch_mkfs >> $seqres.full 2>&1 +_scratch_mount +psize=`get_page_size` +bsize=`_get_file_block_size $SCRATCH_MNT` +# Due to we need page-unaligned blocks, so blocksize < pagesize is necessary. +# If not, try to make a smaller enough block size +if [ $bsize -ge $psize ];then + _scratch_unmount + _scratch_mkfs_blocksized 1024 >> $seqres.full 2>&1 + if [ $? -ne 0 ];then + _notrun "Can't make filesystem block size < page size" + fi + _scratch_mount + bsize=`_get_file_block_size $SCRATCH_MNT` + if [ $bsize -ne 1024 ];then + _notrun "1024 block size is necessary" + fi +fi +swapfile=$SCRATCH_MNT/$seq.swapfile +make_unaligned_swapfile $swapfile +$here/src/swapon $swapfile +swapoff $swapfile + +echo "Silence is golden" +# success, all done +status=0 +exit
tests/generic/639.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 639 +Silence is golden
tests/generic/group +1 -0
@@ -641,3 +641,4 @@ 636 auto quick swap 637 auto quick dir 638 auto quick rw +639 auto quick swap
Signature · 1 line
2.31.1
Quoted 11 lines · Zorro Lang
If a swapfile doesn't contain even a single page-aligned contiguous range of blocks, it's an invalid swapfile, and might cause kernel issue. This case covered commit
5808fecc5723("iomap: Fix negative assignment to unsignedsis->pagesiniomap_swapfile_activate").Signed-off-by Zorro Lang <[email protected]>---
Hi,
Sorry for the late V2, I just back from a longtime sick leave. V2 accord
:( I hope you're doing better!
Quoted 63 lines
to the review points from djwong:
https://lore.kernel.org/fstests/20210525160907.GB202095@locust/
But I didn't change the_scratch_mkfs_blocksized()helper in this patch.CC Ritesh Harjani who's the original author of commit
5808fecc5723, and looks like he sent another test case.Thanks,
Zorrotests/generic/639 | 82 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/639.out | 2 ++ tests/generic/group | 1 + 3 files changed, 85 insertions(+) create mode 100755 tests/generic/639 create mode 100644 tests/generic/639.outtests/generic/639 new file +40
-0@@ -0,0 +1,82 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 Red Hat Inc. All Rights Reserved. +# +# FS QA Test No. 639 +# +# Test small swapfile which doesn't contain even a single page-aligned contiguous +# range of blocks. This case covered commit 5808fecc5723 ("iomap: Fix negative +# assignment to unsigned sis->pages in iomap_swapfile_activate"). +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_require_scratch +_require_scratch_swapfile +_require_test_program mkswap +_require_test_program swapon + +make_unaligned_swapfile()
tests/generic/639 line 50
Quoted 10 lines
tests/generic/639 new file +10
-0+{ + local fname=$1 + local n=$((psize / bsize - 1)) + + # Make sure the swapfile doesn't contain even a single page-aligned + # contiguous range of blocks. This's necessary to cover the bug + $XFS_IO_PROG -f -t -c "pwrite 0 $(((psize + bsize) * n))" $fname >> $seqres.full 2>&1 + for((i=1; i<=n; i++));do + $XFS_IO_PROG -c "fcollapse $(((psize - bsize) * i)) $bsize" $fname + done
_require_xfs_io_command fcollapse
is needed above.
Quoted 11 lines
tests/generic/639 new file +11
-0+ chmod 0600 $fname + $CHATTR_PROG +C $fname > /dev/null 2>&1 + $here/src/mkswap $fname +} + +_scratch_mkfs >> $seqres.full 2>&1 +_scratch_mount +psize=`get_page_size` +bsize=`_get_file_block_size $SCRATCH_MNT` +# Due to we need page-unaligned blocks, so blocksize < pagesize is necessary. +# If not, try to make a smaller enough block size
tests/generic/639 line 71
Quoted 10 lines
tests/generic/639 new file +10
-0+if [ $bsize -ge $psize ];then + _scratch_unmount + _scratch_mkfs_blocksized 1024 >> $seqres.full 2>&1 + if [ $? -ne 0 ];then + _notrun "Can't make filesystem block size < page size" + fi + _scratch_mount + bsize=`_get_file_block_size $SCRATCH_MNT` + if [ $bsize -ne 1024 ];then + _notrun "1024 block size is necessary"
This error message probably should have a little more context.
_notrun "Could not force 1024-byte file block size."
The logic in the test looks good to me now.
--D
Quoted 31 lines
tests/generic/639 new file +11
-0+ fi +fi +swapfile=$SCRATCH_MNT/$seq.swapfile +make_unaligned_swapfile $swapfile +$here/src/swapon $swapfile +swapoff $swapfile + +echo "Silence is golden" +# success, all done +status=0 +exittests/generic/639.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 639 +Silence is goldentests/generic/group +1
-0@@ -641,3 +641,4 @@ 636 auto quick swap 637 auto quick dir 638 auto quick rw +639 auto quick swapSignature · 1 line
2.31.1
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Zorro Lang
If a swapfile doesn't contain even a single page-aligned contiguous range of blocks, it's an invalid swapfile, and might cause kernel issue. This case covered commit
5808fecc5723("iomap: Fix negative assignment to unsignedsis->pagesiniomap_swapfile_activate").
Quoted 8 lines
Quoted 6 lines
Signed-off-by Zorro Lang <[email protected]>---
Hi,
Sorry for the late V2, I just back from a longtime sick leave. V2 accord
:( I hope you're doing better!
Thanks, feel better now, trying to catch what I missed :)
Quoted 68 lines
Quoted 68 lines
to the review points from djwong:
https://lore.kernel.org/fstests/20210525160907.GB202095@locust/
But I didn't change the_scratch_mkfs_blocksized()helper in this patch.CC Ritesh Harjani who's the original author of commit
5808fecc5723, and looks like he sent another test case.Thanks,
Zorrotests/generic/639 | 82 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/639.out | 2 ++ tests/generic/group | 1 + 3 files changed, 85 insertions(+) create mode 100755 tests/generic/639 create mode 100644 tests/generic/639.outtests/generic/639 new file +44
-0@@ -0,0 +1,82 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 Red Hat Inc. All Rights Reserved. +# +# FS QA Test No. 639 +# +# Test small swapfile which doesn't contain even a single page-aligned contiguous +# range of blocks. This case covered commit 5808fecc5723 ("iomap: Fix negative +# assignment to unsigned sis->pages in iomap_swapfile_activate"). +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_require_scratch +_require_scratch_swapfile +_require_test_program mkswap +_require_test_program swapon + +make_unaligned_swapfile() +{ + local fname=$1 + local n=$((psize / bsize - 1)) +
Quoted 8 lines
tests/generic/639 line 50
Quoted 6 lines
tests/generic/639 new file +6
-0+ # Make sure the swapfile doesn't contain even a single page-aligned + # contiguous range of blocks. This's necessary to cover the bug + $XFS_IO_PROG -f -t -c "pwrite 0 $(((psize + bsize) * n))" $fname >> $seqres.full 2>&1 + for((i=1; i<=n; i++));do + $XFS_IO_PROG -c "fcollapse $(((psize - bsize) * i)) $bsize" $fname + done
_require_xfs_io_commandfcollapse
Sure,
Quoted 27 lines
is needed above.
Quoted 11 lines
tests/generic/639 new file +11
-0+ chmod 0600 $fname + $CHATTR_PROG +C $fname > /dev/null 2>&1 + $here/src/mkswap $fname +} + +_scratch_mkfs >> $seqres.full 2>&1 +_scratch_mount +psize=`get_page_size` +bsize=`_get_file_block_size $SCRATCH_MNT` +# Due to we need page-unaligned blocks, so blocksize < pagesize is necessary. +# If not, try to make a smaller enough block sizetests/generic/639 line 71
Quoted 10 lines
tests/generic/639 new file +10
-0+if [ $bsize -ge $psize ];then + _scratch_unmount + _scratch_mkfs_blocksized 1024 >> $seqres.full 2>&1 + if [ $? -ne 0 ];then + _notrun "Can't make filesystem block size < page size" + fi + _scratch_mount + bsize=`_get_file_block_size $SCRATCH_MNT` + if [ $bsize -ne 1024 ];then + _notrun "1024 block size is necessary"This error message probably should have a little more context.
Quoted 1 line
_notrun"Could not force 1024-byte file block size."
Sure. If I don't need to wait your patchset (about new grouplist), I'll change this case now.
Thanks,
Zorro
Quoted 37 lines
The logic in the test looks good to me now.
--D
Quoted 31 lines
tests/generic/639 new file +11
-0+ fi +fi +swapfile=$SCRATCH_MNT/$seq.swapfile +make_unaligned_swapfile $swapfile +$here/src/swapon $swapfile +swapoff $swapfile + +echo "Silence is golden" +# success, all done +status=0 +exittests/generic/639.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 639 +Silence is goldentests/generic/group +1
-0@@ -641,3 +641,4 @@ 636 auto quick swap 637 auto quick dir 638 auto quick rw +639 auto quick swapSignature · 1 line
2.31.1
Quoted 124 lines · Zorro Lang
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Zorro Lang
If a swapfile doesn't contain even a single page-aligned contiguous range of blocks, it's an invalid swapfile, and might cause kernel issue. This case covered commit
5808fecc5723("iomap: Fix negative assignment to unsignedsis->pagesiniomap_swapfile_activate").Quoted 8 lines
Quoted 6 lines
Signed-off-by Zorro Lang <[email protected]>---
Hi,
Sorry for the late V2, I just back from a longtime sick leave. V2 accord
:( I hope you're doing better!
Thanks, feel better now, trying to catch what I missed :)
Quoted 68 lines
Quoted 68 lines
to the review points from djwong:
https://lore.kernel.org/fstests/20210525160907.GB202095@locust/
But I didn't change the_scratch_mkfs_blocksized()helper in this patch.CC Ritesh Harjani who's the original author of commit
5808fecc5723, and looks like he sent another test case.Thanks,
Zorrotests/generic/639 | 82 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/639.out | 2 ++ tests/generic/group | 1 + 3 files changed, 85 insertions(+) create mode 100755 tests/generic/639 create mode 100644 tests/generic/639.outtests/generic/639 new file +44
-0@@ -0,0 +1,82 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 Red Hat Inc. All Rights Reserved. +# +# FS QA Test No. 639 +# +# Test small swapfile which doesn't contain even a single page-aligned contiguous +# range of blocks. This case covered commit 5808fecc5723 ("iomap: Fix negative +# assignment to unsigned sis->pages in iomap_swapfile_activate"). +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_require_scratch +_require_scratch_swapfile +_require_test_program mkswap +_require_test_program swapon + +make_unaligned_swapfile() +{ + local fname=$1 + local n=$((psize / bsize - 1)) +Quoted 8 lines
tests/generic/639 line 50
Quoted 6 lines
tests/generic/639 new file +6
-0+ # Make sure the swapfile doesn't contain even a single page-aligned + # contiguous range of blocks. This's necessary to cover the bug + $XFS_IO_PROG -f -t -c "pwrite 0 $(((psize + bsize) * n))" $fname >> $seqres.full 2>&1 + for((i=1; i<=n; i++));do + $XFS_IO_PROG -c "fcollapse $(((psize - bsize) * i)) $bsize" $fname + done
_require_xfs_io_commandfcollapseSure,
Quoted 27 lines
is needed above.
Quoted 11 lines
tests/generic/639 new file +11
-0+ chmod 0600 $fname + $CHATTR_PROG +C $fname > /dev/null 2>&1 + $here/src/mkswap $fname +} + +_scratch_mkfs >> $seqres.full 2>&1 +_scratch_mount +psize=`get_page_size` +bsize=`_get_file_block_size $SCRATCH_MNT` +# Due to we need page-unaligned blocks, so blocksize < pagesize is necessary. +# If not, try to make a smaller enough block sizetests/generic/639 line 71
Quoted 10 lines
tests/generic/639 new file +10
-0+if [ $bsize -ge $psize ];then + _scratch_unmount + _scratch_mkfs_blocksized 1024 >> $seqres.full 2>&1 + if [ $? -ne 0 ];then + _notrun "Can't make filesystem block size < page size" + fi + _scratch_mount + bsize=`_get_file_block_size $SCRATCH_MNT` + if [ $bsize -ne 1024 ];then + _notrun "1024 block size is necessary"This error message probably should have a little more context.
Quoted 4 lines
Quoted 1 line
_notrun"Could not force 1024-byte file block size."Sure. If I don't need to wait your patchset (about new grouplist), I'll change this case now.
Nah, that whole patchset is at least another week (and reposting) away.
--D
Quoted 41 lines
Thanks,
ZorroQuoted 37 lines
The logic in the test looks good to me now.
--D
Quoted 31 lines
tests/generic/639 new file +11
-0+ fi +fi +swapfile=$SCRATCH_MNT/$seq.swapfile +make_unaligned_swapfile $swapfile +$here/src/swapon $swapfile +swapoff $swapfile + +echo "Silence is golden" +# success, all done +status=0 +exittests/generic/639.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 639 +Silence is goldentests/generic/group +1
-0@@ -641,3 +641,4 @@ 636 auto quick swap 637 auto quick dir 638 auto quick rw +639 auto quick swapSignature · 1 line
2.31.1