Skip to contentSkip to conversation

generic: add test for XFS forkoff miscalcution on 32-bit platform

PATCH Superseded Gao Xiang 3 participants 8 messages Nov 18, 2020 – Nov 24, 2020

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 generic: add test for XFS forkoff miscalcution on 32-bit platform

There is a regression that recent XFS_LITINO(mp) update causes xfs_attr_shortform_bytesfit() returns maxforkoff rather than 0.

Therefore, one result is
"ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));"

Add a regression test in fstests generic to look after that since the testcase itself isn't xfs-specific.

---
I have no usable 32-bit test environment to run xfstests, that is what I have checked:
- checked this new script can pass on x86_64;
- manually ran script commands on i386 buildroot with problematic kernel and the filesystem got stuck on getfattr command.

 tests/generic/618     | 56 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/618.out |  4 ++++
 tests/generic/group   |  1 +
 3 files changed, 61 insertions(+)
 create mode 100755 tests/generic/618
 create mode 100644 tests/generic/618.out
tests/generic/618 new file +56 -0
new file mode 100755
index 00000000..997c6f75
@@ -0,0 +1,56 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Red Hat, Inc. All Rights Reserved.
+#
+# FS QA Test 618
+#
+# Verify that forkoff can be returned as 0 properly if it isn't
+# able to fit inline for XFS.
+# However, this test is fs-neutral and can be done quickly so
+# leave it in generic
+# This test verifies the problem fixed in kernel with commit
+# xxxxxxxxxxxx ("xfs: fix forkoff miscalculation related to XFS_LITINO(mp)")
+
+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
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+_supported_fs generic
+_require_test
+_require_attrs user
+
+localfile="${TEST_DIR}/testfile"
+
+touch "${localfile}"
+"${SETFATTR_PROG}" -n user.0 -v "`seq 0 80`" "${localfile}"
+"${SETFATTR_PROG}" -n user.1 -v "`seq 0 80`" "${localfile}"
+
+# Make sure that changes are written to disk
+_test_cycle_mount
+
+# check getfattr result as well
+_getfattr --absolute-names -ebase64 -d $localfile | tail -n +2 | sort
+
+status=0
+exit
tests/generic/618.out new file +4 -0
new file mode 100644
index 00000000..848fdc58
@@ -0,0 +1,4 @@
+QA output created by 618
+
+user.0=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
+user.1=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
tests/generic/group +1 -0
index 94e860b8..eca9d619 100644
@@ -620,3 +620,4 @@
 615 auto rw
 616 auto rw io_uring stress
 617 auto rw io_uring stress
+618 auto quick attr
Signature · 1 line
2.18.4
#1 lore raw
Quoted 32 lines · Gao Xiang

There is a regression that recent XFS_LITINO(mp) update causes xfs_attr_shortform_bytesfit() returns maxforkoff rather than 0.

Therefore, one result is
"ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));"

Add a regression test in fstests generic to look after that since the testcase itself isn't xfs-specific.

---
I have no usable 32-bit test environment to run xfstests, that is what I have checked:
- checked this new script can pass on x86_64;
- manually ran script commands on i386 buildroot with problematic kernel and the filesystem got stuck on getfattr command.

 tests/generic/618     | 56 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/618.out |  4 ++++
 tests/generic/group   |  1 +
 3 files changed, 61 insertions(+)
 create mode 100755 tests/generic/618
 create mode 100644 tests/generic/618.out
tests/generic/618 new file +2 -0
new file mode 100755
index 00000000..997c6f75
@@ -0,0 +1,56 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0

tests/generic/618 line 12

Quoted 10 lines
tests/generic/618 new file +10 -0
+# Copyright (c) 2020 Red Hat, Inc. All Rights Reserved.
+#
+# FS QA Test 618
+#
+# Verify that forkoff can be returned as 0 properly if it isn't
+# able to fit inline for XFS.
+# However, this test is fs-neutral and can be done quickly so
+# leave it in generic
+# This test verifies the problem fixed in kernel with commit
+# xxxxxxxxxxxx ("xfs: fix forkoff miscalculation related to XFS_LITINO(mp)")

Would you please re-post when the commit is upstream? With the commit ID updated.

Quoted 21 lines
tests/generic/618 new file +21 -0
+
+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
+. ./common/attr
+

tests/generic/618 line 43

Quoted 10 lines
tests/generic/618 new file +10 -0
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+_supported_fs generic
+_require_test
+_require_attrs user
+
+localfile="${TEST_DIR}/testfile"

Usually we use a testfile prefixed with $seq, e.g.

localfile=${TEST_DIR}/$seq.testfile

And remove it before test to avoid side effects from previous runs.

rm -f $localfile
touch $localfile

tests/generic/618 line 47

Quoted 4 lines
tests/generic/618 new file +4 -0
+
+touch "${localfile}"
+"${SETFATTR_PROG}" -n user.0 -v "`seq 0 80`" "${localfile}"
+"${SETFATTR_PROG}" -n user.1 -v "`seq 0 80`" "${localfile}"

I'd be better to add comments on why we need two user attrs and why we need such long attr value.

tests/generic/618 line 52

Quoted 5 lines
tests/generic/618 new file +5 -0
+
+# Make sure that changes are written to disk
+_test_cycle_mount
+
+# check getfattr result as well

Also, better to document the test failure behavior, e.g. kernel crash or hung or just a getfattr failure.

Thanks,
Eryu

Quoted 25 lines
tests/generic/618 new file +4 -0
+_getfattr --absolute-names -ebase64 -d $localfile | tail -n +2 | sort
+
+status=0
+exit
tests/generic/618.out new file +4 -0
new file mode 100644
index 00000000..848fdc58
@@ -0,0 +1,4 @@
+QA output created by 618
+
+user.0=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
+user.1=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
tests/generic/group +1 -0
index 94e860b8..eca9d619 100644
@@ -620,3 +620,4 @@
 615 auto rw
 616 auto rw io_uring stress
 617 auto rw io_uring stress
+618 auto quick attr
Signature · 1 line
2.18.4
author
#2 lore raw

Hi Eryu,

Quoted 1 line · Eryu Guan

On Wed, Nov 18, 2020 at 02:02:58PM +0800, Gao Xiang wrote:

...

Quoted 4 lines
Quoted 1 line

+# xxxxxxxxxxxx ("xfs: fix forkoff miscalculation related to XFS_LITINO(mp)")

Would you please re-post when the commit is upstream? With the commit ID updated.

Sure will definitely do tomorrow.

Quoted 35 lines
Quoted 22 lines
tests/generic/618 new file +21 -0
+
+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
+. ./common/attr
+

tests/generic/618 line 43

Quoted 10 lines
tests/generic/618 new file +10 -0
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+_supported_fs generic
+_require_test
+_require_attrs user
+
+localfile="${TEST_DIR}/testfile"

Usually we use a testfile prefixed with $seq, e.g.

Quoted 6 lines

localfile=${TEST_DIR}/$seq.testfile

And remove it before test to avoid side effects from previous runs.

rm -f $localfile
touch $localfile

okay, will fix.

Actually I didn't take much time on this (just copy from generic/611 and use $TEST_DIR instead.)

Quoted 8 lines

tests/generic/618 line 47

Quoted 5 lines
tests/generic/618 new file +4 -0
+
+touch "${localfile}"
+"${SETFATTR_PROG}" -n user.0 -v "`seq 0 80`" "${localfile}"
+"${SETFATTR_PROG}" -n user.1 -v "`seq 0 80`" "${localfile}"

I'd be better to add comments on why we need two user attrs and why we need such long attr value.

There is no specific reason of using "user attrs" and this combination, just the example in
commit ada49d64fb35 ("xfs: fix forkoff miscalculation related to XFS_LITINO(mp)")

long xattrs which acrosses inline xattr shortform fork can trigger this issue. As I said in the patch, the bug itself is xfs-specific, but the testcase is generic.

