mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Luis Henriques <luis@igalia.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: luis@igalia.com, mszeredi@redhat.com, fuse-devel@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Matt Harvey <mharvey@jumptrading.com>,
	kernel-dev@igalia.com, stable@vger.kernel.org
Subject: [PATCH v2] fuse: fix 'inval_wq' parameter setting during module initialisation
Date: Fri,  6 Nov 2026 15:55:12 +0000	[thread overview]
Message-ID: <20261106155512.24801-1-luis@igalia.com> (raw)

If the fuse module is loaded with a 'inval_wq' parameter the inval_wq_set()
function will schedule work into dentry_tree_work.  However this worked is
not initialised at this point because fuse_dentry_tree_init() will not have
been executed yet.

This can be fixed by delaying the work scheduling until later if the module
is still being initialised.

While there, also simplify the sched/cancel by using mod_delayed_work()
instead of schedule_delayed_work().  This will result in having the period
being changed immediately instead of waiting for the next reschedule.

Fixes: ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries")
Cc: stable@vger.kernel.org
Signed-off-by: Luis Henriques <luis@igalia.com>
---
Hi!

So, here's a different approach that tries to address sashiko comments:
instead of checking the module state and going through all sort of races,
simply define a new state variable and use it instead.  Simpler.  I hope.

 fs/fuse/dir.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index da23ccd8685c..32e052dac2f1 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -35,6 +35,7 @@ struct dentry_bucket {
 #define FUSE_HASH_SIZE	(1 << FUSE_HASH_BITS)
 static struct dentry_bucket dentry_hash[FUSE_HASH_SIZE];
 static struct delayed_work dentry_tree_work;
+static bool dentry_tree_is_initialised __read_mostly;
 
 /* Minimum invalidation work queue frequency */
 #define FUSE_DENTRY_INVAL_FREQ_MIN 5
@@ -43,7 +44,6 @@ unsigned __read_mostly inval_wq;
 static int inval_wq_set(const char *val, const struct kernel_param *kp)
 {
 	unsigned int num;
-	unsigned int old = inval_wq;
 	int ret;
 
 	if (!val)
@@ -62,11 +62,13 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)
 
 	*((unsigned int *)kp->arg) = num;
 
-	if (num && !old)
-		schedule_delayed_work(&dentry_tree_work,
-				      secs_to_jiffies(num));
-	else if (!num && old)
-		cancel_delayed_work_sync(&dentry_tree_work);
+	if (READ_ONCE(dentry_tree_is_initialised)) {
+		if (num)
+			mod_delayed_work(system_percpu_wq, &dentry_tree_work,
+					 secs_to_jiffies(num));
+		else
+			cancel_delayed_work_sync(&dentry_tree_work);
+	}
 
 	return 0;
 }
@@ -217,6 +219,7 @@ void fuse_epoch_work(struct work_struct *work)
 
 void fuse_dentry_tree_init(void)
 {
+	unsigned int delay;
 	int i;
 
 	for (i = 0; i < FUSE_HASH_SIZE; i++) {
@@ -224,6 +227,14 @@ void fuse_dentry_tree_init(void)
 		dentry_hash[i].tree = RB_ROOT;
 	}
 	INIT_DELAYED_WORK(&dentry_tree_work, fuse_dentry_tree_work);
+
+	/* Start workqueue immediately if 'inval_wq' is already set */
+	delay = inval_wq;
+	if (delay)
+		schedule_delayed_work(&dentry_tree_work,
+				      secs_to_jiffies(delay));
+
+	WRITE_ONCE(dentry_tree_is_initialised, true);
 }
 
 void fuse_dentry_tree_cleanup(void)

                 reply	other threads:[~2026-11-06 15:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261106155512.24801-1-luis@igalia.com \
    --to=luis@igalia.com \
    --cc=fuse-devel@lists.linux.dev \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mharvey@jumptrading.com \
    --cc=miklos@szeredi.hu \
    --cc=mszeredi@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®