Skip to content
/ linux Public

Commit 601dd3b

Browse files
sprasad-microsoftSasha Levin
authored andcommitted
cifs: Fix locking usage for tcon fields
[ Upstream commit 96c4af4 ] We used to use the cifs_tcp_ses_lock to protect a lot of objects that are not just the server, ses or tcon lists. We later introduced srv_lock, ses_lock and tc_lock to protect fields within the corresponding structs. This was done to provide a more granular protection and avoid unnecessary serialization. There were still a couple of uses of cifs_tcp_ses_lock to provide tcon fields. In this patch, I've replaced them with tc_lock. Cc: stable@vger.kernel.org Signed-off-by: Shyam Prasad N <sprasad@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7d9e0df commit 601dd3b

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

fs/smb/client/cached_dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,11 @@ static void cfids_laundromat_worker(struct work_struct *work)
769769

770770
dput(dentry);
771771
if (cfid->is_open) {
772-
spin_lock(&cifs_tcp_ses_lock);
772+
spin_lock(&cfid->tcon->tc_lock);
773773
++cfid->tcon->tc_count;
774774
trace_smb3_tcon_ref(cfid->tcon->debug_id, cfid->tcon->tc_count,
775775
netfs_trace_tcon_ref_get_cached_laundromat);
776-
spin_unlock(&cifs_tcp_ses_lock);
776+
spin_unlock(&cfid->tcon->tc_lock);
777777
queue_work(serverclose_wq, &cfid->close_work);
778778
} else
779779
/*

fs/smb/client/smb2misc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,14 +807,14 @@ smb2_handle_cancelled_close(struct cifs_tcon *tcon, __u64 persistent_fid,
807807
int rc;
808808

809809
cifs_dbg(FYI, "%s: tc_count=%d\n", __func__, tcon->tc_count);
810-
spin_lock(&cifs_tcp_ses_lock);
810+
spin_lock(&tcon->tc_lock);
811811
if (tcon->tc_count <= 0) {
812812
struct TCP_Server_Info *server = NULL;
813813

814814
trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
815815
netfs_trace_tcon_ref_see_cancelled_close);
816816
WARN_ONCE(tcon->tc_count < 0, "tcon refcount is negative");
817-
spin_unlock(&cifs_tcp_ses_lock);
817+
spin_unlock(&tcon->tc_lock);
818818

819819
if (tcon->ses) {
820820
server = tcon->ses->server;
@@ -828,7 +828,7 @@ smb2_handle_cancelled_close(struct cifs_tcon *tcon, __u64 persistent_fid,
828828
tcon->tc_count++;
829829
trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
830830
netfs_trace_tcon_ref_get_cancelled_close);
831-
spin_unlock(&cifs_tcp_ses_lock);
831+
spin_unlock(&tcon->tc_lock);
832832

833833
rc = __smb2_handle_cancelled_cmd(tcon, SMB2_CLOSE_HE, 0,
834834
persistent_fid, volatile_fid);

fs/smb/client/smb2ops.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,7 +3000,9 @@ smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
30003000
struct cifs_tcon,
30013001
tcon_list);
30023002
if (tcon) {
3003+
spin_lock(&tcon->tc_lock);
30033004
tcon->tc_count++;
3005+
spin_unlock(&tcon->tc_lock);
30043006
trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
30053007
netfs_trace_tcon_ref_get_dfs_refer);
30063008
}
@@ -3065,13 +3067,9 @@ smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
30653067
out:
30663068
if (tcon && !tcon->ipc) {
30673069
/* ipc tcons are not refcounted */
3068-
spin_lock(&cifs_tcp_ses_lock);
3069-
tcon->tc_count--;
3070+
cifs_put_tcon(tcon, netfs_trace_tcon_ref_put_dfs_refer);
30703071
trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
30713072
netfs_trace_tcon_ref_dec_dfs_refer);
3072-
/* tc_count can never go negative */
3073-
WARN_ON(tcon->tc_count < 0);
3074-
spin_unlock(&cifs_tcp_ses_lock);
30753073
}
30763074
kfree(utf16_path);
30773075
kfree(dfs_req);

fs/smb/client/smb2pdu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4180,7 +4180,9 @@ void smb2_reconnect_server(struct work_struct *work)
41804180

41814181
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
41824182
if (tcon->need_reconnect || tcon->need_reopen_files) {
4183+
spin_lock(&tcon->tc_lock);
41834184
tcon->tc_count++;
4185+
spin_unlock(&tcon->tc_lock);
41844186
trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
41854187
netfs_trace_tcon_ref_get_reconnect_server);
41864188
list_add_tail(&tcon->rlist, &tmp_list);

fs/smb/client/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
EM(netfs_trace_tcon_ref_put_cancelled_close_fid, "PUT Cn-Fid") \
6060
EM(netfs_trace_tcon_ref_put_cancelled_mid, "PUT Cn-Mid") \
6161
EM(netfs_trace_tcon_ref_put_mnt_ctx, "PUT MntCtx") \
62+
EM(netfs_trace_tcon_ref_put_dfs_refer, "PUT DfsRfr") \
6263
EM(netfs_trace_tcon_ref_put_reconnect_server, "PUT Reconn") \
6364
EM(netfs_trace_tcon_ref_put_tlink, "PUT Tlink ") \
6465
EM(netfs_trace_tcon_ref_see_cancelled_close, "SEE Cn-Cls") \

0 commit comments

Comments
 (0)