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() and cifs_sync_mid_result() wake it up once they removed the last mid while the server is exiting. 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/connect.c | 4 +++- fs/smb/client/transport.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index fa2bfab5e77b..c2999f12af4a 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -1187,7 +1187,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/transport.c b/fs/smb/client/transport.c index ea1f4fe42ee5..621acb2a47fe 100644 --- a/fs/smb/client/transport.c +++ b/fs/smb/client/transport.c @@ -113,6 +113,20 @@ void __release_mid(struct TCP_Server_Info *server, struct mid_q_entry *midEntry) mempool_free(midEntry, &cifs_mid_pool); } +/* + * clean_demultiplex_info() waits for the pending mids to + * be removed once the server is exiting. + */ +static void +cifs_wake_up_mid_queue_empty_locked(struct TCP_Server_Info *server) +{ + lockdep_assert_held(&server->mid_queue_lock); + + 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) { @@ -121,6 +135,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); @@ -804,6 +819,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