Quoted 9 lines

tests/generic/618 line 52

Quoted 6 lines
tests/generic/618 new file +5 -0
+
+# Make sure that changes are written to disk
+_test_cycle_mount
+
+# check getfattr result as well

Also, better to document the test failure behavior, e.g. kernel crash or hung or just a getfattr failure.

It depends, since ASSERT already fails in the second setfattr and similar as
https://bugzilla.redhat.com/show_bug.cgi?id=1894177

if CONFIG_XFS_ASSERT_FATAL=n, what I saw was that hung on the _getfattr line. But in any case, _getfattr won't success with the correct result. So I don't think it needs to document such unstable status.

Thanks,
Gao Xiang

Quoted 30 lines

Thanks,
Eryu

Quoted 25 lines
tests/generic/618 new file +4 -0
+_getfattr --absolute-names -ebase64 -d $localfile | tail -n +2 | sort
+
+status=0
+exit
tests/generic/618.out new file +4 -0
new file mode 100644
index 00000000..848fdc58
@@ -0,0 +1,4 @@
+QA output created by 618
+
+user.0=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
+user.1=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
tests/generic/group +1 -0
index 94e860b8..eca9d619 100644
@@ -620,3 +620,4 @@
 615 auto rw
 616 auto rw io_uring stress
 617 auto rw io_uring stress
+618 auto quick attr
Signature · 1 line
2.18.4
author
#3 lore raw

PATCH v2 1/1 generic: add test for XFS forkoff miscalcution on 32-bit platform

In reply to Gao Xiang

There is a regression that recent XFS_LITINO(mp) update causes xfs_attr_shortform_bytesfit() returns maxforkoff rather than 0.

Therefore, one result is
"ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));"

Add a regression test in fstests generic to look after that since the testcase itself isn't xfs-specific.

---
changes since v1:
- update commit id since the fix has been upstreamed (Eryu);
- switch to use scratch_mkfs instead since fixed inode size is prefered to keep XFS_LITINO value can trigger the issue for v4 (412) and v5 (336); and no need to use TEST_DIR "rm localfile" way
- refine some inlined comments.

 tests/generic/618     | 67 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/618.out |  4 +++
 tests/generic/group   |  1 +
 3 files changed, 72 insertions(+)
 create mode 100755 tests/generic/618
 create mode 100644 tests/generic/618.out
tests/generic/618 new file +67 -0
new file mode 100755
index 00000000..bdaa3874
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Red Hat, Inc. All Rights Reserved.
+#
+# FS QA Test 618
+#
+# Verify that forkoff can be returned as 0 properly if it isn't
+# able to fit inline for XFS.
+# However, this test is fs-neutral and can be done quickly so
+# leave it in generic
+# This test verifies the problem fixed in kernel with commit
+# ada49d64fb35 ("xfs: fix forkoff miscalculation related to XFS_LITINO(mp)")
+
+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
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+_supported_fs generic
+_require_scratch
+_require_attrs user
+
+# Use fixed inode size 512, so both v4 and v5 can be tested,
+# and also make sure the issue can be triggered if the default
+# inode size is changed later.
+[ $FSTYP = "xfs" ] && MKFS_OPTIONS="$MKFS_OPTIONS -i size=512"
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount
+
+localfile="${SCRATCH_MNT}/testfile"
+touch $localfile
+
+# value cannot exceed XFS_ATTR_SF_ENTSIZE_MAX (256) or it will turn into
+# leaf form directly; the following combination can trigger the issue for
+# both v4 (XFS_LITINO = 412) & v5 (XFS_LITINO = 336) fses.
+"${SETFATTR_PROG}" -n user.0 -v "`seq 0 80`" "${localfile}"
+"${SETFATTR_PROG}" -n user.1 -v "`seq 0 80`" "${localfile}"
+
+# Make sure that changes are written to disk
+_scratch_cycle_mount
+
+# getfattr won't succeed with the expected result if fails
+_getfattr --absolute-names -ebase64 -d $localfile | tail -n +2 | sort
+
+_scratch_unmount
+status=0
+exit
tests/generic/618.out new file +4 -0
new file mode 100644
index 00000000..848fdc58
@@ -0,0 +1,4 @@
+QA output created by 618
+
+user.0=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
+user.1=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
tests/generic/group +1 -0
index 94e860b8..eca9d619 100644
@@ -620,3 +620,4 @@
 615 auto rw
 616 auto rw io_uring stress
 617 auto rw io_uring stress
