Re: [PATCH] ext4: use a stable source for the kmmpd thread name
From: Jan Kara
Date: Mon Nov 16 2026 - 07:16:26 EST
On Sun 15-11-26 01:25:23, Zhao Gongyi wrote:
> A concurrent MMP mount can make kvasprintf() warn about different
> vsnprintf() return values while creating kmmpd. The call chain is
> ext4_multi_mount_protect() -> kthread_run() -> kvasprintf(): the name
> comes from mmp_bdevname in the MMP block buffer, which may change
> between the two formatting passes.
What can change it? I don't see anything that should be doing that...
Honza
>
> Format the device name into a local buffer and use it for the thread
> name while retaining it in the MMP information field.
>
> Fixes: d6986ce24fc0 ("kthread: dynamically allocate memory to store kthread's full name")
> Signed-off-by: Zhao Gongyi <zhaogongyi@xxxxxxxxxxxxx>
> ---
> Validation: An x86 QEMU A/B run with the same test-only 1s delay in
> kvasprintf() observed the target warning 201 times without this
> patch. With the fix, no target warning appeared during a 600s
> run. Standalone replay without the delay was not reliably
> reproducible.
>
> fs/ext4/mmp.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
> index 4b18ddef468d7..09622862598b3 100644
> --- a/fs/ext4/mmp.c
> +++ b/fs/ext4/mmp.c
> @@ -4,6 +4,7 @@
> #include <linux/buffer_head.h>
> #include <linux/utsname.h>
> #include <linux/kthread.h>
> +#include <linux/string.h>
>
> #include "ext4.h"
>
> @@ -277,6 +278,7 @@ int ext4_multi_mount_protect(struct super_block *sb,
> struct ext4_super_block *es = EXT4_SB(sb)->s_es;
> struct buffer_head *bh = NULL;
> struct mmp_struct *mmp = NULL;
> + char bdevname[BDEVNAME_SIZE];
> u32 seq;
> unsigned int mmp_check_interval = le16_to_cpu(es->s_mmp_update_interval);
> unsigned int wait_time = 0;
> @@ -378,15 +380,16 @@ int ext4_multi_mount_protect(struct super_block *sb,
> EXT4_SB(sb)->s_mmp_bh = bh;
>
> BUILD_BUG_ON(sizeof(mmp->mmp_bdevname) < BDEVNAME_SIZE);
> - snprintf(mmp->mmp_bdevname, sizeof(mmp->mmp_bdevname),
> - "%pg", bh->b_bdev);
> + snprintf(bdevname, sizeof(bdevname), "%pg", bh->b_bdev);
> + strscpy_pad(mmp->mmp_bdevname, bdevname);
>
> /*
> - * Start a kernel thread to update the MMP block periodically.
> + * Start a kernel thread to update the MMP block periodically. Keep
> + * the name source on the stack so kvasprintf() observes the same
> + * string in both of its formatting passes.
> */
> - EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, sb, "kmmpd-%.*s",
> - (int)sizeof(mmp->mmp_bdevname),
> - mmp->mmp_bdevname);
> + EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, sb, "kmmpd-%s",
> + bdevname);
> if (IS_ERR(EXT4_SB(sb)->s_mmp_tsk)) {
> EXT4_SB(sb)->s_mmp_tsk = NULL;
> ext4_warning(sb, "Unable to create kmmpd thread for %s.",
>
> base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
> --
> 2.39.5 (Apple Git-154)
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR