From: Stefan Metzmacher <metze@samba.org>
To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org
Cc: metze@samba.org, stable@vger.kernel.org,
Paulo Alcantara <pc@manguebit.org>,
Namjae Jeon <linkinjeon@kernel.org>,
Ronnie Sahlberg <ronniesahlberg@gmail.com>,
Shyam Prasad N <sprasad@microsoft.com>,
Tom Talpey <tom@talpey.com>, Bharath SM <bharathsm@microsoft.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 07/12] smb: client: wait for pending mids instead of sleeping 46 seconds
Date: Fri, 4 Dec 2026 14:33:32 +0100 [thread overview]
Message-ID: <5a9652527165bb55155902b4d6cff14b1ffcee2f.1796391093.git.metze@samba.org> (raw)
In-Reply-To: <cover.1796391093.git.metze@samba.org>
If there are still mids on pending_mid_q after the demultiplex thread
shut down the others, clean_demultiplex_info() did msleep(46000) in
order to give the waiting threads time to exit, even if they removed
their mids much earlier.
Wait on server->response_q for pending_mid_q to become empty instead,
still with 46 seconds as maximum. delete_mid(),
cifs_sync_mid_result() and the dequeue in __smb2_find_mid(), e.g.
from smb2_decrypt_offload(), wake it up once they removed the last mid
while the server is exiting.
This relies on "smb: client: let in-flight requests hold a
TCP_Server_Info reference": the thread that removes the last mid wakes
cifsd while it still uses the server, which is only safe because its
mid and the request itself hold server references.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Shyam Prasad N <sprasad@microsoft.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Bharath SM <bharathsm@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/client/cifsproto.h | 1 +
fs/smb/client/connect.c | 4 +++-
fs/smb/client/smb2ops.c | 2 ++
fs/smb/client/transport.c | 24 ++++++++++++++++++++++++
4 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h
index f6c95a47525b..402446435105 100644
--- a/fs/smb/client/cifsproto.h
+++ b/fs/smb/client/cifsproto.h
@@ -82,6 +82,7 @@ char *cifs_build_path_to_root(struct smb3_fs_context *ctx,
struct cifs_tcon *tcon, int add_treename);
char *cifs_build_devname(char *nodename, const char *prepath);
void delete_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid);
+void cifs_wake_up_mid_queue_empty_locked(struct TCP_Server_Info *server);
void __release_mid(struct TCP_Server_Info *server,
struct mid_q_entry *midEntry);
void cifs_wake_up_task(struct TCP_Server_Info *server,
diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
index a9531b487e82..ff26b1980bb7 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -1211,7 +1211,9 @@ clean_demultiplex_info(struct TCP_Server_Info *server)
* response and going ahead and killing cifsd.
*/
cifs_dbg(FYI, "Wait for exit from demultiplex thread\n");
- msleep(46000);
+ wait_event_timeout(server->response_q,
+ list_empty_careful(&server->pending_mid_q),
+ 46 * HZ);
/*
* If threads still have not exited they are probably never
* coming home not much else we can do but free the memory.
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 3dbc70cb52ff..0ba6345ed656 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -426,6 +426,8 @@ __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
if (dequeue) {
list_del_init(&mid->qhead);
mid->deleted_from_q = true;
+ /* e.g. smb2_decrypt_offload() while exiting */
+ cifs_wake_up_mid_queue_empty_locked(server);
}
spin_unlock(&server->mid_queue_lock);
return mid;
diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c
index 0fefb84fcd0e..04e1e0f668e8 100644
--- a/fs/smb/client/transport.c
+++ b/fs/smb/client/transport.c
@@ -120,6 +120,28 @@ void __release_mid(struct TCP_Server_Info *server, struct mid_q_entry *midEntry)
cifs_tcp_server_put(server);
}
+/*
+ * clean_demultiplex_info() waits for the pending mids to
+ * be removed once the server is exiting.
+ */
+void
+cifs_wake_up_mid_queue_empty_locked(struct TCP_Server_Info *server)
+{
+ lockdep_assert_held(&server->mid_queue_lock);
+
+ /*
+ * Order the removal of the mid before reading tcpStatus,
+ * clean_demultiplex_info() sets CifsExiting before it checks
+ * pending_mid_q in wait_event_timeout(), which has the barrier
+ * on its side, otherwise both may see the old values and it
+ * would wait the full time.
+ */
+ smp_mb();
+ if (READ_ONCE(server->tcpStatus) == CifsExiting &&
+ list_empty(&server->pending_mid_q))
+ wake_up_all(&server->response_q);
+}
+
void
delete_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
@@ -128,6 +150,7 @@ delete_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid)
if (!mid->deleted_from_q) {
list_del_init(&mid->qhead);
mid->deleted_from_q = true;
+ cifs_wake_up_mid_queue_empty_locked(server);
}
spin_unlock(&server->mid_queue_lock);
@@ -832,6 +855,7 @@ int cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server
if (mid->deleted_from_q == false) {
list_del_init(&mid->qhead);
mid->deleted_from_q = true;
+ cifs_wake_up_mid_queue_empty_locked(server);
}
spin_unlock(&server->mid_queue_lock);
cifs_server_dbg(VFS, "%s: invalid mid state mid=%llu state=%d\n",
--
2.43.0
next prev parent reply other threads:[~2026-12-04 13:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:33 [PATCH 0/12] smb: client: don't sleep through reconnects and umount Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 01/12] smb: client: don't add a decrypted mid back to an exiting server Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 02/12] smb: client: use kref for the TCP_Server_Info object references Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 03/12] smb: client: let in-flight requests hold a TCP_Server_Info reference Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 04/12] smb: client: let the decrypt offload work " Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 05/12] smb: client: let channels hold a reference of the primary server struct Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 06/12] smb: client: stop waiting between reconnect attempts once the server exits Stefan Metzmacher
2026-12-04 13:33 ` Stefan Metzmacher [this message]
2026-12-04 13:33 ` [PATCH v2 08/12] smb: client: add cifs_server_wait_for_exit_ms() Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 09/12] smb: client: use cifs_server_wait_for_exit_ms() for the replay back-off Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 10/12] smb: smbdirect: fail a connect from another address family Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 11/12] smb: client: let SMB Direct connections use the srcaddr= mount option Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 12/12] smb: client: soft mounts only wait until a reconnect attempt failed locally Stefan Metzmacher
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=5a9652527165bb55155902b4d6cff14b1ffcee2f.1796391093.git.metze@samba.org \
--to=metze@samba.org \
--cc=bharathsm@microsoft.com \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pc@manguebit.org \
--cc=ronniesahlberg@gmail.com \
--cc=samba-technical@lists.samba.org \
--cc=sprasad@microsoft.com \
--cc=stable@vger.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
all inboxes | Powered by JetHome®