+618 auto quick attr
Signature · 1 line
2.18.4
#4 lore raw
Quoted 63 lines · Gao Xiang

There is a regression that recent XFS_LITINO(mp) update causes xfs_attr_shortform_bytesfit() returns maxforkoff rather than 0.

Therefore, one result is
"ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));"

Add a regression test in fstests generic to look after that since the testcase itself isn't xfs-specific.

---
changes since v1:
- update commit id since the fix has been upstreamed (Eryu);
- switch to use scratch_mkfs instead since fixed inode size is prefered to keep XFS_LITINO value can trigger the issue for v4 (412) and v5 (336); and no need to use TEST_DIR "rm localfile" way
- refine some inlined comments.

 tests/generic/618     | 67 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/618.out |  4 +++
 tests/generic/group   |  1 +
 3 files changed, 72 insertions(+)
 create mode 100755 tests/generic/618
 create mode 100644 tests/generic/618.out
tests/generic/618 new file +31 -0
new file mode 100755
index 00000000..bdaa3874
@@ -0,0 +1,67 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Red Hat, Inc. All Rights Reserved.
+#
+# FS QA Test 618
+#
+# Verify that forkoff can be returned as 0 properly if it isn't
+# able to fit inline for XFS.
+# However, this test is fs-neutral and can be done quickly so
+# leave it in generic
+# This test verifies the problem fixed in kernel with commit
+# ada49d64fb35 ("xfs: fix forkoff miscalculation related to XFS_LITINO(mp)")
+
+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

tests/generic/618 line 41

Quoted 10 lines
tests/generic/618 new file +10 -0
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+_supported_fs generic
+_require_scratch
+_require_attrs user

Does this require

_require_no_xfs_bug_on_assert ?

Quoted 6 lines
tests/generic/618 new file +6 -0
+
+# Use fixed inode size 512, so both v4 and v5 can be tested,
+# and also make sure the issue can be triggered if the default
+# inode size is changed later.
+[ $FSTYP = "xfs" ] && MKFS_OPTIONS="$MKFS_OPTIONS -i size=512"
+_scratch_mkfs > $seqres.full 2>&1

tests/generic/618 line 57

Quoted 10 lines
tests/generic/618 new file +10 -0
+_scratch_mount
+
+localfile="${SCRATCH_MNT}/testfile"
+touch $localfile
+
+# value cannot exceed XFS_ATTR_SF_ENTSIZE_MAX (256) or it will turn into
+# leaf form directly; the following combination can trigger the issue for
+# both v4 (XFS_LITINO = 412) & v5 (XFS_LITINO = 336) fses.
+"${SETFATTR_PROG}" -n user.0 -v "`seq 0 80`" "${localfile}"
+"${SETFATTR_PROG}" -n user.1 -v "`seq 0 80`" "${localfile}"

It's probably worth mentioning that the second setattr causes an integer underflow that is incorrectly typecast, leading to the assert triggering. Otherwise this seems reasonable to me.

--D

Quoted 32 lines
tests/generic/618 new file +10 -0
+
+# Make sure that changes are written to disk
+_scratch_cycle_mount
+
+# getfattr won't succeed with the expected result if fails
+_getfattr --absolute-names -ebase64 -d $localfile | tail -n +2 | sort
+
+_scratch_unmount
+status=0
+exit
tests/generic/618.out new file +4 -0
new file mode 100644
index 00000000..848fdc58
@@ -0,0 +1,4 @@
+QA output created by 618
+
+user.0=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
+user.1=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
tests/generic/group +1 -0
index 94e860b8..eca9d619 100644
@@ -620,3 +620,4 @@
 615 auto rw
 616 auto rw io_uring stress
 617 auto rw io_uring stress
