Skip to contentSkip to conversation

fuse: defer dentry_tree_work until fuse_dentry_tree_init()

PATCH Superseded Sang-Heon Jeon 3 participants 7 messages Nov 10 – Nov 17

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fuse: defer dentry_tree_work until fuse_dentry_tree_init()

inval_wq_set() schedules dentry_tree_work when inval_wq is enabled.

But inval_wq_set() can be called at boot or module load before fuse_dentry_tree_init() initializes the work, so __queue_delayed_work() warns and the work never starts.

So defer scheduling the work until fuse_dentry_tree_init() sets it up.

Fixes ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries")

---
QEMU based test result
- booted with "fuse.inval_wq=5"

1) AS-IS (before fix)

[    0.011073] Kernel command line: rootwait root=/dev/vda console=tty1 console=ttyS0 nokaslr  fuse.inval_wq=5
[    0.011114] ------------[ cut here ]------------
[    0.011115] WARNING: kernel/workqueue.c:2704 at __queue_delayed_work+0x11a/0x140, CPU#0: swapper/0
[    0.011124] Modules linked in:
[    0.011128] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.4.0-rc1-00010-gab9787d7e66a #1 PREEMPT(undef) 
[    0.011130] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1ubuntu1 04/01/2014
[    0.011131] RIP: 0010:__queue_delayed_work+0x11a/0x140
[    0.011133] Code: c4 08 48 89 df 5b e9 85 28 0a 00 90 0f 0b 90 4c 8b 42 08 48 8d 42 08 49 39 c0 0f 84 1c ff ff ff 90 0f 0b 90 e9 13 ff ff ff 90 <0f> 0b 90 e9 ec fe ff ff bff
[    0.011134] RSP: 0000:ffffffff82e03e00 EFLAGS: 00010003 ORIG_RAX: 0000000000000000
[    0.011135] RAX: 0000000000000000 RBX: 0000000000000040 RCX: 0000000000001388
[    0.011136] RDX: ffffffff83a3f320 RSI: 0000000000000000 RDI: 0000000000000040
[    0.011136] RBP: 0000000000000000 R08: 0000000000000082 R09: 0000000000000001
[    0.011136] R10: 000000000000000a R11: 000000000000000a R12: ffffffff82c09fd0
[    0.011137] R13: ffff88807ffcfb89 R14: 0000000000000000 R15: 0000000000001388
[    0.011140] FS:  0000000000000000(0000) GS:ffff8880fa26e000(0000) knlGS:0000000000000000
[    0.011141] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    0.011141] CR2: ffff888003a67000 CR3: 0000000002e30000 CR4: 00000000000000b0
[    0.011142] Call Trace:
[    0.011143]  <TASK>
[    0.011143]  queue_delayed_work_on+0x6a/0x80
[    0.011145]  inval_wq_set+0xc4/0xe0
[    0.011149]  parse_args+0x299/0x3c0
[    0.011151]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011154]  start_kernel+0x3b8/0x7c0
[    0.011156]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011157]  x86_64_start_reservations+0x24/0x30
[    0.011160]  x86_64_start_kernel+0xd1/0xe0
[    0.011162]  common_startup_64+0x13e/0x158
[    0.011165]  </TASK>
[    0.011166] ---[ end trace 0000000000000000 ]---
[    0.011173] ------------[ cut here ]------------

2) TO-BE (after fix)
- no error while booting, and also fuse_dentry_tree_work works well.

---
 fs/fuse/dir.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/fuse/dir.c +10 -0
index da23ccd8685c..6965a77a871f 100644
@@ -39,6 +39,7 @@ static struct delayed_work dentry_tree_work;
 /* Minimum invalidation work queue frequency */
 #define FUSE_DENTRY_INVAL_FREQ_MIN 5
 
+static bool inval_wq_ready;
 unsigned __read_mostly inval_wq;
 static int inval_wq_set(const char *val, const struct kernel_param *kp)
 {
@@ -62,6 +63,10 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)
 
 	*((unsigned int *)kp->arg) = num;
 
+	/* Defer the work until fuse_dentry_tree_init() sets it up. */
+	if (!inval_wq_ready)
+		return 0;
+
 	if (num && !old)
 		schedule_delayed_work(&dentry_tree_work,
 				      secs_to_jiffies(num));
@@ -224,6 +229,11 @@ void fuse_dentry_tree_init(void)
 		dentry_hash[i].tree = RB_ROOT;
 	}
 	INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work);
