cifs: avoid deadlocks while updating iface
authorShyam Prasad N <sprasad@microsoft.com>
Fri, 24 Jun 2022 09:43:59 +0000 (09:43 +0000)
committerSteve French <stfrench@microsoft.com>
Fri, 24 Jun 2022 14:17:56 +0000 (09:17 -0500)
commit8da33fd11c05b7c64ef6456970f2fce61851806e
treecad8d3ff15fffbbe8c7255f0fd87ac18634d8bf2
parent6e1c1c08cdf3d7d7b8c571c0f032a283af6ca024
cifs: avoid deadlocks while updating iface

We use cifs_tcp_ses_lock to protect a lot of things.
Not only does it protect the lists of connections, sessions,
tree connects, open file lists, etc., we also use it to
protect some fields in each of it's entries.

In this case, cifs_mark_ses_for_reconnect takes the
cifs_tcp_ses_lock to traverse the lists, and then calls
cifs_update_iface. However, that can end up calling
cifs_put_tcp_session, which picks up the same lock again.

Avoid this by taking a ref for the session, drop the lock,
and then call update iface.

Also, in cifs_update_iface, avoid nested locking of iface_lock
and chan_lock, as much as possible. When unavoidable, we need
to pick iface_lock first.

Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/connect.c
fs/cifs/sess.c