From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=144.76.82.148 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796391269; b=XmCsUZfn1pSbYH/WZiZ3ADQOKUK8TxJseMaZUv3RU5HbdL9tLQTuQjQWAL9nTWgBe3EG rqlH4fvOYlzez1RBdna7pDo6aKvZHjOspB4H5QzXDtRGiQbOK+XC8YyFMrg6+uIp4cRj1 rjNGH3/CUKLHsg46UjvdoIMDUJWJ6sRxBjVrJyH+X8NTkoJor3Po7fGXBblvYvzq/1dSa yTarXf4vjtkLEqIQYdXXaEKZrDthMVqft3YoghGjgKMj9BgRVXWTEa4yXLzHWz5G+j1eY IhnOUXAq8sn3AXRcWKZn/PADcaMTlaGhfu+AyPofi4XdXgUhHfsxhJQs8qRGsf3jC+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796391269; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=3wBuMvhRFs2AMHCMpmwMpF2W+c5PRP9gZ9vFFrHzC70=; b=gRLbxXTCmzjtL0Oc3wtDq8KKBhctrKqNtGvoQoDQoFD4eLR7SFWR97lND4ootnSBHDUp TTsWES5/nA8lNs7TQmTEouQJ9ZWLgAsaPiR0b2EiJk0UiaW9U4VR1jT9JR9mPypZlhDCA OXfRPqhovuxAeNGTsm/emUlybvv1fu9wcr6hto27TaeMr7m8nq+A18pqDJU+yL3b4JVz/ OoBF1l4yXbg/vE7zCRNzMuEKQc1czU7XaAzP3Dcia3KUU3A4SxYP72sOjiLWBzFTGnigo Hlcnqph1soTOiAodRMzwND8ajtNnrzIV9ix/qCZY2kGRKn0Yi90kEywcrH07DyCKzCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samba.org; spf=pass smtp.mailfrom=samba.org; dkim=pass header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=2sv0AAZp; arc=none smtp.remote-ip=144.76.82.148 Received: from hr2.samba.org (hr2.samba.org [144.76.82.148]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D417606A336; Fri, 4 Dec 2026 13:34:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4D417606A336 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=samba.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samba.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (3072-bit key) header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=2sv0AAZp DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-ID:Date:Cc:To:From; bh=3wBuMvhRFs2AMHCMpmwMpF2W+c5PRP9gZ9vFFrHzC70=; b=2sv0AAZp6tiM7KNBNb314VBNHo im75VTzA3RJ1j31lytHWdnrTHPt5512QYeDf1leSrnmNsRG8x5W8YFu2lVPdzRNa8p5OGwdG7lG1E NzXIcdrVlhq3diN347gKAPqwYG7sRPOs9STM3R0SurdRGFeQyF/OJTVcxwXU2DsE66Qzo6mBSCqtD 6h92Y9HiFsbrjaSNYmnHvtPWBCMTklwy797kVKMuQN/WYwrWyXZnVLdS+4pRAbChqHYJyBLXf1sF1 ChJv5w9IVnXSitBdc2DDSHgAIgNcthfrKmdxap/NtoYoIlG9KaJ7PevjlnwcZjntMchsN/LAZ4HcB tVQDPBG5dsx0vSPJ+OqRqimjHemp4+xurE+j13nM6I/QQj5KQB5TzmsYZvtHEZx+KFhEzxdNwfhGv iBiylpyKfqDFKTkxwruY6aKujvDHiRxa600M7ZNOKIp5/Wf2bvCnnr4gWof7cgy8hSs1mUk/XorzK MC1+seXCaJKJ5JgBqDYhXmVB; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1xZTQd-00000000IAz-0fAH; Fri, 04 Dec 2026 13:34:23 +0000 From: Stefan Metzmacher To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org Cc: metze@samba.org, stable@vger.kernel.org, Paulo Alcantara , Namjae Jeon , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , 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 Message-ID: <5a9652527165bb55155902b4d6cff14b1ffcee2f.1796391093.git.metze@samba.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Namjae Jeon Cc: Ronnie Sahlberg Cc: Shyam Prasad N Cc: Tom Talpey Cc: Bharath SM Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Stefan Metzmacher --- 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