ext4: Regression test of ext4_lblk_t overflow
PATCH v2 1/1 ext4: Regression test of ext4_lblk_t overflow
Append writes to a file approaching 16T and observe if a kernel crash is caused by ext4_lblk_t overflow triggering BUG_ON at ext4_mb_new_inode_pa(). This is a regression test for commit bc056e7163ac ("ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow")
---V1->V2:
Changes to make the use case more generic, not just for testing ext4.(ext4 and xfs have been tested)
tests/generic/737 | 55 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/737.out | 2 ++ 2 files changed, 57 insertions(+) create mode 100755 tests/generic/737 create mode 100644 tests/generic/737.out
tests/generic/737 new file +55 -0
@@ -0,0 +1,55 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2023 HUAWEI. All Rights Reserved. +# +# FS QA Test No. 737 +# +# Append writes to a file approaching 16T and observe if a kernel crash is +# caused by ext4_lblk_t overflow triggering BUG_ON at ext4_mb_new_inode_pa(). +# This is a regression test for commit +# bc056e7163ac ("ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow") +# +#set -x +. ./common/preamble +. ./common/populate +_begin_fstest auto quick insert prealloc + +# real QA test starts here +_fixed_by_kernel_commit bc056e7163ac \ + "ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow" + +_require_xfs_io_command "falloc" +_require_xfs_io_command "finsert" + +# Initalize a 4k 100M fs +dev_size=$((100 * 1024 * 1024)) +_scratch_mkfs_sized $dev_size >>$seqres.full 2>&1 || _fail "mkfs failed" + +_scratch_mount +blksz="$(_get_block_size ${SCRATCH_MNT})" +_require_odirect $blksz + +# Reserve 1M space +$XFS_IO_PROG -f -c "falloc 0 1M" "${SCRATCH_MNT}/tmp" >> $seqres.full + +# Create a file (~16T) with logical block numbers close to overflow +$XFS_IO_PROG -f -c "falloc 0 10M" "${SCRATCH_MNT}/file" >> $seqres.full +insert_size=$((blksz * 4096 - 10 - 3)) +$XFS_IO_PROG -f -c "finsert 1M ${insert_size}M" "${SCRATCH_MNT}/file" >> $seqres.full + +# Filling up the free space ensures that the pre-allocated space is the reserved space. +nr_free=$(stat -f -c '%f' ${SCRATCH_MNT}) +_fill_fs $((nr_free * blksz)) ${SCRATCH_MNT}/fill $blksz 0 >> $seqres.full 2>&1 +sync + +# Remove reserved space to gain free space for allocation +rm -f ${SCRATCH_MNT}/tmp + +# Trying to allocate two blocks triggers BUG_ON. +$XFS_IO_PROG -c "open -ad ${SCRATCH_MNT}/file" -c "pwrite -S 0xff 0 8192" >> $seqres.full + +echo "Silence is golden" + +# success, all done +status=0 +exit
tests/generic/737.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 737 +Silence is golden
Signature · 1 line
2.31.1
Quoted 10 lines · Baokun Li
Append writes to a file approaching 16T and observe if a kernel crash is caused by
ext4_lblk_toverflow triggeringBUG_ONatext4_mb_new_inode_pa(). This is a regression test for commitbc056e7163ac("ext4: fix BUG inext4_mb_new_inode_pa()due to overflow")Signed-off-by Baokun Li <[email protected]>---
V1->V2:
Changes to make the use case more generic, not just for testing ext4.(ext4 and xfs have been tested)
Thanks for this change,
Quoted 15 lines
tests/generic/737 | 55 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/737.out | 2 ++ 2 files changed, 57 insertions(+) create mode 100755 tests/generic/737 create mode 100644 tests/generic/737.outtests/generic/737 new file +2
-0@@ -0,0 +1,55 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0
tests/generic/737 line 12
Quoted 10 lines
tests/generic/737 new file +10
-0+# Copyright (c) 2023 HUAWEI. All Rights Reserved. +# +# FS QA Test No. 737 +# +# Append writes to a file approaching 16T and observe if a kernel crash is +# caused by ext4_lblk_t overflow triggering BUG_ON at ext4_mb_new_inode_pa(). +# This is a regression test for commit +# bc056e7163ac ("ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow") +# +#set -x
Useless comment "set -x"
tests/generic/737 line 19
Quoted 7 lines
tests/generic/737 new file +7
-0+. ./common/preamble +. ./common/populate +_begin_fstest auto quick insert prealloc + +# real QA test starts here +_fixed_by_kernel_commit bc056e7163ac \ + "ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow"
[[ "$FSTYP" =~ ext* ]] && ....
tests/generic/737 line 24
Quoted 5 lines
tests/generic/737 new file +5
-0+ +_require_xfs_io_command "falloc" +_require_xfs_io_command "finsert" + +# Initalize a 4k 100M fs
It might not be 4k block size, so this comment is useless. Or you can say better to use "4k" block size to tigger the bug:)
tests/generic/737 line 30
Quoted 6 lines
tests/generic/737 new file +6
-0+dev_size=$((100 * 1024 * 1024)) +_scratch_mkfs_sized $dev_size >>$seqres.full 2>&1 || _fail "mkfs failed" + +_scratch_mount +blksz="$(_get_block_size ${SCRATCH_MNT})" +_require_odirect $blksz
I think the _require_odirect can be move up, before the mkfs calling.
Quoted 9 lines
tests/generic/737 new file +9
-0+ +# Reserve 1M space +$XFS_IO_PROG -f -c "falloc 0 1M" "${SCRATCH_MNT}/tmp" >> $seqres.full + +# Create a file (~16T) with logical block numbers close to overflow +$XFS_IO_PROG -f -c "falloc 0 10M" "${SCRATCH_MNT}/file" >> $seqres.full +insert_size=$((blksz * 4096 - 10 - 3)) +$XFS_IO_PROG -f -c "finsert 1M ${insert_size}M" "${SCRATCH_MNT}/file" >> $seqres.full +
tests/generic/737 line 49
Quoted 10 lines
tests/generic/737 new file +10
-0+# Filling up the free space ensures that the pre-allocated space is the reserved space. +nr_free=$(stat -f -c '%f' ${SCRATCH_MNT}) +_fill_fs $((nr_free * blksz)) ${SCRATCH_MNT}/fill $blksz 0 >> $seqres.full 2>&1 +sync + +# Remove reserved space to gain free space for allocation +rm -f ${SCRATCH_MNT}/tmp + +# Trying to allocate two blocks triggers BUG_ON. +$XFS_IO_PROG -c "open -ad ${SCRATCH_MNT}/file" -c "pwrite -S 0xff 0 8192" >> $seqres.full
Shouldn't the 8192 be "$((2 * blksz))", if the comment says "two blocks" ?
I tried 1024 blocksize, really can't reproduce this bug, do you know why? Maybe related with the falloc/finsert size?
Anyway, it covers this bug on default block size of ext4, and can be a generic test on other conditions.
Thanks,
Zorro
Quoted 17 lines
tests/generic/737 new file +6
-0+ +echo "Silence is golden" + +# success, all done +status=0 +exittests/generic/737.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 737 +Silence is goldenSignature · 1 line
2.31.1
Quoted 30 lines · Zorro Lang
Quoted 10 lines · Baokun Li
Append writes to a file approaching 16T and observe if a kernel crash is caused by
ext4_lblk_toverflow triggeringBUG_ONatext4_mb_new_inode_pa(). This is a regression test for commitbc056e7163ac("ext4: fix BUG inext4_mb_new_inode_pa()due to overflow")Signed-off-by Baokun Li <[email protected]>---
V1->V2:
Changes to make the use case more generic, not just for testing ext4.(ext4 and xfs have been tested)Thanks for this change,
Quoted 17 lines
tests/generic/737 | 55 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/737.out | 2 ++ 2 files changed, 57 insertions(+)create mode 100755 tests/generic/737
create mode 100644 tests/generic/737.outtests/generic/737 new file +5
-0@@ -0,0 +1,55 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2023 HUAWEI. All Rights Reserved. +# +# FS QA Test No. 737
Quoted 8 lines
tests/generic/737 line 12
Quoted 7 lines
tests/generic/737 new file +7
-0+# +# Append writes to a file approaching 16T and observe if a kernel crash is +# caused by ext4_lblk_t overflow triggering BUG_ON at ext4_mb_new_inode_pa(). +# This is a regression test for commit +# bc056e7163ac ("ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow") +# +#set -xUseless comment "set -x"
Oh, I'm sorry, it was for debugging and I forgot to delete it.
Quoted 8 lines
tests/generic/737 line 19
Quoted 7 lines
tests/generic/737 new file +7
-0+. ./common/preamble +. ./common/populate +_begin_fstest auto quick insert prealloc + +# real QA test starts here +_fixed_by_kernel_commit bc056e7163ac \ + "ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow"[[ "$FSTYP" =~ ext* ]] && ....
This looks good.
Quoted 8 lines
tests/generic/737 line 24
Quoted 6 lines
tests/generic/737 new file +5
-0+ +_require_xfs_io_command "falloc" +_require_xfs_io_command "finsert" + +# Initalize a 4k 100M fsIt might not be 4k block size, so this comment is useless. Or you can say better to use "4k" block size to tigger the bug:)
OK!
Quoted 7 lines
tests/generic/737 line 30
Quoted 6 lines
tests/generic/737 new file +6
-0+dev_size=$((100 * 1024 * 1024)) +_scratch_mkfs_sized $dev_size >>$seqres.full 2>&1 || _fail "mkfs failed" + +_scratch_mount +blksz="$(_get_block_size ${SCRATCH_MNT})" +_require_odirect $blkszI think the
_require_odirectcan be move up, before the mkfs calling.
Totally agree!
Quoted 12 lines
Quoted 12 lines
tests/generic/737 new file +12
-0+ +# Reserve 1M space +$XFS_IO_PROG -f -c "falloc 0 1M" "${SCRATCH_MNT}/tmp" >> $seqres.full + +# Create a file (~16T) with logical block numbers close to overflow +$XFS_IO_PROG -f -c "falloc 0 10M" "${SCRATCH_MNT}/file" >> $seqres.full +insert_size=$((blksz * 4096 - 10 - 3)) +$XFS_IO_PROG -f -c "finsert 1M ${insert_size}M" "${SCRATCH_MNT}/file" >> $seqres.full + +# Filling up the free space ensures that the pre-allocated space is the reserved space. +nr_free=$(stat -f -c '%f' ${SCRATCH_MNT}) +_fill_fs $((nr_free * blksz)) ${SCRATCH_MNT}/fill $blksz 0 >> $seqres.full 2>&1
Quoted 8 lines
tests/generic/737 line 49
Quoted 7 lines
tests/generic/737 new file +7
-0+sync + +# Remove reserved space to gain free space for allocation +rm -f ${SCRATCH_MNT}/tmp + +# Trying to allocate two blocks triggers BUG_ON. +$XFS_IO_PROG -c "open -ad ${SCRATCH_MNT}/file" -c "pwrite -S 0xff 0 8192" >> $seqres.fullShouldn't the 8192 be "$((2 * blksz))", if the comment says "two blocks" ?
Okay, I'll change it to "$((2 * blksz))".
Quoted 2 lines
I tried 1024 blocksize, really can't reproduce this bug, do you know why? Maybe related with the falloc/finsert size?
I'm not sure why this isn't triggered at a block size of 1024, I haven't looked into this in depth.
Quoted 5 lines
Anyway, it covers this bug on default block size of ext4, and can be a generic test on other conditions.
Thanks,
Zorro
Yes! Thank you very much for your review!
Quoted 9 lines
Quoted 9 lines
tests/generic/737 new file +6
-0+ +echo "Silence is golden" + +# success, all done +status=0 +exittests/generic/737.out new file +0
-0
Quoted 8 lines
Quoted 8 lines
tests/generic/737.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 737 +Silence is goldenSignature · 1 line
2.31.1
Thanks!
Signature · 3 lines
With Best Regards, Baokun Li .