+618 auto quick attr
Signature · 1 line
2.18.4
author
#5 lore raw

Hi Darrick,

Quoted 1 line · Darrick J. Wong

On Mon, Nov 23, 2020 at 04:20:47PM +0800, Gao Xiang wrote:

...

Quoted 8 lines

tests/generic/618 line 41

Quoted 3 lines
tests/generic/618 new file +3 -0
+_supported_fs generic
+_require_scratch
+_require_attrs user

Does this require

_require_no_xfs_bug_on_assert ?

For the sake of harmless testcase, I think that is fine and I will add it in the next version as
[ $FSTYP = "xfs" ] && _require_no_xfs_bug_on_assert

To clarify the synotom:
if bug_on_assert is on, it will bug_on on the second setfattr, _scratch_cycle_mount will fail due to
umount: can't unmount /tmp/mnt: Device or resource busy

if _scratch_cycle_mount is removed, _getfattr will hung due to (I think) unbalanced xfs_ilock(dp, XFS_ILOCK_EXCL) in xfs_attr_set() and xfs_attr_get() will take the lock again.

if bug_on_assert is off, it will fail on _scratch_cycle_mount due to log recovery replay fail when mounting as below

[  856.786226] XFS (sda): Mounting V5 Filesystem                       
[  856.802704] XFS (sda): Starting recovery (logdev: internal)                                                                                                                                                    
[  856.806362] XFS: Assertion failed: len <= XFS_DFORK_ASIZE(dip, mp), file: fs/xfs/xfs_inode_item_recover.c, line: 426

but if the line of _scratch_cycle_mount is removed, _getfattr will success due to

	ifp->if_u1.if_data = krealloc(ifp->if_u1.if_data, roundup(new_size, 4),
				      GFP_NOFS | __GFP_NOFAIL);
	ifp->if_bytes = new_size;

in xfs_idata_realloc(), and xfs_attr_shortform_getvalue() will temporary ok. yet this testcase have _scratch_cycle_mount anyway.

In any case, it's fine with _getfattr after _scratch_cycle_mount for this testcase.

And "bug_on_assert is off" does no harm to the system stablity itself so I think that's better.

Quoted 12 lines
Quoted 12 lines
tests/generic/618 new file +12 -0
+
+# Use fixed inode size 512, so both v4 and v5 can be tested,
+# and also make sure the issue can be triggered if the default
+# inode size is changed later.
+[ $FSTYP = "xfs" ] && MKFS_OPTIONS="$MKFS_OPTIONS -i size=512"
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount
+
+localfile="${SCRATCH_MNT}/testfile"
+touch $localfile
+
+# value cannot exceed XFS_ATTR_SF_ENTSIZE_MAX (256) or it will turn into
Quoted 8 lines

tests/generic/618 line 57

Quoted 4 lines
tests/generic/618 new file +4 -0
+# leaf form directly; the following combination can trigger the issue for
+# both v4 (XFS_LITINO = 412) & v5 (XFS_LITINO = 336) fses.
+"${SETFATTR_PROG}" -n user.0 -v "`seq 0 80`" "${localfile}"
+"${SETFATTR_PROG}" -n user.1 -v "`seq 0 80`" "${localfile}"

It's probably worth mentioning that the second setattr causes an integer underflow that is incorrectly typecast, leading to the assert triggering. Otherwise this seems reasonable to me.

Ok, will try to add in the next version as well.

Thanks,
Gao Xiang

Quoted 36 lines

--D

