* [PATCH v2 0/2] fuse: schedule dentry_tree_work only between dentry tree init and cleanup
@ 2026-11-20 15:00 Sang-Heon Jeon
2026-11-20 15:00 ` [PATCH v2 1/2] fuse: defer dentry_tree_work until fuse_dentry_tree_init() Sang-Heon Jeon
2026-11-20 15:00 ` [PATCH v2 2/2] fuse: do not schedule dentry_tree_work after fuse_dentry_tree_cleanup() Sang-Heon Jeon
0 siblings, 2 replies; 7+ messages in thread
From: Sang-Heon Jeon @ 2026-11-20 15:00 UTC (permalink / raw)
To: Miklos Szeredi; +Cc: fuse-devel, linux-kernel, Luis Henriques, Miklos Szeredi
Hello,
inval_wq_set() schedules dentry_tree_work when inval_wq is enabled, but
it can be called before fuse_dentry_tree_init() and after
fuse_dentry_tree_cleanup(). This series makes inval_wq_set() schedule
the work only between the two.
Patch 1 defers scheduling the work until fuse_dentry_tree_init() sets
it up.
Patch 2 does not schedule the work after fuse_dentry_tree_cleanup()
cancels it.
Both patches hold kernel_param_lock(), because a sysfs write can call
inval_wq_set() at the same time.
---
Changes from v1 [1]
- Hold kernel_param_lock() in fuse_dentry_tree_init()
- Add patch 2 to not schedule the work after fuse_dentry_tree_cleanup()
[1] https://lore.kernel.org/all/20261110150250.71520-1-ekffu200098@gmail.com/
---
Sang-Heon Jeon (2):
fuse: defer dentry_tree_work until fuse_dentry_tree_init()
fuse: do not schedule dentry_tree_work after
fuse_dentry_tree_cleanup()
fs/fuse/dir.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
base-commit: ab9787d7e66ac7e6e94fc975b37c5b56fff98ca9
--
2.53.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 1/2] fuse: defer dentry_tree_work until fuse_dentry_tree_init() 2026-11-20 15:00 [PATCH v2 0/2] fuse: schedule dentry_tree_work only between dentry tree init and cleanup Sang-Heon Jeon @ 2026-11-20 15:00 ` Sang-Heon Jeon 2026-11-24 11:49 ` Luis Henriques 2026-11-20 15:00 ` [PATCH v2 2/2] fuse: do not schedule dentry_tree_work after fuse_dentry_tree_cleanup() Sang-Heon Jeon 1 sibling, 1 reply; 7+ messages in thread From: Sang-Heon Jeon @ 2026-11-20 15:00 UTC (permalink / raw) To: Miklos Szeredi Cc: fuse-devel, linux-kernel, Luis Henriques, Miklos Szeredi, stable 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. Also hold kernel_param_lock() in fuse_dentry_tree_init(), because a sysfs write can call inval_wq_set() at the same time. Fixes: ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries") Cc: stable@vger.kernel.org Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com> --- fs/fuse/dir.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index da23ccd8685c..0d5d04df477b 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -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,14 @@ void fuse_dentry_tree_init(void) dentry_hash[i].tree = RB_ROOT; } INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work); + + kernel_param_lock(THIS_MODULE); + inval_wq_ready = true; + + if (inval_wq) + schedule_delayed_work(&dentry_tree_work, + secs_to_jiffies(inval_wq)); + kernel_param_unlock(THIS_MODULE); } void fuse_dentry_tree_cleanup(void) -- 2.53.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] fuse: defer dentry_tree_work until fuse_dentry_tree_init() 2026-11-20 15:00 ` [PATCH v2 1/2] fuse: defer dentry_tree_work until fuse_dentry_tree_init() Sang-Heon Jeon @ 2026-11-24 11:49 ` Luis Henriques 2026-11-24 15:02 ` Sang-Heon Jeon 0 siblings, 1 reply; 7+ messages in thread From: Luis Henriques @ 2026-11-24 11:49 UTC (permalink / raw) To: Sang-Heon Jeon Cc: Miklos Szeredi, fuse-devel, linux-kernel, Miklos Szeredi, stable On Sat, Nov 21 2026, Sang-Heon Jeon wrote: > 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. > Also hold kernel_param_lock() in fuse_dentry_tree_init(), because a > sysfs write can call inval_wq_set() at the same time. > > Fixes: ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries") > Cc: stable@vger.kernel.org > Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com> > --- > fs/fuse/dir.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c > index da23ccd8685c..0d5d04df477b 100644 > --- a/fs/fuse/dir.c > +++ b/fs/fuse/dir.c > @@ -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,14 @@ void fuse_dentry_tree_init(void) > dentry_hash[i].tree = RB_ROOT; > } > INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work); > + > + kernel_param_lock(THIS_MODULE); I wonder if this is the right solution. The solution I had in my local tree was to simply declare a spinlock with DEFINE_SPINLOCK() and use it to synchronise access in fuse_dentry_tree_work(), fuse_dentry_tree_cleanup() and inval_wq_set(). Do you have a reason for using this kernel_param_lock() instead? (Honest question! I've never used that before :-) ) Cheers, -- Luís > + inval_wq_ready = true; > + > + if (inval_wq) > + schedule_delayed_work(&dentry_tree_work, > + secs_to_jiffies(inval_wq)); > + kernel_param_unlock(THIS_MODULE); > } > > void fuse_dentry_tree_cleanup(void) > -- > 2.53.0 > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] fuse: defer dentry_tree_work until fuse_dentry_tree_init() 2026-11-24 11:49 ` Luis Henriques @ 2026-11-24 15:02 ` Sang-Heon Jeon 2026-11-24 16:23 ` Luis Henriques 0 siblings, 1 reply; 7+ messages in thread From: Sang-Heon Jeon @ 2026-11-24 15:02 UTC (permalink / raw) To: Luis Henriques Cc: Miklos Szeredi, fuse-devel, linux-kernel, Miklos Szeredi, stable Hi, Luis 2026년 11월 24일 (화) 오후 8:49, Luis Henriques <luis@igalia.com>님이 작성: > > On Sat, Nov 21 2026, Sang-Heon Jeon wrote: > > > 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. > > Also hold kernel_param_lock() in fuse_dentry_tree_init(), because a > > sysfs write can call inval_wq_set() at the same time. > > > > Fixes: ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries") > > Cc: stable@vger.kernel.org > > Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com> > > --- > > fs/fuse/dir.c | 13 +++++++++++++ > > 1 file changed, 13 insertions(+) > > > > diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c > > index da23ccd8685c..0d5d04df477b 100644 > > --- a/fs/fuse/dir.c > > +++ b/fs/fuse/dir.c > > @@ -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,14 @@ void fuse_dentry_tree_init(void) > > dentry_hash[i].tree = RB_ROOT; > > } > > INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work); > > + > > + kernel_param_lock(THIS_MODULE); > > I wonder if this is the right solution. The solution I had in my local > tree was to simply declare a spinlock with DEFINE_SPINLOCK() and use it to > synchronise access in fuse_dentry_tree_work(), fuse_dentry_tree_cleanup() > and inval_wq_set(). > > Do you have a reason for using this kernel_param_lock() instead? (Honest > question! I've never used that before :-) ) AFAIU, parse_args() (boot, module load) and param_attr_store() (sysfs) already hold kernel_param_lock() when they call inval_wq_set(). So we don't need to declare another lock if we hold kernel_param_lock during init and cleanup. Let me know if I miss or misunderstand something. But using a spinlock should be okay as well. So if you prefer using a spinlock instead of kernel_param_lock, just let me know and I'll switch in v3. > Cheers, > -- > Luís > > > + inval_wq_ready = true; > > + > > + if (inval_wq) > > + schedule_delayed_work(&dentry_tree_work, > > + secs_to_jiffies(inval_wq)); > > + kernel_param_unlock(THIS_MODULE); > > } > > > > void fuse_dentry_tree_cleanup(void) > > -- > > 2.53.0 > > > Best regards, Sang-Heon Jeon ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] fuse: defer dentry_tree_work until fuse_dentry_tree_init() 2026-11-24 15:02 ` Sang-Heon Jeon @ 2026-11-24 16:23 ` Luis Henriques 2026-11-24 16:33 ` Sang-Heon Jeon 0 siblings, 1 reply; 7+ messages in thread From: Luis Henriques @ 2026-11-24 16:23 UTC (permalink / raw) To: Sang-Heon Jeon Cc: Miklos Szeredi, fuse-devel, linux-kernel, Miklos Szeredi, stable On Wed, Nov 25 2026, Sang-Heon Jeon wrote: > Hi, Luis > > 2026년 11월 24일 (화) 오후 8:49, Luis Henriques <luis@igalia.com>님이 작성: >> >> On Sat, Nov 21 2026, Sang-Heon Jeon wrote: >> >> > 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. >> > Also hold kernel_param_lock() in fuse_dentry_tree_init(), because a >> > sysfs write can call inval_wq_set() at the same time. >> > >> > Fixes: ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries") >> > Cc: stable@vger.kernel.org >> > Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com> >> > --- >> > fs/fuse/dir.c | 13 +++++++++++++ >> > 1 file changed, 13 insertions(+) >> > >> > diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c >> > index da23ccd8685c..0d5d04df477b 100644 >> > --- a/fs/fuse/dir.c >> > +++ b/fs/fuse/dir.c >> > @@ -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,14 @@ void fuse_dentry_tree_init(void) >> > dentry_hash[i].tree = RB_ROOT; >> > } >> > INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work); >> > + >> > + kernel_param_lock(THIS_MODULE); >> >> I wonder if this is the right solution. The solution I had in my local >> tree was to simply declare a spinlock with DEFINE_SPINLOCK() and use it to >> synchronise access in fuse_dentry_tree_work(), fuse_dentry_tree_cleanup() >> and inval_wq_set(). >> >> Do you have a reason for using this kernel_param_lock() instead? (Honest >> question! I've never used that before :-) ) > > AFAIU, parse_args() (boot, module load) and param_attr_store() (sysfs) > already hold kernel_param_lock() when they call inval_wq_set(). So we > don't need to declare another lock if we hold kernel_param_lock during > init and cleanup. Let me know if I miss or misunderstand something. > > But using a spinlock should be okay as well. So if you prefer using a > spinlock instead of kernel_param_lock, just let me know and I'll > switch in v3. Well, I think your solution is correct and it should be OK. My question was mostly a bike-shedding question: we're using a lock that is defined outside of FUSE, and that doesn't seem to be used a lot elsewhere. On the other hand, this kernel_param_lock() was likely created for solving problems like this one so... yeah. Let's just leave it to the maintainers :-) And sorry for the noise. Cheers, -- Luís ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] fuse: defer dentry_tree_work until fuse_dentry_tree_init() 2026-11-24 16:23 ` Luis Henriques @ 2026-11-24 16:33 ` Sang-Heon Jeon 0 siblings, 0 replies; 7+ messages in thread From: Sang-Heon Jeon @ 2026-11-24 16:33 UTC (permalink / raw) To: Luis Henriques Cc: Miklos Szeredi, fuse-devel, linux-kernel, Miklos Szeredi, stable 2026년 11월 25일 (수) 오전 1:23, Luis Henriques <luis@igalia.com>님이 작성: > > On Wed, Nov 25 2026, Sang-Heon Jeon wrote: > > > Hi, Luis > > > > 2026년 11월 24일 (화) 오후 8:49, Luis Henriques <luis@igalia.com>님이 작성: > >> > >> On Sat, Nov 21 2026, Sang-Heon Jeon wrote: > >> > >> > 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. > >> > Also hold kernel_param_lock() in fuse_dentry_tree_init(), because a > >> > sysfs write can call inval_wq_set() at the same time. > >> > > >> > Fixes: ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries") > >> > Cc: stable@vger.kernel.org > >> > Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com> > >> > --- > >> > fs/fuse/dir.c | 13 +++++++++++++ > >> > 1 file changed, 13 insertions(+) > >> > > >> > diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c > >> > index da23ccd8685c..0d5d04df477b 100644 > >> > --- a/fs/fuse/dir.c > >> > +++ b/fs/fuse/dir.c > >> > @@ -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,14 @@ void fuse_dentry_tree_init(void) > >> > dentry_hash[i].tree = RB_ROOT; > >> > } > >> > INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work); > >> > + > >> > + kernel_param_lock(THIS_MODULE); > >> > >> I wonder if this is the right solution. The solution I had in my local > >> tree was to simply declare a spinlock with DEFINE_SPINLOCK() and use it to > >> synchronise access in fuse_dentry_tree_work(), fuse_dentry_tree_cleanup() > >> and inval_wq_set(). > >> > >> Do you have a reason for using this kernel_param_lock() instead? (Honest > >> question! I've never used that before :-) ) > > > > AFAIU, parse_args() (boot, module load) and param_attr_store() (sysfs) > > already hold kernel_param_lock() when they call inval_wq_set(). So we > > don't need to declare another lock if we hold kernel_param_lock during > > init and cleanup. Let me know if I miss or misunderstand something. > > > > But using a spinlock should be okay as well. So if you prefer using a > > spinlock instead of kernel_param_lock, just let me know and I'll > > switch in v3. > > Well, I think your solution is correct and it should be OK. My question > was mostly a bike-shedding question: we're using a lock that is defined > outside of FUSE, and that doesn't seem to be used a lot elsewhere. On the > other hand, this kernel_param_lock() was likely created for solving > problems like this one so... yeah. > > Let's just leave it to the maintainers :-) > > And sorry for the noise. No problem! Thanks for looking into this. > Cheers, > -- > Luís Best regards, Sang-Heon Jeon ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] fuse: do not schedule dentry_tree_work after fuse_dentry_tree_cleanup() 2026-11-20 15:00 [PATCH v2 0/2] fuse: schedule dentry_tree_work only between dentry tree init and cleanup Sang-Heon Jeon 2026-11-20 15:00 ` [PATCH v2 1/2] fuse: defer dentry_tree_work until fuse_dentry_tree_init() Sang-Heon Jeon @ 2026-11-20 15:00 ` Sang-Heon Jeon 1 sibling, 0 replies; 7+ messages in thread From: Sang-Heon Jeon @ 2026-11-20 15:00 UTC (permalink / raw) To: Miklos Szeredi Cc: fuse-devel, linux-kernel, Luis Henriques, Miklos Szeredi, stable fuse_dentry_tree_cleanup() cancels dentry_tree_work at module unload. But a sysfs write can call inval_wq_set() after that and schedule the work again, leading to use-after-free. So do not schedule the work in inval_wq_set() after fuse_dentry_tree_cleanup() cancels it. Also hold kernel_param_lock() in fuse_dentry_tree_cleanup(), because a sysfs write can call inval_wq_set() at the same time. Fixes: ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries") Cc: stable@vger.kernel.org Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com> --- fs/fuse/dir.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 0d5d04df477b..04ca6c9be2bf 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -63,7 +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. */ + /* + * Do not touch the work before fuse_dentry_tree_init() or after + * fuse_dentry_tree_cleanup(). + */ if (!inval_wq_ready) return 0; @@ -243,8 +246,11 @@ void fuse_dentry_tree_cleanup(void) { int i; + kernel_param_lock(THIS_MODULE); + inval_wq_ready = false; inval_wq = 0; cancel_delayed_work_sync(&dentry_tree_work); + kernel_param_unlock(THIS_MODULE); for (i = 0; i < FUSE_HASH_SIZE; i++) WARN_ON_ONCE(!RB_EMPTY_ROOT(&dentry_hash[i].tree)); -- 2.53.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-24 16:33 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-20 15:00 [PATCH v2 0/2] fuse: schedule dentry_tree_work only between dentry tree init and cleanup Sang-Heon Jeon 2026-11-20 15:00 ` [PATCH v2 1/2] fuse: defer dentry_tree_work until fuse_dentry_tree_init() Sang-Heon Jeon 2026-11-24 11:49 ` Luis Henriques 2026-11-24 15:02 ` Sang-Heon Jeon 2026-11-24 16:23 ` Luis Henriques 2026-11-24 16:33 ` Sang-Heon Jeon 2026-11-20 15:00 ` [PATCH v2 2/2] fuse: do not schedule dentry_tree_work after fuse_dentry_tree_cleanup() Sang-Heon Jeon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox