Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Theodore Ts'o" <tytso@mit.edu>,
	"Ext4 Developers List" <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 24/27] ext4: add KUnit tests for fs/ext4/fsmap.c
Date: Thu, 12 Nov 2026 04:30:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-210342@kernel.org> (raw)
In-Reply-To: <20261112040638.1576836-25-tytso@mit.edu>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] ext4: per-CPU disk_stats leak on assert abort in
  fsmap_create_ctx()
- [Low] ext4: unused fail_err field in fsmap_rec_sink and
  fsmap_collect_cb()
--

commit 26245fe40968f50951fa0187b785c405d62e3f12
Author: Theodore Ts'o <tytso@mit.edu>

ext4: add KUnit tests for fs/ext4/fsmap.c

This commit adds a KUnit test suite covering FS_IOC_GETFSMAP reverse-mapping
queries in fs/ext4/fsmap.c.

> diff --git a/fs/ext4/fsmap-test.c b/fs/ext4/fsmap-test.c
> new file mode 100644
> index 0000000000000..63a1061b413a7
> --- /dev/null
> +++ b/fs/ext4/fsmap-test.c
> @@ -0,0 +1,787 @@

[ ... ]

> +struct fsmap_rec_sink {
> +	struct ext4_fsmap recs[FSMAP_TEST_MAX_RECS];
> +	unsigned int count;
> +	unsigned int abort_after;
> +	int fail_err;
> +};

[ ... ]

