Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Huiwen He <huiwen.he@linux.dev>
To: linkinjeon@kernel.org
Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org,
	senozhatsky@chromium.org, tom@talpey.com,
	chenxiaosong@chenxiaosong.com, tj@kernel.org,
	jiangshanlai@gmail.com, stefan.chulski@broadcom.com
Subject: [PATCH 1/4] ksmbd: keep server in RESETTING until defaults are restored
Date: Tue,  1 Dec 2026 11:27:45 +0800	[thread overview]
Message-ID: <20261201032749.2224354-2-huiwen.he@linux.dev> (raw)
In-Reply-To: <20261201032749.2224354-1-huiwen.he@linux.dev>

From: Huiwen He <hehuiwen@kylinos.cn>

server_ctrl_handle_reset() can expose STARTING_UP before reset finishes:
a failed init leaves the server in STARTING_UP when reset clears the
mountd PID, and server_conf_init() sets STARTING_UP before restoring
defaults. Either window lets a new mountd startup race with teardown
and default restoration.

Enter RESETTING before clearing the mountd PID, and publish STARTING_UP
with release/acquire ordering only after defaults are restored.

Fixes: 0626e6641f6b ("cifsd: add server handler for central processing and tranport layers")
Signed-off-by: Huiwen He <hehuiwen@kylinos.cn>
---
 fs/smb/server/server.c | 6 +++---
 fs/smb/server/server.h | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/smb/server/server.c b/fs/smb/server/server.c
index 962f12e969ba..32a2201284f3 100644
--- a/fs/smb/server/server.c
+++ b/fs/smb/server/server.c
@@ -580,7 +580,6 @@ static void server_conf_free(void)
 
 static int server_conf_init(void)
 {
-	WRITE_ONCE(server_conf.state, SERVER_STATE_STARTING_UP);
 	server_conf.enforced_signing = 0;
 	server_conf.min_protocol = ksmbd_min_protocol();
 	server_conf.max_protocol = ksmbd_max_protocol();
@@ -592,6 +591,8 @@ static int server_conf_init(void)
 	server_conf.max_inflight_req = SMB2_MAX_CREDITS;
 	server_conf.max_sessions_per_connection =
 		KSMBD_DEFAULT_MAX_SESSIONS_PER_CONNECTION;
+	/* Publish the defaults before accepting a mountd startup event. */
+	smp_store_release(&server_conf.state, SERVER_STATE_STARTING_UP);
 	return 0;
 }
 
@@ -612,12 +613,12 @@ static void server_ctrl_handle_init(struct server_ctrl_struct *ctrl)
 
 static void server_ctrl_handle_reset(struct server_ctrl_struct *ctrl)
 {
+	WRITE_ONCE(server_conf.state, SERVER_STATE_RESETTING);
 	ksmbd_ipc_soft_reset();
 	ksmbd_conn_transport_destroy();
 	ksmbd_stop_durable_scavenger();
 	server_conf_free();
 	server_conf_init();
-	WRITE_ONCE(server_conf.state, SERVER_STATE_STARTING_UP);
 }
 
 static void server_ctrl_handle_work(struct work_struct *work)
@@ -695,7 +696,6 @@ static ssize_t kill_server_store(const struct class *class,
 
 	pr_info("kill command received\n");
 	mutex_lock(&ctrl_lock);
-	WRITE_ONCE(server_conf.state, SERVER_STATE_RESETTING);
 	__module_get(THIS_MODULE);
 	server_ctrl_handle_reset(NULL);
 	module_put(THIS_MODULE);
diff --git a/fs/smb/server/server.h b/fs/smb/server/server.h
index 7b7df3fafe5b..28704174d8df 100644
--- a/fs/smb/server/server.h
+++ b/fs/smb/server/server.h
@@ -72,7 +72,8 @@ static inline int ksmbd_server_running(void)
 
 static inline int ksmbd_server_configurable(void)
 {
-	return READ_ONCE(server_conf.state) < SERVER_STATE_RESETTING;
+	/* Pairs with the release in server_conf_init(). */
+	return smp_load_acquire(&server_conf.state) < SERVER_STATE_RESETTING;
 }
 
 int server_queue_ctrl_init_work(void);

  reply	other threads:[~2026-12-01  3:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  3:27 [PATCH 0/4] ksmbd: allow request dispatch on an unbound workqueue Huiwen He
2026-12-01  3:27 ` Huiwen He [this message]
2026-12-01  3:27 ` [PATCH 2/4] ksmbd: reset the server directly on startup failure Huiwen He
2026-12-01  3:27 ` [PATCH 3/4] workqueue: export attribute and sysfs setup helpers Huiwen He
2026-12-01  3:27 ` [PATCH 4/4] ksmbd: add request workqueue mode startup option Huiwen He

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=20261201032749.2224354-2-huiwen.he@linux.dev \
    --to=huiwen.he@linux.dev \
    --cc=chenxiaosong@chenxiaosong.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=stefan.chulski@broadcom.com \
    --cc=tj@kernel.org \
    --cc=tom@talpey.com \
    /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