reconnect fixes and improvements
Subsystems (2)
v2 cover reconnect fixes and improvements
Hi all,
Sending v2 to address the issues found by sashiko
https://sashiko.dev/#/patchset/20260925202003.618856-1-ematsumiya%40suse.de
Please refer to the original cover letter for rationale and reproducer
https://lore.kernel.org/linux-cifs/[email protected]/
Cheers,
Enzo Matsumiya (2):
smb: client: fast fail sends if need to reconnect
smb: client: prevent premature discard of requests if reconnecting
fs/smb/client/cifsglob.h | 4 ++ fs/smb/client/connect.c | 58 ++++++++++++++++++++----- fs/smb/client/misc.c | 91 +++++++++++++++++++++++++++------------ fs/smb/client/transport.c | 8 ++++ 4 files changed, 124 insertions(+), 37 deletions(-)
Signature · 1 line
2.55.0
PATCH v2 1/2 smb: client: fast fail sends if need to reconnect
smb_send_kvec() keeps retrying when server needs to reconnect, which makes no sense as cifs_reconnect() will never run in parallel (because both need server mutex).
IOW, retrying will never succeed, but only delay reconnects further.
Bail out early from smb_send_kvec() when need to reconnect.
Also shutdown socket queues when CifsNeedReconnect is first set, so any sends/receives fails immediately (don't wait for socket to timeout).
Consequential change:
To shutdown the socket, we need to hold server mutex. Since not all callers hold it when calling cifs_signal_cifsd_for_reconnect(), we need to keep track of the owner task, so we can lock it as needed.
Add TCP_Server_Info::mutex_owner for that.
---
v1 -> v2 (fix issues detected by sashiko):
- move kernel_sock_shutdown() call out of cifs_tcp_ses_lock
- use server mutex to check/shutdown socket
fs/smb/client/cifsglob.h | 3 +++ fs/smb/client/connect.c | 54 +++++++++++++++++++++++++++++++-------- fs/smb/client/transport.c | 8 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)
fs/smb/client/cifsglob.h +3 -0
@@ -711,6 +711,7 @@ struct TCP_Server_Info {spinlock_t req_lock;/* protect the two values above */ struct mutex _srv_mutex;unsigned int nofs_flag; +struct task_struct *mutex_owner;struct task_struct *tsk;char server_GUID[16 ];__u16 sec_mode;
@@ -847,12 +848,14 @@ static inline void cifs_server_lock(struct TCP_Server_Info *server)mutex_lock (&server->_srv_mutex); server->nofs_flag = nofs_flag; + server->mutex_owner = current; }static inline void cifs_server_unlock (struct TCP_Server_Info *server) {unsigned int nofs_flag = server->nofs_flag; + server->mutex_owner =NULL ;mutex_unlock (&server->_srv_mutex);memalloc_nofs_restore (nofs_flag); }
fs/smb/client/connect.c +44 -10
85 lines not on this page · raw message
fs/smb/client/transport.c +8 -0
@@ -180,6 +180,10 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg,*/ rc =sock_sendmsg (ssocket, smb_msg);if (rc == -EAGAIN ||unlikely (rc == -EINTR &&task_work_pending (current))) { +/* Don't retry if need to reconnect */ +if (unlikely (server->tcpStatus == CifsNeedReconnect)) +return -ECONNRESET ; + retries++;if (retries >=14 || (!server->noblocksnd && (retries >2 ))) {
@@ -191,6 +195,10 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg,continue ; } +/* Blame the need to reconnect for any non-interrupt error */ +if (unlikely (server->tcpStatus == CifsNeedReconnect && !is_interrupt_error (rc))) + rc = -ECONNRESET ; +if (rc <0 )return rc;
Signature · 1 line
2.55.0
Namjae Jeon
maintainerRe: [PATCH v2 1/2] smb: client: fast fail sends if need to reconnect
fs/smb/client/connect.c cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, · line 220
Quoted 8 lines
fs/smb/client/connect.c +3
-0@@ -184,6 +214,9 @@ cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, } } +if (shutdown) +kill_socket_queues (server); +spin_lock (&cifs_tcp_ses_lock);
Since this loop still holds cifs_tcp_ses_lock, It can sleep while holding a spinlock, causing a scheduling-while-atomic failure. The previous set_need_reco macro did not acquire a mutex.
Please check sashiko's review comments.
https://sashiko.dev/#/patchset/20260928150355.850472-1-ematsumiya%40suse.de
Thanks.
Quoted 13 lines
fs/smb/client/connect.c +3
-2list_for_each_entry_safe (server, nserver, &reco, rlist) {list_del_init (&server->rlist);@@ -365,9 +398,10 @@ static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int numcifs_dbg (FYI ,"Mark tcp session as need reconnect\n" );trace_smb3_reconnect (server->current_mid, server->conn_id, server->hostname); - server->tcpStatus = CifsNeedReconnect; -spin_unlock (&server->srv_lock); + +set_need_reco (server); +return true;
Re: [PATCH v2 1/2] smb: client: fast fail sends if need to reconnect
Quoted 10 lines · Namjae Jeon
fs/smb/client/connect.c cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, · line 220
Quoted 8 lines
fs/smb/client/connect.c +3
-0@@ -184,6 +214,9 @@ cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, } } +if (shutdown) +kill_socket_queues (server); +spin_lock (&cifs_tcp_ses_lock);Since this loop still holds
cifs_tcp_ses_lock, It can sleep while holding a spinlock, causing a scheduling-while-atomic failure.
I totally missed that second loop, will handle that in v3.
AFAICS, the new set_need_reco() can be moved to after unlocking cifs_tcp_ses_lock, as tcpStatus is already protected by srv_lock. Any objections to that?
Quoted 2 lines
The
previousset_need_recomacro did not acquire a mutex.
Yes, the server mutex is needed to access/shutdown server->ssocket, which is part of the core change in this patch.
Quoted 3 lines
Please check sashiko's review comments.
https://sashiko.dev/#/patchset/20260928150355.850472-1-ematsumiya%40suse.de
The other concerns could be ignored, but I'll address them anyway in v3.
Cheers,
Enzo
Quoted 14 lines
Thanks.
Quoted 13 lines
fs/smb/client/connect.c +3
-2list_for_each_entry_safe (server, nserver, &reco, rlist) {list_del_init (&server->rlist);@@ -365,9 +398,10 @@ static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int numcifs_dbg (FYI ,"Mark tcp session as need reconnect\n" );trace_smb3_reconnect (server->current_mid, server->conn_id, server->hostname); - server->tcpStatus = CifsNeedReconnect; -spin_unlock (&server->srv_lock); + +set_need_reco (server); +return true;
PATCH v2 2/2 smb: client: prevent premature discard of requests if reconnecting
In reply to Enzo MatsumiyaAdd TCP_Server_Info::reconnecting to track cifs_reconnect() lifetime. Wait for it to be true in cifs_wait_for_server_reconnect(), and only then wait for tcpStatus change.
Also, return -ECONNRESET (instead of -EHOSTDOWN) if reconnect is still ongoing at the end, so requests are not discarded unnecessarily. -ECONNRESET is not immediately retried by intermediate layers, e.g. VFS, but still serves as an indication to userspace that retrying the operation might be successful.
Changes (refactor cifs_wait_for_server_reconnect()):
- remove unnecessary do/while loop; use wait_event_interruptible() for hard mounts
- increase timeout, and base it on echo_interval to match user preferences
- remove useless debug log for interrupt errors
---
v1 -> v2 (fix issues detected by sashiko):
- handle condition changes post-wait_event timeouts
- return -ECONNRESET instead of -EAGAIN when leaving still reconnecting
(not from sashiko):
- add missing wake_up() after setting server->reconnecting to true in cifs_tcp_ses_needs_reconnect()
- handle tcpStatus == CifsExiting in cifs_wait_for_server_reconnect()
fs/smb/client/cifsglob.h | 1 + fs/smb/client/connect.c | 4 ++ fs/smb/client/misc.c | 91 ++++++++++++++++++++++++++++------------ 3 files changed, 69 insertions(+), 27 deletions(-)
fs/smb/client/cifsglob.h +1 -0
@@ -803,6 +803,7 @@ struct TCP_Server_Info {bool posix_ext_supported;struct delayed_work reconnect;/* reconnect workqueue job */ struct mutex reconnect_mutex;/* prevent simultaneous reconnects */ +bool reconnecting;/* if cifs_reconnect() is indeed running */ unsigned long echo_interval;/*
fs/smb/client/connect.c +4 -0
@@ -398,6 +398,8 @@ static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int numcifs_dbg (FYI ,"Mark tcp session as need reconnect\n" );trace_smb3_reconnect (server->current_mid, server->conn_id, server->hostname); + server->reconnecting = true; +wake_up (&server->response_q);spin_unlock (&server->srv_lock);set_need_reco (server);
@@ -475,6 +477,7 @@ static int __cifs_reconnect(struct TCP_Server_Info *server,spin_lock (&server->srv_lock);if (server->tcpStatus == CifsNeedNegotiate)mod_delayed_work (cifsiod_wq, &server->echo,0 ); + server->reconnecting = false;spin_unlock (&server->srv_lock);wake_up (&server->response_q);
@@ -617,6 +620,7 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server)spin_lock (&server->srv_lock);if (server->tcpStatus == CifsNeedNegotiate)mod_delayed_work (cifsiod_wq, &server->echo,0 ); + server->reconnecting = false;spin_unlock (&server->srv_lock);wake_up (&server->response_q);
fs/smb/client/misc.c +64 -27
108 lines not on this page · raw message
Signature · 1 line
2.55.0
Hi,
Any comments on these 2 patches?
We have at least a couple of customers with huge workloads impacted by this problem.
Thanks,
Enzo
Quoted 25 lines · Enzo Matsumiya
Hi all,
Sending v2 to address the issues found by sashiko
https://sashiko.dev/#/patchset/20260925202003.618856-1-ematsumiya%40suse.dePlease refer to the original cover letter for rationale and reproducer
https://lore.kernel.org/linux-cifs/[email protected]/Cheers,
Enzo Matsumiya (2):
smb: client: fast fail sends if need to reconnect
smb: client: prevent premature discard of requests if reconnectingfs/smb/client/cifsglob.h | 4 ++ fs/smb/client/connect.c | 58 ++++++++++++++++++++----- fs/smb/client/misc.c | 91 +++++++++++++++++++++++++++------------ fs/smb/client/transport.c | 8 ++++ 4 files changed, 124 insertions(+), 37 deletions(-)Signature · 1 line
2.55.0
Paulo Alcantara
maintainerQuoted 3 lines · Enzo Matsumiya
Any comments on these 2 patches?
We have at least a couple of customers with huge workloads impacted by this problem.
Did you send v3 addressing sashiko[1] and Namjae reviews?
[1] https://sashiko.dev/#/patchset/20260928150355.850472-1-ematsumiya%40suse.de
Quoted 9 lines · Paulo Alcantara
Quoted 3 lines · Enzo Matsumiya
Any comments on these 2 patches?
We have at least a couple of customers with huge workloads impacted by this problem.Did you send v3 addressing sashiko[1] and Namjae reviews?
[1] https://sashiko.dev/#/patchset/20260928150355.850472-1-ematsumiya%40suse.de
Yes, I did (I just noticed I replied on the v2 thread).
Patch 1:
https://lore.kernel.org/linux-cifs/[email protected]/
Patch 2:
https://lore.kernel.org/linux-cifs/[email protected]/
Thanks,
Enzo