> +static int fsmap_collect_cb(struct ext4_fsmap *fmr, void *priv)
> +{
> +	struct fsmap_rec_sink *sink = priv;
> +
> +	if (sink->fail_err)
> +		return sink->fail_err;

[Severity: Low]
Nothing in this file sets sink->fail_err, leaving the field and this check
in fsmap_collect_cb() unused.

[ ... ]

> +static struct fsmap_test_ctx *fsmap_create_ctx(struct kunit *test,
> +					       unsigned int blocksize_bits,
> +					       unsigned int cluster_bits,
> +					       ext4_group_t groups_count,
> +					       ext4_grpblk_t blocks_per_group)
> +{
> +	struct fsmap_test_ctx *ctx;
> +	struct fs_context *fc;
> +	struct super_block *sb;
> +	struct ext4_sb_info *sbi;
> +	unsigned int blocksize = 1U << blocksize_bits;
> +	ext4_fsblk_t bofs = (blocksize == 1024) ? 1 : 0;
> +	int err;
> +
> +	ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
> +	KUNIT_ASSERT_NOT_NULL(test, ctx);
> +
> +	inode_init_once(&ctx->data_bdev.vfs_inode);
> +	address_space_init_once(&ctx->data_bdev.vfs_inode.i_data);
> +	ctx->data_bdev.vfs_inode.i_data.host = &ctx->data_bdev.vfs_inode;
> +	ctx->data_bdev.bdev.bd_dev = FSMAP_TEST_DATADEV;
> +	ctx->data_bdev.bdev.bd_mapping = &ctx->data_bdev.vfs_inode.i_data;
> +	ctx->data_bdev.bdev.bd_stats = alloc_percpu(struct disk_stats);
> +	KUNIT_ASSERT_NOT_NULL(test, ctx->data_bdev.bdev.bd_stats);
> +
> +	inode_init_once(&ctx->log_bdev.vfs_inode);
> +	address_space_init_once(&ctx->log_bdev.vfs_inode.i_data);
> +	ctx->log_bdev.vfs_inode.i_data.host = &ctx->log_bdev.vfs_inode;
> +	ctx->log_bdev.bdev.bd_dev = FSMAP_TEST_LOGDEV;
> +	ctx->log_bdev.bdev.bd_mapping = &ctx->log_bdev.vfs_inode.i_data;
> +	ctx->log_bdev.bdev.bd_stats = alloc_percpu(struct disk_stats);
> +	KUNIT_ASSERT_NOT_NULL(test, ctx->log_bdev.bdev.bd_stats);
> +	ctx->log_bdev_file.f_mapping = &ctx->log_bdev.vfs_inode.i_data;
> +
> +	sbi = &ctx->sbi;
> +	INIT_WORK(&sbi->s_sb_upd_work, fsmap_noop_work);
> +	timer_setup(&sbi->s_err_report, fsmap_noop_timer, 0);
> +	spin_lock_init(&sbi->s_error_lock);
> +	spin_lock_init(&sbi->s_bdev_wb_lock);
> +	ratelimit_state_init(&sbi->s_err_ratelimit_state,
> +			     DEFAULT_RATELIMIT_INTERVAL,
> +			     DEFAULT_RATELIMIT_BURST);
> +
> +	fc = fs_context_for_mount(&fsmap_test_fs_type, 0);
> +	KUNIT_ASSERT_FALSE(test, IS_ERR(fc));
> +	sb = sget_fc(fc, NULL, fsmap_test_set_super);
> +	put_fs_context(fc);
> +	KUNIT_ASSERT_FALSE(test, IS_ERR(sb));
> +	up_write(&sb->s_umount);
> +
> +	ctx->sb = sb;
> +	err = kunit_add_action_or_reset(test, fsmap_cleanup_ctx, ctx);
> +	KUNIT_ASSERT_EQ(test, err, 0);

[Severity: Low]
Does this leak the per-CPU bd_stats allocations if one of the assertions
before kunit_add_action_or_reset() aborts the test?  Registering
fsmap_cleanup_ctx() before calling alloc_percpu() would ensure they are
freed on early assertion failure.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261112040638.1576836-1-tytso@mit.edu?part=24

  reply	other threads:[~2026-11-12  4:30 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  4:06 [PATCH 00/27] ext4: add lots of KUnit tests! Theodore Ts'o
2026-11-12  4:06 ` [PATCH 01/27] ext4: add KUinit tests for fs/ext4/extents_status.c Theodore Ts'o
2026-11-12  4:18   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 02/27] ext4: add KUnit tests for fs/ext4/extents.c Theodore Ts'o
2026-11-12  4:28   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 03/27] ext4: add KUnit tests for ext4_ext_split() leaf and index splitting Theodore Ts'o
2026-11-12  4:15   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 04/27] ext4: add KUnit tests for fs/ext4/xattr.c Theodore Ts'o
2026-11-12  4:26   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 05/27] ext4: add KUnit tests for fs/ext4/namei.c Theodore Ts'o
2026-11-12  4:21   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 06/27] ext4: expand KUnit tests for fs/ext4/mballoc.c Theodore Ts'o
2026-11-12  4:26   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 07/27] ext4: add KUnit tests for fs/ext4/inline.c Theodore Ts'o
2026-11-12  4:29   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 08/27] ext4: zero s_fc_replay_state in ext4_fc_replay_cleanup() Theodore Ts'o
2026-11-12  4:16   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 09/27] ext4: add KUnit tests for fs/ext4/fast_commit.c Theodore Ts'o
2026-11-12  4:28   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 10/27] ext4: expand KUnit tests for fs/ext4/inode.c Theodore Ts'o
2026-11-12  4:36   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 11/27] ext4: add KUnit tests for fs/ext4/ialloc.c Theodore Ts'o
2026-11-12  4:25   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 12/27] ext4: add KUnit tests for fs/ext4/balloc.c Theodore Ts'o
2026-11-12  4:16   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 13/27] ext4: add KUnit tests for fs/ext4/orphan.c Theodore Ts'o
2026-11-12  4:18   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 14/27] ext4: add KUnit tests for fs/ext4/block_validity.c Theodore Ts'o
2026-11-12  4:21   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 15/27] ext4: check multi-block overlap on left traversal in add_system_zone() Theodore Ts'o
2026-11-12  4:10   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 16/27] ext4: enable full feature coverage in fs/ext4/.kunitconfig Theodore Ts'o
2026-11-12  4:24   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 17/27] ext4: add KUnit tests for fs/ext4/super.c Theodore Ts'o
2026-11-12  4:27   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 18/27] ext4: add KUnit tests for fs/ext4/sysfs.c Theodore Ts'o
2026-11-12  4:32   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 19/27] ext4: add KUnit tests for fs/ext4/ioctl.c Theodore Ts'o
2026-11-12  4:35   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 20/27] ext4: add KUnit tests for fs/ext4/resize.c Theodore Ts'o
2026-11-12  4:34   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 21/27] ext4: add KUnit tests for fs/ext4/migrate.c Theodore Ts'o
2026-11-12  4:37   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 22/27] ext4: add KUnit tests for fs/ext4/indirect.c Theodore Ts'o
2026-11-12  4:46   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 23/27] ext4: expand KUnit tests in fs/ext4/extents-test.c for file range operations Theodore Ts'o
2026-11-12  4:34   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 24/27] ext4: add KUnit tests for fs/ext4/fsmap.c Theodore Ts'o
2026-11-12  4:30   ` sashiko-bot [this message]
2026-11-12  4:06 ` [PATCH 25/27] ext4: add KUnit tests for fs/ext4/move_extent.c Theodore Ts'o
2026-11-12  4:36   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 26/27] ext4: add KUnit tests for fs/ext4/mmp.c Theodore Ts'o
2026-11-12  4:29   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 27/27] ext4: add KUnit tests for fs/ext4/dir.c Theodore Ts'o
2026-11-12  4:41   ` sashiko-bot

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=sashiko-outbox-210342@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /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