Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] ext4: use a stable source for the kmmpd thread name
@ 2026-11-14 17:25 Zhao Gongyi
  2026-11-14 17:32 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Zhao Gongyi @ 2026-11-14 17:25 UTC (permalink / raw)
  To: tytso
  Cc: linux-ext4, linux-kernel, adilger.kernel, libaokun, jack, ojaswin,
	ritesh.list, yi.zhang, Zhao Gongyi

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.

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@bytedance.com>
---
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)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-14 17:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14 17:25 [PATCH] ext4: use a stable source for the kmmpd thread name Zhao Gongyi
2026-11-14 17:32 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox