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
  2026-11-16 12:16 ` Jan Kara
  0 siblings, 2 replies; 5+ 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] 5+ messages in thread

* Re: [PATCH] ext4: use a stable source for the kmmpd thread name
  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
  2026-11-16 12:16 ` Jan Kara
  1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-14 17:32 UTC (permalink / raw)
  To: Zhao Gongyi; +Cc: linux-ext4, tytso

> 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>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261114172523.5888-1-zhaogongyi@bytedance.com?part=1


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

* Re: [PATCH] ext4: use a stable source for the kmmpd thread name
  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
@ 2026-11-16 12:16 ` Jan Kara
  2026-11-16 16:36   ` Zhao Gongyi
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Kara @ 2026-11-16 12:16 UTC (permalink / raw)
  To: Zhao Gongyi
  Cc: tytso, linux-ext4, linux-kernel, adilger.kernel, libaokun, jack,
	ojaswin, ritesh.list, yi.zhang

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@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)
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] ext4: use a stable source for the kmmpd thread name
  2026-11-16 12:16 ` Jan Kara
@ 2026-11-16 16:36   ` Zhao Gongyi
  2026-11-16 16:42     ` sashiko-bot
  0 siblings, 1 reply; 5+ messages in thread
From: Zhao Gongyi @ 2026-11-16 16:36 UTC (permalink / raw)
  To: Jan Kara
  Cc: tytso, linux-ext4, linux-kernel, adilger.kernel, libaokun,
	ojaswin, ritesh.list, yi.zhang

[-- Attachment #1: Type: text/plain, Size: 2210 bytes --]

Hi Jan,

On 11/16/26 8:16 PM, Jan Kara wrote:
> What can change it? I don't see anything that should be doing that...

A concurrent buffered write to the loop block device can change it. In
one diagnostic run, the write reached the page-cache buffer ext4 was
using for MMP. mmp_bdevname is embedded at bh->b_data + 0x50.

In an x86 QEMU diagnostic run based on commit
7475ea8b58616b33c04afb976cf0fbaad9dd63fb, kvasprintf() first read
"loop0" at ffff888013e1d050. A kprobe on mark_buffer_dirty() then
fired for a buffer starting at ffff888013e1d000, covering that field.
The stack was:

   ksys_write -> blkdev_write_iter -> blkdev_buffered_write
     -> iomap_file_buffered_write -> iomap_write_end
     -> block_write_end -> block_commit_write -> mark_buffer_dirty

The buffered write path copies data into the page cache before
block_commit_write(). About one second later, the same source page
contained an empty string, and kvasprintf() reported return values 11
and 6. The kprobe records the buffer being dirtied; it does not trap
the byte-copy instruction itself. My earlier description of a
concurrent MMP mount changing the name was imprecise.

The original syzkaller manager report shows the warning on an
unmodified kernel. Standalone QEMU replays without a delay did not hit
it reliably. To obtain the trace above, I used a diagnostic build with
a one-second delay after the first vsnprintf() pass, source snapshots,
an exported MMP buffer address, and a kprobe module. The attached 
test-only delay patch widens the window but does not collect the writer 
trace by itself. None of this diagnostic code is part of the proposed fix.

The attached repro.syz is input to syz-execprog. I ran it in the guest with:

   /root/syz-execprog -executor=/root/syz-executor -arch=amd64 \
     -sandbox=none -procs=12 -repeat=0 -threaded=true -slowdown=1 \
     -sandbox_arg=0 -type=qemu /root/repro.syz

I understand that raw writes to a block device during ext4 access can
corrupt metadata. The proposed change gives the two-pass thread-name
formatting a stable source; it does not change MMP's protection logic.
I can provide the full diagnostic diff, kprobe module, and console log
if useful.

Thanks,
Gongyi

[-- Attachment #2: repro.syz --]
[-- Type: text/plain, Size: 9996 bytes --]

# {Threaded:true Repeat:true RepeatTimes:0 Procs:1 Slowdown:1 Sandbox: SandboxArg:0 Leak:false NetInjection:false NetDevices:false NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:true HandleSegv:true Trace:false CallComments:true LegacyOptions:{Collide:false Fault:false FaultCall:0 FaultNth:0}}
r0 = syz_open_dev$ptys(0xc, 0x3, 0x1)
r1 = syz_open_dev$sg(&(0x7f0000000140), 0x4cf, 0x60300)
mmap(&(0x7f0000ffc000/0x4000)=nil, 0x4000, 0x0, 0x13, r1, 0x0)
mmap(&(0x7f0000ffc000/0x4000)=nil, 0x4000, 0x0, 0x13, r1, 0x0)
mremap(&(0x7f0000ff6000/0x4000)=nil, 0x4000, 0x4000, 0x3, &(0x7f0000ffb000/0x4000)=nil)
madvise(&(0x7f0000ffc000/0x4000)=nil, 0x4000, 0x15)
ioctl$TIOCSPTLCK(r0, 0x40045431, &(0x7f0000000000)) (async)
ioctl$RTC_EPOCH_SET(0xffffffffffffffff, 0x4008700e, 0x70b) (async)
openat(0xffffffffffffff9c, &(0x7f0000000040)='./file1\x00', 0x42, 0x1ff)
syz_mount_image$ext4(&(0x7f0000000c00)='ext4\x00', &(0x7f00000045c0)='./file1\x00', 0x9400, &(0x7f0000000080)={[{@nomblk_io_submit}, {@errors_continue}]}, 0x1, 0xc28, &(0x7f00000046c0)="$eJzs2M9vG1kdAPDvTOI0/UGTIoRYLhvBYSvBOk3SVGXhsBVCSIiVKuCI1LVSNwm14yh2pY1XaLPaAxcOOaCVEOKAhMQBDtUeuNITN26A2D8ACVZUHOAGyGjscTZt4jjZup62+Xyk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dfP/f39O/O/8/vP9/On9Mg/BtYVdtLv1wWN3R8Q+cljT+Hx4x/g+7///SMdtovOz9Zlid+T8AAAAAAAAAAAAAAAAAAAAAAAAAAADnUWdre2Wh1WpsnGKm6GsEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgKL8NwAA//+71f46")
openat(0xffffffffffffff9c, &(0x7f0000000040)='./file1\x00', 0x84402, 0x0)
write(r2, &(0x7f0000000000)="01", 0xfffffec2)
truncate(0x0, 0xb)
write$FUSE_NOTIFY_POLL(0xffffffffffffffff, 0x0, 0x0) (async)
write$FUSE_NOTIFY_POLL(0xffffffffffffffff, 0x0, 0x0)
ioctl$TIOCGPTPEER(r0, 0x5441, 0x80000001) (async)
r3 = ioctl$TIOCGPTPEER(r0, 0x5441, 0x80000001)
fallocate(0xffffffffffffffff, 0x30, 0x100, 0xe60) (async)
fallocate(0xffffffffffffffff, 0x30, 0x100, 0xe60)
syz_open_dev$tty1(0xc, 0x4, 0x3)
symlinkat(&(0x7f0000004480)='./file0\x00', 0xffffffffffffffff, &(0x7f0000004540)='./file0\x00') (async)
symlinkat(&(0x7f0000004480)='./file0\x00', 0xffffffffffffffff, &(0x7f0000004540)='./file0\x00')
openat$ptmx(0xffffffffffffff9c, &(0x7f0000004580), 0x80, 0x0)
ioctl$VT_GETMODE(r3, 0x5601, 0x0)

[-- Attachment #3: delay-kvasprintf-kmmpd-name-race-v2.patch --]
[-- Type: text/plain, Size: 1795 bytes --]

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Date: Sat, 14 Nov 2026 22:35:00 +0800
Subject: [PATCH] DEBUG: kvasprintf: widen old and fixed kmmpd name windows

This is a reproducer-only delay patch for validating:

	WARNING in __kthread_create_on_node
	different return values (11 and 6) from vsnprintf("kmmpd-%.*s", ...)

The first delay patch only matched "kmmpd-%.*s".  That made the A side
easy to reproduce, but after applying the fix the B side uses
"kmmpd-%s" and therefore did not hit the same artificial kvasprintf()
delay window.

Delay both old and fixed kmmpd thread-name formats after kvasprintf()'s
first vsnprintf() pass.  With this patch, A verifies that the original
buffer-backed string can change during the widened window, while B uses
the same widened kvasprintf() window but passes the fixed stack-backed
string source.

Do not use this patch as a fix and do not ship it outside validation.
---
 lib/kasprintf.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/kasprintf.c b/lib/kasprintf.c
index 6ec7e041c5cc..000000000000 100644
--- a/lib/kasprintf.c
+++ b/lib/kasprintf.c
@@ -7,6 +7,7 @@
 
 #include <linux/stdarg.h>
 #include <linux/export.h>
+#include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/string.h>
@@ -21,6 +22,15 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
 	first = vsnprintf(NULL, 0, fmt, aq);
 	va_end(aq);
 
+	/*
+	 * Reproducer-only delay.  Cover both the original ext4 MMP thread-name
+	 * format and the fixed format so A and B execute the same widened
+	 * kvasprintf() window.
+	 */
+	if (!strcmp(fmt, "kmmpd-%.*s") ||
+	    !strcmp(fmt, "kmmpd-%s"))
+		msleep(1000);
+
 	p = kmalloc_track_caller(first+1, gfp);
 	if (!p)
 		return NULL;
-- 
2.50.1


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

* Re: [PATCH] ext4: use a stable source for the kmmpd thread name
  2026-11-16 16:36   ` Zhao Gongyi
@ 2026-11-16 16:42     ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-16 16:42 UTC (permalink / raw)
  To: Zhao Gongyi; +Cc: linux-ext4, tytso

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] lib/kasprintf: reproducer-only msleep(1000) delay committed in
  kvasprintf()
- [High] ext4: missing Signed-off-by trailer in commit message
- [Medium] ext4: commit title and raw email reply body do not match code
  changes
--

commit d8ecd786cfd0874e564c2e769446a7a6d1cd1f7f
Author: Zhao Gongyi <zhaogongyi@bytedance.com>

> ext4: use a stable source for the kmmpd thread name
>
> Hi Jan,
>
> On 11/16/26 8:16 PM, Jan Kara wrote:
> > What can change it? I don't see anything that should be doing that...
>
> A concurrent buffered write to the loop block device can change it. In
> one diagnostic run, the write reached the page-cache buffer ext4 was
> using for MMP. mmp_bdevname is embedded at bh->b_data + 0x50.
>
> In an x86 QEMU diagnostic run based on commit
> 7475ea8b58616b33c04afb976cf0fbaad9dd63fb, kvasprintf() first read
> "loop0" at ffff888013e1d050. A kprobe on mark_buffer_dirty() then
> fired for a buffer starting at ffff888013e1d000, covering that field.
> The stack was:
>
>    ksys_write -> blkdev_write_iter -> blkdev_buffered_write
>      -> iomap_file_buffered_write -> iomap_write_end
>      -> block_write_end -> block_commit_write -> mark_buffer_dirty
>
> The buffered write path copies data into the page cache before
> block_commit_write(). About one second later, the same source page
> contained an empty string, and kvasprintf() reported return values 11
> and 6. The kprobe records the buffer being dirtied; it does not trap
> the byte-copy instruction itself. My earlier description of a
> concurrent MMP mount changing the name was imprecise.
>
> The original syzkaller manager report shows the warning on an
> unmodified kernel. Standalone QEMU replays without a delay did not hit
> it reliably. To obtain the trace above, I used a diagnostic build with
> a one-second delay after the first vsnprintf() pass, source snapshots,
> an exported MMP buffer address, and a kprobe module. The attached
> test-only delay patch widens the window but does not collect the writer
> trace by itself. None of this diagnostic code is part of the proposed fix.
>
> The attached repro.syz is input to syz-execprog. I ran it in the guest with:
>
>    /root/syz-execprog -executor=/root/syz-executor -arch=amd64 \
>      -sandbox=none -procs=12 -repeat=0 -threaded=true -slowdown=1 \
>      -sandbox_arg=0 -type=qemu /root/repro.syz
>
> I understand that raw writes to a block device during ext4 access can
> corrupt metadata. The proposed change gives the two-pass thread-name
> formatting a stable source; it does not change MMP's protection logic.
> I can provide the full diagnostic diff, kprobe module, and console log
> if useful.
>
> Thanks,
> Gongyi
>
> This is a reproducer-only delay patch for validating:
>
>         WARNING in __kthread_create_on_node
>         different return values (11 and 6) from vsnprintf("kmmpd-%.*s", ...)
>
> The first delay patch only matched "kmmpd-%.*s".  That made the A side
> easy to reproduce, but after applying the fix the B side uses
> "kmmpd-%s" and therefore did not hit the same artificial kvasprintf()
> delay window.
>
> Delay both old and fixed kmmpd thread-name formats after kvasprintf()'s
> first vsnprintf() pass.  With this patch, A verifies that the original
> buffer-backed string can change during the widened window, while B uses
> the same widened kvasprintf() window but passes the fixed stack-backed
> string source.
>
> Do not use this patch as a fix and do not ship it outside validation.