Quoted 32 lines
tests/generic/618 new file +10 -0
+
+# Make sure that changes are written to disk
+_scratch_cycle_mount
+
+# getfattr won't succeed with the expected result if fails
+_getfattr --absolute-names -ebase64 -d $localfile | tail -n +2 | sort
+
+_scratch_unmount
+status=0
+exit
tests/generic/618.out new file +4 -0
new file mode 100644
index 00000000..848fdc58
@@ -0,0 +1,4 @@
+QA output created by 618
+
+user.0=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
+user.1=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
tests/generic/group +1 -0
index 94e860b8..eca9d619 100644
@@ -620,3 +620,4 @@
 615 auto rw
 616 auto rw io_uring stress
 617 auto rw io_uring stress
+618 auto quick attr
Signature · 1 line
2.18.4
author
#6 lore raw

PATCH v3 1/1 generic: add test for XFS forkoff miscalcution on 32-bit platform

In reply to Gao Xiang

There is a regression that recent XFS_LITINO(mp) update causes xfs_attr_shortform_bytesfit() returns maxforkoff rather than 0.

Therefore, one result is
"ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));"

Add a regression test in fstests generic to look after that since the testcase itself isn't xfs-specific.

---
changes since v2:
- "_require_no_xfs_bug_on_assert" to avoid crashing the system (Darrick);
- refine a commit for more details (Darrick)

 tests/generic/618     | 75 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/618.out |  4 +++
 tests/generic/group   |  1 +
 3 files changed, 80 insertions(+)
 create mode 100755 tests/generic/618
 create mode 100644 tests/generic/618.out
tests/generic/618 new file +75 -0
new file mode 100755
index 00000000..f1c1605e
@@ -0,0 +1,75 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Red Hat, Inc. All Rights Reserved.
+#
+# FS QA Test 618
+#
+# Verify that forkoff can be returned as 0 properly if it isn't
+# able to fit inline for XFS.
+# However, this test is fs-neutral and can be done quickly so
+# leave it in generic
+# This test verifies the problem fixed in kernel with commit
+# ada49d64fb35 ("xfs: fix forkoff miscalculation related to XFS_LITINO(mp)")
+
+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
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+_supported_fs generic
+_require_scratch
+_require_attrs user
+
+if [ $FSTYP = "xfs" ]; then
+	# avoid crashing the system if possible
+	_require_no_xfs_bug_on_assert
+
+	# Use fixed inode size 512, so both v4 and v5 can be tested,
+	# and also make sure the issue can be triggered if the default
+	# inode size is changed later.
+	MKFS_OPTIONS="$MKFS_OPTIONS -i size=512"
+fi
+
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount
+
+localfile="${SCRATCH_MNT}/testfile"
+touch $localfile
+
+# value cannot exceed XFS_ATTR_SF_ENTSIZE_MAX (256) or it will turn into leaf
+# form directly; the following combination can trigger the issue for both v4
+# (XFS_LITINO = 412) & v5 (XFS_LITINO = 336) fses, in details the 2nd setattr
+# causes an integer underflow that is incorrectly typecast, leading to the
+# assert triggering.
+"${SETFATTR_PROG}" -n user.0 -v "`seq 0 80`" "${localfile}"
+"${SETFATTR_PROG}" -n user.1 -v "`seq 0 80`" "${localfile}"
+
+# Make sure that changes are written to disk
+_scratch_cycle_mount
+
+# getfattr won't succeed with the expected result if fails
+_getfattr --absolute-names -ebase64 -d $localfile | tail -n +2 | sort
+
+_scratch_unmount
+status=0
+exit
tests/generic/618.out new file +4 -0
new file mode 100644
index 00000000..848fdc58
@@ -0,0 +1,4 @@
+QA output created by 618
+
+user.0=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
+user.1=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
tests/generic/group +1 -0
index 94e860b8..eca9d619 100644
@@ -620,3 +620,4 @@
 615 auto rw
 616 auto rw io_uring stress
 617 auto rw io_uring stress
+618 auto quick attr
Signature · 1 line
2.18.4
Reviewed-by on v3 1/1
#7 lore raw
Quoted 10 lines · Gao Xiang