+	inval_wq_ready = true;
+
+	if (inval_wq)
+		schedule_delayed_work(&dentry_tree_work,
+				      secs_to_jiffies(inval_wq));
 }
 
 void fuse_dentry_tree_cleanup(void)

base-commit: ab9787d7e66ac7e6e94fc975b37c5b56fff98ca9

Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Sang-Heon Jeon

inval_wq_set() schedules dentry_tree_work when inval_wq is enabled.

But inval_wq_set() can be called at boot or module load before fuse_dentry_tree_init() initializes the work, so __queue_delayed_work() warns and the work never starts.

Quoted 8 lines

So defer scheduling the work until fuse_dentry_tree_init() sets it up.

Fixes ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries")

---
QEMU based test result
- booted with "fuse.inval_wq=5"

Thank you, Sang-Heon. I've sent a fix for this already[1], but sashiko still has some race complains which I haven't looked into yet. But maybe Miklos is happier with your patch, in which case you can add my

[1] https://lore.kernel.org/20261106155512.24801-1-luis%40igalia.com

Cheers,

Signature · 1 line
Luís
Quoted 82 lines

1) AS-IS (before fix)

[    0.011073] Kernel command line: rootwait root=/dev/vda console=tty1 console=ttyS0 nokaslr  fuse.inval_wq=5
[    0.011114] ------------[ cut here ]------------
[    0.011115] WARNING: kernel/workqueue.c:2704 at __queue_delayed_work+0x11a/0x140, CPU#0: swapper/0
[    0.011124] Modules linked in:
[    0.011128] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.4.0-rc1-00010-gab9787d7e66a #1 PREEMPT(undef) 
[    0.011130] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1ubuntu1 04/01/2014
[    0.011131] RIP: 0010:__queue_delayed_work+0x11a/0x140
[ 0.011133] Code: c4 08 48 89 df 5b e9 85 28 0a 00 90 0f 0b 90 4c 8b 42 08 48 8d
42 08 49 39 c0 0f 84 1c ff ff ff 90 0f 0b 90 e9 13 ff ff ff 90 <0f> 0b 90 e9 ec
fe ff ff bff
[    0.011134] RSP: 0000:ffffffff82e03e00 EFLAGS: 00010003 ORIG_RAX: 0000000000000000
[    0.011135] RAX: 0000000000000000 RBX: 0000000000000040 RCX: 0000000000001388
[    0.011136] RDX: ffffffff83a3f320 RSI: 0000000000000000 RDI: 0000000000000040
[    0.011136] RBP: 0000000000000000 R08: 0000000000000082 R09: 0000000000000001
[    0.011136] R10: 000000000000000a R11: 000000000000000a R12: ffffffff82c09fd0
[    0.011137] R13: ffff88807ffcfb89 R14: 0000000000000000 R15: 0000000000001388
[    0.011140] FS:  0000000000000000(0000) GS:ffff8880fa26e000(0000) knlGS:0000000000000000
[    0.011141] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    0.011141] CR2: ffff888003a67000 CR3: 0000000002e30000 CR4: 00000000000000b0
[    0.011142] Call Trace:
[    0.011143]  <TASK>
[    0.011143]  queue_delayed_work_on+0x6a/0x80
[    0.011145]  inval_wq_set+0xc4/0xe0
[    0.011149]  parse_args+0x299/0x3c0
[    0.011151]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011154]  start_kernel+0x3b8/0x7c0
[    0.011156]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011157]  x86_64_start_reservations+0x24/0x30
[    0.011160]  x86_64_start_kernel+0xd1/0xe0
[    0.011162]  common_startup_64+0x13e/0x158
[    0.011165]  </TASK>
[    0.011166] ---[ end trace 0000000000000000 ]---
[    0.011173] ------------[ cut here ]------------

2) TO-BE (after fix)
- no error while booting, and also fuse_dentry_tree_work works well.

---
 fs/fuse/dir.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/fuse/dir.c +10 -0
index da23ccd8685c..6965a77a871f 100644
@@ -39,6 +39,7 @@ static struct delayed_work dentry_tree_work;
 /* Minimum invalidation work queue frequency */
 #define FUSE_DENTRY_INVAL_FREQ_MIN 5
 
+static bool inval_wq_ready;
 unsigned __read_mostly inval_wq;
 static int inval_wq_set(const char *val, const struct kernel_param *kp)
 {
@@ -62,6 +63,10 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)
 
 	*((unsigned int *)kp->arg) = num;
 