[Severity: High]
The commit message is missing a Signed-off-by: trailer.

[Severity: Medium]
Does the commit subject and message match the code change?  The title claims
to provide a stable source for the ext4 kmmpd thread name and the body
contains a mailing-list reply concatenated with validation notes, while the
diff only modifies lib/kasprintf.c.

> diff --git a/lib/kasprintf.c b/lib/kasprintf.c
> index cd2f5974ed987..77cbf8a1cbdd4 100644
> --- a/lib/kasprintf.c
> +++ b/lib/kasprintf.c
> @@ -7,6 +7,7 @@
>  
>  #include <linux/stdarg.h>
>  #include <linux/export.h>
> +#include <linux/delay.h>
>  #include <linux/slab.h>
>  #include <linux/types.h>
>  #include <linux/string.h>
> @@ -22,6 +23,15 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
>  	first = vsnprintf(NULL, 0, fmt, aq);
>  	va_end(aq);
>  
> +	/*
> +	 * Reproducer-only delay.  Cover both the original ext4 MMP thread-name
> +	 * format and the fixed format so A and B execute the same widened
> +	 * kvasprintf() window.
> +	 */
> +	if (!strcmp(fmt, "kmmpd-%.*s") ||
> +	    !strcmp(fmt, "kmmpd-%s"))
> +		msleep(1000);

[Severity: High]
Was this reproducer-only delay patch committed instead of the ext4 fix in
ext4_multi_mount_protect()?

Rather than stabilizing the thread name in fs/ext4/mmp.c, this regression
adds an unconditional msleep(1000) between the two vsnprintf() passes in
kvasprintf().  It stalls every ext4 MMP mount by one second, widens the race
window that triggers the vsnprintf() mismatch warning, and sleeps without
checking whether gfp allows blocking.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/da634961-1d13-4d21-b181-f366fd72e0d1@bytedance.com?part=1

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

end of thread, other threads:[~2026-11-16 16:42 UTC | newest]

Thread overview: 5+ 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
2026-11-16 12:16 ` Jan Kara
2026-11-16 16:36   ` Zhao Gongyi
2026-11-16 16:42     ` sashiko-bot

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