There is a regression that recent XFS_LITINO(mp) update causes xfs_attr_shortform_bytesfit() returns maxforkoff rather than 0.

Therefore, one result is
"ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));"

Add a regression test in fstests generic to look after that since the testcase itself isn't xfs-specific.

Looks good to me,

--D

Quoted 115 lines

---
changes since v2:
- "_require_no_xfs_bug_on_assert" to avoid crashing the system (Darrick);
- refine a commit for more details (Darrick)

 tests/generic/618     | 75 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/618.out |  4 +++
 tests/generic/group   |  1 +
 3 files changed, 80 insertions(+)
 create mode 100755 tests/generic/618
 create mode 100644 tests/generic/618.out
tests/generic/618 new file +75 -0
new file mode 100755
index 00000000..f1c1605e
@@ -0,0 +1,75 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Red Hat, Inc. All Rights Reserved.
+#
+# FS QA Test 618
+#
+# Verify that forkoff can be returned as 0 properly if it isn't
+# able to fit inline for XFS.
+# However, this test is fs-neutral and can be done quickly so
+# leave it in generic
+# This test verifies the problem fixed in kernel with commit
+# ada49d64fb35 ("xfs: fix forkoff miscalculation related to XFS_LITINO(mp)")
+
+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
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+_supported_fs generic
+_require_scratch
+_require_attrs user
+
+if [ $FSTYP = "xfs" ]; then
+	# avoid crashing the system if possible
+	_require_no_xfs_bug_on_assert
+
+	# Use fixed inode size 512, so both v4 and v5 can be tested,
+	# and also make sure the issue can be triggered if the default
+	# inode size is changed later.
+	MKFS_OPTIONS="$MKFS_OPTIONS -i size=512"
+fi
+
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount
+
+localfile="${SCRATCH_MNT}/testfile"
+touch $localfile
+
+# value cannot exceed XFS_ATTR_SF_ENTSIZE_MAX (256) or it will turn into leaf
+# form directly; the following combination can trigger the issue for both v4
+# (XFS_LITINO = 412) & v5 (XFS_LITINO = 336) fses, in details the 2nd setattr
+# causes an integer underflow that is incorrectly typecast, leading to the
+# assert triggering.
+"${SETFATTR_PROG}" -n user.0 -v "`seq 0 80`" "${localfile}"
+"${SETFATTR_PROG}" -n user.1 -v "`seq 0 80`" "${localfile}"
+
+# Make sure that changes are written to disk
+_scratch_cycle_mount
+
+# getfattr won't succeed with the expected result if fails
+_getfattr --absolute-names -ebase64 -d $localfile | tail -n +2 | sort
+
+_scratch_unmount
+status=0
+exit
tests/generic/618.out new file +4 -0
new file mode 100644
index 00000000..848fdc58
@@ -0,0 +1,4 @@
+QA output created by 618
+
+user.0=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
+user.1=0sMAoxCjIKMwo0CjUKNgo3CjgKOQoxMAoxMQoxMgoxMwoxNAoxNQoxNgoxNwoxOAoxOQoyMAoyMQoyMgoyMwoyNAoyNQoyNgoyNwoyOAoyOQozMAozMQozMgozMwozNAozNQozNgozNwozOAozOQo0MAo0MQo0Mgo0Mwo0NAo0NQo0Ngo0Nwo0OAo0OQo1MAo1MQo1Mgo1Mwo1NAo1NQo1Ngo1Nwo1OAo1OQo2MAo2MQo2Mgo2Mwo2NAo2NQo2Ngo2Nwo2OAo2OQo3MAo3MQo3Mgo3Mwo3NAo3NQo3Ngo3Nwo3OAo3OQo4MA==
tests/generic/group +1 -0
index 94e860b8..eca9d619 100644
@@ -620,3 +620,4 @@
 615 auto rw
 616 auto rw io_uring stress
 617 auto rw io_uring stress
+618 auto quick attr
Signature · 1 line
2.18.4