+	/* Defer the work until fuse_dentry_tree_init() sets it up. */
+	if (!inval_wq_ready)
+		return 0;
+
 	if (num && !old)
 		schedule_delayed_work(&dentry_tree_work,
 				      secs_to_jiffies(num));
@@ -224,6 +229,11 @@ void fuse_dentry_tree_init(void)
 		dentry_hash[i].tree = RB_ROOT;
 	}
 	INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work);
+	inval_wq_ready = true;
+
+	if (inval_wq)
+		schedule_delayed_work(&dentry_tree_work,
+				      secs_to_jiffies(inval_wq));
 }
 
 void fuse_dentry_tree_cleanup(void)

base-commit: ab9787d7e66ac7e6e94fc975b37c5b56fff98ca9

Signature · 1 line
2.53.0
#2 lore raw

Hi, Luis

2026년 11월 11일 (수) 오후 6:28, Luis Henriques <[email protected]>님이 작성:

Quoted 18 lines · Sang-Heon Jeon
Quoted 7 lines

inval_wq_set() schedules dentry_tree_work when inval_wq is enabled.

But inval_wq_set() can be called at boot or module load before fuse_dentry_tree_init() initializes the work, so __queue_delayed_work() warns and the work never starts.

Quoted 8 lines

So defer scheduling the work until fuse_dentry_tree_init() sets it up.

Fixes ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries")

---
QEMU based test result
- booted with "fuse.inval_wq=5"

Quoted 3 lines

Thank you, Sang-Heon. I've sent a fix for this already[1], but sashiko still has some race complains which I haven't looked into yet. But maybe Miklos is happier with your patch, in which case you can add my

Sorry, I missed that thread.. sashiko also complains about the same race condition between init and sysfs setup. But I'm not sure it is a realistic scenario. So I want to hear other voices as well.

Quoted 1 line

Thanks for your review :)

Quoted 82 lines

[1] https://lore.kernel.org/20261106155512.24801-1-luis%40igalia.com

Cheers,
--
Luís

Quoted 76 lines

1) AS-IS (before fix)

[    0.011073] Kernel command line: rootwait root=/dev/vda console=tty1 console=ttyS0 nokaslr  fuse.inval_wq=5
[    0.011114] ------------[ cut here ]------------
[    0.011115] WARNING: kernel/workqueue.c:2704 at __queue_delayed_work+0x11a/0x140, CPU#0: swapper/0
[    0.011124] Modules linked in:
[    0.011128] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.4.0-rc1-00010-gab9787d7e66a #1 PREEMPT(undef)
[    0.011130] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1ubuntu1 04/01/2014
[    0.011131] RIP: 0010:__queue_delayed_work+0x11a/0x140
[ 0.011133] Code: c4 08 48 89 df 5b e9 85 28 0a 00 90 0f 0b 90 4c 8b 42 08 48 8d
42 08 49 39 c0 0f 84 1c ff ff ff 90 0f 0b 90 e9 13 ff ff ff 90 <0f> 0b 90 e9 ec
fe ff ff bff
[    0.011134] RSP: 0000:ffffffff82e03e00 EFLAGS: 00010003 ORIG_RAX: 0000000000000000
[    0.011135] RAX: 0000000000000000 RBX: 0000000000000040 RCX: 0000000000001388
[    0.011136] RDX: ffffffff83a3f320 RSI: 0000000000000000 RDI: 0000000000000040
[    0.011136] RBP: 0000000000000000 R08: 0000000000000082 R09: 0000000000000001
[    0.011136] R10: 000000000000000a R11: 000000000000000a R12: ffffffff82c09fd0
[    0.011137] R13: ffff88807ffcfb89 R14: 0000000000000000 R15: 0000000000001388
[    0.011140] FS:  0000000000000000(0000) GS:ffff8880fa26e000(0000) knlGS:0000000000000000
[    0.011141] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    0.011141] CR2: ffff888003a67000 CR3: 0000000002e30000 CR4: 00000000000000b0
[    0.011142] Call Trace:
[    0.011143]  <TASK>
[    0.011143]  queue_delayed_work_on+0x6a/0x80
[    0.011145]  inval_wq_set+0xc4/0xe0
[    0.011149]  parse_args+0x299/0x3c0
[    0.011151]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011154]  start_kernel+0x3b8/0x7c0
[    0.011156]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011157]  x86_64_start_reservations+0x24/0x30
[    0.011160]  x86_64_start_kernel+0xd1/0xe0
[    0.011162]  common_startup_64+0x13e/0x158
[    0.011165]  </TASK>
[    0.011166] ---[ end trace 0000000000000000 ]---
[    0.011173] ------------[ cut here ]------------

2) TO-BE (after fix)
- no error while booting, and also fuse_dentry_tree_work works well.

---
 fs/fuse/dir.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/fuse/dir.c +10 -0
index da23ccd8685c..6965a77a871f 100644
@@ -39,6 +39,7 @@ static struct delayed_work dentry_tree_work;
 /* Minimum invalidation work queue frequency */
 #define FUSE_DENTRY_INVAL_FREQ_MIN 5
 
+static bool inval_wq_ready;
 unsigned __read_mostly inval_wq;
 static int inval_wq_set(const char *val, const struct kernel_param *kp)
 {
@@ -62,6 +63,10 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)
 
      *((unsigned int *)kp->arg) = num;
 
+     /* Defer the work until fuse_dentry_tree_init() sets it up. */
+     if (!inval_wq_ready)
+             return 0;
+
      if (num && !old)
              schedule_delayed_work(&dentry_tree_work,
                                    secs_to_jiffies(num));
@@ -224,6 +229,11 @@ void fuse_dentry_tree_init(void)
              dentry_hash[i].tree = RB_ROOT;
      }
      INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work);
+     inval_wq_ready = true;
+
+     if (inval_wq)
+             schedule_delayed_work(&dentry_tree_work,
+                                   secs_to_jiffies(inval_wq));
 }
 
Quoted 7 lines
Quoted 6 lines
fs/fuse/dir.c +0 -0
 void fuse_dentry_tree_cleanup(void)

base-commit: ab9787d7e66ac7e6e94fc975b37c5b56fff98ca9 --
2.53.0

Best regards,
Sang-Heon Jeon

#3 lore raw

2026년 11월 11일 (수) 오후 8:27, Sang-Heon Jeon <[email protected]>님이 작성:

Quoted 22 lines

Hi, Luis

2026년 11월 11일 (수) 오후 6:28, Luis Henriques <[email protected]>님이 작성:

Quoted 18 lines · Sang-Heon Jeon
Quoted 15 lines

inval_wq_set() schedules dentry_tree_work when inval_wq is enabled.

But inval_wq_set() can be called at boot or module load before fuse_dentry_tree_init() initializes the work, so __queue_delayed_work() warns and the work never starts.

So defer scheduling the work until fuse_dentry_tree_init() sets it up.

Fixes ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries")

---
QEMU based test result
- booted with "fuse.inval_wq=5"

Quoted 7 lines
Quoted 3 lines

Thank you, Sang-Heon. I've sent a fix for this already[1], but sashiko still has some race complains which I haven't looked into yet. But maybe Miklos is happier with your patch, in which case you can add my

Sorry, I missed that thread.. sashiko also complains about the same race condition between init and sysfs setup. But I'm not sure it is a realistic scenario. So I want to hear other voices as well.

I also checked the other sashiko's complaints from your patch, the one about race between module cleanup and sysfs. It looks easier to reproduce, but still I'm not sure this is a realistic problem. If it is worth fixing, I will sent v2 with serialization between module init, cleanup and inval_wq_set()

Quoted 96 lines
Quoted 1 line

Thanks for your review :)

Quoted 82 lines

[1] https://lore.kernel.org/20261106155512.24801-1-luis%40igalia.com

Cheers,
--
Luís

Quoted 76 lines

1) AS-IS (before fix)

[    0.011073] Kernel command line: rootwait root=/dev/vda console=tty1 console=ttyS0 nokaslr  fuse.inval_wq=5
[    0.011114] ------------[ cut here ]------------
[    0.011115] WARNING: kernel/workqueue.c:2704 at __queue_delayed_work+0x11a/0x140, CPU#0: swapper/0
[    0.011124] Modules linked in:
[    0.011128] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.4.0-rc1-00010-gab9787d7e66a #1 PREEMPT(undef)
[    0.011130] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1ubuntu1 04/01/2014
[    0.011131] RIP: 0010:__queue_delayed_work+0x11a/0x140
[ 0.011133] Code: c4 08 48 89 df 5b e9 85 28 0a 00 90 0f 0b 90 4c 8b 42 08 48 8d
42 08 49 39 c0 0f 84 1c ff ff ff 90 0f 0b 90 e9 13 ff ff ff 90 <0f> 0b 90 e9 ec
fe ff ff bff
[    0.011134] RSP: 0000:ffffffff82e03e00 EFLAGS: 00010003 ORIG_RAX: 0000000000000000
[    0.011135] RAX: 0000000000000000 RBX: 0000000000000040 RCX: 0000000000001388
[    0.011136] RDX: ffffffff83a3f320 RSI: 0000000000000000 RDI: 0000000000000040
[    0.011136] RBP: 0000000000000000 R08: 0000000000000082 R09: 0000000000000001
[    0.011136] R10: 000000000000000a R11: 000000000000000a R12: ffffffff82c09fd0
[    0.011137] R13: ffff88807ffcfb89 R14: 0000000000000000 R15: 0000000000001388
[    0.011140] FS:  0000000000000000(0000) GS:ffff8880fa26e000(0000) knlGS:0000000000000000
[    0.011141] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    0.011141] CR2: ffff888003a67000 CR3: 0000000002e30000 CR4: 00000000000000b0
[    0.011142] Call Trace:
[    0.011143]  <TASK>
[    0.011143]  queue_delayed_work_on+0x6a/0x80
[    0.011145]  inval_wq_set+0xc4/0xe0
[    0.011149]  parse_args+0x299/0x3c0
[    0.011151]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011154]  start_kernel+0x3b8/0x7c0
[    0.011156]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011157]  x86_64_start_reservations+0x24/0x30
[    0.011160]  x86_64_start_kernel+0xd1/0xe0
[    0.011162]  common_startup_64+0x13e/0x158
[    0.011165]  </TASK>
[    0.011166] ---[ end trace 0000000000000000 ]---
[    0.011173] ------------[ cut here ]------------

2) TO-BE (after fix)
- no error while booting, and also fuse_dentry_tree_work works well.

---
 fs/fuse/dir.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/fuse/dir.c +10 -0
index da23ccd8685c..6965a77a871f 100644
@@ -39,6 +39,7 @@ static struct delayed_work dentry_tree_work;
 /* Minimum invalidation work queue frequency */
 #define FUSE_DENTRY_INVAL_FREQ_MIN 5
 
+static bool inval_wq_ready;
 unsigned __read_mostly inval_wq;
 static int inval_wq_set(const char *val, const struct kernel_param *kp)
 {
@@ -62,6 +63,10 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)
 
      *((unsigned int *)kp->arg) = num;
 
+     /* Defer the work until fuse_dentry_tree_init() sets it up. */
+     if (!inval_wq_ready)
+             return 0;
+
      if (num && !old)
              schedule_delayed_work(&dentry_tree_work,
                                    secs_to_jiffies(num));
@@ -224,6 +229,11 @@ void fuse_dentry_tree_init(void)
              dentry_hash[i].tree = RB_ROOT;
      }
      INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work);
+     inval_wq_ready = true;
+
+     if (inval_wq)
+             schedule_delayed_work(&dentry_tree_work,
+                                   secs_to_jiffies(inval_wq));
 }
 
Quoted 7 lines
Quoted 6 lines
fs/fuse/dir.c +0 -0
 void fuse_dentry_tree_cleanup(void)

base-commit: ab9787d7e66ac7e6e94fc975b37c5b56fff98ca9 --
2.53.0

Best regards,
Sang-Heon Jeon

#4 lore raw
Quoted 31 lines · Sang-Heon Jeon

2026년 11월 11일 (수) 오후 8:27, Sang-Heon Jeon <[email protected]>님이 작성:

Quoted 22 lines

Hi, Luis

2026년 11월 11일 (수) 오후 6:28, Luis Henriques <[email protected]>님이 작성:

Quoted 18 lines · Sang-Heon Jeon
Quoted 15 lines

inval_wq_set() schedules dentry_tree_work when inval_wq is enabled.

But inval_wq_set() can be called at boot or module load before fuse_dentry_tree_init() initializes the work, so __queue_delayed_work() warns and the work never starts.

So defer scheduling the work until fuse_dentry_tree_init() sets it up.

Fixes ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries")

---
QEMU based test result
- booted with "fuse.inval_wq=5"

Quoted 7 lines
Quoted 3 lines

Thank you, Sang-Heon. I've sent a fix for this already[1], but sashiko still has some race complains which I haven't looked into yet. But maybe Miklos is happier with your patch, in which case you can add my

Sorry, I missed that thread.. sashiko also complains about the same race condition between init and sysfs setup. But I'm not sure it is a realistic scenario. So I want to hear other voices as well.

Quoted 5 lines

I also checked the other sashiko's complaints from your patch, the one about race between module cleanup and sysfs. It looks easier to reproduce, but still I'm not sure this is a realistic problem. If it is worth fixing, I will sent v2 with serialization between module init, cleanup and inval_wq_set()

I agree that the first race doesn't look realistic, though it could be fixed by adding an extra spinlock (which could protect both inval_wq and dentry_tree_is_initialised).

The second race would be easier to fix by setting dentry_tree_is_initialised back to 'false' in fuse_dentry_tree_cleanup().

One thing I like with my version of the fix is that it replaces the usage of schedule_delayed_work() by mod_delayed_work(). But maybe that's out of the scope of this fix, and I should send that separately.

Cheers,

Signature · 1 line
Luís
Quoted 96 lines
Quoted 96 lines
Quoted 1 line

Thanks for your review :)

Quoted 82 lines

[1] https://lore.kernel.org/20261106155512.24801-1-luis%40igalia.com

Cheers,
--
Luís

Quoted 76 lines

1) AS-IS (before fix)

[    0.011073] Kernel command line: rootwait root=/dev/vda console=tty1 console=ttyS0 nokaslr  fuse.inval_wq=5
[    0.011114] ------------[ cut here ]------------
[    0.011115] WARNING: kernel/workqueue.c:2704 at __queue_delayed_work+0x11a/0x140, CPU#0: swapper/0
[    0.011124] Modules linked in:
[    0.011128] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.4.0-rc1-00010-gab9787d7e66a #1 PREEMPT(undef)
[    0.011130] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1ubuntu1 04/01/2014
[    0.011131] RIP: 0010:__queue_delayed_work+0x11a/0x140
[ 0.011133] Code: c4 08 48 89 df 5b e9 85 28 0a 00 90 0f 0b 90 4c 8b 42 08 48 8d
42 08 49 39 c0 0f 84 1c ff ff ff 90 0f 0b 90 e9 13 ff ff ff 90 <0f> 0b 90 e9 ec
fe ff ff bff
[    0.011134] RSP: 0000:ffffffff82e03e00 EFLAGS: 00010003 ORIG_RAX: 0000000000000000
[    0.011135] RAX: 0000000000000000 RBX: 0000000000000040 RCX: 0000000000001388
[    0.011136] RDX: ffffffff83a3f320 RSI: 0000000000000000 RDI: 0000000000000040
[    0.011136] RBP: 0000000000000000 R08: 0000000000000082 R09: 0000000000000001
[    0.011136] R10: 000000000000000a R11: 000000000000000a R12: ffffffff82c09fd0
[    0.011137] R13: ffff88807ffcfb89 R14: 0000000000000000 R15: 0000000000001388
[    0.011140] FS:  0000000000000000(0000) GS:ffff8880fa26e000(0000) knlGS:0000000000000000
[    0.011141] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    0.011141] CR2: ffff888003a67000 CR3: 0000000002e30000 CR4: 00000000000000b0
[    0.011142] Call Trace:
[    0.011143]  <TASK>
[    0.011143]  queue_delayed_work_on+0x6a/0x80
[    0.011145]  inval_wq_set+0xc4/0xe0
[    0.011149]  parse_args+0x299/0x3c0
[    0.011151]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011154]  start_kernel+0x3b8/0x7c0
[    0.011156]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011157]  x86_64_start_reservations+0x24/0x30
[    0.011160]  x86_64_start_kernel+0xd1/0xe0
[    0.011162]  common_startup_64+0x13e/0x158
[    0.011165]  </TASK>
[    0.011166] ---[ end trace 0000000000000000 ]---
[    0.011173] ------------[ cut here ]------------

2) TO-BE (after fix)
- no error while booting, and also fuse_dentry_tree_work works well.

---
 fs/fuse/dir.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/fuse/dir.c +10 -0
index da23ccd8685c..6965a77a871f 100644
@@ -39,6 +39,7 @@ static struct delayed_work dentry_tree_work;
 /* Minimum invalidation work queue frequency */
 #define FUSE_DENTRY_INVAL_FREQ_MIN 5
 
+static bool inval_wq_ready;
 unsigned __read_mostly inval_wq;
 static int inval_wq_set(const char *val, const struct kernel_param *kp)
 {
@@ -62,6 +63,10 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)
 
      *((unsigned int *)kp->arg) = num;
 
+     /* Defer the work until fuse_dentry_tree_init() sets it up. */
+     if (!inval_wq_ready)
+             return 0;
+
      if (num && !old)
              schedule_delayed_work(&dentry_tree_work,
                                    secs_to_jiffies(num));
@@ -224,6 +229,11 @@ void fuse_dentry_tree_init(void)
              dentry_hash[i].tree = RB_ROOT;
      }
      INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work);
+     inval_wq_ready = true;
+
+     if (inval_wq)
+             schedule_delayed_work(&dentry_tree_work,
+                                   secs_to_jiffies(inval_wq));
 }
 
Quoted 7 lines
Quoted 6 lines
fs/fuse/dir.c +0 -0
 void fuse_dentry_tree_cleanup(void)

base-commit: ab9787d7e66ac7e6e94fc975b37c5b56fff98ca9 --
2.53.0

Best regards,
Sang-Heon Jeon

#5 lore raw

2026년 11월 11일 (수) 오후 10:58, Luis Henriques <[email protected]>님이 작성:

Quoted 40 lines · Sang-Heon Jeon
Quoted 32 lines

2026년 11월 11일 (수) 오후 8:27, Sang-Heon Jeon <[email protected]>님이 작성:

Quoted 22 lines

Hi, Luis

2026년 11월 11일 (수) 오후 6:28, Luis Henriques <[email protected]>님이 작성:

Quoted 18 lines · Sang-Heon Jeon
Quoted 15 lines

inval_wq_set() schedules dentry_tree_work when inval_wq is enabled.

But inval_wq_set() can be called at boot or module load before fuse_dentry_tree_init() initializes the work, so __queue_delayed_work() warns and the work never starts.

So defer scheduling the work until fuse_dentry_tree_init() sets it up.

Fixes ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries")

---
QEMU based test result
- booted with "fuse.inval_wq=5"

Quoted 7 lines
Quoted 3 lines

Thank you, Sang-Heon. I've sent a fix for this already[1], but sashiko still has some race complains which I haven't looked into yet. But maybe Miklos is happier with your patch, in which case you can add my

Sorry, I missed that thread.. sashiko also complains about the same race condition between init and sysfs setup. But I'm not sure it is a realistic scenario. So I want to hear other voices as well.

Quoted 5 lines

I also checked the other sashiko's complaints from your patch, the one about race between module cleanup and sysfs. It looks easier to reproduce, but still I'm not sure this is a realistic problem. If it is worth fixing, I will sent v2 with serialization between module init, cleanup and inval_wq_set()

Quoted 6 lines

I agree that the first race doesn't look realistic, though it could be fixed by adding an extra spinlock (which could protect both inval_wq and dentry_tree_is_initialised).

The second race would be easier to fix by setting dentry_tree_is_initialised back to 'false' in fuse_dentry_tree_cleanup().

But I think race can still exist with that.

CPU0

                    CPU1

                       inval_wq_set()

                        READ_ONCE(dentry_tree_is_initialised) // true

                        <sleep>

fuse_dentry_tree_cleanup()
WRITE_ONCE(dentry_tree_is_initialised, false);
cancel_delayed_work_sync(&dentry_tree_work);

<wakeup>

mod_delayed_work(&dentry_tree_work) // already
false but executed

fuse_dentry_tree_work() // later can cause
UAF?

IMO, if we need to fix the first and second race both, then I prefer to use lock. But if we need to fix the second race only, then disable_delayed_work_sync(sashiko's suggestion) looks better.

Please correct me if I misunderstand something.

Quoted 3 lines

One thing I like with my version of the fix is that it replaces the usage of schedule_delayed_work() by mod_delayed_work(). But maybe that's out of the scope of this fix, and I should send that separately.

I do believe that is a great enhancement. But as you said it could be applied separately :)

Quoted 101 lines

Cheers,
--
Luís

Quoted 96 lines
Quoted 96 lines
Quoted 1 line

Thanks for your review :)

Quoted 82 lines

[1] https://lore.kernel.org/20261106155512.24801-1-luis%40igalia.com

Cheers,
--
Luís

Quoted 76 lines

1) AS-IS (before fix)

[    0.011073] Kernel command line: rootwait root=/dev/vda console=tty1 console=ttyS0 nokaslr  fuse.inval_wq=5
[    0.011114] ------------[ cut here ]------------
[    0.011115] WARNING: kernel/workqueue.c:2704 at __queue_delayed_work+0x11a/0x140, CPU#0: swapper/0
[    0.011124] Modules linked in:
[    0.011128] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.4.0-rc1-00010-gab9787d7e66a #1 PREEMPT(undef)
[    0.011130] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1ubuntu1 04/01/2014
[    0.011131] RIP: 0010:__queue_delayed_work+0x11a/0x140
[ 0.011133] Code: c4 08 48 89 df 5b e9 85 28 0a 00 90 0f 0b 90 4c 8b 42 08 48 8d
42 08 49 39 c0 0f 84 1c ff ff ff 90 0f 0b 90 e9 13 ff ff ff 90 <0f> 0b 90 e9 ec
fe ff ff bff
[    0.011134] RSP: 0000:ffffffff82e03e00 EFLAGS: 00010003 ORIG_RAX: 0000000000000000
[    0.011135] RAX: 0000000000000000 RBX: 0000000000000040 RCX: 0000000000001388
[    0.011136] RDX: ffffffff83a3f320 RSI: 0000000000000000 RDI: 0000000000000040
[    0.011136] RBP: 0000000000000000 R08: 0000000000000082 R09: 0000000000000001
[    0.011136] R10: 000000000000000a R11: 000000000000000a R12: ffffffff82c09fd0
[    0.011137] R13: ffff88807ffcfb89 R14: 0000000000000000 R15: 0000000000001388
[    0.011140] FS:  0000000000000000(0000) GS:ffff8880fa26e000(0000) knlGS:0000000000000000
[    0.011141] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    0.011141] CR2: ffff888003a67000 CR3: 0000000002e30000 CR4: 00000000000000b0
[    0.011142] Call Trace:
[    0.011143]  <TASK>
[    0.011143]  queue_delayed_work_on+0x6a/0x80
[    0.011145]  inval_wq_set+0xc4/0xe0
[    0.011149]  parse_args+0x299/0x3c0
[    0.011151]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011154]  start_kernel+0x3b8/0x7c0
[    0.011156]  ? __pfx_unknown_bootoption+0x10/0x10
[    0.011157]  x86_64_start_reservations+0x24/0x30
[    0.011160]  x86_64_start_kernel+0xd1/0xe0
[    0.011162]  common_startup_64+0x13e/0x158
[    0.011165]  </TASK>
[    0.011166] ---[ end trace 0000000000000000 ]---
[    0.011173] ------------[ cut here ]------------

2) TO-BE (after fix)
- no error while booting, and also fuse_dentry_tree_work works well.

---
 fs/fuse/dir.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/fuse/dir.c +10 -0
index da23ccd8685c..6965a77a871f 100644
@@ -39,6 +39,7 @@ static struct delayed_work dentry_tree_work;
 /* Minimum invalidation work queue frequency */
 #define FUSE_DENTRY_INVAL_FREQ_MIN 5
 
+static bool inval_wq_ready;
 unsigned __read_mostly inval_wq;
 static int inval_wq_set(const char *val, const struct kernel_param *kp)
 {
@@ -62,6 +63,10 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)
 
      *((unsigned int *)kp->arg) = num;
 
+     /* Defer the work until fuse_dentry_tree_init() sets it up. */
+     if (!inval_wq_ready)
+             return 0;
+
      if (num && !old)
              schedule_delayed_work(&dentry_tree_work,
                                    secs_to_jiffies(num));
@@ -224,6 +229,11 @@ void fuse_dentry_tree_init(void)
              dentry_hash[i].tree = RB_ROOT;
      }
      INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work);
+     inval_wq_ready = true;
+
+     if (inval_wq)
+             schedule_delayed_work(&dentry_tree_work,
+                                   secs_to_jiffies(inval_wq));
 }
 
Quoted 7 lines
Quoted 6 lines
fs/fuse/dir.c +0 -0
 void fuse_dentry_tree_cleanup(void)

base-commit: ab9787d7e66ac7e6e94fc975b37c5b56fff98ca9 --
2.53.0

Best regards,
Sang-Heon Jeon

Best regards,
Sang-Heon Jeon

maintainer
#6 lore raw
In reply to Sang-Heon Jeon
Quoted 8 lines · Sang-Heon Jeon

inval_wq_set() schedules dentry_tree_work when inval_wq is enabled.

But inval_wq_set() can be called at boot or module load before fuse_dentry_tree_init() initializes the work, so __queue_delayed_work() warns and the work never starts.

So defer scheduling the work until fuse_dentry_tree_init() sets it up.

Please add locking as sashiko's suggested.

Thanks,
Miklos