* Re: [PATCH 1/2] ext4: alloc test super block from sget
2024-03-01 12:08 ` [PATCH 1/2] ext4: alloc test super block from sget Kemeng Shi
@ 2024-03-01 8:25 ` Christian Brauner
2024-03-01 8:29 ` Christian Brauner
2024-03-01 9:03 ` Kemeng Shi
0 siblings, 2 replies; 6+ messages in thread
From: Christian Brauner @ 2024-03-01 8:25 UTC (permalink / raw)
To: Kemeng Shi
Cc: tytso, adilger.kernel, linux-ext4, linux-kernel, naresh.kamboju,
daniel.diaz, linux
On Fri, Mar 01, 2024 at 08:08:15PM +0800, Kemeng Shi wrote:
> This fix the oops in ext4 unit test which is cuased by NULL sb.s_user_ns
> as following:
> <4>[ 14.344565] map_id_range_down (kernel/user_namespace.c:318)
> <4>[ 14.345378] make_kuid (kernel/user_namespace.c:415)
> <4>[ 14.345998] inode_init_always (include/linux/fs.h:1375 fs/inode.c:174)
> <4>[ 14.346696] alloc_inode (fs/inode.c:268)
> <4>[ 14.347353] new_inode_pseudo (fs/inode.c:1007)
> <4>[ 14.348016] new_inode (fs/inode.c:1033)
> <4>[ 14.348644] ext4_mb_init (fs/ext4/mballoc.c:3404 fs/ext4/mballoc.c:3719)
> <4>[ 14.349312] mbt_kunit_init (fs/ext4/mballoc-test.c:57
> fs/ext4/mballoc-test.c:314)
> <4>[ 14.349983] kunit_try_run_case (lib/kunit/test.c:388 lib/kunit/test.c:443)
> <4>[ 14.350696] kunit_generic_run_threadfn_adapter (lib/kunit/try-catch.c:30)
> <4>[ 14.351530] kthread (kernel/kthread.c:388)
> <4>[ 14.352168] ret_from_fork (arch/arm64/kernel/entry.S:861)
> <0>[ 14.353385] Code: 52808004 b8236ae7 72be5e44 b90004c4 (38e368a1)
>
> Alloc test super block from sget to properly initialize test super block
> to fix the issue.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> ---
> fs/ext4/mballoc-test.c | 46 ++++++++++++++++++++++++++++--------------
> 1 file changed, 31 insertions(+), 15 deletions(-)
>
> diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c
> index 12d0b22cabe1..1da52bbf4599 100644
> --- a/fs/ext4/mballoc-test.c
> +++ b/fs/ext4/mballoc-test.c
> @@ -21,16 +21,27 @@ struct mbt_ctx {
> };
>
> struct mbt_ext4_super_block {
> - struct super_block sb;
> + struct ext4_super_block es;
> + struct ext4_sb_info sbi;
> struct mbt_ctx mbt_ctx;
> };
>
> -#define MBT_CTX(_sb) (&(container_of((_sb), struct mbt_ext4_super_block, sb)->mbt_ctx))
> +#define MBT_SB(_sb) (container_of((_sb)->s_fs_info, struct mbt_ext4_super_block, sbi))
> +#define MBT_CTX(_sb) (&MBT_SB(_sb)->mbt_ctx)
> #define MBT_GRP_CTX(_sb, _group) (&MBT_CTX(_sb)->grp_ctx[_group])
>
> static const struct super_operations mbt_sops = {
> };
>
> +static void mbt_kill_sb(struct super_block *sb)
> +{
> +}
> +
> +static struct file_system_type mbt_fs_type = {
> + .name = "mballoc test",
> + .kill_sb = mbt_kill_sb,
> +};
> +
> static int mbt_mb_init(struct super_block *sb)
> {
> int ret;
> @@ -72,43 +83,48 @@ static void mbt_mb_release(struct super_block *sb)
> kfree(sb->s_bdev);
> }
>
> +static int mbt_set(struct super_block *sb, void *data)
> +{
> + return 0;
> +}
> +
> static struct super_block *mbt_ext4_alloc_super_block(void)
> {
> - struct ext4_super_block *es = kzalloc(sizeof(*es), GFP_KERNEL);
> - struct ext4_sb_info *sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
> struct mbt_ext4_super_block *fsb = kzalloc(sizeof(*fsb), GFP_KERNEL);
> + struct super_block *sb = sget(&mbt_fs_type, NULL, mbt_set, 0, NULL);
> + struct ext4_sb_info *sbi;
>
> - if (fsb == NULL || sbi == NULL || es == NULL)
> + if (fsb == NULL || sb == NULL)
sget() returns error pointer on failure. So you should check for IS_ERR(sb).
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] ext4: alloc test super block from sget
2024-03-01 8:25 ` Christian Brauner
@ 2024-03-01 8:29 ` Christian Brauner
2024-03-01 9:03 ` Kemeng Shi
1 sibling, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2024-03-01 8:29 UTC (permalink / raw)
To: Kemeng Shi
Cc: tytso, adilger.kernel, linux-ext4, linux-kernel, naresh.kamboju,
daniel.diaz, linux
On Fri, Mar 01, 2024 at 09:25:59AM +0100, Christian Brauner wrote:
> On Fri, Mar 01, 2024 at 08:08:15PM +0800, Kemeng Shi wrote:
> > This fix the oops in ext4 unit test which is cuased by NULL sb.s_user_ns
> > as following:
> > <4>[ 14.344565] map_id_range_down (kernel/user_namespace.c:318)
> > <4>[ 14.345378] make_kuid (kernel/user_namespace.c:415)
> > <4>[ 14.345998] inode_init_always (include/linux/fs.h:1375 fs/inode.c:174)
> > <4>[ 14.346696] alloc_inode (fs/inode.c:268)
> > <4>[ 14.347353] new_inode_pseudo (fs/inode.c:1007)
> > <4>[ 14.348016] new_inode (fs/inode.c:1033)
> > <4>[ 14.348644] ext4_mb_init (fs/ext4/mballoc.c:3404 fs/ext4/mballoc.c:3719)
> > <4>[ 14.349312] mbt_kunit_init (fs/ext4/mballoc-test.c:57
> > fs/ext4/mballoc-test.c:314)
> > <4>[ 14.349983] kunit_try_run_case (lib/kunit/test.c:388 lib/kunit/test.c:443)
> > <4>[ 14.350696] kunit_generic_run_threadfn_adapter (lib/kunit/try-catch.c:30)
> > <4>[ 14.351530] kthread (kernel/kthread.c:388)
> > <4>[ 14.352168] ret_from_fork (arch/arm64/kernel/entry.S:861)
> > <0>[ 14.353385] Code: 52808004 b8236ae7 72be5e44 b90004c4 (38e368a1)
> >
> > Alloc test super block from sget to properly initialize test super block
> > to fix the issue.
> >
> > Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> > Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
> > Reported-by: Guenter Roeck <linux@roeck-us.net>
> > ---
> > fs/ext4/mballoc-test.c | 46 ++++++++++++++++++++++++++++--------------
> > 1 file changed, 31 insertions(+), 15 deletions(-)
> >
> > diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c
> > index 12d0b22cabe1..1da52bbf4599 100644
> > --- a/fs/ext4/mballoc-test.c
> > +++ b/fs/ext4/mballoc-test.c
> > @@ -21,16 +21,27 @@ struct mbt_ctx {
> > };
> >
> > struct mbt_ext4_super_block {
> > - struct super_block sb;
> > + struct ext4_super_block es;
> > + struct ext4_sb_info sbi;
> > struct mbt_ctx mbt_ctx;
> > };
> >
> > -#define MBT_CTX(_sb) (&(container_of((_sb), struct mbt_ext4_super_block, sb)->mbt_ctx))
> > +#define MBT_SB(_sb) (container_of((_sb)->s_fs_info, struct mbt_ext4_super_block, sbi))
> > +#define MBT_CTX(_sb) (&MBT_SB(_sb)->mbt_ctx)
> > #define MBT_GRP_CTX(_sb, _group) (&MBT_CTX(_sb)->grp_ctx[_group])
> >
> > static const struct super_operations mbt_sops = {
> > };
> >
> > +static void mbt_kill_sb(struct super_block *sb)
> > +{
> > +}
> > +
> > +static struct file_system_type mbt_fs_type = {
> > + .name = "mballoc test",
> > + .kill_sb = mbt_kill_sb,
> > +};
> > +
> > static int mbt_mb_init(struct super_block *sb)
> > {
> > int ret;
> > @@ -72,43 +83,48 @@ static void mbt_mb_release(struct super_block *sb)
> > kfree(sb->s_bdev);
> > }
> >
> > +static int mbt_set(struct super_block *sb, void *data)
> > +{
> > + return 0;
> > +}
> > +
> > static struct super_block *mbt_ext4_alloc_super_block(void)
> > {
> > - struct ext4_super_block *es = kzalloc(sizeof(*es), GFP_KERNEL);
> > - struct ext4_sb_info *sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
> > struct mbt_ext4_super_block *fsb = kzalloc(sizeof(*fsb), GFP_KERNEL);
> > + struct super_block *sb = sget(&mbt_fs_type, NULL, mbt_set, 0, NULL);
> > + struct ext4_sb_info *sbi;
> >
> > - if (fsb == NULL || sbi == NULL || es == NULL)
> > + if (fsb == NULL || sb == NULL)
>
> sget() returns error pointer on failure. So you should check for IS_ERR(sb).
You also want to unlock that superblock up_write(sb->s_umount) if it
succeeded and then call deactivate_super() when you are done with it in
mbt_kunit_exit().
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] ext4: alloc test super block from sget
2024-03-01 8:25 ` Christian Brauner
2024-03-01 8:29 ` Christian Brauner
@ 2024-03-01 9:03 ` Kemeng Shi
1 sibling, 0 replies; 6+ messages in thread
From: Kemeng Shi @ 2024-03-01 9:03 UTC (permalink / raw)
To: Christian Brauner
Cc: tytso, adilger.kernel, linux-ext4, linux-kernel, naresh.kamboju,
daniel.diaz, linux
on 3/1/2024 4:25 PM, Christian Brauner wrote:
> On Fri, Mar 01, 2024 at 08:08:15PM +0800, Kemeng Shi wrote:
>> This fix the oops in ext4 unit test which is cuased by NULL sb.s_user_ns
>> as following:
>> <4>[ 14.344565] map_id_range_down (kernel/user_namespace.c:318)
>> <4>[ 14.345378] make_kuid (kernel/user_namespace.c:415)
>> <4>[ 14.345998] inode_init_always (include/linux/fs.h:1375 fs/inode.c:174)
>> <4>[ 14.346696] alloc_inode (fs/inode.c:268)
>> <4>[ 14.347353] new_inode_pseudo (fs/inode.c:1007)
>> <4>[ 14.348016] new_inode (fs/inode.c:1033)
>> <4>[ 14.348644] ext4_mb_init (fs/ext4/mballoc.c:3404 fs/ext4/mballoc.c:3719)
>> <4>[ 14.349312] mbt_kunit_init (fs/ext4/mballoc-test.c:57
>> fs/ext4/mballoc-test.c:314)
>> <4>[ 14.349983] kunit_try_run_case (lib/kunit/test.c:388 lib/kunit/test.c:443)
>> <4>[ 14.350696] kunit_generic_run_threadfn_adapter (lib/kunit/try-catch.c:30)
>> <4>[ 14.351530] kthread (kernel/kthread.c:388)
>> <4>[ 14.352168] ret_from_fork (arch/arm64/kernel/entry.S:861)
>> <0>[ 14.353385] Code: 52808004 b8236ae7 72be5e44 b90004c4 (38e368a1)
>>
>> Alloc test super block from sget to properly initialize test super block
>> to fix the issue.
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
>> Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
>> Reported-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>> fs/ext4/mballoc-test.c | 46 ++++++++++++++++++++++++++++--------------
>> 1 file changed, 31 insertions(+), 15 deletions(-)
>>
>> diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c
>> index 12d0b22cabe1..1da52bbf4599 100644
>> --- a/fs/ext4/mballoc-test.c
>> +++ b/fs/ext4/mballoc-test.c
>> @@ -21,16 +21,27 @@ struct mbt_ctx {
>> };
>>
>> struct mbt_ext4_super_block {
>> - struct super_block sb;
>> + struct ext4_super_block es;
>> + struct ext4_sb_info sbi;
>> struct mbt_ctx mbt_ctx;
>> };
>>
>> -#define MBT_CTX(_sb) (&(container_of((_sb), struct mbt_ext4_super_block, sb)->mbt_ctx))
>> +#define MBT_SB(_sb) (container_of((_sb)->s_fs_info, struct mbt_ext4_super_block, sbi))
>> +#define MBT_CTX(_sb) (&MBT_SB(_sb)->mbt_ctx)
>> #define MBT_GRP_CTX(_sb, _group) (&MBT_CTX(_sb)->grp_ctx[_group])
>>
>> static const struct super_operations mbt_sops = {
>> };
>>
>> +static void mbt_kill_sb(struct super_block *sb)
>> +{
>> +}
>> +
>> +static struct file_system_type mbt_fs_type = {
>> + .name = "mballoc test",
>> + .kill_sb = mbt_kill_sb,
>> +};
>> +
>> static int mbt_mb_init(struct super_block *sb)
>> {
>> int ret;
>> @@ -72,43 +83,48 @@ static void mbt_mb_release(struct super_block *sb)
>> kfree(sb->s_bdev);
>> }
>>
>> +static int mbt_set(struct super_block *sb, void *data)
>> +{
>> + return 0;
>> +}
>> +
>> static struct super_block *mbt_ext4_alloc_super_block(void)
>> {
>> - struct ext4_super_block *es = kzalloc(sizeof(*es), GFP_KERNEL);
>> - struct ext4_sb_info *sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
>> struct mbt_ext4_super_block *fsb = kzalloc(sizeof(*fsb), GFP_KERNEL);
>> + struct super_block *sb = sget(&mbt_fs_type, NULL, mbt_set, 0, NULL);
>> + struct ext4_sb_info *sbi;
>>
>> - if (fsb == NULL || sbi == NULL || es == NULL)
>> + if (fsb == NULL || sb == NULL)
>
> sget() returns error pointer on failure. So you should check for IS_ERR(sb).
>
Thanks a lot for review. I will fix it in next version.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 0/2] Fix crashes in ext4 unit test
@ 2024-03-01 12:08 Kemeng Shi
2024-03-01 12:08 ` [PATCH 1/2] ext4: alloc test super block from sget Kemeng Shi
2024-03-01 12:08 ` [PATCH 2/2] ext4: hold group lock in ext4 kunit test Kemeng Shi
0 siblings, 2 replies; 6+ messages in thread
From: Kemeng Shi @ 2024-03-01 12:08 UTC (permalink / raw)
To: tytso, adilger.kernel
Cc: linux-ext4, linux-kernel, naresh.kamboju, daniel.diaz, linux,
brauner
Previously, the new mballoc unit tests are only tested by running
"./tools/testing/kunit/kunit.py run ..." in which case only rare configs
are enabled.
This series fixes the reported issue and changes are tested with and
without kunit_tool [1].
Result with kunit_tool:
./tools/testing/kunit/kunit.py run --kunitconfig=fs/ext4/.kunitconfig --raw_output
[17:40:24] Configuring KUnit Kernel ...
[17:40:24] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make ARCH=um O=.kunit --jobs=88
[17:40:28] Starting KUnit Kernel (1/1)...
KTAP version 1
1..2
KTAP version 1
# Subtest: ext4_mballoc_test
# module: ext4
1..6
KTAP version 1
# Subtest: test_new_blocks_simple
ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
# test_new_blocks_simple: pass:3 fail:0 skip:0 total:3
ok 1 test_new_blocks_simple
KTAP version 1
# Subtest: test_free_blocks_simple
ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
# test_free_blocks_simple: pass:3 fail:0 skip:0 total:3
ok 2 test_free_blocks_simple
KTAP version 1
# Subtest: test_mb_generate_buddy
ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
# test_mb_generate_buddy: pass:3 fail:0 skip:0 total:3
ok 3 test_mb_generate_buddy
KTAP version 1
# Subtest: test_mb_mark_used
ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
# SKIP blocksize exceeds pagesize
# test_mb_mark_used: pass:2 fail:0 skip:1 total:3
ok 4 test_mb_mark_used
KTAP version 1
# Subtest: test_mb_free_blocks
ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
# SKIP blocksize exceeds pagesize
# test_mb_free_blocks: pass:2 fail:0 skip:1 total:3
ok 5 test_mb_free_blocks
KTAP version 1
# Subtest: test_mark_diskspace_used
ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
# test_mark_diskspace_used: pass:3 fail:0 skip:0 total:3
ok 6 test_mark_diskspace_used
# ext4_mballoc_test: pass:6 fail:0 skip:0 total:6
# Totals: pass:16 fail:0 skip:2 total:18
ok 1 ext4_mballoc_test
KTAP version 1
# Subtest: ext4_inode_test
# module: ext4_inode_test
1..1
KTAP version 1
# Subtest: inode_test_xtimestamp_decoding
ok 1 1901-12-13 Lower bound of 32bit < 0 timestamp, no extra bits
ok 2 1969-12-31 Upper bound of 32bit < 0 timestamp, no extra bits
ok 3 1970-01-01 Lower bound of 32bit >=0 timestamp, no extra bits
ok 4 2038-01-19 Upper bound of 32bit >=0 timestamp, no extra bits
ok 5 2038-01-19 Lower bound of 32bit <0 timestamp, lo extra sec bit on
ok 6 2106-02-07 Upper bound of 32bit <0 timestamp, lo extra sec bit on
ok 7 2106-02-07 Lower bound of 32bit >=0 timestamp, lo extra sec bit on
ok 8 2174-02-25 Upper bound of 32bit >=0 timestamp, lo extra sec bit on
ok 9 2174-02-25 Lower bound of 32bit <0 timestamp, hi extra sec bit on
ok 10 2242-03-16 Upper bound of 32bit <0 timestamp, hi extra sec bit on
ok 11 2242-03-16 Lower bound of 32bit >=0 timestamp, hi extra sec bit on
ok 12 2310-04-04 Upper bound of 32bit >=0 timestamp, hi extra sec bit on
ok 13 2310-04-04 Upper bound of 32bit>=0 timestamp, hi extra sec bit 1. 1 ns
ok 14 2378-04-22 Lower bound of 32bit>= timestamp. Extra sec bits 1. Max ns
ok 15 2378-04-22 Lower bound of 32bit >=0 timestamp. All extra sec bits on
ok 16 2446-05-10 Upper bound of 32bit >=0 timestamp. All extra sec bits on
# inode_test_xtimestamp_decoding: pass:16 fail:0 skip:0 total:16
ok 1 inode_test_xtimestamp_decoding
# Totals: pass:16 fail:0 skip:0 total:16
ok 2 ext4_inode_test
[17:40:28] Elapsed time: 3.990s total, 0.001s configuring, 3.823s building, 0.123s running
Result without kunit_tool (built-in):
Mar 1 18:24:36 localhost kernel: [ 5.260386] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.260558] 1..2
Mar 1 18:24:36 localhost kernel: [ 5.261225] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.261387] # Subtest: ext4_mballoc_test
Mar 1 18:24:36 localhost kernel: [ 5.261581] # module: ext4
Mar 1 18:24:36 localhost kernel: [ 5.261583] 1..6
Mar 1 18:24:36 localhost kernel: [ 5.261886] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.262050] # Subtest: test_new_blocks_simple
Mar 1 18:24:36 localhost kernel: [ 5.262409] ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.263342] ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.264334] ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.264664] # test_new_blocks_simple: pass:3 fail:0 skip:0 total:3
Mar 1 18:24:36 localhost kernel: [ 5.264669] ok 1 test_new_blocks_simple
Mar 1 18:24:36 localhost kernel: [ 5.264893] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.265230] # Subtest: test_free_blocks_simple
Mar 1 18:24:36 localhost kernel: [ 5.265552] ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.266451] ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.267183] ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.267508] # test_free_blocks_simple: pass:3 fail:0 skip:0 total:3
Mar 1 18:24:36 localhost kernel: [ 5.267510] ok 2 test_free_blocks_simple
Mar 1 18:24:36 localhost kernel: [ 5.267748] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.268087] # Subtest: test_mb_generate_buddy
Mar 1 18:24:36 localhost kernel: [ 5.268493] ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.269542] ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.270824] ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.271287] # test_mb_generate_buddy: pass:3 fail:0 skip:0 total:3
Mar 1 18:24:36 localhost kernel: [ 5.271288] ok 3 test_mb_generate_buddy
Mar 1 18:24:36 localhost kernel: [ 5.271512] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.271873] # Subtest: test_mb_mark_used
Mar 1 18:24:36 localhost kernel: [ 5.272194] ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.273105] ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.273855] ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64#012 # SKIP blocksize exceeds pagesize
Mar 1 18:24:36 localhost kernel: [ 5.273857] # test_mb_mark_used: pass:2 fail:0 skip:1 total:3
Mar 1 18:24:36 localhost kernel: [ 5.274306] ok 4 test_mb_mark_used
Mar 1 18:24:36 localhost kernel: [ 5.274526] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.274863] # Subtest: test_mb_free_blocks
Mar 1 18:24:36 localhost kernel: [ 5.275146] ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.275935] ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.276706] ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64#012 # SKIP blocksize exceeds pagesize
Mar 1 18:24:36 localhost kernel: [ 5.276708] # test_mb_free_blocks: pass:2 fail:0 skip:1 total:3
Mar 1 18:24:36 localhost kernel: [ 5.277155] ok 5 test_mb_free_blocks
Mar 1 18:24:36 localhost kernel: [ 5.277370] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.277711] # Subtest: test_mark_diskspace_used
Mar 1 18:24:36 localhost kernel: [ 5.277936] ok 1 block_bits=10 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.278825] ok 2 block_bits=12 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.279712] ok 3 block_bits=16 cluster_bits=3 blocks_per_group=8192 group_count=4 desc_size=64
Mar 1 18:24:36 localhost kernel: [ 5.280039] # test_mark_diskspace_used: pass:3 fail:0 skip:0 total:3
Mar 1 18:24:36 localhost kernel: [ 5.280041] ok 6 test_mark_diskspace_used
Mar 1 18:24:36 localhost kernel: [ 5.280262] # ext4_mballoc_test: pass:6 fail:0 skip:0 total:6
Mar 1 18:24:36 localhost kernel: [ 5.280438] # Totals: pass:16 fail:0 skip:2 total:18
Mar 1 18:24:36 localhost kernel: [ 5.280661] ok 1 ext4_mballoc_test
Mar 1 18:24:36 localhost kernel: [ 5.281017] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.281168] # Subtest: ext4_inode_test
Mar 1 18:24:36 localhost kernel: [ 5.281347] # module: ext4_inode_test
Mar 1 18:24:36 localhost kernel: [ 5.281349] 1..1
Mar 1 18:24:36 localhost kernel: [ 5.281698] KTAP version 1
Mar 1 18:24:36 localhost kernel: [ 5.281863] # Subtest: inode_test_xtimestamp_decoding
Mar 1 18:24:36 localhost kernel: [ 5.282082] ok 1 1901-12-13 Lower bound of 32bit < 0 timestamp, no extra bits
Mar 1 18:24:36 localhost kernel: [ 5.282463] ok 2 1969-12-31 Upper bound of 32bit < 0 timestamp, no extra bits
Mar 1 18:24:36 localhost kernel: [ 5.282936] ok 3 1970-01-01 Lower bound of 32bit >=0 timestamp, no extra bits
Mar 1 18:24:36 localhost kernel: [ 5.283425] ok 4 2038-01-19 Upper bound of 32bit >=0 timestamp, no extra bits
Mar 1 18:24:36 localhost kernel: [ 5.283909] ok 5 2038-01-19 Lower bound of 32bit <0 timestamp, lo extra sec bit on
Mar 1 18:24:36 localhost kernel: [ 5.284398] ok 6 2106-02-07 Upper bound of 32bit <0 timestamp, lo extra sec bit on
Mar 1 18:24:36 localhost kernel: [ 5.284895] ok 7 2106-02-07 Lower bound of 32bit >=0 timestamp, lo extra sec bit on
Mar 1 18:24:36 localhost kernel: [ 5.285360] ok 8 2174-02-25 Upper bound of 32bit >=0 timestamp, lo extra sec bit on
Mar 1 18:24:36 localhost kernel: [ 5.285849] ok 9 2174-02-25 Lower bound of 32bit <0 timestamp, hi extra sec bit on
Mar 1 18:24:36 localhost kernel: [ 5.286307] ok 10 2242-03-16 Upper bound of 32bit <0 timestamp, hi extra sec bit on
Mar 1 18:24:36 localhost kernel: [ 5.287497] ok 11 2242-03-16 Lower bound of 32bit >=0 timestamp, hi extra sec bit on
Mar 1 18:24:36 localhost kernel: [ 5.288002] ok 12 2310-04-04 Upper bound of 32bit >=0 timestamp, hi extra sec bit on
Mar 1 18:24:36 localhost kernel: [ 5.288469] ok 13 2310-04-04 Upper bound of 32bit>=0 timestamp, hi extra sec bit 1. 1 ns
Mar 1 18:24:36 localhost kernel: [ 5.288971] ok 14 2378-04-22 Lower bound of 32bit>= timestamp. Extra sec bits 1. Max ns
Mar 1 18:24:36 localhost kernel: [ 5.289479] ok 15 2378-04-22 Lower bound of 32bit >=0 timestamp. All extra sec bits on
Mar 1 18:24:36 localhost kernel: [ 5.290023] ok 16 2446-05-10 Upper bound of 32bit >=0 timestamp. All extra sec bits on
Mar 1 18:24:36 localhost kernel: [ 5.290326] # inode_test_xtimestamp_decoding: pass:16 fail:0 skip:0 total:16
Mar 1 18:24:36 localhost kernel: [ 5.290651] ok 1 inode_test_xtimestamp_decoding
Mar 1 18:24:36 localhost kernel: [ 5.290930] # Totals: pass:16 fail:0 skip:0 total:16
Mar 1 18:24:36 localhost kernel: [ 5.291123] ok 2 ext4_inode_test
[1] https://docs.kernel.org/dev-tools/kunit/run_manual.html
Kemeng Shi (2):
ext4: alloc test super block from sget
ext4: hold group lock in ext4 kunit test
fs/ext4/mballoc-test.c | 55 ++++++++++++++++++++++++++++++------------
1 file changed, 40 insertions(+), 15 deletions(-)
--
2.30.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] ext4: alloc test super block from sget
2024-03-01 12:08 [PATCH 0/2] Fix crashes in ext4 unit test Kemeng Shi
@ 2024-03-01 12:08 ` Kemeng Shi
2024-03-01 8:25 ` Christian Brauner
2024-03-01 12:08 ` [PATCH 2/2] ext4: hold group lock in ext4 kunit test Kemeng Shi
1 sibling, 1 reply; 6+ messages in thread
From: Kemeng Shi @ 2024-03-01 12:08 UTC (permalink / raw)
To: tytso, adilger.kernel
Cc: linux-ext4, linux-kernel, naresh.kamboju, daniel.diaz, linux,
brauner
This fix the oops in ext4 unit test which is cuased by NULL sb.s_user_ns
as following:
<4>[ 14.344565] map_id_range_down (kernel/user_namespace.c:318)
<4>[ 14.345378] make_kuid (kernel/user_namespace.c:415)
<4>[ 14.345998] inode_init_always (include/linux/fs.h:1375 fs/inode.c:174)
<4>[ 14.346696] alloc_inode (fs/inode.c:268)
<4>[ 14.347353] new_inode_pseudo (fs/inode.c:1007)
<4>[ 14.348016] new_inode (fs/inode.c:1033)
<4>[ 14.348644] ext4_mb_init (fs/ext4/mballoc.c:3404 fs/ext4/mballoc.c:3719)
<4>[ 14.349312] mbt_kunit_init (fs/ext4/mballoc-test.c:57
fs/ext4/mballoc-test.c:314)
<4>[ 14.349983] kunit_try_run_case (lib/kunit/test.c:388 lib/kunit/test.c:443)
<4>[ 14.350696] kunit_generic_run_threadfn_adapter (lib/kunit/try-catch.c:30)
<4>[ 14.351530] kthread (kernel/kthread.c:388)
<4>[ 14.352168] ret_from_fork (arch/arm64/kernel/entry.S:861)
<0>[ 14.353385] Code: 52808004 b8236ae7 72be5e44 b90004c4 (38e368a1)
Alloc test super block from sget to properly initialize test super block
to fix the issue.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Reported-by: Guenter Roeck <linux@roeck-us.net>
---
fs/ext4/mballoc-test.c | 46 ++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 15 deletions(-)
diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c
index 12d0b22cabe1..1da52bbf4599 100644
--- a/fs/ext4/mballoc-test.c
+++ b/fs/ext4/mballoc-test.c
@@ -21,16 +21,27 @@ struct mbt_ctx {
};
struct mbt_ext4_super_block {
- struct super_block sb;
+ struct ext4_super_block es;
+ struct ext4_sb_info sbi;
struct mbt_ctx mbt_ctx;
};
-#define MBT_CTX(_sb) (&(container_of((_sb), struct mbt_ext4_super_block, sb)->mbt_ctx))
+#define MBT_SB(_sb) (container_of((_sb)->s_fs_info, struct mbt_ext4_super_block, sbi))
+#define MBT_CTX(_sb) (&MBT_SB(_sb)->mbt_ctx)
#define MBT_GRP_CTX(_sb, _group) (&MBT_CTX(_sb)->grp_ctx[_group])
static const struct super_operations mbt_sops = {
};
+static void mbt_kill_sb(struct super_block *sb)
+{
+}
+
+static struct file_system_type mbt_fs_type = {
+ .name = "mballoc test",
+ .kill_sb = mbt_kill_sb,
+};
+
static int mbt_mb_init(struct super_block *sb)
{
int ret;
@@ -72,43 +83,48 @@ static void mbt_mb_release(struct super_block *sb)
kfree(sb->s_bdev);
}
+static int mbt_set(struct super_block *sb, void *data)
+{
+ return 0;
+}
+
static struct super_block *mbt_ext4_alloc_super_block(void)
{
- struct ext4_super_block *es = kzalloc(sizeof(*es), GFP_KERNEL);
- struct ext4_sb_info *sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
struct mbt_ext4_super_block *fsb = kzalloc(sizeof(*fsb), GFP_KERNEL);
+ struct super_block *sb = sget(&mbt_fs_type, NULL, mbt_set, 0, NULL);
+ struct ext4_sb_info *sbi;
- if (fsb == NULL || sbi == NULL || es == NULL)
+ if (fsb == NULL || sb == NULL)
goto out;
+ sbi = &fsb->sbi;
+
sbi->s_blockgroup_lock =
kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
if (!sbi->s_blockgroup_lock)
- goto out;
+ goto out_deactivate;
bgl_lock_init(sbi->s_blockgroup_lock);
- sbi->s_es = es;
- fsb->sb.s_fs_info = sbi;
+ sbi->s_es = &fsb->es;
+ sb->s_fs_info = sbi;
- return &fsb->sb;
+ return sb;
+out_deactivate:
+ deactivate_locked_super(sb);
out:
kfree(fsb);
- kfree(sbi);
- kfree(es);
return NULL;
}
static void mbt_ext4_free_super_block(struct super_block *sb)
{
- struct mbt_ext4_super_block *fsb =
- container_of(sb, struct mbt_ext4_super_block, sb);
+ struct mbt_ext4_super_block *fsb = MBT_SB(sb);
struct ext4_sb_info *sbi = EXT4_SB(sb);
kfree(sbi->s_blockgroup_lock);
- kfree(sbi->s_es);
- kfree(sbi);
+ deactivate_locked_super(sb);
kfree(fsb);
}
--
2.30.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] ext4: hold group lock in ext4 kunit test
2024-03-01 12:08 [PATCH 0/2] Fix crashes in ext4 unit test Kemeng Shi
2024-03-01 12:08 ` [PATCH 1/2] ext4: alloc test super block from sget Kemeng Shi
@ 2024-03-01 12:08 ` Kemeng Shi
1 sibling, 0 replies; 6+ messages in thread
From: Kemeng Shi @ 2024-03-01 12:08 UTC (permalink / raw)
To: tytso, adilger.kernel
Cc: linux-ext4, linux-kernel, naresh.kamboju, daniel.diaz, linux,
brauner
Although there is no concurrent block allocation/free in unit test,
internal functions mb_mark_used and mb_free_blocks assert group
lock is always held. Acquire group before calling mb_mark_used and
mb_free_blocks in unit test to avoid the assertion.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reported-by: Guenter Roeck <linux@roeck-us.net>
---
fs/ext4/mballoc-test.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c
index 1da52bbf4599..40e878ea8258 100644
--- a/fs/ext4/mballoc-test.c
+++ b/fs/ext4/mballoc-test.c
@@ -694,7 +694,10 @@ test_mb_mark_used_range(struct kunit *test, struct ext4_buddy *e4b,
ex.fe_start = start;
ex.fe_len = len;
ex.fe_group = TEST_GOAL_GROUP;
+
+ ext4_lock_group(sb, TEST_GOAL_GROUP);
mb_mark_used(e4b, &ex);
+ ext4_unlock_group(sb, TEST_GOAL_GROUP);
mb_set_bits(bitmap, start, len);
/* bypass bb_free validatoin in ext4_mb_generate_buddy */
@@ -754,7 +757,9 @@ test_mb_free_blocks_range(struct kunit *test, struct ext4_buddy *e4b,
if (len == 0)
return;
+ ext4_lock_group(sb, e4b->bd_group);
mb_free_blocks(NULL, e4b, start, len);
+ ext4_unlock_group(sb, e4b->bd_group);
mb_clear_bits(bitmap, start, len);
/* bypass bb_free validatoin in ext4_mb_generate_buddy */
@@ -798,7 +803,11 @@ static void test_mb_free_blocks(struct kunit *test)
ex.fe_start = 0;
ex.fe_len = EXT4_CLUSTERS_PER_GROUP(sb);
ex.fe_group = TEST_GOAL_GROUP;
+
+ ext4_lock_group(sb, TEST_GOAL_GROUP);
mb_mark_used(&e4b, &ex);
+ ext4_unlock_group(sb, TEST_GOAL_GROUP);
+
grp->bb_free = 0;
memset(bitmap, 0xff, sb->s_blocksize);
--
2.30.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-03-01 9:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-01 12:08 [PATCH 0/2] Fix crashes in ext4 unit test Kemeng Shi
2024-03-01 12:08 ` [PATCH 1/2] ext4: alloc test super block from sget Kemeng Shi
2024-03-01 8:25 ` Christian Brauner
2024-03-01 8:29 ` Christian Brauner
2024-03-01 9:03 ` Kemeng Shi
2024-03-01 12:08 ` [PATCH 2/2] ext4: hold group lock in ext4 kunit test Kemeng Shi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox