History

Merge tag '5.20-rc-smb3-client-fixes-part1' of git://git.samba.org/sfrench/cifs-2.6

Pull cifs updates from Steve French: "Mostly cleanup, including smb1 refactoring: - multichannel perf improvement - move additional SMB1 code to not be compiled in when legacy support is disabled. - bug fixes, including one important one for memory leak - various cleanup patches We are still working on and testing some deferred close improvements including an important lease break fix for case when multiple deferred closes are still open, and also some additional perf improvements - those are not included here" * tag '5.20-rc-smb3-client-fixes-part1' of git://git.samba.org/sfrench/cifs-2.6: cifs: update internal module number cifs: alloc_mid function should be marked as static cifs: remove "cifs_" prefix from init/destroy mids functions cifs: remove useless DeleteMidQEntry() cifs: when insecure legacy is disabled shrink amount of SMB1 code cifs: trivial style fixup cifs: fix wrong unlock before return from cifs_tree_connect() cifs: avoid use of global locks for high contention data cifs: remove remaining build warnings cifs: list_for_each() -> list_for_each_entry() cifs: update MAINTAINERS file with reviewers smb2: small refactor in smb2_check_message() cifs: Fix memory leak when using fscache cifs: remove minor build warning cifs: remove some camelCase and also some static build warnings cifs: remove unnecessary (void*) conversions. cifs: remove unnecessary type castings cifs: remove redundant initialization to variable mnt_sign_enabled smb3: check xattr value length earlier

Linus Torvalds committed 4 years ago

Commit 3bc1bc02 parents eb5699b 0d168a527 files · +1104 −907Browse files

Unified · Split

27 files
  1. MAINTAINERS +5 −2
  2. fs/cifs/Makefile +2 −2
  3. fs/cifs/cifs_debug.c +23 −49
  4. fs/cifs/cifsacl.c +2 −0
  5. fs/cifs/cifsencrypt.c +3 −3
  6. fs/cifs/cifsfs.c +41 −12
  7. fs/cifs/cifsfs.h +2 −2
  8. fs/cifs/cifsglob.h +91 −44
  9. fs/cifs/cifsproto.h +4 −6
  10. fs/cifs/cifssmb.c +14 −463
  11. fs/cifs/connect.c +187 −112
  12. fs/cifs/dfs_cache.c +7 −1
  13. fs/cifs/dir.c +8 −0
  14. fs/cifs/file.c +269 −14
  15. fs/cifs/inode.c +57 −7
  16. fs/cifs/ioctl.c +2 −0
  17. fs/cifs/link.c +8 −0
  18. fs/cifs/misc.c +13 −20
  19. fs/cifs/netmisc.c +1 −1
  20. fs/cifs/sess.c +4 −1
  21. fs/cifs/smb1ops.c +5 −5
  22. fs/cifs/smb2misc.c +29 −20
  23. fs/cifs/smb2ops.c +32 −29
  24. fs/cifs/smb2pdu.c +16 −16
  25. fs/cifs/smb2transport.c +20 −18
  26. fs/cifs/transport.c +255 −79
  27. fs/cifs/xattr.c +4 −1
MAINTAINERS+5−2
@@ -5123,12 +5123,15 @@ F: include/linux/clk/ · 5122 unmodified lines
51235123 F: include/linux/of_clk.h
51245124 X: drivers/clk/clkdev.c
51255125
5126−COMMON INTERNET FILE SYSTEM CLIENT (CIFS)
5126+COMMON INTERNET FILE SYSTEM CLIENT (CIFS and SMB3)
51275127 M: Steve French <sfrench@samba.org>
5128+R: Paulo Alcantara <pc@cjr.nz> (DFS, global name space)
5129+R: Ronnie Sahlberg <lsahlber@redhat.com> (directory leases, sparse files)
5130+R: Shyam Prasad N <sprasad@microsoft.com> (multichannel)
51285131 L: linux-cifs@vger.kernel.org
51295132 L: samba-technical@lists.samba.org (moderated for non-subscribers)
51305133 S: Supported
5131−W: http://linux-cifs.samba.org/
5134+W: https://wiki.samba.org/index.php/LinuxCIFS
51325135 T: git git://git.samba.org/sfrench/cifs-2.6.git
51335136 F: Documentation/admin-guide/cifs/
51345137 F: fs/cifs/
fs/cifs/Makefile+2−2
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 ccflags-y += -I$(src) # needed for trace events
66 obj-$(CONFIG_CIFS) += cifs.o
77
8−cifs-y := trace.o cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o \
8+cifs-y := trace.o cifsfs.o cifs_debug.o connect.o dir.o file.o \
99 inode.o link.o misc.o netmisc.o smbencrypt.o transport.o \
1010 cifs_unicode.o nterr.o cifsencrypt.o \
1111 readdir.o ioctl.o sess.o export.o unc.o winucase.o \
@@ -31,4 +31,4 @@ cifs-$(CONFIG_CIFS_SMB_DIRECT) += smbdirect.o · 19 unmodified lines
3131
3232 cifs-$(CONFIG_CIFS_ROOT) += cifsroot.o
3333
34−cifs-$(CONFIG_CIFS_ALLOW_INSECURE_LEGACY) += smb1ops.o
34+cifs-$(CONFIG_CIFS_ALLOW_INSECURE_LEGACY) += smb1ops.o cifssmb.o
fs/cifs/cifs_debug.c+23−49
@@ -36,7 +36,7 @@ cifs_dump_mem(char *label, void *data, int length) · 35 unmodified lines
3636 void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
3737 {
3838 #ifdef CONFIG_CIFS_DEBUG2
39− struct smb_hdr *smb = (struct smb_hdr *)buf;
39+ struct smb_hdr *smb = buf;
4040
4141 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
4242 smb->Command, smb->Status.CifsError,
@@ -55,7 +55,7 @@ void cifs_dump_mids(struct TCP_Server_Info *server) · 12 unmodified lines
5555 return;
5656
5757 cifs_dbg(VFS, "Dump pending requests:\n");
58− spin_lock(&GlobalMid_Lock);
58+ spin_lock(&server->mid_lock);
5959 list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
6060 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
6161 mid_entry->mid_state,
@@ -78,7 +78,7 @@ void cifs_dump_mids(struct TCP_Server_Info *server) · 16 unmodified lines
7878 mid_entry->resp_buf, 62);
7979 }
8080 }
81− spin_unlock(&GlobalMid_Lock);
81+ spin_unlock(&server->mid_lock);
8282 #endif /* CONFIG_CIFS_DEBUG2 */
8383 }
8484
@@ -168,7 +168,6 @@ cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface) · 83 unmodified lines
168168
169169 static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
170170 {
171− struct list_head *tmp, *tmp1, *tmp2;
172171 struct TCP_Server_Info *server;
173172 struct cifs_ses *ses;
174173 struct cifs_tcon *tcon;
@@ -184,14 +183,10 @@ static int cifs_debug_files_proc_show(struct seq_file *m, void *v) · 9 unmodified lines
184183 #endif /* CIFS_DEBUG2 */
185184 spin_lock(&cifs_tcp_ses_lock);
186185 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
187− list_for_each(tmp, &server->smb_ses_list) {
188− ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
189− list_for_each(tmp1, &ses->tcon_list) {
190− tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
186+ list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
187+ list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
191188 spin_lock(&tcon->open_file_lock);
192− list_for_each(tmp2, &tcon->openFileList) {
193− cfile = list_entry(tmp2, struct cifsFileInfo,
194− tlist);
189+ list_for_each_entry(cfile, &tcon->openFileList, tlist) {
195190 seq_printf(m,
196191 "0x%x 0x%llx 0x%x %d %d %d %pd",
197192 tcon->tid,
@@ -218,7 +213,6 @@ static int cifs_debug_files_proc_show(struct seq_file *m, void *v) · 20 unmodified lines
218213
219214 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
220215 {
221− struct list_head *tmp2, *tmp3;
222216 struct mid_q_entry *mid_entry;
223217 struct TCP_Server_Info *server;
224218 struct cifs_ses *ses;
@@ -381,9 +375,7 @@ skip_rdma: · 156 unmodified lines
381375
382376 seq_printf(m, "\n\n\tSessions: ");
383377 i = 0;
384− list_for_each(tmp2, &server->smb_ses_list) {
385− ses = list_entry(tmp2, struct cifs_ses,
386− smb_ses_list);
378+ list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
387379 i++;
388380 if ((ses->serverDomain == NULL) ||
389381 (ses->serverOS == NULL) ||
@@ -447,9 +439,7 @@ skip_rdma: · 57 unmodified lines
447439 else
448440 seq_puts(m, "none\n");
449441
450− list_for_each(tmp3, &ses->tcon_list) {
451− tcon = list_entry(tmp3, struct cifs_tcon,
452− tcon_list);
442+ list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
453443 ++j;
454444 seq_printf(m, "\n\t%d) ", j);
455445 cifs_debug_tcon(m, tcon);
@@ -473,10 +463,8 @@ skip_rdma: · 17 unmodified lines
473463 seq_printf(m, "\n\t\t[NONE]");
474464
475465 seq_puts(m, "\n\n\tMIDs: ");
476− spin_lock(&GlobalMid_Lock);
477− list_for_each(tmp3, &server->pending_mid_q) {
478− mid_entry = list_entry(tmp3, struct mid_q_entry,
479− qhead);
466+ spin_lock(&server->mid_lock);
467+ list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
480468 seq_printf(m, "\n\tState: %d com: %d pid:"
481469 " %d cbdata: %p mid %llu\n",
482470 mid_entry->mid_state,
@@ -485,7 +473,7 @@ skip_rdma: · 2 unmodified lines
485473 mid_entry->callback_data,
486474 mid_entry->mid);
487475 }
488− spin_unlock(&GlobalMid_Lock);
476+ spin_unlock(&server->mid_lock);
489477 seq_printf(m, "\n--\n");
490478 }
491479 if (c == 0)
@@ -504,7 +492,6 @@ static ssize_t cifs_stats_proc_write(struct file *file, · 12 unmodified lines
504492 {
505493 bool bv;
506494 int rc;
507− struct list_head *tmp1, *tmp2, *tmp3;
508495 struct TCP_Server_Info *server;
509496 struct cifs_ses *ses;
510497 struct cifs_tcon *tcon;
@@ -514,8 +501,8 @@ static ssize_t cifs_stats_proc_write(struct file *file, · 3 unmodified lines
514501 #ifdef CONFIG_CIFS_STATS2
515502 int i;
516503
517− atomic_set(&totBufAllocCount, 0);
518− atomic_set(&totSmBufAllocCount, 0);
504+ atomic_set(&total_buf_alloc_count, 0);
505+ atomic_set(&total_small_buf_alloc_count, 0);
519506 #endif /* CONFIG_CIFS_STATS2 */
520507 atomic_set(&tcpSesReconnectCount, 0);
521508 atomic_set(&tconInfoReconnectCount, 0);
@@ -525,9 +512,7 @@ static ssize_t cifs_stats_proc_write(struct file *file, · 3 unmodified lines
525512 GlobalCurrentXid = 0;
526513 spin_unlock(&GlobalMid_Lock);
527514 spin_lock(&cifs_tcp_ses_lock);
528− list_for_each(tmp1, &cifs_tcp_ses_list) {
529− server = list_entry(tmp1, struct TCP_Server_Info,
530− tcp_ses_list);
515+ list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
531516 server->max_in_flight = 0;
532517 #ifdef CONFIG_CIFS_STATS2
533518 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
@@ -538,13 +523,8 @@ static ssize_t cifs_stats_proc_write(struct file *file, · 4 unmodified lines
538523 server->fastest_cmd[0] = 0;
539524 }
540525 #endif /* CONFIG_CIFS_STATS2 */
541− list_for_each(tmp2, &server->smb_ses_list) {
542− ses = list_entry(tmp2, struct cifs_ses,
543− smb_ses_list);
544− list_for_each(tmp3, &ses->tcon_list) {
545− tcon = list_entry(tmp3,
546− struct cifs_tcon,
547− tcon_list);
526+ list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
527+ list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
548528 atomic_set(&tcon->num_smbs_sent, 0);
549529 spin_lock(&tcon->stat_lock);
550530 tcon->bytes_read = 0;
@@ -569,7 +549,6 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v) · 18 unmodified lines
569549 #ifdef CONFIG_CIFS_STATS2
570550 int j;
571551 #endif /* STATS2 */
572− struct list_head *tmp2, *tmp3;
573552 struct TCP_Server_Info *server;
574553 struct cifs_ses *ses;
575554 struct cifs_tcon *tcon;
@@ -579,17 +558,17 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v) · 3 unmodified lines
579558 seq_printf(m, "Share (unique mount targets): %d\n",
580559 tconInfoAllocCount.counter);
581560 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
582− bufAllocCount.counter,
561+ buf_alloc_count.counter,
583562 cifs_min_rcv + tcpSesAllocCount.counter);
584563 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
585− smBufAllocCount.counter, cifs_min_small);
564+ small_buf_alloc_count.counter, cifs_min_small);
586565 #ifdef CONFIG_CIFS_STATS2
587566 seq_printf(m, "Total Large %d Small %d Allocations\n",
588− atomic_read(&totBufAllocCount),
589− atomic_read(&totSmBufAllocCount));
567+ atomic_read(&total_buf_alloc_count),
568+ atomic_read(&total_small_buf_alloc_count));
590569 #endif /* CONFIG_CIFS_STATS2 */
591570
592− seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
571+ seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&mid_count));
593572 seq_printf(m,
594573 "\n%d session %d share reconnects\n",
595574 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
@@ -619,13 +598,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v) · 23 unmodified lines
619598 atomic_read(&server->smb2slowcmd[j]),
620599 server->hostname, j);
621600 #endif /* STATS2 */
622− list_for_each(tmp2, &server->smb_ses_list) {
623− ses = list_entry(tmp2, struct cifs_ses,
624− smb_ses_list);
625− list_for_each(tmp3, &ses->tcon_list) {
626− tcon = list_entry(tmp3,
627− struct cifs_tcon,
628− tcon_list);
601+ list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
602+ list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
629603 i++;
630604 seq_printf(m, "\n%d) %s", i, tcon->treeName);
631605 if (tcon->need_reconnect)
fs/cifs/cifsacl.c+2−0
@@ -1379,6 +1379,7 @@ chown_chgrp_exit: · 1378 unmodified lines
13791379 return rc;
13801380 }
13811381
1382+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
13821383 struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
13831384 const struct cifs_fid *cifsfid, u32 *pacllen,
13841385 u32 __maybe_unused unused)
@@ -1512,6 +1513,7 @@ out: · 127 unmodified lines
15121513 cifs_put_tlink(tlink);
15131514 return rc;
15141515 }
1516+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
15151517
15161518 /* Translate the CIFS ACL (similar to NTFS ACL) for a file into mode bits */
15171519 int
fs/cifs/cifsencrypt.c+3−3
@@ -141,13 +141,13 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, · 140 unmodified lines
141141 if ((cifs_pdu == NULL) || (server == NULL))
142142 return -EINVAL;
143143
144− spin_lock(&cifs_tcp_ses_lock);
144+ spin_lock(&server->srv_lock);
145145 if (!(cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) ||
146146 server->tcpStatus == CifsNeedNegotiate) {
147− spin_unlock(&cifs_tcp_ses_lock);
147+ spin_unlock(&server->srv_lock);
148148 return rc;
149149 }
150− spin_unlock(&cifs_tcp_ses_lock);
150+ spin_unlock(&server->srv_lock);
151151
152152 if (!server->session_estab) {
153153 memcpy(cifs_pdu->Signature.SecuritySignature, "BSRSPYL", 8);
fs/cifs/cifsfs.c+41−12
@@ -68,6 +68,34 @@ bool enable_negotiate_signing; /* false by default */ · 67 unmodified lines
6868 unsigned int global_secflags = CIFSSEC_DEF;
6969 /* unsigned int ntlmv2_support = 0; */
7070 unsigned int sign_CIFS_PDUs = 1;
71+
72+/*
73+ * Global transaction id (XID) information
74+ */
75+unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
76+unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
77+unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
78+spinlock_t GlobalMid_Lock; /* protects above & list operations on midQ entries */
79+
80+/*
81+ * Global counters, updated atomically
82+ */
83+atomic_t sesInfoAllocCount;
84+atomic_t tconInfoAllocCount;
85+atomic_t tcpSesNextId;
86+atomic_t tcpSesAllocCount;
87+atomic_t tcpSesReconnectCount;
88+atomic_t tconInfoReconnectCount;
89+
90+atomic_t mid_count;
91+atomic_t buf_alloc_count;
92+atomic_t small_buf_alloc_count;
93+#ifdef CONFIG_CIFS_STATS2
94+atomic_t total_buf_alloc_count;
95+atomic_t total_small_buf_alloc_count;
96+#endif/* STATS2 */
97+struct list_head cifs_tcp_ses_list;
98+spinlock_t cifs_tcp_ses_lock;
7199 static const struct super_operations cifs_super_ops;
72100 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
73101 module_param(CIFSMaxBufSize, uint, 0444);
@@ -703,14 +731,17 @@ static void cifs_umount_begin(struct super_block *sb) · 629 unmodified lines
703731 tcon = cifs_sb_master_tcon(cifs_sb);
704732
705733 spin_lock(&cifs_tcp_ses_lock);
734+ spin_lock(&tcon->tc_lock);
706735 if ((tcon->tc_count > 1) || (tcon->status == TID_EXITING)) {
707736 /* we have other mounts to same share or we have
708737 already tried to force umount this and woken up
709738 all waiting network requests, nothing to do */
739+ spin_unlock(&tcon->tc_lock);
710740 spin_unlock(&cifs_tcp_ses_lock);
711741 return;
712742 } else if (tcon->tc_count == 1)
713743 tcon->status = TID_EXITING;
744+ spin_unlock(&tcon->tc_lock);
714745 spin_unlock(&cifs_tcp_ses_lock);
715746
716747 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
@@ -1537,8 +1568,7 @@ cifs_destroy_request_bufs(void) · 820 unmodified lines
15371568 kmem_cache_destroy(cifs_sm_req_cachep);
15381569 }
15391570
1540−static int
1541−cifs_init_mids(void)
1571+static int init_mids(void)
15421572 {
15431573 cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
15441574 sizeof(struct mid_q_entry), 0,
@@ -1556,8 +1586,7 @@ cifs_init_mids(void) · 11 unmodified lines
15561586 return 0;
15571587 }
15581588
1559−static void
1560−cifs_destroy_mids(void)
1589+static void destroy_mids(void)
15611590 {
15621591 mempool_destroy(cifs_mid_poolp);
15631592 kmem_cache_destroy(cifs_mid_cachep);
@@ -1579,11 +1608,11 @@ init_cifs(void) · 15 unmodified lines
15791608 atomic_set(&tcpSesReconnectCount, 0);
15801609 atomic_set(&tconInfoReconnectCount, 0);
15811610
1582− atomic_set(&bufAllocCount, 0);
1583− atomic_set(&smBufAllocCount, 0);
1611+ atomic_set(&buf_alloc_count, 0);
1612+ atomic_set(&small_buf_alloc_count, 0);
15841613 #ifdef CONFIG_CIFS_STATS2
1585− atomic_set(&totBufAllocCount, 0);
1586− atomic_set(&totSmBufAllocCount, 0);
1614+ atomic_set(&total_buf_alloc_count, 0);
1615+ atomic_set(&total_small_buf_alloc_count, 0);
15871616 if (slow_rsp_threshold < 1)
15881617 cifs_dbg(FYI, "slow_response_threshold msgs disabled\n");
15891618 else if (slow_rsp_threshold > 32767)
@@ -1591,7 +1620,7 @@ init_cifs(void) · 1 unmodified line
15911620 "slow response threshold set higher than recommended (0 to 32767)\n");
15921621 #endif /* CONFIG_CIFS_STATS2 */
15931622
1594− atomic_set(&midCount, 0);
1623+ atomic_set(&mid_count, 0);
15951624 GlobalCurrentXid = 0;
15961625 GlobalTotalActiveXid = 0;
15971626 GlobalMaxActiveXid = 0;
@@ -1654,7 +1683,7 @@ init_cifs(void) · 56 unmodified lines
16541683 if (rc)
16551684 goto out_destroy_deferredclose_wq;
16561685
1657− rc = cifs_init_mids();
1686+ rc = init_mids();
16581687 if (rc)
16591688 goto out_destroy_inodecache;
16601689
@@ -1711,7 +1740,7 @@ out_destroy_request_bufs: · 50 unmodified lines
17111740 #endif
17121741 cifs_destroy_request_bufs();
17131742 out_destroy_mids:
1714− cifs_destroy_mids();
1743+ destroy_mids();
17151744 out_destroy_inodecache:
17161745 cifs_destroy_inodecache();
17171746 out_destroy_deferredclose_wq:
@@ -1747,7 +1776,7 @@ exit_cifs(void) · 29 unmodified lines
17471776 dfs_cache_destroy();
17481777 #endif
17491778 cifs_destroy_request_bufs();
1750− cifs_destroy_mids();
1779+ destroy_mids();
17511780 cifs_destroy_inodecache();
17521781 destroy_workqueue(deferredclose_wq);
17531782 destroy_workqueue(cifsoplockd_wq);
fs/cifs/cifsfs.h+2−2
@@ -153,6 +153,6 @@ extern const struct export_operations cifs_export_ops; · 152 unmodified lines
153153 #endif /* CONFIG_CIFS_NFSD_EXPORT */
154154
155155 /* when changing internal version - update following two lines at same time */
156−#define SMB3_PRODUCT_BUILD 37
157−#define CIFS_VERSION "2.37"
156+#define SMB3_PRODUCT_BUILD 38
157+#define CIFS_VERSION "2.38"
158158 #endif /* _CIFSFS_H */
fs/cifs/cifsglob.h+91−44
@@ -605,6 +605,7 @@ inc_rfc1001_len(void *buf, int count) · 604 unmodified lines
605605 struct TCP_Server_Info {
606606 struct list_head tcp_ses_list;
607607 struct list_head smb_ses_list;
608+ spinlock_t srv_lock; /* protect anything here that is not protected */
608609 __u64 conn_id; /* connection identifier (useful for debugging) */
609610 int srv_count; /* reference counter */
610611 /* 15 character server name + 0x20 16th byte indicating type = srv */
@@ -622,6 +623,7 @@ struct TCP_Server_Info { · 11 unmodified lines
622623 #endif
623624 wait_queue_head_t response_q;
624625 wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
626+ spinlock_t mid_lock; /* protect mid queue and it's entries */
625627 struct list_head pending_mid_q;
626628 bool noblocksnd; /* use blocking sendmsg */
627629 bool noautotune; /* do not autotune send buf sizes */
@@ -1008,6 +1010,7 @@ struct cifs_ses { · 380 unmodified lines
10081010 struct list_head rlist; /* reconnect list */
10091011 struct list_head tcon_list;
10101012 struct cifs_tcon *tcon_ipc;
1013+ spinlock_t ses_lock; /* protect anything here that is not protected */
10111014 struct mutex session_mutex;
10121015 struct TCP_Server_Info *server; /* pointer to server info */
10131016 int ses_count; /* reference counter */
@@ -1169,6 +1172,7 @@ struct cifs_tcon { · 155 unmodified lines
11691172 struct list_head tcon_list;
11701173 int tc_count;
11711174 struct list_head rlist; /* reconnect list */
1175+ spinlock_t tc_lock; /* protect anything here that is not protected */
11721176 atomic_t num_local_opens; /* num of all opens including disconnected */
11731177 atomic_t num_remote_opens; /* num of all network opens on server */
11741178 struct list_head openFileList;
@@ -1899,33 +1903,78 @@ require use of the stronger protocol */ · 724 unmodified lines
18991903 */
19001904
19011905 /****************************************************************************
1902− * Locking notes. All updates to global variables and lists should be
1903− * protected by spinlocks or semaphores.
1906+ * Here are all the locks (spinlock, mutex, semaphore) in cifs.ko, arranged according
1907+ * to the locking order. i.e. if two locks are to be held together, the lock that
1908+ * appears higher in this list needs to be taken before the other.
19041909 *
1905− * Spinlocks
1906− * ---------
1907− * GlobalMid_Lock protects:
1908− * list operations on pending_mid_q and oplockQ
1909− * updates to XID counters, multiplex id and SMB sequence numbers
1910− * list operations on global DnotifyReqList
1911− * updates to ses->status and TCP_Server_Info->tcpStatus
1912− * updates to server->CurrentMid
1913− * tcp_ses_lock protects:
1914− * list operations on tcp and SMB session lists
1915− * tcon->open_file_lock protects the list of open files hanging off the tcon
1916− * inode->open_file_lock protects the openFileList hanging off the inode
1917− * cfile->file_info_lock protects counters and fields in cifs file struct
1918− * f_owner.lock protects certain per file struct operations
1919− * mapping->page_lock protects certain per page operations
1910+ * If you hold a lock that is lower in this list, and you need to take a higher lock
1911+ * (or if you think that one of the functions that you're calling may need to), first
1912+ * drop the lock you hold, pick up the higher lock, then the lower one. This will
1913+ * ensure that locks are picked up only in one direction in the below table
1914+ * (top to bottom).
19201915 *
1921− * Note that the cifs_tcon.open_file_lock should be taken before
1922− * not after the cifsInodeInfo.open_file_lock
1916+ * Also, if you expect a function to be called with a lock held, explicitly document
1917+ * this in the comments on top of your function definition.
19231918 *
1924− * Semaphores
1925− * ----------
1926− * cifsInodeInfo->lock_sem protects:
1927− * the list of locks held by the inode
1919+ * And also, try to keep the critical sections (lock hold time) to be as minimal as
1920+ * possible. Blocking / calling other functions with a lock held always increase
1921+ * the risk of a possible deadlock.
19281922 *
1923+ * Following this rule will avoid unnecessary deadlocks, which can get really hard to
1924+ * debug. Also, any new lock that you introduce, please add to this list in the correct
1925+ * order.
1926+ *
1927+ * Please populate this list whenever you introduce new locks in your changes. Or in
1928+ * case I've missed some existing locks. Please ensure that it's added in the list
1929+ * based on the locking order expected.
1930+ *
1931+ * =====================================================================================
1932+ * Lock Protects Initialization fn
1933+ * =====================================================================================
1934+ * vol_list_lock
1935+ * vol_info->ctx_lock vol_info->ctx
1936+ * cifs_sb_info->tlink_tree_lock cifs_sb_info->tlink_tree cifs_setup_cifs_sb
1937+ * TCP_Server_Info-> TCP_Server_Info cifs_get_tcp_session
1938+ * reconnect_mutex
1939+ * TCP_Server_Info->srv_mutex TCP_Server_Info cifs_get_tcp_session
1940+ * cifs_ses->session_mutex cifs_ses sesInfoAlloc
1941+ * cifs_tcon
1942+ * cifs_tcon->open_file_lock cifs_tcon->openFileList tconInfoAlloc
1943+ * cifs_tcon->pending_opens
1944+ * cifs_tcon->stat_lock cifs_tcon->bytes_read tconInfoAlloc
1945+ * cifs_tcon->bytes_written
1946+ * cifs_tcp_ses_lock cifs_tcp_ses_list sesInfoAlloc
1947+ * GlobalMid_Lock GlobalMaxActiveXid init_cifs
1948+ * GlobalCurrentXid
1949+ * GlobalTotalActiveXid
1950+ * TCP_Server_Info->srv_lock (anything in struct not protected by another lock and can change)
1951+ * TCP_Server_Info->mid_lock TCP_Server_Info->pending_mid_q cifs_get_tcp_session
1952+ * ->CurrentMid
1953+ * (any changes in mid_q_entry fields)
1954+ * TCP_Server_Info->req_lock TCP_Server_Info->in_flight cifs_get_tcp_session
1955+ * ->credits
1956+ * ->echo_credits
1957+ * ->oplock_credits
1958+ * ->reconnect_instance
1959+ * cifs_ses->ses_lock (anything that is not protected by another lock and can change)
1960+ * cifs_ses->iface_lock cifs_ses->iface_list sesInfoAlloc
1961+ * ->iface_count
1962+ * ->iface_last_update
1963+ * cifs_ses->chan_lock cifs_ses->chans
1964+ * ->chans_need_reconnect
1965+ * ->chans_in_reconnect
1966+ * cifs_tcon->tc_lock (anything that is not protected by another lock and can change)
1967+ * cifsInodeInfo->open_file_lock cifsInodeInfo->openFileList cifs_alloc_inode
1968+ * cifsInodeInfo->writers_lock cifsInodeInfo->writers cifsInodeInfo_alloc
1969+ * cifsInodeInfo->lock_sem cifsInodeInfo->llist cifs_init_once
1970+ * ->can_cache_brlcks
1971+ * cifsInodeInfo->deferred_lock cifsInodeInfo->deferred_closes cifsInodeInfo_alloc
1972+ * cached_fid->fid_mutex cifs_tcon->crfid tconInfoAlloc
1973+ * cifsFileInfo->fh_mutex cifsFileInfo cifs_new_fileinfo
1974+ * cifsFileInfo->file_info_lock cifsFileInfo->count cifs_new_fileinfo
1975+ * ->invalidHandle initiate_cifs_search
1976+ * ->oplock_break_cancelled
1977+ * cifs_aio_ctx->aio_mutex cifs_aio_ctx cifs_aio_ctx_alloc
19291978 ****************************************************************************/
19301979
19311980 #ifdef DECLARE_GLOBALS_HERE
@@ -1941,47 +1990,44 @@ require use of the stronger protocol */ · 9 unmodified lines
19411990 * sessions (and from that the tree connections) can be found
19421991 * by iterating over cifs_tcp_ses_list
19431992 */
1944−GLOBAL_EXTERN struct list_head cifs_tcp_ses_list;
1993+extern struct list_head cifs_tcp_ses_list;
19451994
19461995 /*
19471996 * This lock protects the cifs_tcp_ses_list, the list of smb sessions per
19481997 * tcp session, and the list of tcon's per smb session. It also protects
1949− * the reference counters for the server, smb session, and tcon. It also
1950− * protects some fields in the TCP_Server_Info struct such as dstaddr. Finally,
1951− * changes to the tcon->tidStatus should be done while holding this lock.
1998+ * the reference counters for the server, smb session, and tcon.
19521999 * generally the locks should be taken in order tcp_ses_lock before
19532000 * tcon->open_file_lock and that before file->file_info_lock since the
19542001 * structure order is cifs_socket-->cifs_ses-->cifs_tcon-->cifs_file
19552002 */
1956−GLOBAL_EXTERN spinlock_t cifs_tcp_ses_lock;
2003+extern spinlock_t cifs_tcp_ses_lock;
19572004
19582005 /*
19592006 * Global transaction id (XID) information
19602007 */
1961−GLOBAL_EXTERN unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
1962−GLOBAL_EXTERN unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
1963−GLOBAL_EXTERN unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
1964−GLOBAL_EXTERN spinlock_t GlobalMid_Lock; /* protects above & list operations */
1965− /* on midQ entries */
2008+extern unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
2009+extern unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
2010+extern unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
2011+extern spinlock_t GlobalMid_Lock; /* protects above & list operations on midQ entries */
2012+
19662013 /*
19672014 * Global counters, updated atomically
19682015 */
1969−GLOBAL_EXTERN atomic_t sesInfoAllocCount;
1970−GLOBAL_EXTERN atomic_t tconInfoAllocCount;
1971−GLOBAL_EXTERN atomic_t tcpSesNextId;
1972−GLOBAL_EXTERN atomic_t tcpSesAllocCount;
1973−GLOBAL_EXTERN atomic_t tcpSesReconnectCount;
1974−GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
2016+extern atomic_t sesInfoAllocCount;
2017+extern atomic_t tconInfoAllocCount;
2018+extern atomic_t tcpSesNextId;
2019+extern atomic_t tcpSesAllocCount;
2020+extern atomic_t tcpSesReconnectCount;
2021+extern atomic_t tconInfoReconnectCount;
19752022
19762023 /* Various Debug counters */
1977−GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
2024+extern atomic_t buf_alloc_count; /* current number allocated */
2025+extern atomic_t small_buf_alloc_count;
19782026 #ifdef CONFIG_CIFS_STATS2
1979−GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
1980−GLOBAL_EXTERN atomic_t totSmBufAllocCount;
2027+extern atomic_t total_buf_alloc_count; /* total allocated over all time */
2028+extern atomic_t total_small_buf_alloc_count;
19812029 extern unsigned int slow_rsp_threshold; /* number of secs before logging */
19822030 #endif
1983−GLOBAL_EXTERN atomic_t smBufAllocCount;
1984−GLOBAL_EXTERN atomic_t midCount;
19852031
19862032 /* Misc globals */
19872033 extern bool enable_oplocks; /* enable or disable oplocks */
@@ -1998,6 +2044,7 @@ extern unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */ · 10 unmodified lines
19982044 extern unsigned int cifs_min_small; /* min size of small buf pool */
19992045 extern unsigned int cifs_max_pending; /* MAX requests at once to server*/
20002046 extern bool disable_legacy_dialects; /* forbid vers=1.0 and vers=2.0 mounts */
2047+extern atomic_t mid_count;
20012048
20022049 void cifs_oplock_break(struct work_struct *work);
20032050 void cifs_queue_oplock_break(struct cifsFileInfo *cfile);
fs/cifs/cifsproto.h+4−6
@@ -78,12 +78,8 @@ extern char *build_wildcard_path_from_dentry(struct dentry *direntry); · 77 unmodified lines
7878 extern char *cifs_compose_mount_options(const char *sb_mountdata,
7979 const char *fullpath, const struct dfs_info3_param *ref,
8080 char **devname);
81−/* extern void renew_parental_timestamps(struct dentry *direntry);*/
82−extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer,
83− struct TCP_Server_Info *server);
84−extern void DeleteMidQEntry(struct mid_q_entry *midEntry);
85−extern void cifs_delete_mid(struct mid_q_entry *mid);
86−extern void cifs_mid_q_entry_release(struct mid_q_entry *midEntry);
81+extern void delete_mid(struct mid_q_entry *mid);
82+extern void release_mid(struct mid_q_entry *mid);
8783 extern void cifs_wake_up_task(struct mid_q_entry *mid);
8884 extern int cifs_handle_standard(struct TCP_Server_Info *server,
8985 struct mid_q_entry *mid);
@@ -521,6 +517,7 @@ extern int generate_smb30signingkey(struct cifs_ses *ses, · 431 unmodified lines
521517 extern int generate_smb311signingkey(struct cifs_ses *ses,
522518 struct TCP_Server_Info *server);
523519
520+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
524521 extern int CIFSSMBCopy(unsigned int xid,
525522 struct cifs_tcon *source_tcon,
526523 const char *fromName,
@@ -551,6 +548,7 @@ extern int CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, · 24 unmodified lines
551548 const struct nls_table *nls_codepage, int remap_special_chars);
552549 extern int CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon,
553550 const int netfid, __u64 *pExtAttrBits, __u64 *pMask);
551+#endif /* CIFS_ALLOW_INSECURE_LEGACY */
554552 extern void cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb);
555553 extern bool couldbe_mf_symlink(const struct cifs_fattr *fattr);
556554 extern int check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
fs/cifs/cifssmb.c+14−463
@@ -29,7 +29,6 @@ · 28 unmodified lines
2929 #include "cifsproto.h"
3030 #include "cifs_unicode.h"
3131 #include "cifs_debug.h"
32−#include "smb2proto.h"
3332 #include "fscache.h"
3433 #include "smbdirect.h"
3534 #ifdef CONFIG_CIFS_DFS_UPCALL
@@ -62,52 +61,6 @@ static struct { · 26 unmodified lines
6261 #define CIFS_NUM_PROT 1
6362 #endif /* CIFS_POSIX */
6463
65−/*
66− * Mark as invalid, all open files on tree connections since they
67− * were closed when session to server was lost.
68− */
69−void
70−cifs_mark_open_files_invalid(struct cifs_tcon *tcon)
71−{
72− struct cifsFileInfo *open_file = NULL;
73− struct list_head *tmp;
74− struct list_head *tmp1;
75−
76− /* only send once per connect */
77− spin_lock(&cifs_tcp_ses_lock);
78− if ((tcon->ses->ses_status != SES_GOOD) || (tcon->status != TID_NEED_RECON)) {
79− spin_unlock(&cifs_tcp_ses_lock);
80− return;
81− }
82− tcon->status = TID_IN_FILES_INVALIDATE;
83− spin_unlock(&cifs_tcp_ses_lock);
84−
85− /* list all files open on tree connection and mark them invalid */
86− spin_lock(&tcon->open_file_lock);
87− list_for_each_safe(tmp, tmp1, &tcon->openFileList) {
88− open_file = list_entry(tmp, struct cifsFileInfo, tlist);
89− open_file->invalidHandle = true;
90− open_file->oplock_break_cancelled = true;
91− }
92− spin_unlock(&tcon->open_file_lock);
93−
94− mutex_lock(&tcon->crfid.fid_mutex);
95− tcon->crfid.is_valid = false;
96− /* cached handle is not valid, so SMB2_CLOSE won't be sent below */
97− close_cached_dir_lease_locked(&tcon->crfid);
98− memset(tcon->crfid.fid, 0, sizeof(struct cifs_fid));
99− mutex_unlock(&tcon->crfid.fid_mutex);
100−
101− spin_lock(&cifs_tcp_ses_lock);
102− if (tcon->status == TID_IN_FILES_INVALIDATE)
103− tcon->status = TID_NEED_TCON;
104− spin_unlock(&cifs_tcp_ses_lock);
105−
106− /*
107− * BB Add call to invalidate_inodes(sb) for all superblocks mounted
108− * to this tcon.
109− */
110−}
11164
11265 /* reconnect the socket, tcon, and smb session if needed */
11366 static int
@@ -134,18 +87,18 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) · 20 unmodified lines
13487 * only tree disconnect, open, and write, (and ulogoff which does not
13588 * have tcon) are allowed as we start force umount
13689 */
137− spin_lock(&cifs_tcp_ses_lock);
90+ spin_lock(&tcon->tc_lock);
13891 if (tcon->status == TID_EXITING) {
13992 if (smb_command != SMB_COM_WRITE_ANDX &&
14093 smb_command != SMB_COM_OPEN_ANDX &&
14194 smb_command != SMB_COM_TREE_DISCONNECT) {
142− spin_unlock(&cifs_tcp_ses_lock);
95+ spin_unlock(&tcon->tc_lock);
14396 cifs_dbg(FYI, "can not send cmd %d while umounting\n",
14497 smb_command);
14598 return -ENODEV;
14699 }
147100 }
148− spin_unlock(&cifs_tcp_ses_lock);
101+ spin_unlock(&tcon->tc_lock);
149102
150103 retries = server->nr_targets;
151104
@@ -165,12 +118,12 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) · 13 unmodified lines
165118 }
166119
167120 /* are we still trying to reconnect? */
168− spin_lock(&cifs_tcp_ses_lock);
121+ spin_lock(&server->srv_lock);
169122 if (server->tcpStatus != CifsNeedReconnect) {
170− spin_unlock(&cifs_tcp_ses_lock);
123+ spin_unlock(&server->srv_lock);
171124 break;
172125 }
173− spin_unlock(&cifs_tcp_ses_lock);
126+ spin_unlock(&server->srv_lock);
174127
175128 if (retries && --retries)
176129 continue;
@@ -201,13 +154,13 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) · 24 unmodified lines
201154 * and the server never sends an answer the socket will be closed
202155 * and tcpStatus set to reconnect.
203156 */
204− spin_lock(&cifs_tcp_ses_lock);
157+ spin_lock(&server->srv_lock);
205158 if (server->tcpStatus == CifsNeedReconnect) {
206− spin_unlock(&cifs_tcp_ses_lock);
159+ spin_unlock(&server->srv_lock);
207160 rc = -EHOSTDOWN;
208161 goto out;
209162 }
210− spin_unlock(&cifs_tcp_ses_lock);
163+ spin_unlock(&server->srv_lock);
211164
212165 /*
213166 * need to prevent multiple threads trying to simultaneously
@@ -457,52 +410,6 @@ decode_ext_sec_blob(struct cifs_ses *ses, NEGOTIATE_RSP *pSMBr) · 243 unmodified lines
457410 return 0;
458411 }
459412
460−int
461−cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required)
462−{
463− bool srv_sign_required = server->sec_mode & server->vals->signing_required;
464− bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled;
465− bool mnt_sign_enabled = global_secflags & CIFSSEC_MAY_SIGN;
466−
467− /*
468− * Is signing required by mnt options? If not then check
469− * global_secflags to see if it is there.
470− */
471− if (!mnt_sign_required)
472− mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) ==
473− CIFSSEC_MUST_SIGN);
474−
475− /*
476− * If signing is required then it's automatically enabled too,
477− * otherwise, check to see if the secflags allow it.
478− */
479− mnt_sign_enabled = mnt_sign_required ? mnt_sign_required :
480− (global_secflags & CIFSSEC_MAY_SIGN);
481−
482− /* If server requires signing, does client allow it? */
483− if (srv_sign_required) {
484− if (!mnt_sign_enabled) {
485− cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!\n");
486− return -ENOTSUPP;
487− }
488− server->sign = true;
489− }
490−
491− /* If client requires signing, does server allow it? */
492− if (mnt_sign_required) {
493− if (!srv_sign_enabled) {
494− cifs_dbg(VFS, "Server does not support signing!\n");
495− return -ENOTSUPP;
496− }
497− server->sign = true;
498− }
499−
500− if (cifs_rdma_enabled(server) && server->sign)
501− cifs_dbg(VFS, "Signing is enabled, and RDMA read/write will be disabled\n");
502−
503− return 0;
504−}
505−
506413 static bool
507414 should_set_ext_sec_flag(enum securityEnum sectype)
508415 {
@@ -684,7 +591,7 @@ cifs_echo_callback(struct mid_q_entry *mid) · 175 unmodified lines
684591 struct TCP_Server_Info *server = mid->callback_data;
685592 struct cifs_credits credits = { .value = 1, .instance = 0 };
686593
687− DeleteMidQEntry(mid);
594+ release_mid(mid);
688595 add_credits(server, &credits, CIFS_ECHO_OP);
689596 }
690597
@@ -1379,184 +1286,6 @@ openRetry: · 688 unmodified lines
13791286 return rc;
13801287 }
13811288
1382−/*
1383− * Discard any remaining data in the current SMB. To do this, we borrow the
1384− * current bigbuf.
1385− */
1386−int
1387−cifs_discard_remaining_data(struct TCP_Server_Info *server)
1388−{
1389− unsigned int rfclen = server->pdu_size;
1390− int remaining = rfclen + server->vals->header_preamble_size -
1391− server->total_read;
1392−
1393− while (remaining > 0) {
1394− int length;
1395−
1396− length = cifs_discard_from_socket(server,
1397− min_t(size_t, remaining,
1398− CIFSMaxBufSize + MAX_HEADER_SIZE(server)));
1399− if (length < 0)
1400− return length;
1401− server->total_read += length;
1402− remaining -= length;
1403− }
1404−
1405− return 0;
1406−}
1407−
1408−static int
1409−__cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid,
1410− bool malformed)
1411−{
1412− int length;
1413−
1414− length = cifs_discard_remaining_data(server);
1415− dequeue_mid(mid, malformed);
1416− mid->resp_buf = server->smallbuf;
1417− server->smallbuf = NULL;
1418− return length;
1419−}
1420−
1421−static int
1422−cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1423−{
1424− struct cifs_readdata *rdata = mid->callback_data;
1425−
1426− return __cifs_readv_discard(server, mid, rdata->result);
1427−}
1428−
1429−int
1430−cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1431−{
1432− int length, len;
1433− unsigned int data_offset, data_len;
1434− struct cifs_readdata *rdata = mid->callback_data;
1435− char *buf = server->smallbuf;
1436− unsigned int buflen = server->pdu_size +
1437− server->vals->header_preamble_size;
1438− bool use_rdma_mr = false;
1439−
1440− cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n",
1441− __func__, mid->mid, rdata->offset, rdata->bytes);
1442−
1443− /*
1444− * read the rest of READ_RSP header (sans Data array), or whatever we
1445− * can if there's not enough data. At this point, we've read down to
1446− * the Mid.
1447− */
1448− len = min_t(unsigned int, buflen, server->vals->read_rsp_size) -
1449− HEADER_SIZE(server) + 1;
1450−
1451− length = cifs_read_from_socket(server,
1452− buf + HEADER_SIZE(server) - 1, len);
1453− if (length < 0)
1454− return length;
1455− server->total_read += length;
1456−
1457− if (server->ops->is_session_expired &&
1458− server->ops->is_session_expired(buf)) {
1459− cifs_reconnect(server, true);
1460− return -1;
1461− }
1462−
1463− if (server->ops->is_status_pending &&
1464− server->ops->is_status_pending(buf, server)) {
1465− cifs_discard_remaining_data(server);
1466− return -1;
1467− }
1468−
1469− /* set up first two iov for signature check and to get credits */
1470− rdata->iov[0].iov_base = buf;
1471− rdata->iov[0].iov_len = server->vals->header_preamble_size;
1472− rdata->iov[1].iov_base = buf + server->vals->header_preamble_size;
1473− rdata->iov[1].iov_len =
1474− server->total_read - server->vals->header_preamble_size;
1475− cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
1476− rdata->iov[0].iov_base, rdata->iov[0].iov_len);
1477− cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
1478− rdata->iov[1].iov_base, rdata->iov[1].iov_len);
1479−
1480− /* Was the SMB read successful? */
1481− rdata->result = server->ops->map_error(buf, false);
1482− if (rdata->result != 0) {
1483− cifs_dbg(FYI, "%s: server returned error %d\n",
1484− __func__, rdata->result);
1485− /* normal error on read response */
1486− return __cifs_readv_discard(server, mid, false);
1487− }
1488−
1489− /* Is there enough to get to the rest of the READ_RSP header? */
1490− if (server->total_read < server->vals->read_rsp_size) {
1491− cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n",
1492− __func__, server->total_read,
1493− server->vals->read_rsp_size);
1494− rdata->result = -EIO;
1495− return cifs_readv_discard(server, mid);
1496− }
1497−
1498− data_offset = server->ops->read_data_offset(buf) +
1499− server->vals->header_preamble_size;
1500− if (data_offset < server->total_read) {
1501− /*
1502− * win2k8 sometimes sends an offset of 0 when the read
1503− * is beyond the EOF. Treat it as if the data starts just after
1504− * the header.
1505− */
1506− cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
1507− __func__, data_offset);
1508− data_offset = server->total_read;
1509− } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
1510− /* data_offset is beyond the end of smallbuf */
1511− cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
1512− __func__, data_offset);
1513− rdata->result = -EIO;
1514− return cifs_readv_discard(server, mid);
1515− }
1516−
1517− cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n",
1518− __func__, server->total_read, data_offset);
1519−
1520− len = data_offset - server->total_read;
1521− if (len > 0) {
1522− /* read any junk before data into the rest of smallbuf */
1523− length = cifs_read_from_socket(server,
1524− buf + server->total_read, len);
1525− if (length < 0)
1526− return length;
1527− server->total_read += length;
1528− }
1529−
1530− /* how much data is in the response? */
1531−#ifdef CONFIG_CIFS_SMB_DIRECT
1532− use_rdma_mr = rdata->mr;
1533−#endif
1534− data_len = server->ops->read_data_length(buf, use_rdma_mr);
1535− if (!use_rdma_mr && (data_offset + data_len > buflen)) {
1536− /* data_len is corrupt -- discard frame */
1537− rdata->result = -EIO;
1538− return cifs_readv_discard(server, mid);
1539− }
1540−
1541− length = rdata->read_into_pages(server, rdata, data_len);
1542− if (length < 0)
1543− return length;
1544−
1545− server->total_read += length;
1546−
1547− cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n",
1548− server->total_read, buflen, data_len);
1549−
1550− /* discard anything left over */
1551− if (server->total_read < buflen)
1552− return cifs_readv_discard(server, mid);
1553−
1554− dequeue_mid(mid, false);
1555− mid->resp_buf = server->smallbuf;
1556− server->smallbuf = NULL;
1557− return length;
1558−}
1559−
15601289 static void
15611290 cifs_readv_callback(struct mid_q_entry *mid)
15621291 {
@@ -1607,7 +1336,7 @@ cifs_readv_callback(struct mid_q_entry *mid) · 44 unmodified lines
16071336 }
16081337
16091338 queue_work(cifsiod_wq, &rdata->work);
1610− DeleteMidQEntry(mid);
1339+ release_mid(mid);
16111340 add_credits(server, &credits, 0);
16121341 }
16131342
@@ -1909,183 +1638,6 @@ CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, · 295 unmodified lines
19091638 return rc;
19101639 }
19111640
1912−void
1913−cifs_writedata_release(struct kref *refcount)
1914−{
1915− struct cifs_writedata *wdata = container_of(refcount,
1916− struct cifs_writedata, refcount);
1917−#ifdef CONFIG_CIFS_SMB_DIRECT
1918− if (wdata->mr) {
1919− smbd_deregister_mr(wdata->mr);
1920− wdata->mr = NULL;
1921− }
1922−#endif
1923−
1924− if (wdata->cfile)
1925− cifsFileInfo_put(wdata->cfile);
1926−
1927− kvfree(wdata->pages);
1928− kfree(wdata);
1929−}
1930−
1931−/*
1932− * Write failed with a retryable error. Resend the write request. It's also
1933− * possible that the page was redirtied so re-clean the page.
1934− */
1935−static void
1936−cifs_writev_requeue(struct cifs_writedata *wdata)
1937−{
1938− int i, rc = 0;
1939− struct inode *inode = d_inode(wdata->cfile->dentry);
1940− struct TCP_Server_Info *server;
1941− unsigned int rest_len;
1942−
1943− server = tlink_tcon(wdata->cfile->tlink)->ses->server;
1944− i = 0;
1945− rest_len = wdata->bytes;
1946− do {
1947− struct cifs_writedata *wdata2;
1948− unsigned int j, nr_pages, wsize, tailsz, cur_len;
1949−
1950− wsize = server->ops->wp_retry_size(inode);
1951− if (wsize < rest_len) {
1952− nr_pages = wsize / PAGE_SIZE;
1953− if (!nr_pages) {
1954− rc = -ENOTSUPP;
1955− break;
1956− }
1957− cur_len = nr_pages * PAGE_SIZE;
1958− tailsz = PAGE_SIZE;
1959− } else {
1960− nr_pages = DIV_ROUND_UP(rest_len, PAGE_SIZE);
1961− cur_len = rest_len;
1962− tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE;
1963− }
1964−
1965− wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete);
1966− if (!wdata2) {
1967− rc = -ENOMEM;
1968− break;
1969− }
1970−
1971− for (j = 0; j < nr_pages; j++) {
1972− wdata2->pages[j] = wdata->pages[i + j];
1973− lock_page(wdata2->pages[j]);
1974− clear_page_dirty_for_io(wdata2->pages[j]);
1975− }
1976−
1977− wdata2->sync_mode = wdata->sync_mode;
1978− wdata2->nr_pages = nr_pages;
1979− wdata2->offset = page_offset(wdata2->pages[0]);
1980− wdata2->pagesz = PAGE_SIZE;
1981− wdata2->tailsz = tailsz;
1982− wdata2->bytes = cur_len;
1983−
1984− rc = cifs_get_writable_file(CIFS_I(inode), FIND_WR_ANY,
1985− &wdata2->cfile);
1986− if (!wdata2->cfile) {
1987− cifs_dbg(VFS, "No writable handle to retry writepages rc=%d\n",
1988− rc);
1989− if (!is_retryable_error(rc))
1990− rc = -EBADF;
1991− } else {
1992− wdata2->pid = wdata2->cfile->pid;
1993− rc = server->ops->async_writev(wdata2,
1994− cifs_writedata_release);
1995− }
1996−
1997− for (j = 0; j < nr_pages; j++) {
1998− unlock_page(wdata2->pages[j]);
1999− if (rc != 0 && !is_retryable_error(rc)) {
2000− SetPageError(wdata2->pages[j]);
2001− end_page_writeback(wdata2->pages[j]);
2002− put_page(wdata2->pages[j]);
2003− }
2004− }
2005−
2006− kref_put(&wdata2->refcount, cifs_writedata_release);
2007− if (rc) {
2008− if (is_retryable_error(rc))
2009− continue;
2010− i += nr_pages;
2011− break;
2012− }
2013−
2014− rest_len -= cur_len;
2015− i += nr_pages;
2016− } while (i < wdata->nr_pages);
2017−
2018− /* cleanup remaining pages from the original wdata */
2019− for (; i < wdata->nr_pages; i++) {
2020− SetPageError(wdata->pages[i]);
2021− end_page_writeback(wdata->pages[i]);
2022− put_page(wdata->pages[i]);
2023− }
2024−
2025− if (rc != 0 && !is_retryable_error(rc))
2026− mapping_set_error(inode->i_mapping, rc);
2027− kref_put(&wdata->refcount, cifs_writedata_release);
2028−}
2029−
2030−void
2031−cifs_writev_complete(struct work_struct *work)
2032−{
2033− struct cifs_writedata *wdata = container_of(work,
2034− struct cifs_writedata, work);
2035− struct inode *inode = d_inode(wdata->cfile->dentry);
2036− int i = 0;
2037−
2038− if (wdata->result == 0) {
2039− spin_lock(&inode->i_lock);
2040− cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes);
2041− spin_unlock(&inode->i_lock);
2042− cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink),
2043− wdata->bytes);
2044− } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN)
2045− return cifs_writev_requeue(wdata);
2046−
2047− for (i = 0; i < wdata->nr_pages; i++) {
2048− struct page *page = wdata->pages[i];
2049− if (wdata->result == -EAGAIN)
2050− __set_page_dirty_nobuffers(page);
2051− else if (wdata->result < 0)
2052− SetPageError(page);
2053− end_page_writeback(page);
2054− cifs_readpage_to_fscache(inode, page);
2055− put_page(page);
2056− }
2057− if (wdata->result != -EAGAIN)
2058− mapping_set_error(inode->i_mapping, wdata->result);
2059− kref_put(&wdata->refcount, cifs_writedata_release);
2060−}
2061−
2062−struct cifs_writedata *
2063−cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
2064−{
2065− struct page **pages =
2066− kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
2067− if (pages)
2068− return cifs_writedata_direct_alloc(pages, complete);
2069−
2070− return NULL;
2071−}
2072−
2073−struct cifs_writedata *
2074−cifs_writedata_direct_alloc(struct page **pages, work_func_t complete)
2075−{
2076− struct cifs_writedata *wdata;
2077−
2078− wdata = kzalloc(sizeof(*wdata), GFP_NOFS);
2079− if (wdata != NULL) {
2080− wdata->pages = pages;
2081− kref_init(&wdata->refcount);
2082− INIT_LIST_HEAD(&wdata->list);
2083− init_completion(&wdata->done);
2084− INIT_WORK(&wdata->work, complete);
2085− }
2086− return wdata;
2087−}
2088−
20891641 /*
20901642 * Check the mid_state and signature on received buffer (if any), and queue the
20911643 * workqueue completion task.
@@ -2132,7 +1684,7 @@ cifs_writev_callback(struct mid_q_entry *mid) · 40 unmodified lines
21321684 }
21331685
21341686 queue_work(cifsiod_wq, &wdata->work);
2135− DeleteMidQEntry(mid);
1687+ release_mid(mid);
21361688 add_credits(tcon->ses->server, &credits, 0);
21371689 }
21381690
@@ -3660,7 +3212,6 @@ setACLerrorExit: · 1521 unmodified lines
36603212 return rc;
36613213 }
36623214
3663−/* BB fix tabs in this function FIXME BB */
36643215 int
36653216 CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon,
36663217 const int netfid, __u64 *pExtAttrBits, __u64 *pMask)
@@ -3677,7 +3228,7 @@ CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, · 10 unmodified lines
36773228
36783229 GetExtAttrRetry:
36793230 rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
3680− (void **) &pSMBr);
3231+ (void **) &pSMBr);
36813232 if (rc)
36823233 return rc;
36833234
@@ -3723,7 +3274,7 @@ GetExtAttrRetry: · 39 unmodified lines
37233274 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
37243275 __u16 count = le16_to_cpu(pSMBr->t2.DataCount);
37253276 struct file_chattr_info *pfinfo;
3726− /* BB Do we need a cast or hash here ? */
3277+
37273278 if (count != 16) {
37283279 cifs_dbg(FYI, "Invalid size ret in GetExtAttr\n");
37293280 rc = -EIO;
fs/cifs/connect.c+187−112
@@ -119,10 +119,10 @@ static int reconn_set_ipaddr_from_hostname(struct TCP_Server_Info *server) · 118 unmodified lines
119119 goto requeue_resolve;
120120 }
121121
122− spin_lock(&cifs_tcp_ses_lock);
122+ spin_lock(&server->srv_lock);
123123 rc = cifs_convert_address((struct sockaddr *)&server->dstaddr, ipaddr,
124124 strlen(ipaddr));
125− spin_unlock(&cifs_tcp_ses_lock);
125+ spin_unlock(&server->srv_lock);
126126 kfree(ipaddr);
127127
128128 /* rc == 1 means success here */
@@ -205,17 +205,22 @@ cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, · 76 unmodified lines
205205 /* If server is a channel, select the primary channel */
206206 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
207207
208− spin_lock(&cifs_tcp_ses_lock);
208+ spin_lock(&pserver->srv_lock);
209209 if (!all_channels) {
210210 pserver->tcpStatus = CifsNeedReconnect;
211− spin_unlock(&cifs_tcp_ses_lock);
211+ spin_unlock(&pserver->srv_lock);
212212 return;
213213 }
214+ spin_unlock(&pserver->srv_lock);
214215
216+ spin_lock(&cifs_tcp_ses_lock);
215217 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
216218 spin_lock(&ses->chan_lock);
217− for (i = 0; i < ses->chan_count; i++)
219+ for (i = 0; i < ses->chan_count; i++) {
220+ spin_lock(&ses->chans[i].server->srv_lock);
218221 ses->chans[i].server->tcpStatus = CifsNeedReconnect;
222+ spin_unlock(&ses->chans[i].server->srv_lock);
223+ }
219224 spin_unlock(&ses->chan_lock);
220225 }
221226 spin_unlock(&cifs_tcp_ses_lock);
@@ -252,17 +257,8 @@ cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server, · 30 unmodified lines
252257 spin_lock(&cifs_tcp_ses_lock);
253258 list_for_each_entry_safe(ses, nses, &pserver->smb_ses_list, smb_ses_list) {
254259 /* check if iface is still active */
255− if (!cifs_chan_is_iface_active(ses, server)) {
256− /*
257− * HACK: drop the lock before calling
258− * cifs_chan_update_iface to avoid deadlock
259− */
260− ses->ses_count++;
261− spin_unlock(&cifs_tcp_ses_lock);
260+ if (!cifs_chan_is_iface_active(ses, server))
262261 cifs_chan_update_iface(ses, server);
263− spin_lock(&cifs_tcp_ses_lock);
264− ses->ses_count--;
265− }
266262
267263 spin_lock(&ses->chan_lock);
268264 if (!mark_smb_session && cifs_chan_needs_reconnect(ses, server))
@@ -323,7 +319,7 @@ cifs_abort_connection(struct TCP_Server_Info *server) · 54 unmodified lines
323319 /* mark submitted MIDs for retry and issue callback */
324320 INIT_LIST_HEAD(&retry_list);
325321 cifs_dbg(FYI, "%s: moving mids to private list\n", __func__);
326− spin_lock(&GlobalMid_Lock);
322+ spin_lock(&server->mid_lock);
327323 list_for_each_entry_safe(mid, nmid, &server->pending_mid_q, qhead) {
328324 kref_get(&mid->refcount);
329325 if (mid->mid_state == MID_REQUEST_SUBMITTED)
@@ -331,14 +327,14 @@ cifs_abort_connection(struct TCP_Server_Info *server) · 1 unmodified line
331327 list_move(&mid->qhead, &retry_list);
332328 mid->mid_flags |= MID_DELETED;
333329 }
334− spin_unlock(&GlobalMid_Lock);
330+ spin_unlock(&server->mid_lock);
335331 cifs_server_unlock(server);
336332
337333 cifs_dbg(FYI, "%s: issuing mid callbacks\n", __func__);
338334 list_for_each_entry_safe(mid, nmid, &retry_list, qhead) {
339335 list_del_init(&mid->qhead);
340336 mid->callback(mid);
341− cifs_mid_q_entry_release(mid);
337+ release_mid(mid);
342338 }
343339
344340 if (cifs_rdma_enabled(server)) {
@@ -350,11 +346,11 @@ cifs_abort_connection(struct TCP_Server_Info *server) · 5 unmodified lines
350346
351347 static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int num_targets)
352348 {
353− spin_lock(&cifs_tcp_ses_lock);
349+ spin_lock(&server->srv_lock);
354350 server->nr_targets = num_targets;
355351 if (server->tcpStatus == CifsExiting) {
356352 /* the demux thread will exit normally next time through the loop */
357− spin_unlock(&cifs_tcp_ses_lock);
353+ spin_unlock(&server->srv_lock);
358354 wake_up(&server->response_q);
359355 return false;
360356 }
@@ -364,7 +360,7 @@ static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int num · 3 unmodified lines
364360 server->hostname);
365361 server->tcpStatus = CifsNeedReconnect;
366362
367− spin_unlock(&cifs_tcp_ses_lock);
363+ spin_unlock(&server->srv_lock);
368364 return true;
369365 }
370366
@@ -414,20 +410,20 @@ static int __cifs_reconnect(struct TCP_Server_Info *server, · 43 unmodified lines
414410 } else {
415411 atomic_inc(&tcpSesReconnectCount);
416412 set_credits(server, 1);
417− spin_lock(&cifs_tcp_ses_lock);
413+ spin_lock(&server->srv_lock);
418414 if (server->tcpStatus != CifsExiting)
419415 server->tcpStatus = CifsNeedNegotiate;
420− spin_unlock(&cifs_tcp_ses_lock);
416+ spin_unlock(&server->srv_lock);
421417 cifs_swn_reset_server_dstaddr(server);
422418 cifs_server_unlock(server);
423419 mod_delayed_work(cifsiod_wq, &server->reconnect, 0);
424420 }
425421 } while (server->tcpStatus == CifsNeedReconnect);
426422
427− spin_lock(&cifs_tcp_ses_lock);
423+ spin_lock(&server->srv_lock);
428424 if (server->tcpStatus == CifsNeedNegotiate)
429425 mod_delayed_work(cifsiod_wq, &server->echo, 0);
430− spin_unlock(&cifs_tcp_ses_lock);
426+ spin_unlock(&server->srv_lock);
431427
432428 wake_up(&server->response_q);
433429 return rc;
@@ -541,10 +537,10 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server) · 107 unmodified lines
541537 */
542538 atomic_inc(&tcpSesReconnectCount);
543539 set_credits(server, 1);
544− spin_lock(&cifs_tcp_ses_lock);
540+ spin_lock(&server->srv_lock);
545541 if (server->tcpStatus != CifsExiting)
546542 server->tcpStatus = CifsNeedNegotiate;
547− spin_unlock(&cifs_tcp_ses_lock);
543+ spin_unlock(&server->srv_lock);
548544 cifs_swn_reset_server_dstaddr(server);
549545 cifs_server_unlock(server);
550546 mod_delayed_work(cifsiod_wq, &server->reconnect, 0);
@@ -556,11 +552,10 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server) · 5 unmodified lines
556552 dfs_cache_free_tgts(&tl);
557553
558554 /* Need to set up echo worker again once connection has been established */
559− spin_lock(&cifs_tcp_ses_lock);
555+ spin_lock(&server->srv_lock);
560556 if (server->tcpStatus == CifsNeedNegotiate)
561557 mod_delayed_work(cifsiod_wq, &server->echo, 0);
562−
563− spin_unlock(&cifs_tcp_ses_lock);
558+ spin_unlock(&server->srv_lock);
564559
565560 wake_up(&server->response_q);
566561 return rc;
@@ -569,12 +564,12 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server) · 2 unmodified lines
569564 int cifs_reconnect(struct TCP_Server_Info *server, bool mark_smb_session)
570565 {
571566 /* If tcp session is not an dfs connection, then reconnect to last target server */
572− spin_lock(&cifs_tcp_ses_lock);
567+ spin_lock(&server->srv_lock);
573568 if (!server->is_dfs_conn) {
574− spin_unlock(&cifs_tcp_ses_lock);
569+ spin_unlock(&server->srv_lock);
575570 return __cifs_reconnect(server, mark_smb_session);
576571 }
577− spin_unlock(&cifs_tcp_ses_lock);
572+ spin_unlock(&server->srv_lock);
578573
579574 mutex_lock(&server->refpath_lock);
580575 if (!server->origin_fullpath || !server->leaf_fullpath) {
@@ -670,18 +665,18 @@ server_unresponsive(struct TCP_Server_Info *server) · 89 unmodified lines
670665 * 65s kernel_recvmsg times out, and we see that we haven't gotten
671666 * a response in >60s.
672667 */
673− spin_lock(&cifs_tcp_ses_lock);
668+ spin_lock(&server->srv_lock);
674669 if ((server->tcpStatus == CifsGood ||
675670 server->tcpStatus == CifsNeedNegotiate) &&
676671 (!server->ops->can_echo || server->ops->can_echo(server)) &&
677672 time_after(jiffies, server->lstrp + 3 * server->echo_interval)) {
678− spin_unlock(&cifs_tcp_ses_lock);
673+ spin_unlock(&server->srv_lock);
679674 cifs_server_dbg(VFS, "has not responded in %lu seconds. Reconnecting...\n",
680675 (3 * server->echo_interval) / HZ);
681676 cifs_reconnect(server, false);
682677 return true;
683678 }
684− spin_unlock(&cifs_tcp_ses_lock);
679+ spin_unlock(&server->srv_lock);
685680
686681 return false;
687682 }
@@ -726,18 +721,18 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg) · 38 unmodified lines
726721 else
727722 length = sock_recvmsg(server->ssocket, smb_msg, 0);
728723
729− spin_lock(&cifs_tcp_ses_lock);
724+ spin_lock(&server->srv_lock);
730725 if (server->tcpStatus == CifsExiting) {
731− spin_unlock(&cifs_tcp_ses_lock);
726+ spin_unlock(&server->srv_lock);
732727 return -ESHUTDOWN;
733728 }
734729
735730 if (server->tcpStatus == CifsNeedReconnect) {
736− spin_unlock(&cifs_tcp_ses_lock);
731+ spin_unlock(&server->srv_lock);
737732 cifs_reconnect(server, false);
738733 return -ECONNABORTED;
739734 }
740− spin_unlock(&cifs_tcp_ses_lock);
735+ spin_unlock(&server->srv_lock);
741736
742737 if (length == -ERESTARTSYS ||
743738 length == -EAGAIN ||
@@ -849,7 +844,7 @@ dequeue_mid(struct mid_q_entry *mid, bool malformed) · 105 unmodified lines
849844 #ifdef CONFIG_CIFS_STATS2
850845 mid->when_received = jiffies;
851846 #endif
852− spin_lock(&GlobalMid_Lock);
847+ spin_lock(&mid->server->mid_lock);
853848 if (!malformed)
854849 mid->mid_state = MID_RESPONSE_RECEIVED;
855850 else
@@ -859,12 +854,12 @@ dequeue_mid(struct mid_q_entry *mid, bool malformed) · 3 unmodified lines
859854 * function has finished processing it is a bug.
860855 */
861856 if (mid->mid_flags & MID_DELETED) {
862− spin_unlock(&GlobalMid_Lock);
857+ spin_unlock(&mid->server->mid_lock);
863858 pr_warn_once("trying to dequeue a deleted mid\n");
864859 } else {
865860 list_del_init(&mid->qhead);
866861 mid->mid_flags |= MID_DELETED;
867− spin_unlock(&GlobalMid_Lock);
862+ spin_unlock(&mid->server->mid_lock);
868863 }
869864 }
870865
@@ -903,21 +898,68 @@ handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server, · 32 unmodified lines
903898 dequeue_mid(mid, malformed);
904899 }
905900
901+int
902+cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required)
903+{
904+ bool srv_sign_required = server->sec_mode & server->vals->signing_required;
905+ bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled;
906+ bool mnt_sign_enabled;
907+
908+ /*
909+ * Is signing required by mnt options? If not then check
910+ * global_secflags to see if it is there.
911+ */
912+ if (!mnt_sign_required)
913+ mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) ==
914+ CIFSSEC_MUST_SIGN);
915+
916+ /*
917+ * If signing is required then it's automatically enabled too,
918+ * otherwise, check to see if the secflags allow it.
919+ */
920+ mnt_sign_enabled = mnt_sign_required ? mnt_sign_required :
921+ (global_secflags & CIFSSEC_MAY_SIGN);
922+
923+ /* If server requires signing, does client allow it? */
924+ if (srv_sign_required) {
925+ if (!mnt_sign_enabled) {
926+ cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!\n");
927+ return -EOPNOTSUPP;
928+ }
929+ server->sign = true;
930+ }
931+
932+ /* If client requires signing, does server allow it? */
933+ if (mnt_sign_required) {
934+ if (!srv_sign_enabled) {
935+ cifs_dbg(VFS, "Server does not support signing!\n");
936+ return -EOPNOTSUPP;
937+ }
938+ server->sign = true;
939+ }
940+
941+ if (cifs_rdma_enabled(server) && server->sign)
942+ cifs_dbg(VFS, "Signing is enabled, and RDMA read/write will be disabled\n");
943+
944+ return 0;
945+}
946+
947+
906948 static void clean_demultiplex_info(struct TCP_Server_Info *server)
907949 {
908950 int length;
909951
910952 /* take it off the list, if it's not already */
911− spin_lock(&cifs_tcp_ses_lock);
953+ spin_lock(&server->srv_lock);
912954 list_del_init(&server->tcp_ses_list);
913− spin_unlock(&cifs_tcp_ses_lock);
955+ spin_unlock(&server->srv_lock);
914956
915957 cancel_delayed_work_sync(&server->echo);
916958 cancel_delayed_work_sync(&server->resolve);
917959
918− spin_lock(&cifs_tcp_ses_lock);
960+ spin_lock(&server->srv_lock);
919961 server->tcpStatus = CifsExiting;
920− spin_unlock(&cifs_tcp_ses_lock);
962+ spin_unlock(&server->srv_lock);
921963 wake_up_all(&server->response_q);
922964
923965 /* check if we have blocked requests that need to free */
@@ -948,7 +990,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server) · 24 unmodified lines
948990 struct list_head *tmp, *tmp2;
949991
950992 INIT_LIST_HEAD(&dispose_list);
951− spin_lock(&GlobalMid_Lock);
993+ spin_lock(&server->mid_lock);
952994 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
953995 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
954996 cifs_dbg(FYI, "Clearing mid %llu\n", mid_entry->mid);
@@ -957,7 +999,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server) · 2 unmodified lines
957999 list_move(&mid_entry->qhead, &dispose_list);
9581000 mid_entry->mid_flags |= MID_DELETED;
9591001 }
960− spin_unlock(&GlobalMid_Lock);
1002+ spin_unlock(&server->mid_lock);
9611003
9621004 /* now walk dispose list and issue callbacks */
9631005 list_for_each_safe(tmp, tmp2, &dispose_list) {
@@ -965,7 +1007,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server) · 1 unmodified line
9651007 cifs_dbg(FYI, "Callback mid %llu\n", mid_entry->mid);
9661008 list_del_init(&mid_entry->qhead);
9671009 mid_entry->callback(mid_entry);
968− cifs_mid_q_entry_release(mid_entry);
1010+ release_mid(mid_entry);
9691011 }
9701012 /* 1/8th of sec is more than enough time for them to exit */
9711013 msleep(125);
@@ -1039,19 +1081,18 @@ int · 67 unmodified lines
10391081 cifs_handle_standard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
10401082 {
10411083 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
1042− int length;
1084+ int rc;
10431085
10441086 /*
10451087 * We know that we received enough to get to the MID as we
10461088 * checked the pdu_length earlier. Now check to see
1047− * if the rest of the header is OK. We borrow the length
1048− * var for the rest of the loop to avoid a new stack var.
1089+ * if the rest of the header is OK.
10491090 *
10501091 * 48 bytes is enough to display the header and a little bit
10511092 * into the payload for debugging purposes.
10521093 */
1053− length = server->ops->check_message(buf, server->total_read, server);
1054− if (length != 0)
1094+ rc = server->ops->check_message(buf, server->total_read, server);
1095+ if (rc)
10551096 cifs_dump_mem("Bad SMB: ", buf,
10561097 min_t(unsigned int, server->total_read, 48));
10571098
@@ -1066,9 +1107,9 @@ cifs_handle_standard(struct TCP_Server_Info *server, struct mid_q_entry *mid) · 8 unmodified lines
10661107 return -1;
10671108
10681109 if (!mid)
1069− return length;
1110+ return rc;
10701111
1071− handle_mid(mid, server, buf, length);
1112+ handle_mid(mid, server, buf, rc);
10721113 return 0;
10731114 }
10741115
@@ -1205,7 +1246,7 @@ next_pdu: · 130 unmodified lines
12051246 if (length < 0) {
12061247 for (i = 0; i < num_mids; i++)
12071248 if (mids[i])
1208− cifs_mid_q_entry_release(mids[i]);
1249+ release_mid(mids[i]);
12091250 continue;
12101251 }
12111252
@@ -1232,7 +1273,7 @@ next_pdu: · 20 unmodified lines
12321273 if (!mids[i]->multiRsp || mids[i]->multiEnd)
12331274 mids[i]->callback(mids[i]);
12341275
1235− cifs_mid_q_entry_release(mids[i]);
1276+ release_mid(mids[i]);
12361277 } else if (server->ops->is_oplock_break &&
12371278 server->ops->is_oplock_break(bufs[i],
12381279 server)) {
@@ -1240,7 +1281,7 @@ next_pdu: · 1 unmodified line
12401281 cifs_dbg(FYI, "Received oplock break\n");
12411282 } else {
12421283 cifs_server_dbg(VFS, "No task to wake, unknown frame received! NumMids %d\n",
1243− atomic_read(&midCount));
1284+ atomic_read(&mid_count));
12441285 cifs_dump_mem("Received Data is: ", bufs[i],
12451286 HEADER_SIZE(server));
12461287 smb2_add_credits_from_hdr(bufs[i], server);
@@ -1411,6 +1452,7 @@ match_security(struct TCP_Server_Info *server, struct smb3_fs_context *ctx) · 164 unmodified lines
14111452 return true;
14121453 }
14131454
1455+/* this function must be called with srv_lock held */
14141456 static int match_server(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
14151457 {
14161458 struct sockaddr *addr = (struct sockaddr *)&ctx->dstaddr;
@@ -1471,6 +1513,7 @@ cifs_find_tcp_session(struct smb3_fs_context *ctx) · 54 unmodified lines
14711513
14721514 spin_lock(&cifs_tcp_ses_lock);
14731515 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
1516+ spin_lock(&server->srv_lock);
14741517 #ifdef CONFIG_CIFS_DFS_UPCALL
14751518 /*
14761519 * DFS failover implementation in cifs_reconnect() requires unique tcp sessions for
@@ -1478,15 +1521,20 @@ cifs_find_tcp_session(struct smb3_fs_context *ctx) · 1 unmodified line
14781521 * shares or even links that may connect to same server but having completely
14791522 * different failover targets.
14801523 */
1481− if (server->is_dfs_conn)
1524+ if (server->is_dfs_conn) {
1525+ spin_unlock(&server->srv_lock);
14821526 continue;
1527+ }
14831528 #endif
14841529 /*
14851530 * Skip ses channels since they're only handled in lower layers
14861531 * (e.g. cifs_send_recv).
14871532 */
1488− if (CIFS_SERVER_IS_CHAN(server) || !match_server(server, ctx))
1533+ if (CIFS_SERVER_IS_CHAN(server) || !match_server(server, ctx)) {
1534+ spin_unlock(&server->srv_lock);
14891535 continue;
1536+ }
1537+ spin_unlock(&server->srv_lock);
14901538
14911539 ++server->srv_count;
14921540 spin_unlock(&cifs_tcp_ses_lock);
@@ -1534,9 +1582,9 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect) · 41 unmodified lines
15341582 else
15351583 cancel_delayed_work_sync(&server->reconnect);
15361584
1537− spin_lock(&cifs_tcp_ses_lock);
1585+ spin_lock(&server->srv_lock);
15381586 server->tcpStatus = CifsExiting;
1539− spin_unlock(&cifs_tcp_ses_lock);
1587+ spin_unlock(&server->srv_lock);
15401588
15411589 cifs_crypto_secmech_release(server);
15421590
@@ -1595,8 +1643,8 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx, · 52 unmodified lines
15951643 if (primary_server) {
15961644 spin_lock(&cifs_tcp_ses_lock);
15971645 ++primary_server->srv_count;
1598− tcp_ses->primary_server = primary_server;
15991646 spin_unlock(&cifs_tcp_ses_lock);
1647+ tcp_ses->primary_server = primary_server;
16001648 }
16011649 init_waitqueue_head(&tcp_ses->response_q);
16021650 init_waitqueue_head(&tcp_ses->request_q);
@@ -1612,6 +1660,8 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx, · 9 unmodified lines
16121660 tcp_ses->lstrp = jiffies;
16131661 tcp_ses->compress_algorithm = cpu_to_le16(ctx->compression);
16141662 spin_lock_init(&tcp_ses->req_lock);
1663+ spin_lock_init(&tcp_ses->srv_lock);
1664+ spin_lock_init(&tcp_ses->mid_lock);
16151665 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list);
16161666 INIT_LIST_HEAD(&tcp_ses->smb_ses_list);
16171667 INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request);
@@ -1685,9 +1735,9 @@ smbd_connected: · 67 unmodified lines
16851735 * to the struct since the kernel thread not created yet
16861736 * no need to spinlock this update of tcpStatus
16871737 */
1688− spin_lock(&cifs_tcp_ses_lock);
1738+ spin_lock(&tcp_ses->srv_lock);
16891739 tcp_ses->tcpStatus = CifsNeedNegotiate;
1690− spin_unlock(&cifs_tcp_ses_lock);
1740+ spin_unlock(&tcp_ses->srv_lock);
16911741
16921742 if ((ctx->max_credits < 20) || (ctx->max_credits > 60000))
16931743 tcp_ses->max_credits = SMB2_MAX_CREDITS_AVAILABLE;
@@ -1729,6 +1779,7 @@ out_err: · 35 unmodified lines
17291779 return ERR_PTR(rc);
17301780 }
17311781
1782+/* this function must be called with ses_lock held */
17321783 static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
17331784 {
17341785 if (ctx->sectype != Unspecified &&
@@ -1864,10 +1915,17 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx) · 129 unmodified lines
18641915
18651916 spin_lock(&cifs_tcp_ses_lock);
18661917 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
1867− if (ses->ses_status == SES_EXITING)
1918+ spin_lock(&ses->ses_lock);
1919+ if (ses->ses_status == SES_EXITING) {
1920+ spin_unlock(&ses->ses_lock);
18681921 continue;
1869− if (!match_session(ses, ctx))
1922+ }
1923+ if (!match_session(ses, ctx)) {
1924+ spin_unlock(&ses->ses_lock);
18701925 continue;
1926+ }
1927+ spin_unlock(&ses->ses_lock);
1928+
18711929 ++ses->ses_count;
18721930 spin_unlock(&cifs_tcp_ses_lock);
18731931 return ses;
@@ -1882,26 +1940,28 @@ void cifs_put_smb_ses(struct cifs_ses *ses) · 8 unmodified lines
18821940 unsigned int chan_count;
18831941 struct TCP_Server_Info *server = ses->server;
18841942
1885− spin_lock(&cifs_tcp_ses_lock);
1943+ spin_lock(&ses->ses_lock);
18861944 if (ses->ses_status == SES_EXITING) {
1887− spin_unlock(&cifs_tcp_ses_lock);
1945+ spin_unlock(&ses->ses_lock);
18881946 return;
18891947 }
1948+ spin_unlock(&ses->ses_lock);
18901949
18911950 cifs_dbg(FYI, "%s: ses_count=%d\n", __func__, ses->ses_count);
18921951 cifs_dbg(FYI, "%s: ses ipc: %s\n", __func__, ses->tcon_ipc ? ses->tcon_ipc->treeName : "NONE");
18931952
1953+ spin_lock(&cifs_tcp_ses_lock);
18941954 if (--ses->ses_count > 0) {
18951955 spin_unlock(&cifs_tcp_ses_lock);
18961956 return;
18971957 }
1958+ spin_unlock(&cifs_tcp_ses_lock);
18981959
18991960 /* ses_count can never go negative */
19001961 WARN_ON(ses->ses_count < 0);
19011962
19021963 if (ses->ses_status == SES_GOOD)
19031964 ses->ses_status = SES_EXITING;
1904− spin_unlock(&cifs_tcp_ses_lock);
19051965
19061966 cifs_free_ipc(ses);
19071967
@@ -2236,6 +2296,7 @@ get_ses_fail: · 328 unmodified lines
22362296 return ERR_PTR(rc);
22372297 }
22382298
2299+/* this function must be called with tc_lock held */
22392300 static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
22402301 {
22412302 if (tcon->status == TID_EXITING)
@@ -2258,16 +2319,17 @@ static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) · 16 unmodified lines
22582319 static struct cifs_tcon *
22592320 cifs_find_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
22602321 {
2261− struct list_head *tmp;
22622322 struct cifs_tcon *tcon;
22632323
22642324 spin_lock(&cifs_tcp_ses_lock);
2265− list_for_each(tmp, &ses->tcon_list) {
2266− tcon = list_entry(tmp, struct cifs_tcon, tcon_list);
2267−
2268− if (!match_tcon(tcon, ctx))
2325+ list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2326+ spin_lock(&tcon->tc_lock);
2327+ if (!match_tcon(tcon, ctx)) {
2328+ spin_unlock(&tcon->tc_lock);
22692329 continue;
2330+ }
22702331 ++tcon->tc_count;
2332+ spin_unlock(&tcon->tc_lock);
22712333 spin_unlock(&cifs_tcp_ses_lock);
22722334 return tcon;
22732335 }
@@ -2644,7 +2706,7 @@ match_prepath(struct super_block *sb, struct cifs_mnt_data *mnt_data) · 370 unmodified lines
26442706 int
26452707 cifs_match_super(struct super_block *sb, void *data)
26462708 {
2647− struct cifs_mnt_data *mnt_data = (struct cifs_mnt_data *)data;
2709+ struct cifs_mnt_data *mnt_data = data;
26482710 struct smb3_fs_context *ctx;
26492711 struct cifs_sb_info *cifs_sb;
26502712 struct TCP_Server_Info *tcp_srv;
@@ -2667,6 +2729,9 @@ cifs_match_super(struct super_block *sb, void *data) · 16 unmodified lines
26672729
26682730 ctx = mnt_data->ctx;
26692731
2732+ spin_lock(&tcp_srv->srv_lock);
2733+ spin_lock(&ses->ses_lock);
2734+ spin_lock(&tcon->tc_lock);
26702735 if (!match_server(tcp_srv, ctx) ||
26712736 !match_session(ses, ctx) ||
26722737 !match_tcon(tcon, ctx) ||
@@ -2677,6 +2742,10 @@ cifs_match_super(struct super_block *sb, void *data) · 4 unmodified lines
26772742
26782743 rc = compare_mount_options(sb, mnt_data);
26792744 out:
2745+ spin_unlock(&tcon->tc_lock);
2746+ spin_unlock(&ses->ses_lock);
2747+ spin_unlock(&tcp_srv->srv_lock);
2748+
26802749 spin_unlock(&cifs_tcp_ses_lock);
26812750 cifs_put_tlink(tlink);
26822751 return rc;
@@ -2954,6 +3023,7 @@ ip_connect(struct TCP_Server_Info *server) · 271 unmodified lines
29543023 return generic_ip_connect(server);
29553024 }
29563025
3026+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
29573027 void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon,
29583028 struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
29593029 {
@@ -3059,6 +3129,7 @@ void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, · 99 unmodified lines
30593129 }
30603130 }
30613131 }
3132+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
30623133
30633134 int cifs_setup_cifs_sb(struct cifs_sb_info *cifs_sb)
30643135 {
@@ -3175,6 +3246,7 @@ static int mount_get_conns(struct mount_ctx *mnt_ctx) · 110 unmodified lines
31753246 if (tcon->posix_extensions)
31763247 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_POSIX_PATHS;
31773248
3249+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
31783250 /* tell server which Unix caps we support */
31793251 if (cap_unix(tcon->ses)) {
31803252 /*
@@ -3182,16 +3254,17 @@ static int mount_get_conns(struct mount_ctx *mnt_ctx) · 1 unmodified line
31823254 * for just this mount.
31833255 */
31843256 reset_cifs_unix_caps(xid, tcon, cifs_sb, ctx);
3185− spin_lock(&cifs_tcp_ses_lock);
3257+ spin_lock(&tcon->ses->server->srv_lock);
31863258 if ((tcon->ses->server->tcpStatus == CifsNeedReconnect) &&
31873259 (le64_to_cpu(tcon->fsUnixInfo.Capability) &
31883260 CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP)) {
3189− spin_unlock(&cifs_tcp_ses_lock);
3261+ spin_unlock(&tcon->ses->server->srv_lock);
31903262 rc = -EACCES;
31913263 goto out;
31923264 }
3193− spin_unlock(&cifs_tcp_ses_lock);
3265+ spin_unlock(&tcon->ses->server->srv_lock);
31943266 } else
3267+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
31953268 tcon->unix_ext = 0; /* server does not support them */
31963269
31973270 /* do not care if a following call succeed - informational */
@@ -3273,9 +3346,9 @@ static int mount_get_dfs_conns(struct mount_ctx *mnt_ctx) · 75 unmodified lines
32733346 rc = mount_get_conns(mnt_ctx);
32743347 if (mnt_ctx->server) {
32753348 cifs_dbg(FYI, "%s: marking tcp session as a dfs connection\n", __func__);
3276− spin_lock(&cifs_tcp_ses_lock);
3349+ spin_lock(&mnt_ctx->server->srv_lock);
32773350 mnt_ctx->server->is_dfs_conn = true;
3278− spin_unlock(&cifs_tcp_ses_lock);
3351+ spin_unlock(&mnt_ctx->server->srv_lock);
32793352 }
32803353 return rc;
32813354 }
@@ -3990,28 +4063,28 @@ cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses, · 708 unmodified lines
39904063 return -ENOSYS;
39914064
39924065 /* only send once per connect */
3993− spin_lock(&cifs_tcp_ses_lock);
4066+ spin_lock(&server->srv_lock);
39944067 if (!server->ops->need_neg(server) ||
39954068 server->tcpStatus != CifsNeedNegotiate) {
3996− spin_unlock(&cifs_tcp_ses_lock);
4069+ spin_unlock(&server->srv_lock);
39974070 return 0;
39984071 }
39994072 server->tcpStatus = CifsInNegotiate;
4000− spin_unlock(&cifs_tcp_ses_lock);
4073+ spin_unlock(&server->srv_lock);
40014074
40024075 rc = server->ops->negotiate(xid, ses, server);
40034076 if (rc == 0) {
4004− spin_lock(&cifs_tcp_ses_lock);
4077+ spin_lock(&server->srv_lock);
40054078 if (server->tcpStatus == CifsInNegotiate)
40064079 server->tcpStatus = CifsGood;
40074080 else
40084081 rc = -EHOSTDOWN;
4009− spin_unlock(&cifs_tcp_ses_lock);
4082+ spin_unlock(&server->srv_lock);
40104083 } else {
4011− spin_lock(&cifs_tcp_ses_lock);
4084+ spin_lock(&server->srv_lock);
40124085 if (server->tcpStatus == CifsInNegotiate)
40134086 server->tcpStatus = CifsNeedNegotiate;
4014− spin_unlock(&cifs_tcp_ses_lock);
4087+ spin_unlock(&server->srv_lock);
40154088 }
40164089
40174090 return rc;
@@ -4027,7 +4100,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, · 9 unmodified lines
40274100 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
40284101 bool is_binding = false;
40294102
4030− spin_lock(&cifs_tcp_ses_lock);
4103+ spin_lock(&ses->ses_lock);
40314104 if (server->dstaddr.ss_family == AF_INET6)
40324105 scnprintf(ses->ip_addr, sizeof(ses->ip_addr), "%pI6", &addr6->sin6_addr);
40334106 else
@@ -4036,7 +4109,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, · 2 unmodified lines
40364109 if (ses->ses_status != SES_GOOD &&
40374110 ses->ses_status != SES_NEW &&
40384111 ses->ses_status != SES_NEED_RECON) {
4039− spin_unlock(&cifs_tcp_ses_lock);
4112+ spin_unlock(&ses->ses_lock);
40404113 return 0;
40414114 }
40424115
@@ -4045,7 +4118,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, · 2 unmodified lines
40454118 if (CIFS_ALL_CHANS_GOOD(ses) ||
40464119 cifs_chan_in_reconnect(ses, server)) {
40474120 spin_unlock(&ses->chan_lock);
4048− spin_unlock(&cifs_tcp_ses_lock);
4121+ spin_unlock(&ses->ses_lock);
40494122 return 0;
40504123 }
40514124 is_binding = !CIFS_ALL_CHANS_NEED_RECONNECT(ses);
@@ -4054,7 +4127,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, · 2 unmodified lines
40544127
40554128 if (!is_binding)
40564129 ses->ses_status = SES_IN_SETUP;
4057− spin_unlock(&cifs_tcp_ses_lock);
4130+ spin_unlock(&ses->ses_lock);
40584131
40594132 if (!is_binding) {
40604133 ses->capabilities = server->capabilities;
@@ -4078,22 +4151,22 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, · 17 unmodified lines
40784151
40794152 if (rc) {
40804153 cifs_server_dbg(VFS, "Send error in SessSetup = %d\n", rc);
4081− spin_lock(&cifs_tcp_ses_lock);
4154+ spin_lock(&ses->ses_lock);
40824155 if (ses->ses_status == SES_IN_SETUP)
40834156 ses->ses_status = SES_NEED_RECON;
40844157 spin_lock(&ses->chan_lock);
40854158 cifs_chan_clear_in_reconnect(ses, server);
40864159 spin_unlock(&ses->chan_lock);
4087− spin_unlock(&cifs_tcp_ses_lock);
4160+ spin_unlock(&ses->ses_lock);
40884161 } else {
4089− spin_lock(&cifs_tcp_ses_lock);
4162+ spin_lock(&ses->ses_lock);
40904163 if (ses->ses_status == SES_IN_SETUP)
40914164 ses->ses_status = SES_GOOD;
40924165 spin_lock(&ses->chan_lock);
40934166 cifs_chan_clear_in_reconnect(ses, server);
40944167 cifs_chan_clear_need_reconnect(ses, server);
40954168 spin_unlock(&ses->chan_lock);
4096− spin_unlock(&cifs_tcp_ses_lock);
4169+ spin_unlock(&ses->ses_lock);
40974170 }
40984171
40994172 return rc;
@@ -4167,8 +4240,10 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid) · 67 unmodified lines
41674240 goto out;
41684241 }
41694242
4243+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
41704244 if (cap_unix(ses))
41714245 reset_cifs_unix_caps(0, tcon, NULL, ctx);
4246+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
41724247
41734248 out:
41744249 kfree(ctx->username);
@@ -4557,15 +4632,15 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru · 382 unmodified lines
45574632 struct dfs_info3_param ref = {0};
45584633
45594634 /* only send once per connect */
4560− spin_lock(&cifs_tcp_ses_lock);
4635+ spin_lock(&tcon->tc_lock);
45614636 if (tcon->ses->ses_status != SES_GOOD ||
45624637 (tcon->status != TID_NEW &&
45634638 tcon->status != TID_NEED_TCON)) {
4564− spin_unlock(&cifs_tcp_ses_lock);
4639+ spin_unlock(&tcon->tc_lock);
45654640 return 0;
45664641 }
45674642 tcon->status = TID_IN_TCON;
4568− spin_unlock(&cifs_tcp_ses_lock);
4643+ spin_unlock(&tcon->tc_lock);
45694644
45704645 tree = kzalloc(MAX_TREE_SIZE, GFP_KERNEL);
45714646 if (!tree) {
@@ -4604,15 +4679,15 @@ out: · 32 unmodified lines
46044679 cifs_put_tcp_super(sb);
46054680
46064681 if (rc) {
4607− spin_lock(&cifs_tcp_ses_lock);
4682+ spin_lock(&tcon->tc_lock);
46084683 if (tcon->status == TID_IN_TCON)
46094684 tcon->status = TID_NEED_TCON;
4610− spin_unlock(&cifs_tcp_ses_lock);
4685+ spin_unlock(&tcon->tc_lock);
46114686 } else {
4612− spin_lock(&cifs_tcp_ses_lock);
4687+ spin_lock(&tcon->tc_lock);
46134688 if (tcon->status == TID_IN_TCON)
46144689 tcon->status = TID_GOOD;
4615− spin_unlock(&cifs_tcp_ses_lock);
4690+ spin_unlock(&tcon->tc_lock);
46164691 tcon->need_reconnect = false;
46174692 }
46184693
@@ -4625,28 +4700,28 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru · 6 unmodified lines
46254700 const struct smb_version_operations *ops = tcon->ses->server->ops;
46264701
46274702 /* only send once per connect */
4628− spin_lock(&cifs_tcp_ses_lock);
4703+ spin_lock(&tcon->tc_lock);
46294704 if (tcon->ses->ses_status != SES_GOOD ||
46304705 (tcon->status != TID_NEW &&
46314706 tcon->status != TID_NEED_TCON)) {
4632− spin_unlock(&cifs_tcp_ses_lock);
4707+ spin_unlock(&tcon->tc_lock);
46334708 return 0;
46344709 }
46354710 tcon->status = TID_IN_TCON;
4636− spin_unlock(&cifs_tcp_ses_lock);
4711+ spin_unlock(&tcon->tc_lock);
46374712
46384713 rc = ops->tree_connect(xid, tcon->ses, tcon->treeName, tcon, nlsc);
46394714 if (rc) {
4640− spin_lock(&cifs_tcp_ses_lock);
4715+ spin_lock(&tcon->tc_lock);
46414716 if (tcon->status == TID_IN_TCON)
46424717 tcon->status = TID_NEED_TCON;
4643− spin_unlock(&cifs_tcp_ses_lock);
4718+ spin_unlock(&tcon->tc_lock);
46444719 } else {
4645− spin_lock(&cifs_tcp_ses_lock);
4720+ spin_lock(&tcon->tc_lock);
46464721 if (tcon->status == TID_IN_TCON)
46474722 tcon->status = TID_GOOD;
4648− spin_unlock(&cifs_tcp_ses_lock);
46494723 tcon->need_reconnect = false;
4724+ spin_unlock(&tcon->tc_lock);
46504725 }
46514726
46524727 return rc;
fs/cifs/dfs_cache.c+7−1
@@ -1526,15 +1526,21 @@ static void refresh_mounts(struct cifs_ses **sessions) · 1525 unmodified lines
15261526
15271527 spin_lock(&cifs_tcp_ses_lock);
15281528 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
1529− if (!server->is_dfs_conn)
1529+ spin_lock(&server->srv_lock);
1530+ if (!server->is_dfs_conn) {
1531+ spin_unlock(&server->srv_lock);
15301532 continue;
1533+ }
1534+ spin_unlock(&server->srv_lock);
15311535
15321536 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
15331537 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
1538+ spin_lock(&tcon->tc_lock);
15341539 if (!tcon->ipc && !tcon->need_reconnect) {
15351540 tcon->tc_count++;
15361541 list_add_tail(&tcon->ulist, &tcons);
15371542 }
1543+ spin_unlock(&tcon->tc_lock);
15381544 }
15391545 }
15401546 }
fs/cifs/dir.c+8−0
@@ -193,6 +193,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, · 192 unmodified lines
193193 return PTR_ERR(full_path);
194194 }
195195
196+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
196197 if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open &&
197198 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
198199 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
@@ -261,6 +262,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, · 62 unmodified lines
261262 * rare for path not covered on files)
262263 */
263264 }
265+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
264266
265267 desired_access = 0;
266268 if (OPEN_FMODE(oflags) & FMODE_READ)
@@ -316,6 +318,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, · 49 unmodified lines
316318 goto out;
317319 }
318320
321+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
319322 /*
320323 * If Open reported that we actually created a file then we now have to
321324 * set the mode if possible.
@@ -357,6 +360,9 @@ cifs_create_get_file_info: · 35 unmodified lines
357360 rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb,
358361 xid);
359362 else {
363+#else
364+ {
365+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
360366 /* TODO: Add support for calling POSIX query info here, but passing in fid */
361367 rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb,
362368 xid, fid);
@@ -377,7 +383,9 @@ cifs_create_get_file_info: · 14 unmodified lines
377383 }
378384 }
379385
386+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
380387 cifs_create_set_dentry:
388+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
381389 if (rc != 0) {
382390 cifs_dbg(FYI, "Create worked, get_inode_info failed rc = %d\n",
383391 rc);
fs/cifs/file.c+269−14
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include "cifspdu.h"
2727 #include "cifsglob.h"
2828 #include "cifsproto.h"
29+#include "smb2proto.h"
2930 #include "cifs_unicode.h"
3031 #include "cifs_debug.h"
3132 #include "cifs_fs_sb.h"
@@ -34,6 +35,53 @@ · 2 unmodified lines
3435 #include "fs_context.h"
3536 #include "cifs_ioctl.h"
3637
38+/*
39+ * Mark as invalid, all open files on tree connections since they
40+ * were closed when session to server was lost.
41+ */
42+void
43+cifs_mark_open_files_invalid(struct cifs_tcon *tcon)
44+{
45+ struct cifsFileInfo *open_file = NULL;
46+ struct list_head *tmp;
47+ struct list_head *tmp1;
48+
49+ /* only send once per connect */
50+ spin_lock(&tcon->ses->ses_lock);
51+ if ((tcon->ses->ses_status != SES_GOOD) || (tcon->status != TID_NEED_RECON)) {
52+ spin_unlock(&tcon->ses->ses_lock);
53+ return;
54+ }
55+ tcon->status = TID_IN_FILES_INVALIDATE;
56+ spin_unlock(&tcon->ses->ses_lock);
57+
58+ /* list all files open on tree connection and mark them invalid */
59+ spin_lock(&tcon->open_file_lock);
60+ list_for_each_safe(tmp, tmp1, &tcon->openFileList) {
61+ open_file = list_entry(tmp, struct cifsFileInfo, tlist);
62+ open_file->invalidHandle = true;
63+ open_file->oplock_break_cancelled = true;
64+ }
65+ spin_unlock(&tcon->open_file_lock);
66+
67+ mutex_lock(&tcon->crfid.fid_mutex);
68+ tcon->crfid.is_valid = false;
69+ /* cached handle is not valid, so SMB2_CLOSE won't be sent below */
70+ close_cached_dir_lease_locked(&tcon->crfid);
71+ memset(tcon->crfid.fid, 0, sizeof(struct cifs_fid));
72+ mutex_unlock(&tcon->crfid.fid_mutex);
73+
74+ spin_lock(&tcon->tc_lock);
75+ if (tcon->status == TID_IN_FILES_INVALIDATE)
76+ tcon->status = TID_NEED_TCON;
77+ spin_unlock(&tcon->tc_lock);
78+
79+ /*
80+ * BB Add call to invalidate_inodes(sb) for all superblocks mounted
81+ * to this tcon.
82+ */
83+}
84+
3785 static inline int cifs_convert_flags(unsigned int flags)
3886 {
3987 if ((flags & O_ACCMODE) == O_RDONLY)
@@ -52,6 +100,7 @@ static inline int cifs_convert_flags(unsigned int flags) · 12 unmodified lines
52100 FILE_READ_DATA);
53101 }
54102
103+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
55104 static u32 cifs_posix_convert_flags(unsigned int flags)
56105 {
57106 u32 posix_flags = 0;
@@ -85,6 +134,7 @@ static u32 cifs_posix_convert_flags(unsigned int flags) · 27 unmodified lines
85134
86135 return posix_flags;
87136 }
137+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
88138
89139 static inline int cifs_get_disposition(unsigned int flags)
90140 {
@@ -100,6 +150,7 @@ static inline int cifs_get_disposition(unsigned int flags) · 9 unmodified lines
100150 return FILE_OPEN;
101151 }
102152
153+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
103154 int cifs_posix_open(const char *full_path, struct inode **pinode,
104155 struct super_block *sb, int mode, unsigned int f_flags,
105156 __u32 *poplock, __u16 *pnetfid, unsigned int xid)
@@ -161,6 +212,7 @@ posix_open_ret: · 55 unmodified lines
161212 kfree(presp_data);
162213 return rc;
163214 }
215+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
164216
165217 static int
166218 cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
@@ -579,6 +631,7 @@ int cifs_open(struct inode *inode, struct file *file) · 412 unmodified lines
579631 else
580632 oplock = 0;
581633
634+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
582635 if (!tcon->broken_posix_open && tcon->unix_ext &&
583636 cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
584637 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
@@ -603,6 +656,7 @@ int cifs_open(struct inode *inode, struct file *file) · 18 unmodified lines
603656 * or DFS errors.
604657 */
605658 }
659+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
606660
607661 if (server->ops->get_lease_key)
608662 server->ops->get_lease_key(inode, &fid);
@@ -630,6 +684,7 @@ int cifs_open(struct inode *inode, struct file *file) · 21 unmodified lines
630684 goto out;
631685 }
632686
687+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
633688 if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) {
634689 /*
635690 * Time to set mode which we can not set earlier due to
@@ -647,6 +702,7 @@ int cifs_open(struct inode *inode, struct file *file) · 11 unmodified lines
647702 CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid.netfid,
648703 cfile->pid);
649704 }
705+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
650706
651707 use_cache:
652708 fscache_use_cookie(cifs_inode_cookie(file_inode(file)),
@@ -664,7 +720,9 @@ out: · 11 unmodified lines
664720 return rc;
665721 }
666722
723+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
667724 static int cifs_push_posix_locks(struct cifsFileInfo *cfile);
725+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
668726
669727 /*
670728 * Try to reacquire byte range locks that were released when session
@@ -673,10 +731,12 @@ static int cifs_push_posix_locks(struct cifsFileInfo *cfile); · 2 unmodified lines
673731 static int
674732 cifs_relock_file(struct cifsFileInfo *cfile)
675733 {
676− struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
677734 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
678735 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
679736 int rc = 0;
737+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
738+ struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
739+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
680740
681741 down_read_nested(&cinode->lock_sem, SINGLE_DEPTH_NESTING);
682742 if (cinode->can_cache_brlcks) {
@@ -685,11 +745,13 @@ cifs_relock_file(struct cifsFileInfo *cfile) · 2 unmodified lines
685745 return rc;
686746 }
687747
748+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
688749 if (cap_unix(tcon->ses) &&
689750 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
690751 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
691752 rc = cifs_push_posix_locks(cfile);
692753 else
754+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
693755 rc = tcon->ses->server->ops->push_mand_locks(cfile);
694756
695757 up_read(&cinode->lock_sem);
@@ -750,6 +812,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) · 54 unmodified lines
750812 else
751813 oplock = 0;
752814
815+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
753816 if (tcon->unix_ext && cap_unix(tcon->ses) &&
754817 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
755818 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
@@ -773,6 +836,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) · 17 unmodified lines
773836 * in the reconnect path it is important to retry hard
774837 */
775838 }
839+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
776840
777841 desired_access = cifs_convert_flags(cfile->f_flags);
778842
@@ -817,7 +881,9 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) · 38 unmodified lines
817881 goto reopen_error_exit;
818882 }
819883
884+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
820885 reopen_success:
886+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
821887 cfile->invalidHandle = false;
822888 mutex_unlock(&cfile->fh_mutex);
823889 cinode = CIFS_I(inode);
@@ -928,9 +994,7 @@ int cifs_close(struct inode *inode, struct file *file) · 104 unmodified lines
928994 void
929995 cifs_reopen_persistent_handles(struct cifs_tcon *tcon)
930996 {
931− struct cifsFileInfo *open_file;
932− struct list_head *tmp;
933− struct list_head *tmp1;
997+ struct cifsFileInfo *open_file, *tmp;
934998 struct list_head tmp_list;
935999
9361000 if (!tcon->use_persistent || !tcon->need_reopen_files)
@@ -943,8 +1007,7 @@ cifs_reopen_persistent_handles(struct cifs_tcon *tcon) · 6 unmodified lines
9431007
9441008 /* list all files open on tree connection, reopen resilient handles */
9451009 spin_lock(&tcon->open_file_lock);
946− list_for_each(tmp, &tcon->openFileList) {
947− open_file = list_entry(tmp, struct cifsFileInfo, tlist);
1010+ list_for_each_entry(open_file, &tcon->openFileList, tlist) {
9481011 if (!open_file->invalidHandle)
9491012 continue;
9501013 cifsFileInfo_get(open_file);
@@ -952,8 +1015,7 @@ cifs_reopen_persistent_handles(struct cifs_tcon *tcon) · 1 unmodified line
9521015 }
9531016 spin_unlock(&tcon->open_file_lock);
9541017
955− list_for_each_safe(tmp, tmp1, &tmp_list) {
956− open_file = list_entry(tmp, struct cifsFileInfo, rlist);
1018+ list_for_each_entry_safe(open_file, tmp, &tmp_list, rlist) {
9571019 if (cifs_reopen_file(open_file, false /* do not flush */))
9581020 tcon->need_reopen_files = true;
9591021 list_del_init(&open_file->rlist);
@@ -1196,6 +1258,7 @@ try_again: · 236 unmodified lines
11961258 return rc;
11971259 }
11981260
1261+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
11991262 /*
12001263 * Check if there is another lock that prevents us to set the lock (posix
12011264 * style). If such a lock exists, update the flock structure with its
@@ -1334,6 +1397,7 @@ hash_lockowner(fl_owner_t owner) · 132 unmodified lines
13341397 {
13351398 return cifs_lock_secret ^ hash32_ptr((const void *)owner);
13361399 }
1400+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
13371401
13381402 struct lock_to_push {
13391403 struct list_head llist;
@@ -1344,6 +1408,7 @@ struct lock_to_push { · 4 unmodified lines
13441408 __u8 type;
13451409 };
13461410
1411+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
13471412 static int
13481413 cifs_push_posix_locks(struct cifsFileInfo *cfile)
13491414 {
@@ -1431,14 +1496,17 @@ err_out: · 81 unmodified lines
14311496 }
14321497 goto out;
14331498 }
1499+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
14341500
14351501 static int
14361502 cifs_push_locks(struct cifsFileInfo *cfile)
14371503 {
1438− struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
14391504 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
14401505 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
14411506 int rc = 0;
1507+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
1508+ struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
1509+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
14421510
14431511 /* we are going to update can_cache_brlcks here - need a write access */
14441512 cifs_down_write(&cinode->lock_sem);
@@ -1447,11 +1515,13 @@ cifs_push_locks(struct cifsFileInfo *cfile) · 2 unmodified lines
14471515 return rc;
14481516 }
14491517
1518+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
14501519 if (cap_unix(tcon->ses) &&
14511520 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
14521521 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
14531522 rc = cifs_push_posix_locks(cfile);
14541523 else
1524+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
14551525 rc = tcon->ses->server->ops->push_mand_locks(cfile);
14561526
14571527 cinode->can_cache_brlcks = false;
@@ -1515,6 +1585,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, · 57 unmodified lines
15151585 struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
15161586 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
15171587 struct TCP_Server_Info *server = tcon->ses->server;
1588+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
15181589 __u16 netfid = cfile->fid.netfid;
15191590
15201591 if (posix_lck) {
@@ -1534,6 +1605,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, · 13 unmodified lines
15341605 posix_lock_type, wait_flag);
15351606 return rc;
15361607 }
1608+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
15371609
15381610 rc = cifs_lock_test(cfile, flock->fl_start, length, type, flock);
15391611 if (!rc)
@@ -1594,6 +1666,7 @@ cifs_free_llist(struct list_head *llist) · 54 unmodified lines
15941666 }
15951667 }
15961668
1669+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
15971670 int
15981671 cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
15991672 unsigned int xid)
@@ -1706,6 +1779,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, · 106 unmodified lines
17061779 kfree(buf);
17071780 return rc;
17081781 }
1782+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
17091783
17101784 static int
17111785 cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
@@ -1719,6 +1793,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, · 7 unmodified lines
17191793 struct TCP_Server_Info *server = tcon->ses->server;
17201794 struct inode *inode = d_inode(cfile->dentry);
17211795
1796+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
17221797 if (posix_lck) {
17231798 int posix_lock_type;
17241799
@@ -1740,7 +1815,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, · 15 unmodified lines
17401815 NULL, posix_lock_type, wait_flag);
17411816 goto out;
17421817 }
1743−
1818+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
17441819 if (lock) {
17451820 struct cifsLockInfo *lock;
17461821
@@ -2204,6 +2279,185 @@ cifs_get_readable_path(struct cifs_tcon *tcon, const char *name, · 457 unmodified lines
22042279 return -ENOENT;
22052280 }
22062281
2282+void
2283+cifs_writedata_release(struct kref *refcount)
2284+{
2285+ struct cifs_writedata *wdata = container_of(refcount,
2286+ struct cifs_writedata, refcount);
2287+#ifdef CONFIG_CIFS_SMB_DIRECT
2288+ if (wdata->mr) {
2289+ smbd_deregister_mr(wdata->mr);
2290+ wdata->mr = NULL;
2291+ }
2292+#endif
2293+
2294+ if (wdata->cfile)
2295+ cifsFileInfo_put(wdata->cfile);
2296+
2297+ kvfree(wdata->pages);
2298+ kfree(wdata);
2299+}
2300+
2301+/*
2302+ * Write failed with a retryable error. Resend the write request. It's also
2303+ * possible that the page was redirtied so re-clean the page.
2304+ */
2305+static void
2306+cifs_writev_requeue(struct cifs_writedata *wdata)
2307+{
2308+ int i, rc = 0;
2309+ struct inode *inode = d_inode(wdata->cfile->dentry);
2310+ struct TCP_Server_Info *server;
2311+ unsigned int rest_len;
2312+
2313+ server = tlink_tcon(wdata->cfile->tlink)->ses->server;
2314+ i = 0;
2315+ rest_len = wdata->bytes;
2316+ do {
2317+ struct cifs_writedata *wdata2;
2318+ unsigned int j, nr_pages, wsize, tailsz, cur_len;
2319+
2320+ wsize = server->ops->wp_retry_size(inode);
2321+ if (wsize < rest_len) {
2322+ nr_pages = wsize / PAGE_SIZE;
2323+ if (!nr_pages) {
2324+ rc = -EOPNOTSUPP;
2325+ break;
2326+ }
2327+ cur_len = nr_pages * PAGE_SIZE;
2328+ tailsz = PAGE_SIZE;
2329+ } else {
2330+ nr_pages = DIV_ROUND_UP(rest_len, PAGE_SIZE);
2331+ cur_len = rest_len;
2332+ tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE;
2333+ }
2334+
2335+ wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete);
2336+ if (!wdata2) {
2337+ rc = -ENOMEM;
2338+ break;
2339+ }
2340+
2341+ for (j = 0; j < nr_pages; j++) {
2342+ wdata2->pages[j] = wdata->pages[i + j];
2343+ lock_page(wdata2->pages[j]);
2344+ clear_page_dirty_for_io(wdata2->pages[j]);
2345+ }
2346+
2347+ wdata2->sync_mode = wdata->sync_mode;
2348+ wdata2->nr_pages = nr_pages;
2349+ wdata2->offset = page_offset(wdata2->pages[0]);
2350+ wdata2->pagesz = PAGE_SIZE;
2351+ wdata2->tailsz = tailsz;
2352+ wdata2->bytes = cur_len;
2353+
2354+ rc = cifs_get_writable_file(CIFS_I(inode), FIND_WR_ANY,
2355+ &wdata2->cfile);
2356+ if (!wdata2->cfile) {
2357+ cifs_dbg(VFS, "No writable handle to retry writepages rc=%d\n",
2358+ rc);
2359+ if (!is_retryable_error(rc))
2360+ rc = -EBADF;
2361+ } else {
2362+ wdata2->pid = wdata2->cfile->pid;
2363+ rc = server->ops->async_writev(wdata2,
2364+ cifs_writedata_release);
2365+ }
2366+
2367+ for (j = 0; j < nr_pages; j++) {
2368+ unlock_page(wdata2->pages[j]);
2369+ if (rc != 0 && !is_retryable_error(rc)) {
2370+ SetPageError(wdata2->pages[j]);
2371+ end_page_writeback(wdata2->pages[j]);
2372+ put_page(wdata2->pages[j]);
2373+ }
2374+ }
2375+
2376+ kref_put(&wdata2->refcount, cifs_writedata_release);
2377+ if (rc) {
2378+ if (is_retryable_error(rc))
2379+ continue;
2380+ i += nr_pages;
2381+ break;
2382+ }
2383+
2384+ rest_len -= cur_len;
2385+ i += nr_pages;
2386+ } while (i < wdata->nr_pages);
2387+
2388+ /* cleanup remaining pages from the original wdata */
2389+ for (; i < wdata->nr_pages; i++) {
2390+ SetPageError(wdata->pages[i]);
2391+ end_page_writeback(wdata->pages[i]);
2392+ put_page(wdata->pages[i]);
2393+ }
2394+
2395+ if (rc != 0 && !is_retryable_error(rc))
2396+ mapping_set_error(inode->i_mapping, rc);
2397+ kref_put(&wdata->refcount, cifs_writedata_release);
2398+}
2399+
2400+void
2401+cifs_writev_complete(struct work_struct *work)
2402+{
2403+ struct cifs_writedata *wdata = container_of(work,
2404+ struct cifs_writedata, work);
2405+ struct inode *inode = d_inode(wdata->cfile->dentry);
2406+ int i = 0;
2407+
2408+ if (wdata->result == 0) {
2409+ spin_lock(&inode->i_lock);
2410+ cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes);
2411+ spin_unlock(&inode->i_lock);
2412+ cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink),
2413+ wdata->bytes);
2414+ } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN)
2415+ return cifs_writev_requeue(wdata);
2416+
2417+ for (i = 0; i < wdata->nr_pages; i++) {
2418+ struct page *page = wdata->pages[i];
2419+
2420+ if (wdata->result == -EAGAIN)
2421+ __set_page_dirty_nobuffers(page);
2422+ else if (wdata->result < 0)
2423+ SetPageError(page);
2424+ end_page_writeback(page);
2425+ cifs_readpage_to_fscache(inode, page);
2426+ put_page(page);
2427+ }
2428+ if (wdata->result != -EAGAIN)
2429+ mapping_set_error(inode->i_mapping, wdata->result);
2430+ kref_put(&wdata->refcount, cifs_writedata_release);
2431+}
2432+
2433+struct cifs_writedata *
2434+cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
2435+{
2436+ struct page **pages =
2437+ kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
2438+ if (pages)
2439+ return cifs_writedata_direct_alloc(pages, complete);
2440+
2441+ return NULL;
2442+}
2443+
2444+struct cifs_writedata *
2445+cifs_writedata_direct_alloc(struct page **pages, work_func_t complete)
2446+{
2447+ struct cifs_writedata *wdata;
2448+
2449+ wdata = kzalloc(sizeof(*wdata), GFP_NOFS);
2450+ if (wdata != NULL) {
2451+ wdata->pages = pages;
2452+ kref_init(&wdata->refcount);
2453+ INIT_LIST_HEAD(&wdata->list);
2454+ init_completion(&wdata->done);
2455+ INIT_WORK(&wdata->work, complete);
2456+ }
2457+ return wdata;
2458+}
2459+
2460+
22072461 static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
22082462 {
22092463 struct address_space *mapping = page->mapping;
@@ -4459,10 +4713,11 @@ static void cifs_readahead(struct readahead_control *ractl) · 2249 unmodified lines
44594713 * TODO: Send a whole batch of pages to be read
44604714 * by the cache.
44614715 */
4462− page = readahead_page(ractl);
4463− last_batch_size = 1 << thp_order(page);
4716+ struct folio *folio = readahead_folio(ractl);
4717+
4718+ last_batch_size = folio_nr_pages(folio);
44644719 if (cifs_readpage_from_fscache(ractl->mapping->host,
4465− page) < 0) {
4720+ &folio->page) < 0) {
44664721 /*
44674722 * TODO: Deal with cache read failure
44684723 * here, but for the moment, delegate
@@ -4470,7 +4725,7 @@ static void cifs_readahead(struct readahead_control *ractl) · 1 unmodified line
44704725 */
44714726 caching = false;
44724727 }
4473− unlock_page(page);
4728+ folio_unlock(folio);
44744729 next_cached++;
44754730 cache_nr_pages--;
44764731 if (cache_nr_pages == 0)
fs/cifs/inode.c+57−7
@@ -339,6 +339,7 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb) · 338 unmodified lines
339339 fattr->cf_flags = CIFS_FATTR_DFS_REFERRAL;
340340 }
341341
342+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
342343 static int
343344 cifs_get_file_info_unix(struct file *filp)
344345 {
@@ -432,6 +433,14 @@ int cifs_get_inode_info_unix(struct inode **pinode, · 87 unmodified lines
432433 cgiiu_exit:
433434 return rc;
434435 }
436+#else
437+int cifs_get_inode_info_unix(struct inode **pinode,
438+ const unsigned char *full_path,
439+ struct super_block *sb, unsigned int xid)
440+{
441+ return -EOPNOTSUPP;
442+}
443+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
435444
436445 static int
437446 cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
@@ -795,6 +804,7 @@ static __u64 simple_hashstr(const char *str) · 357 unmodified lines
795804 return hash;
796805 }
797806
807+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
798808 /**
799809 * cifs_backup_query_path_info - SMB1 fallback code to get ino
800810 *
@@ -847,6 +857,7 @@ cifs_backup_query_path_info(int xid, · 46 unmodified lines
847857 *data = (FILE_ALL_INFO *)info.srch_entries_start;
848858 return 0;
849859 }
860+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
850861
851862 static void
852863 cifs_set_fattr_ino(int xid,
@@ -991,6 +1002,7 @@ cifs_get_inode_info(struct inode **inode, · 138 unmodified lines
9911002 rc = 0;
9921003 break;
9931004 case -EACCES:
1005+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
9941006 /*
9951007 * perm errors, try again with backup flags if possible
9961008 *
@@ -1022,6 +1034,9 @@ cifs_get_inode_info(struct inode **inode, · 25 unmodified lines
10221034 /* nothing we can do, bail out */
10231035 goto out;
10241036 }
1037+#else
1038+ goto out;
1039+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
10251040 break;
10261041 default:
10271042 cifs_dbg(FYI, "%s: unhandled err rc %d\n", __func__, rc);
@@ -1037,8 +1052,9 @@ cifs_get_inode_info(struct inode **inode, · 9 unmodified lines
10371052 /*
10381053 * 4. Tweak fattr based on mount options
10391054 */
1040−
1055+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
10411056 handle_mnt_opt:
1057+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
10421058 /* query for SFU type info if supported and needed */
10431059 if (fattr.cf_cifsattrs & ATTR_SYSTEM &&
10441060 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
@@ -1223,7 +1239,7 @@ static const struct inode_operations cifs_ipc_inode_ops = { · 178 unmodified lines
12231239 static int
12241240 cifs_find_inode(struct inode *inode, void *opaque)
12251241 {
1226− struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
1242+ struct cifs_fattr *fattr = opaque;
12271243
12281244 /* don't match inode with different uniqueid */
12291245 if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
@@ -1247,7 +1263,7 @@ cifs_find_inode(struct inode *inode, void *opaque) · 17 unmodified lines
12471263 static int
12481264 cifs_init_inode(struct inode *inode, void *opaque)
12491265 {
1250− struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
1266+ struct cifs_fattr *fattr = opaque;
12511267
12521268 CIFS_I(inode)->uniqueid = fattr->cf_uniqueid;
12531269 CIFS_I(inode)->createtime = fattr->cf_createtime;
@@ -1435,6 +1451,7 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, · 181 unmodified lines
14351451 return server->ops->set_file_info(inode, full_path, &info_buf, xid);
14361452 }
14371453
1454+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
14381455 /*
14391456 * Open the given file (if it isn't already), set the DELETE_ON_CLOSE bit
14401457 * and rename it to a random name that hopefully won't conflict with
@@ -1565,6 +1582,7 @@ undo_setattr: · 124 unmodified lines
15651582
15661583 goto out_close;
15671584 }
1585+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
15681586
15691587 /* copied from fs/nfs/dir.c with small changes */
15701588 static void
@@ -1627,6 +1645,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) · 56 unmodified lines
16271645 }
16281646
16291647 cifs_close_deferred_file_under_dentry(tcon, full_path);
1648+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
16301649 if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
16311650 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
16321651 rc = CIFSPOSIXDelFile(xid, tcon, full_path,
@@ -1636,6 +1655,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) · 3 unmodified lines
16361655 if ((rc == 0) || (rc == -ENOENT))
16371656 goto psx_del_no_retry;
16381657 }
1658+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
16391659
16401660 retry_std_delete:
16411661 if (!server->ops->unlink) {
@@ -1714,9 +1734,11 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, · 72 unmodified lines
17141734
17151735 if (tcon->posix_extensions)
17161736 rc = smb311_posix_get_inode_info(&inode, full_path, parent->i_sb, xid);
1737+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
17171738 else if (tcon->unix_ext)
17181739 rc = cifs_get_inode_info_unix(&inode, full_path, parent->i_sb,
17191740 xid);
1741+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
17201742 else
17211743 rc = cifs_get_inode_info(&inode, full_path, NULL, parent->i_sb,
17221744 xid, NULL);
@@ -1746,6 +1768,7 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, · 23 unmodified lines
17461768 if (parent->i_mode & S_ISGID)
17471769 mode |= S_ISGID;
17481770
1771+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
17491772 if (tcon->unix_ext) {
17501773 struct cifs_unix_set_info_args args = {
17511774 .mode = mode,
@@ -1768,6 +1791,9 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, · 16 unmodified lines
17681791 cifs_sb->local_nls,
17691792 cifs_remap(cifs_sb));
17701793 } else {
1794+#else
1795+ {
1796+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
17711797 struct TCP_Server_Info *server = tcon->ses->server;
17721798 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) &&
17731799 (mode & S_IWUGO) == 0 && server->ops->mkdir_setinfo)
@@ -1788,6 +1814,7 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, · 14 unmodified lines
17881814 return 0;
17891815 }
17901816
1817+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
17911818 static int
17921819 cifs_posix_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode,
17931820 const char *full_path, struct cifs_sb_info *cifs_sb,
@@ -1850,6 +1877,7 @@ posix_mkdir_get_info: · 56 unmodified lines
18501877 xid);
18511878 goto posix_mkdir_out;
18521879 }
1880+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
18531881
18541882 int cifs_mkdir(struct user_namespace *mnt_userns, struct inode *inode,
18551883 struct dentry *direntry, umode_t mode)
@@ -1892,6 +1920,7 @@ int cifs_mkdir(struct user_namespace *mnt_userns, struct inode *inode, · 36 unmodified lines
18921920 goto mkdir_out;
18931921 }
18941922
1923+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
18951924 if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
18961925 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
18971926 rc = cifs_posix_mkdir(inode, direntry, mode, full_path, cifs_sb,
@@ -1899,6 +1928,7 @@ int cifs_mkdir(struct user_namespace *mnt_userns, struct inode *inode, · 1 unmodified line
18991928 if (rc != -EOPNOTSUPP)
19001929 goto mkdir_out;
19011930 }
1931+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
19021932
19031933 if (!server->ops->mkdir) {
19041934 rc = -ENOSYS;
@@ -2015,9 +2045,12 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, · 110 unmodified lines
20152045 struct tcon_link *tlink;
20162046 struct cifs_tcon *tcon;
20172047 struct TCP_Server_Info *server;
2048+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
20182049 struct cifs_fid fid;
20192050 struct cifs_open_parms oparms;
2020− int oplock, rc;
2051+ int oplock;
2052+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
2053+ int rc;
20212054
20222055 tlink = cifs_sb_tlink(cifs_sb);
20232056 if (IS_ERR(tlink))
@@ -2043,6 +2076,7 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, · 19 unmodified lines
20432076 if (server->vals->protocol_id != 0)
20442077 goto do_rename_exit;
20452078
2079+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
20462080 /* open-file renames don't work across directories */
20472081 if (to_dentry->d_parent != from_dentry->d_parent)
20482082 goto do_rename_exit;
@@ -2064,6 +2098,7 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, · 15 unmodified lines
20642098 cifs_sb->local_nls, cifs_remap(cifs_sb));
20652099 CIFSSMBClose(xid, tcon, fid.netfid);
20662100 }
2101+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
20672102 do_rename_exit:
20682103 if (rc == 0)
20692104 d_move(from_dentry, to_dentry);
@@ -2081,11 +2116,13 @@ cifs_rename2(struct user_namespace *mnt_userns, struct inode *source_dir, · 11 unmodified lines
20812116 struct cifs_sb_info *cifs_sb;
20822117 struct tcon_link *tlink;
20832118 struct cifs_tcon *tcon;
2084− FILE_UNIX_BASIC_INFO *info_buf_source = NULL;
2085− FILE_UNIX_BASIC_INFO *info_buf_target;
20862119 unsigned int xid;
20872120 int rc, tmprc;
20882121 int retry_count = 0;
2122+ FILE_UNIX_BASIC_INFO *info_buf_source = NULL;
2123+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
2124+ FILE_UNIX_BASIC_INFO *info_buf_target;
2125+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
20892126
20902127 if (flags & ~RENAME_NOREPLACE)
20912128 return -EINVAL;
@@ -2139,6 +2176,7 @@ cifs_rename2(struct user_namespace *mnt_userns, struct inode *source_dir, · 47 unmodified lines
21392176 if (flags & RENAME_NOREPLACE)
21402177 goto cifs_rename_exit;
21412178
2179+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
21422180 if (rc == -EEXIST && tcon->unix_ext) {
21432181 /*
21442182 * Are src and dst hardlinks of same inode? We can only tell
@@ -2178,6 +2216,8 @@ cifs_rename2(struct user_namespace *mnt_userns, struct inode *source_dir, · 33 unmodified lines
21782216 */
21792217
21802218 unlink_target:
2219+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
2220+
21812221 /* Try unlinking the target dentry if it's not negative */
21822222 if (d_really_is_positive(target_dentry) && (rc == -EACCES || rc == -EEXIST)) {
21832223 if (d_is_dir(target_dentry))
@@ -2337,14 +2377,18 @@ int cifs_revalidate_file_attr(struct file *filp) · 153 unmodified lines
23372377 {
23382378 int rc = 0;
23392379 struct dentry *dentry = file_dentry(filp);
2380+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
23402381 struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data;
2382+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
23412383
23422384 if (!cifs_dentry_needs_reval(dentry))
23432385 return rc;
23442386
2387+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
23452388 if (tlink_tcon(cfile->tlink)->unix_ext)
23462389 rc = cifs_get_file_info_unix(filp);
23472390 else
2391+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
23482392 rc = cifs_get_file_info(filp);
23492393
23502394 return rc;
@@ -2653,6 +2697,7 @@ set_size_out: · 302 unmodified lines
26532697 return rc;
26542698 }
26552699
2700+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
26562701 static int
26572702 cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
26582703 {
@@ -2800,6 +2845,7 @@ out: · 141 unmodified lines
28002845 free_xid(xid);
28012846 return rc;
28022847 }
2848+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
28032849
28042850 static int
28052851 cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
@@ -2995,16 +3041,20 @@ cifs_setattr(struct user_namespace *mnt_userns, struct dentry *direntry, · 189 unmodified lines
29953041 struct iattr *attrs)
29963042 {
29973043 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
2998− struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
29993044 int rc, retries = 0;
3045+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
3046+ struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
3047+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
30003048
30013049 if (unlikely(cifs_forced_shutdown(cifs_sb)))
30023050 return -EIO;
30033051
30043052 do {
3053+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
30053054 if (pTcon->unix_ext)
30063055 rc = cifs_setattr_unix(direntry, attrs);
30073056 else
3057+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
30083058 rc = cifs_setattr_nounix(direntry, attrs);
30093059 retries++;
30103060 } while (is_retryable_error(rc) && retries < 2);
fs/cifs/ioctl.c+2−0
@@ -333,6 +333,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) · 332 unmodified lines
333333 tcon = tlink_tcon(pSMBFile->tlink);
334334 caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
335335 #ifdef CONFIG_CIFS_POSIX
336+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
336337 if (CIFS_UNIX_EXTATTR_CAP & caps) {
337338 __u64 ExtAttrMask = 0;
338339 rc = CIFSGetExtAttr(xid, tcon,
@@ -345,6 +346,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) · 6 unmodified lines
345346 if (rc != EOPNOTSUPP)
346347 break;
347348 }
349+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
348350 #endif /* CONFIG_CIFS_POSIX */
349351 rc = 0;
350352 if (CIFS_I(inode)->cifsAttrs & ATTR_COMPRESSED) {
fs/cifs/link.c+8−0
@@ -286,6 +286,7 @@ out: · 285 unmodified lines
286286 return rc;
287287 }
288288
289+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
289290 /*
290291 * SMB 1.0 Protocol specific functions
291292 */
@@ -368,6 +369,7 @@ cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, · 76 unmodified lines
368369 CIFSSMBClose(xid, tcon, fid.netfid);
369370 return rc;
370371 }
372+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
371373
372374 /*
373375 * SMB 2.1/SMB3 Protocol specific functions
@@ -532,11 +534,15 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode, · 158 unmodified lines
532534 goto cifs_hl_exit;
533535 }
534536
537+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
535538 if (tcon->unix_ext)
536539 rc = CIFSUnixCreateHardLink(xid, tcon, from_name, to_name,
537540 cifs_sb->local_nls,
538541 cifs_remap(cifs_sb));
539542 else {
543+#else
544+ {
545+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
540546 server = tcon->ses->server;
541547 if (!server->ops->create_hardlink) {
542548 rc = -ENOSYS;
@@ -704,10 +710,12 @@ cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode, · 161 unmodified lines
704710 /* BB what if DFS and this volume is on different share? BB */
705711 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
706712 rc = create_mf_symlink(xid, pTcon, cifs_sb, full_path, symname);
713+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
707714 else if (pTcon->unix_ext)
708715 rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
709716 cifs_sb->local_nls,
710717 cifs_remap(cifs_sb));
718+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
711719 /* else
712720 rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,
713721 cifs_sb_target->local_nls); */
fs/cifs/misc.c+13−20
@@ -69,6 +69,7 @@ sesInfoAlloc(void) · 68 unmodified lines
6969 ret_buf = kzalloc(sizeof(struct cifs_ses), GFP_KERNEL);
7070 if (ret_buf) {
7171 atomic_inc(&sesInfoAllocCount);
72+ spin_lock_init(&ret_buf->ses_lock);
7273 ret_buf->ses_status = SES_NEW;
7374 ++ret_buf->ses_count;
7475 INIT_LIST_HEAD(&ret_buf->smb_ses_list);
@@ -126,6 +127,7 @@ tconInfoAlloc(void) · 51 unmodified lines
126127 atomic_inc(&tconInfoAllocCount);
127128 ret_buf->status = TID_NEW;
128129 ++ret_buf->tc_count;
130+ spin_lock_init(&ret_buf->tc_lock);
129131 INIT_LIST_HEAD(&ret_buf->openFileList);
130132 INIT_LIST_HEAD(&ret_buf->tcon_list);
131133 spin_lock_init(&ret_buf->open_file_lock);
@@ -172,9 +174,9 @@ cifs_buf_get(void) · 40 unmodified lines
172174 /* clear the first few header bytes */
173175 /* for most paths, more is cleared in header_assemble */
174176 memset(ret_buf, 0, buf_size + 3);
175− atomic_inc(&bufAllocCount);
177+ atomic_inc(&buf_alloc_count);
176178 #ifdef CONFIG_CIFS_STATS2
177− atomic_inc(&totBufAllocCount);
179+ atomic_inc(&total_buf_alloc_count);
178180 #endif /* CONFIG_CIFS_STATS2 */
179181
180182 return ret_buf;
@@ -189,7 +191,7 @@ cifs_buf_release(void *buf_to_free) · 8 unmodified lines
189191 }
190192 mempool_free(buf_to_free, cifs_req_poolp);
191193
192− atomic_dec(&bufAllocCount);
194+ atomic_dec(&buf_alloc_count);
193195 return;
194196 }
195197
@@ -205,9 +207,9 @@ cifs_small_buf_get(void) · 9 unmodified lines
205207 ret_buf = mempool_alloc(cifs_sm_req_poolp, GFP_NOFS);
206208 /* No need to clear memory here, cleared in header assemble */
207209 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
208− atomic_inc(&smBufAllocCount);
210+ atomic_inc(&small_buf_alloc_count);
209211 #ifdef CONFIG_CIFS_STATS2
210− atomic_inc(&totSmBufAllocCount);
212+ atomic_inc(&total_small_buf_alloc_count);
211213 #endif /* CONFIG_CIFS_STATS2 */
212214
213215 return ret_buf;
@@ -223,7 +225,7 @@ cifs_small_buf_release(void *buf_to_free) · 9 unmodified lines
223225 }
224226 mempool_free(buf_to_free, cifs_sm_req_poolp);
225227
226− atomic_dec(&smBufAllocCount);
228+ atomic_dec(&small_buf_alloc_count);
227229 return;
228230 }
229231
@@ -400,7 +402,6 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv) · 170 unmodified lines
400402 {
401403 struct smb_hdr *buf = (struct smb_hdr *)buffer;
402404 struct smb_com_lock_req *pSMB = (struct smb_com_lock_req *)buf;
403− struct list_head *tmp, *tmp1, *tmp2;
404405 struct cifs_ses *ses;
405406 struct cifs_tcon *tcon;
406407 struct cifsInodeInfo *pCifsInode;
@@ -467,18 +468,14 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv) · 60 unmodified lines
467468
468469 /* look up tcon based on tid & uid */
469470 spin_lock(&cifs_tcp_ses_lock);
470− list_for_each(tmp, &srv->smb_ses_list) {
471− ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
472− list_for_each(tmp1, &ses->tcon_list) {
473− tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
471+ list_for_each_entry(ses, &srv->smb_ses_list, smb_ses_list) {
472+ list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
474473 if (tcon->tid != buf->Tid)
475474 continue;
476475
477476 cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks);
478477 spin_lock(&tcon->open_file_lock);
479− list_for_each(tmp2, &tcon->openFileList) {
480− netfile = list_entry(tmp2, struct cifsFileInfo,
481− tlist);
478+ list_for_each_entry(netfile, &tcon->openFileList, tlist) {
482479 if (pSMB->Fid != netfile->fid.netfid)
483480 continue;
484481
@@ -763,14 +760,12 @@ void · 278 unmodified lines
763760 cifs_close_all_deferred_files(struct cifs_tcon *tcon)
764761 {
765762 struct cifsFileInfo *cfile;
766− struct list_head *tmp;
767763 struct file_list *tmp_list, *tmp_next_list;
768764 struct list_head file_head;
769765
770766 INIT_LIST_HEAD(&file_head);
771767 spin_lock(&tcon->open_file_lock);
772− list_for_each(tmp, &tcon->openFileList) {
773− cfile = list_entry(tmp, struct cifsFileInfo, tlist);
768+ list_for_each_entry(cfile, &tcon->openFileList, tlist) {
774769 if (delayed_work_pending(&cfile->deferred)) {
775770 if (cancel_delayed_work(&cfile->deferred)) {
776771 tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
@@ -793,7 +788,6 @@ void · 16 unmodified lines
793788 cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
794789 {
795790 struct cifsFileInfo *cfile;
796− struct list_head *tmp;
797791 struct file_list *tmp_list, *tmp_next_list;
798792 struct list_head file_head;
799793 void *page;
@@ -802,8 +796,7 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path) · 2 unmodified lines
802796 INIT_LIST_HEAD(&file_head);
803797 page = alloc_dentry_path();
804798 spin_lock(&tcon->open_file_lock);
805− list_for_each(tmp, &tcon->openFileList) {
806− cfile = list_entry(tmp, struct cifsFileInfo, tlist);
799+ list_for_each_entry(cfile, &tcon->openFileList, tlist) {
807800 full_path = build_path_from_dentry(cfile->dentry, page);
808801 if (strstr(full_path, path)) {
809802 if (delayed_work_pending(&cfile->deferred)) {
fs/cifs/netmisc.c+1−1
@@ -911,7 +911,7 @@ map_and_check_smb_error(struct mid_q_entry *mid, bool logErr) · 910 unmodified lines
911911 unsigned int
912912 smbCalcSize(void *buf, struct TCP_Server_Info *server)
913913 {
914− struct smb_hdr *ptr = (struct smb_hdr *)buf;
914+ struct smb_hdr *ptr = buf;
915915 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
916916 2 /* size of the bcc field */ + get_bcc(ptr));
917917 }
fs/cifs/sess.c+4−1
@@ -499,6 +499,7 @@ out: · 498 unmodified lines
499499 return rc;
500500 }
501501
502+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
502503 static __u32 cifs_ssetup_hdr(struct cifs_ses *ses,
503504 struct TCP_Server_Info *server,
504505 SESSION_SETUP_ANDX *pSMB)
@@ -591,7 +592,6 @@ static void unicode_domain_string(char **pbcc_area, struct cifs_ses *ses, · 86 unmodified lines
591592 *pbcc_area = bcc_ptr;
592593 }
593594
594−
595595 static void unicode_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
596596 const struct nls_table *nls_cp)
597597 {
@@ -753,6 +753,7 @@ static void decode_ascii_ssetup(char **pbcc_area, __u16 bleft, · 155 unmodified lines
753753 for it later, but it is not very important */
754754 cifs_dbg(FYI, "ascii: bytes left %d\n", bleft);
755755 }
756+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
756757
757758 int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
758759 struct cifs_ses *ses)
@@ -1170,6 +1171,7 @@ struct sess_data { · 411 unmodified lines
11701171 struct kvec iov[3];
11711172 };
11721173
1174+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
11731175 static int
11741176 sess_alloc_buffer(struct sess_data *sess_data, int wct)
11751177 {
@@ -1846,3 +1848,4 @@ out: · 670 unmodified lines
18461848 kfree(sess_data);
18471849 return rc;
18481850 }
1851+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
fs/cifs/smb1ops.c+5−5
@@ -92,17 +92,17 @@ cifs_find_mid(struct TCP_Server_Info *server, char *buffer) · 91 unmodified lines
9292 struct smb_hdr *buf = (struct smb_hdr *)buffer;
9393 struct mid_q_entry *mid;
9494
95− spin_lock(&GlobalMid_Lock);
95+ spin_lock(&server->mid_lock);
9696 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
9797 if (compare_mid(mid->mid, buf) &&
9898 mid->mid_state == MID_REQUEST_SUBMITTED &&
9999 le16_to_cpu(mid->command) == buf->Command) {
100100 kref_get(&mid->refcount);
101− spin_unlock(&GlobalMid_Lock);
101+ spin_unlock(&server->mid_lock);
102102 return mid;
103103 }
104104 }
105− spin_unlock(&GlobalMid_Lock);
105+ spin_unlock(&server->mid_lock);
106106 return NULL;
107107 }
108108
@@ -166,7 +166,7 @@ cifs_get_next_mid(struct TCP_Server_Info *server) · 57 unmodified lines
166166 __u16 last_mid, cur_mid;
167167 bool collision, reconnect = false;
168168
169− spin_lock(&GlobalMid_Lock);
169+ spin_lock(&server->mid_lock);
170170
171171 /* mid is 16 bit only for CIFS/SMB */
172172 cur_mid = (__u16)((server->CurrentMid) & 0xffff);
@@ -225,7 +225,7 @@ cifs_get_next_mid(struct TCP_Server_Info *server) · 52 unmodified lines
225225 }
226226 cur_mid++;
227227 }
228− spin_unlock(&GlobalMid_Lock);
228+ spin_unlock(&server->mid_lock);
229229
230230 if (reconnect) {
231231 cifs_signal_cifsd_for_reconnect(server, false);
fs/cifs/smb2misc.c+29−20
@@ -132,15 +132,15 @@ static __u32 get_neg_ctxt_len(struct smb2_hdr *hdr, __u32 len, · 131 unmodified lines
132132 }
133133
134134 int
135−smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *srvr)
135+smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *server)
136136 {
137137 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
138138 struct smb2_pdu *pdu = (struct smb2_pdu *)shdr;
139− __u64 mid;
140− __u32 clc_len; /* calculated length */
141− int command;
142− int pdu_size = sizeof(struct smb2_pdu);
143139 int hdr_size = sizeof(struct smb2_hdr);
140+ int pdu_size = sizeof(struct smb2_pdu);
141+ int command;
142+ __u32 calc_len; /* calculated length */
143+ __u64 mid;
144144
145145 /*
146146 * Add function to do table lookup of StructureSize by command
@@ -154,7 +154,7 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *srvr) · 7 unmodified lines
154154
155155 /* decrypt frame now that it is completely read in */
156156 spin_lock(&cifs_tcp_ses_lock);
157− list_for_each_entry(iter, &srvr->smb_ses_list, smb_ses_list) {
157+ list_for_each_entry(iter, &server->smb_ses_list, smb_ses_list) {
158158 if (iter->Suid == le64_to_cpu(thdr->SessionId)) {
159159 ses = iter;
160160 break;
@@ -221,30 +221,33 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *srvr) · 60 unmodified lines
221221 }
222222 }
223223
224− clc_len = smb2_calc_size(buf, srvr);
224+ calc_len = smb2_calc_size(buf, server);
225+
226+ /* For SMB2_IOCTL, OutputOffset and OutputLength are optional, so might
227+ * be 0, and not a real miscalculation */
228+ if (command == SMB2_IOCTL_HE && calc_len == 0)
229+ return 0;
225230
226− if (shdr->Command == SMB2_NEGOTIATE)
227− clc_len += get_neg_ctxt_len(shdr, len, clc_len);
231+ if (command == SMB2_NEGOTIATE_HE)
232+ calc_len += get_neg_ctxt_len(shdr, len, calc_len);
228233
229− if (len != clc_len) {
230− cifs_dbg(FYI, "Calculated size %u length %u mismatch mid %llu\n",
231− clc_len, len, mid);
234+ if (len != calc_len) {
232235 /* create failed on symlink */
233236 if (command == SMB2_CREATE_HE &&
234237 shdr->Status == STATUS_STOPPED_ON_SYMLINK)
235238 return 0;
236239 /* Windows 7 server returns 24 bytes more */
237− if (clc_len + 24 == len && command == SMB2_OPLOCK_BREAK_HE)
240+ if (calc_len + 24 == len && command == SMB2_OPLOCK_BREAK_HE)
238241 return 0;
239242 /* server can return one byte more due to implied bcc[0] */
240− if (clc_len == len + 1)
243+ if (calc_len == len + 1)
241244 return 0;
242245
243246 /*
244247 * Some windows servers (win2016) will pad also the final
245248 * PDU in a compound to 8 bytes.
246249 */
247− if (((clc_len + 7) & ~7) == len)
250+ if (((calc_len + 7) & ~7) == len)
248251 return 0;
249252
250253 /*
@@ -253,12 +256,18 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *srvr) · 2 unmodified lines
253256 * SMB2/SMB3 frame length (header + smb2 response specific data)
254257 * Some windows servers also pad up to 8 bytes when compounding.
255258 */
256− if (clc_len < len)
259+ if (calc_len < len)
257260 return 0;
258261
259− pr_warn_once(
260− "srv rsp too short, len %d not %d. cmd:%d mid:%llu\n",
261− len, clc_len, command, mid);
262+ /* Only log a message if len was really miscalculated */
263+ if (unlikely(cifsFYI))
264+ cifs_dbg(FYI, "Server response too short: calculated "
265+ "length %u doesn't match read length %u (cmd=%d, mid=%llu)\n",
266+ calc_len, len, command, mid);
267+ else
268+ pr_warn("Server response too short: calculated length "
269+ "%u doesn't match read length %u (cmd=%d, mid=%llu)\n",
270+ calc_len, len, command, mid);
262271
263272 return 1;
264273 }
@@ -402,7 +411,7 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *shdr) · 137 unmodified lines
402411 unsigned int
403412 smb2_calc_size(void *buf, struct TCP_Server_Info *srvr)
404413 {
405− struct smb2_pdu *pdu = (struct smb2_pdu *)buf;
414+ struct smb2_pdu *pdu = buf;
406415 struct smb2_hdr *shdr = &pdu->hdr;
407416 int offset; /* the offset from the beginning of SMB to data area */
408417 int data_length; /* the length of the variable length data area */
fs/cifs/smb2ops.c+32−29
@@ -126,13 +126,13 @@ smb2_add_credits(struct TCP_Server_Info *server, · 125 unmodified lines
126126 optype, scredits, add);
127127 }
128128
129− spin_lock(&cifs_tcp_ses_lock);
129+ spin_lock(&server->srv_lock);
130130 if (server->tcpStatus == CifsNeedReconnect
131131 || server->tcpStatus == CifsExiting) {
132− spin_unlock(&cifs_tcp_ses_lock);
132+ spin_unlock(&server->srv_lock);
133133 return;
134134 }
135− spin_unlock(&cifs_tcp_ses_lock);
135+ spin_unlock(&server->srv_lock);
136136
137137 switch (rc) {
138138 case -1:
@@ -218,12 +218,12 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, · 79 unmodified lines
218218 spin_lock(&server->req_lock);
219219 } else {
220220 spin_unlock(&server->req_lock);
221− spin_lock(&cifs_tcp_ses_lock);
221+ spin_lock(&server->srv_lock);
222222 if (server->tcpStatus == CifsExiting) {
223− spin_unlock(&cifs_tcp_ses_lock);
223+ spin_unlock(&server->srv_lock);
224224 return -ENOENT;
225225 }
226− spin_unlock(&cifs_tcp_ses_lock);
226+ spin_unlock(&server->srv_lock);
227227
228228 spin_lock(&server->req_lock);
229229 scredits = server->credits;
@@ -319,19 +319,19 @@ smb2_get_next_mid(struct TCP_Server_Info *server) · 89 unmodified lines
319319 {
320320 __u64 mid;
321321 /* for SMB2 we need the current value */
322− spin_lock(&GlobalMid_Lock);
322+ spin_lock(&server->mid_lock);
323323 mid = server->CurrentMid++;
324− spin_unlock(&GlobalMid_Lock);
324+ spin_unlock(&server->mid_lock);
325325 return mid;
326326 }
327327
328328 static void
329329 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
330330 {
331− spin_lock(&GlobalMid_Lock);
331+ spin_lock(&server->mid_lock);
332332 if (server->CurrentMid >= val)
333333 server->CurrentMid -= val;
334− spin_unlock(&GlobalMid_Lock);
334+ spin_unlock(&server->mid_lock);
335335 }
336336
337337 static struct mid_q_entry *
@@ -346,7 +346,7 @@ __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue) · 8 unmodified lines
346346 return NULL;
347347 }
348348
349− spin_lock(&GlobalMid_Lock);
349+ spin_lock(&server->mid_lock);
350350 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
351351 if ((mid->mid == wire_mid) &&
352352 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
@@ -356,11 +356,11 @@ __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue) · 3 unmodified lines
356356 list_del_init(&mid->qhead);
357357 mid->mid_flags |= MID_DELETED;
358358 }
359− spin_unlock(&GlobalMid_Lock);
359+ spin_unlock(&server->mid_lock);
360360 return mid;
361361 }
362362 }
363− spin_unlock(&GlobalMid_Lock);
363+ spin_unlock(&server->mid_lock);
364364 return NULL;
365365 }
366366
@@ -403,9 +403,9 @@ smb2_negotiate(const unsigned int xid, · 36 unmodified lines
403403 {
404404 int rc;
405405
406− spin_lock(&GlobalMid_Lock);
406+ spin_lock(&server->mid_lock);
407407 server->CurrentMid = 0;
408− spin_unlock(&GlobalMid_Lock);
408+ spin_unlock(&server->mid_lock);
409409 rc = SMB2_negotiate(xid, ses, server);
410410 /* BB we probably don't need to retry with modern servers */
411411 if (rc == -EAGAIN)
@@ -1145,9 +1145,7 @@ move_smb2_ea_to_cifs(char *dst, size_t dst_size, · 733 unmodified lines
11451145 size_t name_len, value_len, user_name_len;
11461146
11471147 while (src_size > 0) {
1148− name = &src->ea_data[0];
11491148 name_len = (size_t)src->ea_name_length;
1150− value = &src->ea_data[src->ea_name_length + 1];
11511149 value_len = (size_t)le16_to_cpu(src->ea_value_length);
11521150
11531151 if (name_len == 0)
@@ -1159,6 +1157,9 @@ move_smb2_ea_to_cifs(char *dst, size_t dst_size, · 5 unmodified lines
11591157 goto out;
11601158 }
11611159
1160+ name = &src->ea_data[0];
1161+ value = &src->ea_data[src->ea_name_length + 1];
1162+
11621163 if (ea_name) {
11631164 if (ea_name_len == name_len &&
11641165 memcmp(ea_name, name, name_len) == 0) {
@@ -2574,7 +2575,6 @@ static void · 1409 unmodified lines
25742575 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
25752576 {
25762577 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2577− struct list_head *tmp, *tmp1;
25782578 struct cifs_ses *ses;
25792579 struct cifs_tcon *tcon;
25802580
@@ -2582,12 +2582,12 @@ smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server) · 1 unmodified line
25822582 return;
25832583
25842584 spin_lock(&cifs_tcp_ses_lock);
2585− list_for_each(tmp, &server->smb_ses_list) {
2586− ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
2587− list_for_each(tmp1, &ses->tcon_list) {
2588− tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
2585+ list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2586+ list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
25892587 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2588+ spin_lock(&tcon->tc_lock);
25902589 tcon->need_reconnect = true;
2590+ spin_unlock(&tcon->tc_lock);
25912591 spin_unlock(&cifs_tcp_ses_lock);
25922592 pr_warn_once("Server share %s deleted.\n",
25932593 tcon->treeName);
@@ -4563,9 +4563,11 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) · 1969 unmodified lines
45634563 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
45644564 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
45654565 if (ses->Suid == ses_id) {
4566+ spin_lock(&ses->ses_lock);
45664567 ses_enc_key = enc ? ses->smb3encryptionkey :
45674568 ses->smb3decryptionkey;
45684569 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4570+ spin_unlock(&ses->ses_lock);
45694571 spin_unlock(&cifs_tcp_ses_lock);
45704572 return 0;
45714573 }
@@ -5080,23 +5082,24 @@ static void smb2_decrypt_offload(struct work_struct *work) · 508 unmodified lines
50805082
50815083 mid->callback(mid);
50825084 } else {
5083− spin_lock(&cifs_tcp_ses_lock);
5084− spin_lock(&GlobalMid_Lock);
5085+ spin_lock(&dw->server->srv_lock);
50855086 if (dw->server->tcpStatus == CifsNeedReconnect) {
5087+ spin_lock(&dw->server->mid_lock);
50865088 mid->mid_state = MID_RETRY_NEEDED;
5087− spin_unlock(&GlobalMid_Lock);
5088− spin_unlock(&cifs_tcp_ses_lock);
5089+ spin_unlock(&dw->server->mid_lock);
5090+ spin_unlock(&dw->server->srv_lock);
50895091 mid->callback(mid);
50905092 } else {
5093+ spin_lock(&dw->server->mid_lock);
50915094 mid->mid_state = MID_REQUEST_SUBMITTED;
50925095 mid->mid_flags &= ~(MID_DELETED);
50935096 list_add_tail(&mid->qhead,
50945097 &dw->server->pending_mid_q);
5095− spin_unlock(&GlobalMid_Lock);
5096− spin_unlock(&cifs_tcp_ses_lock);
5098+ spin_unlock(&dw->server->mid_lock);
5099+ spin_unlock(&dw->server->srv_lock);
50975100 }
50985101 }
5099− cifs_mid_q_entry_release(mid);
5102+ release_mid(mid);
51005103 }
51015104
51025105 free_pages:
fs/cifs/smb2pdu.c+16−16
@@ -162,7 +162,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, · 161 unmodified lines
162162 if (smb2_command == SMB2_TREE_CONNECT || smb2_command == SMB2_IOCTL)
163163 return 0;
164164
165− spin_lock(&cifs_tcp_ses_lock);
165+ spin_lock(&tcon->tc_lock);
166166 if (tcon->status == TID_EXITING) {
167167 /*
168168 * only tree disconnect, open, and write,
@@ -172,13 +172,13 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, · 3 unmodified lines
172172 if ((smb2_command != SMB2_WRITE) &&
173173 (smb2_command != SMB2_CREATE) &&
174174 (smb2_command != SMB2_TREE_DISCONNECT)) {
175− spin_unlock(&cifs_tcp_ses_lock);
175+ spin_unlock(&tcon->tc_lock);
176176 cifs_dbg(FYI, "can not send cmd %d while umounting\n",
177177 smb2_command);
178178 return -ENODEV;
179179 }
180180 }
181− spin_unlock(&cifs_tcp_ses_lock);
181+ spin_unlock(&tcon->tc_lock);
182182 if ((!tcon->ses) || (tcon->ses->ses_status == SES_EXITING) ||
183183 (!tcon->ses->server) || !server)
184184 return -EIO;
@@ -217,12 +217,12 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, · 32 unmodified lines
217217 }
218218
219219 /* are we still trying to reconnect? */
220− spin_lock(&cifs_tcp_ses_lock);
220+ spin_lock(&server->srv_lock);
221221 if (server->tcpStatus != CifsNeedReconnect) {
222− spin_unlock(&cifs_tcp_ses_lock);
222+ spin_unlock(&server->srv_lock);
223223 break;
224224 }
225− spin_unlock(&cifs_tcp_ses_lock);
225+ spin_unlock(&server->srv_lock);
226226
227227 if (retries && --retries)
228228 continue;
@@ -256,13 +256,13 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, · 27 unmodified lines
256256 * and the server never sends an answer the socket will be closed
257257 * and tcpStatus set to reconnect.
258258 */
259− spin_lock(&cifs_tcp_ses_lock);
259+ spin_lock(&server->srv_lock);
260260 if (server->tcpStatus == CifsNeedReconnect) {
261− spin_unlock(&cifs_tcp_ses_lock);
261+ spin_unlock(&server->srv_lock);
262262 rc = -EHOSTDOWN;
263263 goto out;
264264 }
265− spin_unlock(&cifs_tcp_ses_lock);
265+ spin_unlock(&server->srv_lock);
266266
267267 /*
268268 * need to prevent multiple threads trying to simultaneously
@@ -354,7 +354,7 @@ fill_small_buf(__le16 smb2_command, struct cifs_tcon *tcon, · 85 unmodified lines
354354 void *buf,
355355 unsigned int *total_len)
356356 {
357− struct smb2_pdu *spdu = (struct smb2_pdu *)buf;
357+ struct smb2_pdu *spdu = buf;
358358 /* lookup word count ie StructureSize from table */
359359 __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_command)];
360360
@@ -3776,7 +3776,7 @@ smb2_echo_callback(struct mid_q_entry *mid) · 3415 unmodified lines
37763776 credits.instance = server->reconnect_instance;
37773777 }
37783778
3779− DeleteMidQEntry(mid);
3779+ release_mid(mid);
37803780 add_credits(server, &credits, CIFS_ECHO_OP);
37813781 }
37823782
@@ -3911,15 +3911,15 @@ SMB2_echo(struct TCP_Server_Info *server) · 128 unmodified lines
39113911
39123912 cifs_dbg(FYI, "In echo request for conn_id %lld\n", server->conn_id);
39133913
3914− spin_lock(&cifs_tcp_ses_lock);
3914+ spin_lock(&server->srv_lock);
39153915 if (server->ops->need_neg &&
39163916 server->ops->need_neg(server)) {
3917− spin_unlock(&cifs_tcp_ses_lock);
3917+ spin_unlock(&server->srv_lock);
39183918 /* No need to send echo on newly established connections */
39193919 mod_delayed_work(cifsiod_wq, &server->reconnect, 0);
39203920 return rc;
39213921 }
3922− spin_unlock(&cifs_tcp_ses_lock);
3922+ spin_unlock(&server->srv_lock);
39233923
39243924 rc = smb2_plain_req_init(SMB2_ECHO, NULL, server,
39253925 (void **)&req, &total_len);
@@ -4201,7 +4201,7 @@ smb2_readv_callback(struct mid_q_entry *mid) · 275 unmodified lines
42014201 rdata->offset, rdata->got_bytes);
42024202
42034203 queue_work(cifsiod_wq, &rdata->work);
4204− DeleteMidQEntry(mid);
4204+ release_mid(mid);
42054205 add_credits(server, &credits, 0);
42064206 }
42074207
@@ -4440,7 +4440,7 @@ smb2_writev_callback(struct mid_q_entry *mid) · 232 unmodified lines
44404440 wdata->offset, wdata->bytes);
44414441
44424442 queue_work(cifsiod_wq, &wdata->work);
4443− DeleteMidQEntry(mid);
4443+ release_mid(mid);
44444444 add_credits(server, &credits, 0);
44454445 }
44464446
fs/cifs/smb2transport.c+20−18
@@ -640,13 +640,13 @@ smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) · 639 unmodified lines
640640
641641 if (!is_signed)
642642 return 0;
643− spin_lock(&cifs_tcp_ses_lock);
643+ spin_lock(&server->srv_lock);
644644 if (server->ops->need_neg &&
645645 server->ops->need_neg(server)) {
646− spin_unlock(&cifs_tcp_ses_lock);
646+ spin_unlock(&server->srv_lock);
647647 return 0;
648648 }
649− spin_unlock(&cifs_tcp_ses_lock);
649+ spin_unlock(&server->srv_lock);
650650 if (!is_binding && !server->session_estab) {
651651 strncpy(shdr->Signature, "BSRSPYL", 8);
652652 return 0;
@@ -750,7 +750,7 @@ smb2_mid_entry_alloc(const struct smb2_hdr *shdr, · 97 unmodified lines
750750 temp->callback = cifs_wake_up_task;
751751 temp->callback_data = current;
752752
753− atomic_inc(&midCount);
753+ atomic_inc(&mid_count);
754754 temp->mid_state = MID_REQUEST_ALLOCATED;
755755 trace_smb3_cmd_enter(le32_to_cpu(shdr->Id.SyncId.TreeId),
756756 le64_to_cpu(shdr->SessionId),
@@ -762,28 +762,30 @@ static int · 5 unmodified lines
762762 smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,
763763 struct smb2_hdr *shdr, struct mid_q_entry **mid)
764764 {
765− spin_lock(&cifs_tcp_ses_lock);
765+ spin_lock(&server->srv_lock);
766766 if (server->tcpStatus == CifsExiting) {
767− spin_unlock(&cifs_tcp_ses_lock);
767+ spin_unlock(&server->srv_lock);
768768 return -ENOENT;
769769 }
770770
771771 if (server->tcpStatus == CifsNeedReconnect) {
772− spin_unlock(&cifs_tcp_ses_lock);
772+ spin_unlock(&server->srv_lock);
773773 cifs_dbg(FYI, "tcp session dead - return to caller to retry\n");
774774 return -EAGAIN;
775775 }
776776
777777 if (server->tcpStatus == CifsNeedNegotiate &&
778778 shdr->Command != SMB2_NEGOTIATE) {
779− spin_unlock(&cifs_tcp_ses_lock);
779+ spin_unlock(&server->srv_lock);
780780 return -EAGAIN;
781781 }
782+ spin_unlock(&server->srv_lock);
782783
784+ spin_lock(&ses->ses_lock);
783785 if (ses->ses_status == SES_NEW) {
784786 if ((shdr->Command != SMB2_SESSION_SETUP) &&
785787 (shdr->Command != SMB2_NEGOTIATE)) {
786− spin_unlock(&cifs_tcp_ses_lock);
788+ spin_unlock(&ses->ses_lock);
787789 return -EAGAIN;
788790 }
789791 /* else ok - we are setting up session */
@@ -791,19 +793,19 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server, · 1 unmodified line
791793
792794 if (ses->ses_status == SES_EXITING) {
793795 if (shdr->Command != SMB2_LOGOFF) {
794− spin_unlock(&cifs_tcp_ses_lock);
796+ spin_unlock(&ses->ses_lock);
795797 return -EAGAIN;
796798 }
797799 /* else ok - we are shutting down the session */
798800 }
799− spin_unlock(&cifs_tcp_ses_lock);
801+ spin_unlock(&ses->ses_lock);
800802
801803 *mid = smb2_mid_entry_alloc(shdr, server);
802804 if (*mid == NULL)
803805 return -ENOMEM;
804− spin_lock(&GlobalMid_Lock);
806+ spin_lock(&server->mid_lock);
805807 list_add_tail(&(*mid)->qhead, &server->pending_mid_q);
806− spin_unlock(&GlobalMid_Lock);
808+ spin_unlock(&server->mid_lock);
807809
808810 return 0;
809811 }
@@ -854,7 +856,7 @@ smb2_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *server, · 44 unmodified lines
854856 rc = smb2_sign_rqst(rqst, server);
855857 if (rc) {
856858 revert_current_mid_from_hdr(server, shdr);
857− cifs_delete_mid(mid);
859+ delete_mid(mid);
858860 return ERR_PTR(rc);
859861 }
860862
@@ -869,13 +871,13 @@ smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) · 8 unmodified lines
869871 (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
870872 struct mid_q_entry *mid;
871873
872− spin_lock(&cifs_tcp_ses_lock);
874+ spin_lock(&server->srv_lock);
873875 if (server->tcpStatus == CifsNeedNegotiate &&
874876 shdr->Command != SMB2_NEGOTIATE) {
875− spin_unlock(&cifs_tcp_ses_lock);
877+ spin_unlock(&server->srv_lock);
876878 return ERR_PTR(-EAGAIN);
877879 }
878− spin_unlock(&cifs_tcp_ses_lock);
880+ spin_unlock(&server->srv_lock);
879881
880882 smb2_seq_num_into_buf(server, shdr);
881883
@@ -888,7 +890,7 @@ smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) · 6 unmodified lines
888890 rc = smb2_sign_rqst(rqst, server);
889891 if (rc) {
890892 revert_current_mid_from_hdr(server, shdr);
891− DeleteMidQEntry(mid);
893+ release_mid(mid);
892894 return ERR_PTR(rc);
893895 }
894896
fs/cifs/transport.c+255−79
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <asm/processor.h>
2222 #include <linux/mempool.h>
2323 #include <linux/sched/signal.h>
24+#include <linux/task_io_accounting_ops.h>
2425 #include "cifspdu.h"
2526 #include "cifsglob.h"
2627 #include "cifsproto.h"
@@ -37,13 +38,13 @@ cifs_wake_up_task(struct mid_q_entry *mid) · 10 unmodified lines
3738 wake_up_process(mid->callback_data);
3839 }
3940
40−struct mid_q_entry *
41−AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
41+static struct mid_q_entry *
42+alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
4243 {
4344 struct mid_q_entry *temp;
4445
4546 if (server == NULL) {
46− cifs_dbg(VFS, "Null TCP session in AllocMidQEntry\n");
47+ cifs_dbg(VFS, "%s: null TCP session\n", __func__);
4748 return NULL;
4849 }
4950
@@ -68,12 +69,12 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) · 18 unmodified lines
6869 temp->callback = cifs_wake_up_task;
6970 temp->callback_data = current;
7071
71− atomic_inc(&midCount);
72+ atomic_inc(&mid_count);
7273 temp->mid_state = MID_REQUEST_ALLOCATED;
7374 return temp;
7475 }
7576
76−static void _cifs_mid_q_entry_release(struct kref *refcount)
77+static void __release_mid(struct kref *refcount)
7778 {
7879 struct mid_q_entry *midEntry =
7980 container_of(refcount, struct mid_q_entry, refcount);
@@ -91,7 +92,7 @@ static void _cifs_mid_q_entry_release(struct kref *refcount) · 11 unmodified lines
9192 server->ops->handle_cancelled_mid(midEntry, server);
9293
9394 midEntry->mid_state = MID_FREE;
94− atomic_dec(&midCount);
95+ atomic_dec(&mid_count);
9596 if (midEntry->large_buf)
9697 cifs_buf_release(midEntry->resp_buf);
9798 else
@@ -152,29 +153,26 @@ static void _cifs_mid_q_entry_release(struct kref *refcount) · 54 unmodified lines
152153 mempool_free(midEntry, cifs_mid_poolp);
153154 }
154155
155−void cifs_mid_q_entry_release(struct mid_q_entry *midEntry)
156+void release_mid(struct mid_q_entry *mid)
156157 {
157− spin_lock(&GlobalMid_Lock);
158− kref_put(&midEntry->refcount, _cifs_mid_q_entry_release);
159− spin_unlock(&GlobalMid_Lock);
160−}
158+ struct TCP_Server_Info *server = mid->server;
161159
162−void DeleteMidQEntry(struct mid_q_entry *midEntry)
163−{
164− cifs_mid_q_entry_release(midEntry);
160+ spin_lock(&server->mid_lock);
161+ kref_put(&mid->refcount, __release_mid);
162+ spin_unlock(&server->mid_lock);
165163 }
166164
167165 void
168−cifs_delete_mid(struct mid_q_entry *mid)
166+delete_mid(struct mid_q_entry *mid)
169167 {
170− spin_lock(&GlobalMid_Lock);
168+ spin_lock(&mid->server->mid_lock);
171169 if (!(mid->mid_flags & MID_DELETED)) {
172170 list_del_init(&mid->qhead);
173171 mid->mid_flags |= MID_DELETED;
174172 }
175− spin_unlock(&GlobalMid_Lock);
173+ spin_unlock(&mid->server->mid_lock);
176174
177− DeleteMidQEntry(mid);
175+ release_mid(mid);
178176 }
179177
180178 /*
@@ -577,12 +575,12 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, · 396 unmodified lines
577575 } else {
578576 spin_unlock(&server->req_lock);
579577
580− spin_lock(&cifs_tcp_ses_lock);
578+ spin_lock(&server->srv_lock);
581579 if (server->tcpStatus == CifsExiting) {
582− spin_unlock(&cifs_tcp_ses_lock);
580+ spin_unlock(&server->srv_lock);
583581 return -ENOENT;
584582 }
585− spin_unlock(&cifs_tcp_ses_lock);
583+ spin_unlock(&server->srv_lock);
586584
587585 /*
588586 * For normal commands, reserve the last MAX_COMPOUND
@@ -725,11 +723,11 @@ cifs_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, · 136 unmodified lines
725723 static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
726724 struct mid_q_entry **ppmidQ)
727725 {
728− spin_lock(&cifs_tcp_ses_lock);
726+ spin_lock(&ses->ses_lock);
729727 if (ses->ses_status == SES_NEW) {
730728 if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) &&
731729 (in_buf->Command != SMB_COM_NEGOTIATE)) {
732− spin_unlock(&cifs_tcp_ses_lock);
730+ spin_unlock(&ses->ses_lock);
733731 return -EAGAIN;
734732 }
735733 /* else ok - we are setting up session */
@@ -738,19 +736,19 @@ static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf, · 2 unmodified lines
738736 if (ses->ses_status == SES_EXITING) {
739737 /* check if SMB session is bad because we are setting it up */
740738 if (in_buf->Command != SMB_COM_LOGOFF_ANDX) {
741− spin_unlock(&cifs_tcp_ses_lock);
739+ spin_unlock(&ses->ses_lock);
742740 return -EAGAIN;
743741 }
744742 /* else ok - we are shutting down session */
745743 }
746− spin_unlock(&cifs_tcp_ses_lock);
744+ spin_unlock(&ses->ses_lock);
747745
748− *ppmidQ = AllocMidQEntry(in_buf, ses->server);
746+ *ppmidQ = alloc_mid(in_buf, ses->server);
749747 if (*ppmidQ == NULL)
750748 return -ENOMEM;
751− spin_lock(&GlobalMid_Lock);
749+ spin_lock(&ses->server->mid_lock);
752750 list_add_tail(&(*ppmidQ)->qhead, &ses->server->pending_mid_q);
753− spin_unlock(&GlobalMid_Lock);
751+ spin_unlock(&ses->server->mid_lock);
754752 return 0;
755753 }
756754
@@ -782,13 +780,13 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) · 25 unmodified lines
782780 if (server->sign)
783781 hdr->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
784782
785− mid = AllocMidQEntry(hdr, server);
783+ mid = alloc_mid(hdr, server);
786784 if (mid == NULL)
787785 return ERR_PTR(-ENOMEM);
788786
789787 rc = cifs_sign_rqst(rqst, server, &mid->sequence_number);
790788 if (rc) {
791− DeleteMidQEntry(mid);
789+ release_mid(mid);
792790 return ERR_PTR(rc);
793791 }
794792
@@ -849,9 +847,9 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, · 54 unmodified lines
849847 mid->mid_state = MID_REQUEST_SUBMITTED;
850848
851849 /* put it on the pending_mid_q */
852− spin_lock(&GlobalMid_Lock);
850+ spin_lock(&server->mid_lock);
853851 list_add_tail(&mid->qhead, &server->pending_mid_q);
854− spin_unlock(&GlobalMid_Lock);
852+ spin_unlock(&server->mid_lock);
855853
856854 /*
857855 * Need to store the time in mid before calling I/O. For call_async,
@@ -865,7 +863,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, · 7 unmodified lines
865863 if (rc < 0) {
866864 revert_current_mid(server, mid->credits);
867865 server->sequence_number -= 2;
868− cifs_delete_mid(mid);
866+ delete_mid(mid);
869867 }
870868
871869 cifs_server_unlock(server);
@@ -912,10 +910,10 @@ cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server) · 40 unmodified lines
912910 cifs_dbg(FYI, "%s: cmd=%d mid=%llu state=%d\n",
913911 __func__, le16_to_cpu(mid->command), mid->mid, mid->mid_state);
914912
915− spin_lock(&GlobalMid_Lock);
913+ spin_lock(&server->mid_lock);
916914 switch (mid->mid_state) {
917915 case MID_RESPONSE_RECEIVED:
918− spin_unlock(&GlobalMid_Lock);
916+ spin_unlock(&server->mid_lock);
919917 return rc;
920918 case MID_RETRY_NEEDED:
921919 rc = -EAGAIN;
@@ -935,9 +933,9 @@ cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server) · 13 unmodified lines
935933 __func__, mid->mid, mid->mid_state);
936934 rc = -EIO;
937935 }
938− spin_unlock(&GlobalMid_Lock);
936+ spin_unlock(&server->mid_lock);
939937
940− DeleteMidQEntry(mid);
938+ release_mid(mid);
941939 return rc;
942940 }
943941
@@ -997,7 +995,7 @@ cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored, · 53 unmodified lines
997995 return ERR_PTR(rc);
998996 rc = cifs_sign_rqst(rqst, ses->server, &mid->sequence_number);
999997 if (rc) {
1000− cifs_delete_mid(mid);
998+ delete_mid(mid);
1001999 return ERR_PTR(rc);
10021000 }
10031001 return mid;
@@ -1026,7 +1024,7 @@ static void · 22 unmodified lines
10261024 cifs_cancelled_callback(struct mid_q_entry *mid)
10271025 {
10281026 cifs_compound_callback(mid);
1029− DeleteMidQEntry(mid);
1027+ release_mid(mid);
10301028 }
10311029
10321030 /*
@@ -1078,12 +1076,12 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · 45 unmodified lines
10781076 return -EIO;
10791077 }
10801078
1081− spin_lock(&cifs_tcp_ses_lock);
1079+ spin_lock(&server->srv_lock);
10821080 if (server->tcpStatus == CifsExiting) {
1083− spin_unlock(&cifs_tcp_ses_lock);
1081+ spin_unlock(&server->srv_lock);
10841082 return -ENOENT;
10851083 }
1086− spin_unlock(&cifs_tcp_ses_lock);
1084+ spin_unlock(&server->srv_lock);
10871085
10881086 /*
10891087 * Wait for all the requests to become available.
@@ -1130,7 +1128,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · 40 unmodified lines
11301128 if (IS_ERR(midQ[i])) {
11311129 revert_current_mid(server, i);
11321130 for (j = 0; j < i; j++)
1133− cifs_delete_mid(midQ[j]);
1131+ delete_mid(midQ[j]);
11341132 cifs_server_unlock(server);
11351133
11361134 /* Update # of requests on wire to server */
@@ -1186,17 +1184,17 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · 49 unmodified lines
11861184 /*
11871185 * Compounding is never used during session establish.
11881186 */
1189− spin_lock(&cifs_tcp_ses_lock);
1187+ spin_lock(&ses->ses_lock);
11901188 if ((ses->ses_status == SES_NEW) || (optype & CIFS_NEG_OP) || (optype & CIFS_SESS_OP)) {
1191− spin_unlock(&cifs_tcp_ses_lock);
1189+ spin_unlock(&ses->ses_lock);
11921190
11931191 cifs_server_lock(server);
11941192 smb311_update_preauth_hash(ses, server, rqst[0].rq_iov, rqst[0].rq_nvec);
11951193 cifs_server_unlock(server);
11961194
1197− spin_lock(&cifs_tcp_ses_lock);
1195+ spin_lock(&ses->ses_lock);
11981196 }
1199− spin_unlock(&cifs_tcp_ses_lock);
1197+ spin_unlock(&ses->ses_lock);
12001198
12011199 for (i = 0; i < num_rqst; i++) {
12021200 rc = wait_for_response(server, midQ[i]);
@@ -1208,14 +1206,14 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · 5 unmodified lines
12081206 cifs_server_dbg(FYI, "Cancelling wait for mid %llu cmd: %d\n",
12091207 midQ[i]->mid, le16_to_cpu(midQ[i]->command));
12101208 send_cancel(server, &rqst[i], midQ[i]);
1211− spin_lock(&GlobalMid_Lock);
1209+ spin_lock(&server->mid_lock);
12121210 midQ[i]->mid_flags |= MID_WAIT_CANCELLED;
12131211 if (midQ[i]->mid_state == MID_REQUEST_SUBMITTED) {
12141212 midQ[i]->callback = cifs_cancelled_callback;
12151213 cancelled_mid[i] = true;
12161214 credits[i].value = 0;
12171215 }
1218− spin_unlock(&GlobalMid_Lock);
1216+ spin_unlock(&server->mid_lock);
12191217 }
12201218 }
12211219
@@ -1250,7 +1248,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · 28 unmodified lines
12501248 rc = server->ops->check_receive(midQ[i], server,
12511249 flags & CIFS_LOG_ERROR);
12521250
1253− /* mark it so buf will not be freed by cifs_delete_mid */
1251+ /* mark it so buf will not be freed by delete_mid */
12541252 if ((flags & CIFS_NO_RSP_BUF) == 0)
12551253 midQ[i]->resp_buf = NULL;
12561254
@@ -1259,19 +1257,19 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · 2 unmodified lines
12591257 /*
12601258 * Compounding is never used during session establish.
12611259 */
1262− spin_lock(&cifs_tcp_ses_lock);
1260+ spin_lock(&ses->ses_lock);
12631261 if ((ses->ses_status == SES_NEW) || (optype & CIFS_NEG_OP) || (optype & CIFS_SESS_OP)) {
12641262 struct kvec iov = {
12651263 .iov_base = resp_iov[0].iov_base,
12661264 .iov_len = resp_iov[0].iov_len
12671265 };
1268− spin_unlock(&cifs_tcp_ses_lock);
1266+ spin_unlock(&ses->ses_lock);
12691267 cifs_server_lock(server);
12701268 smb311_update_preauth_hash(ses, server, &iov, 1);
12711269 cifs_server_unlock(server);
1272− spin_lock(&cifs_tcp_ses_lock);
1270+ spin_lock(&ses->ses_lock);
12731271 }
1274− spin_unlock(&cifs_tcp_ses_lock);
1272+ spin_unlock(&ses->ses_lock);
12751273
12761274 out:
12771275 /*
@@ -1282,7 +1280,7 @@ out: · 4 unmodified lines
12821280 */
12831281 for (i = 0; i < num_rqst; i++) {
12841282 if (!cancelled_mid[i])
1285− cifs_delete_mid(midQ[i]);
1283+ delete_mid(midQ[i]);
12861284 }
12871285
12881286 return rc;
@@ -1360,12 +1358,12 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, · 71 unmodified lines
13601358 return -EIO;
13611359 }
13621360
1363− spin_lock(&cifs_tcp_ses_lock);
1361+ spin_lock(&server->srv_lock);
13641362 if (server->tcpStatus == CifsExiting) {
1365− spin_unlock(&cifs_tcp_ses_lock);
1363+ spin_unlock(&server->srv_lock);
13661364 return -ENOENT;
13671365 }
1368− spin_unlock(&cifs_tcp_ses_lock);
1366+ spin_unlock(&server->srv_lock);
13691367
13701368 /* Ensure that we do not send more than 50 overlapping requests
13711369 to the same server. We may make this configurable later or
@@ -1419,15 +1417,15 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, · 47 unmodified lines
14191417 rc = wait_for_response(server, midQ);
14201418 if (rc != 0) {
14211419 send_cancel(server, &rqst, midQ);
1422− spin_lock(&GlobalMid_Lock);
1420+ spin_lock(&server->mid_lock);
14231421 if (midQ->mid_state == MID_REQUEST_SUBMITTED) {
14241422 /* no longer considered to be "in-flight" */
1425− midQ->callback = DeleteMidQEntry;
1426− spin_unlock(&GlobalMid_Lock);
1423+ midQ->callback = release_mid;
1424+ spin_unlock(&server->mid_lock);
14271425 add_credits(server, &credits, 0);
14281426 return rc;
14291427 }
1430− spin_unlock(&GlobalMid_Lock);
1428+ spin_unlock(&server->mid_lock);
14311429 }
14321430
14331431 rc = cifs_sync_mid_result(midQ, server);
@@ -1447,7 +1445,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, · 13 unmodified lines
14471445 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4);
14481446 rc = cifs_check_receive(midQ, server, 0);
14491447 out:
1450− cifs_delete_mid(midQ);
1448+ delete_mid(midQ);
14511449 add_credits(server, &credits, 0);
14521450
14531451 return rc;
@@ -1505,12 +1503,12 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, · 51 unmodified lines
15051503 return -EIO;
15061504 }
15071505
1508− spin_lock(&cifs_tcp_ses_lock);
1506+ spin_lock(&server->srv_lock);
15091507 if (server->tcpStatus == CifsExiting) {
1510− spin_unlock(&cifs_tcp_ses_lock);
1508+ spin_unlock(&server->srv_lock);
15111509 return -ENOENT;
15121510 }
1513− spin_unlock(&cifs_tcp_ses_lock);
1511+ spin_unlock(&server->srv_lock);
15141512
15151513 /* Ensure that we do not send more than 50 overlapping requests
15161514 to the same server. We may make this configurable later or
@@ -1540,7 +1538,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, · 23 unmodified lines
15401538
15411539 rc = cifs_sign_smb(in_buf, server, &midQ->sequence_number);
15421540 if (rc) {
1543− cifs_delete_mid(midQ);
1541+ delete_mid(midQ);
15441542 cifs_server_unlock(server);
15451543 return rc;
15461544 }
@@ -1557,7 +1555,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, · 10 unmodified lines
15571555 cifs_server_unlock(server);
15581556
15591557 if (rc < 0) {
1560− cifs_delete_mid(midQ);
1558+ delete_mid(midQ);
15611559 return rc;
15621560 }
15631561
@@ -1568,19 +1566,19 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, · 4 unmodified lines
15681566 (server->tcpStatus != CifsNew)));
15691567
15701568 /* Were we interrupted by a signal ? */
1571− spin_lock(&cifs_tcp_ses_lock);
1569+ spin_lock(&server->srv_lock);
15721570 if ((rc == -ERESTARTSYS) &&
15731571 (midQ->mid_state == MID_REQUEST_SUBMITTED) &&
15741572 ((server->tcpStatus == CifsGood) ||
15751573 (server->tcpStatus == CifsNew))) {
1576− spin_unlock(&cifs_tcp_ses_lock);
1574+ spin_unlock(&server->srv_lock);
15771575
15781576 if (in_buf->Command == SMB_COM_TRANSACTION2) {
15791577 /* POSIX lock. We send a NT_CANCEL SMB to cause the
15801578 blocking lock to return. */
15811579 rc = send_cancel(server, &rqst, midQ);
15821580 if (rc) {
1583− cifs_delete_mid(midQ);
1581+ delete_mid(midQ);
15841582 return rc;
15851583 }
15861584 } else {
@@ -1592,7 +1590,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, · 5 unmodified lines
15921590 /* If we get -ENOLCK back the lock may have
15931591 already been removed. Don't exit in this case. */
15941592 if (rc && rc != -ENOLCK) {
1595− cifs_delete_mid(midQ);
1593+ delete_mid(midQ);
15961594 return rc;
15971595 }
15981596 }
@@ -1600,21 +1598,21 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, · 1 unmodified line
16001598 rc = wait_for_response(server, midQ);
16011599 if (rc) {
16021600 send_cancel(server, &rqst, midQ);
1603− spin_lock(&GlobalMid_Lock);
1601+ spin_lock(&server->mid_lock);
16041602 if (midQ->mid_state == MID_REQUEST_SUBMITTED) {
16051603 /* no longer considered to be "in-flight" */
1606− midQ->callback = DeleteMidQEntry;
1607− spin_unlock(&GlobalMid_Lock);
1604+ midQ->callback = release_mid;
1605+ spin_unlock(&server->mid_lock);
16081606 return rc;
16091607 }
1610− spin_unlock(&GlobalMid_Lock);
1608+ spin_unlock(&server->mid_lock);
16111609 }
16121610
16131611 /* We got the response - restart system call. */
16141612 rstart = 1;
1615− spin_lock(&cifs_tcp_ses_lock);
1613+ spin_lock(&server->srv_lock);
16161614 }
1617− spin_unlock(&cifs_tcp_ses_lock);
1615+ spin_unlock(&server->srv_lock);
16181616
16191617 rc = cifs_sync_mid_result(midQ, server);
16201618 if (rc != 0)
@@ -1631,8 +1629,186 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, · 10 unmodified lines
16311629 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4);
16321630 rc = cifs_check_receive(midQ, server, 0);
16331631 out:
1634− cifs_delete_mid(midQ);
1632+ delete_mid(midQ);
16351633 if (rstart && rc == -EACCES)
16361634 return -ERESTARTSYS;
16371635 return rc;
16381636 }
1637+
1638+/*
1639+ * Discard any remaining data in the current SMB. To do this, we borrow the
1640+ * current bigbuf.
1641+ */
1642+int
1643+cifs_discard_remaining_data(struct TCP_Server_Info *server)
1644+{
1645+ unsigned int rfclen = server->pdu_size;
1646+ int remaining = rfclen + server->vals->header_preamble_size -
1647+ server->total_read;
1648+
1649+ while (remaining > 0) {
1650+ int length;
1651+
1652+ length = cifs_discard_from_socket(server,
1653+ min_t(size_t, remaining,
1654+ CIFSMaxBufSize + MAX_HEADER_SIZE(server)));
1655+ if (length < 0)
1656+ return length;
1657+ server->total_read += length;
1658+ remaining -= length;
1659+ }
1660+
1661+ return 0;
1662+}
1663+
1664+static int
1665+__cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid,
1666+ bool malformed)
1667+{
1668+ int length;
1669+
1670+ length = cifs_discard_remaining_data(server);
1671+ dequeue_mid(mid, malformed);
1672+ mid->resp_buf = server->smallbuf;
1673+ server->smallbuf = NULL;
1674+ return length;
1675+}
1676+
1677+static int
1678+cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1679+{
1680+ struct cifs_readdata *rdata = mid->callback_data;
1681+
1682+ return __cifs_readv_discard(server, mid, rdata->result);
1683+}
1684+
1685+int
1686+cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1687+{
1688+ int length, len;
1689+ unsigned int data_offset, data_len;
1690+ struct cifs_readdata *rdata = mid->callback_data;
1691+ char *buf = server->smallbuf;
1692+ unsigned int buflen = server->pdu_size +
1693+ server->vals->header_preamble_size;
1694+ bool use_rdma_mr = false;
1695+
1696+ cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n",
1697+ __func__, mid->mid, rdata->offset, rdata->bytes);
1698+
1699+ /*
1700+ * read the rest of READ_RSP header (sans Data array), or whatever we
1701+ * can if there's not enough data. At this point, we've read down to
1702+ * the Mid.
1703+ */
1704+ len = min_t(unsigned int, buflen, server->vals->read_rsp_size) -
1705+ HEADER_SIZE(server) + 1;
1706+
1707+ length = cifs_read_from_socket(server,
1708+ buf + HEADER_SIZE(server) - 1, len);
1709+ if (length < 0)
1710+ return length;
1711+ server->total_read += length;
1712+
1713+ if (server->ops->is_session_expired &&
1714+ server->ops->is_session_expired(buf)) {
1715+ cifs_reconnect(server, true);
1716+ return -1;
1717+ }
1718+
1719+ if (server->ops->is_status_pending &&
1720+ server->ops->is_status_pending(buf, server)) {
1721+ cifs_discard_remaining_data(server);
1722+ return -1;
1723+ }
1724+
1725+ /* set up first two iov for signature check and to get credits */
1726+ rdata->iov[0].iov_base = buf;
1727+ rdata->iov[0].iov_len = server->vals->header_preamble_size;
1728+ rdata->iov[1].iov_base = buf + server->vals->header_preamble_size;
1729+ rdata->iov[1].iov_len =
1730+ server->total_read - server->vals->header_preamble_size;
1731+ cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
1732+ rdata->iov[0].iov_base, rdata->iov[0].iov_len);
1733+ cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
1734+ rdata->iov[1].iov_base, rdata->iov[1].iov_len);
1735+
1736+ /* Was the SMB read successful? */
1737+ rdata->result = server->ops->map_error(buf, false);
1738+ if (rdata->result != 0) {
1739+ cifs_dbg(FYI, "%s: server returned error %d\n",
1740+ __func__, rdata->result);
1741+ /* normal error on read response */
1742+ return __cifs_readv_discard(server, mid, false);
1743+ }
1744+
1745+ /* Is there enough to get to the rest of the READ_RSP header? */
1746+ if (server->total_read < server->vals->read_rsp_size) {
1747+ cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n",
1748+ __func__, server->total_read,
1749+ server->vals->read_rsp_size);
1750+ rdata->result = -EIO;
1751+ return cifs_readv_discard(server, mid);
1752+ }
1753+
1754+ data_offset = server->ops->read_data_offset(buf) +
1755+ server->vals->header_preamble_size;
1756+ if (data_offset < server->total_read) {
1757+ /*
1758+ * win2k8 sometimes sends an offset of 0 when the read
1759+ * is beyond the EOF. Treat it as if the data starts just after
1760+ * the header.
1761+ */
1762+ cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
1763+ __func__, data_offset);
1764+ data_offset = server->total_read;
1765+ } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
1766+ /* data_offset is beyond the end of smallbuf */
1767+ cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
1768+ __func__, data_offset);
1769+ rdata->result = -EIO;
1770+ return cifs_readv_discard(server, mid);
1771+ }
1772+
1773+ cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n",
1774+ __func__, server->total_read, data_offset);
1775+
1776+ len = data_offset - server->total_read;
1777+ if (len > 0) {
1778+ /* read any junk before data into the rest of smallbuf */
1779+ length = cifs_read_from_socket(server,
1780+ buf + server->total_read, len);
1781+ if (length < 0)
1782+ return length;
1783+ server->total_read += length;
1784+ }
1785+
1786+ /* how much data is in the response? */
1787+#ifdef CONFIG_CIFS_SMB_DIRECT
1788+ use_rdma_mr = rdata->mr;
1789+#endif
1790+ data_len = server->ops->read_data_length(buf, use_rdma_mr);
1791+ if (!use_rdma_mr && (data_offset + data_len > buflen)) {
1792+ /* data_len is corrupt -- discard frame */
1793+ rdata->result = -EIO;
1794+ return cifs_readv_discard(server, mid);
1795+ }
1796+
1797+ length = rdata->read_into_pages(server, rdata, data_len);
1798+ if (length < 0)
1799+ return length;
1800+
1801+ server->total_read += length;
1802+
1803+ cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n",
1804+ server->total_read, buflen, data_len);
1805+
1806+ /* discard anything left over */
1807+ if (server->total_read < buflen)
1808+ return cifs_readv_discard(server, mid);
1809+
1810+ dequeue_mid(mid, false);
1811+ mid->resp_buf = server->smallbuf;
1812+ server->smallbuf = NULL;
1813+ return length;
1814+}
fs/cifs/xattr.c+4−1
@@ -201,6 +201,7 @@ static int cifs_xattr_set(const struct xattr_handler *handler, · 200 unmodified lines
201201 break;
202202 }
203203
204+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
204205 case XATTR_ACL_ACCESS:
205206 #ifdef CONFIG_CIFS_POSIX
206207 if (!value)
@@ -224,6 +225,7 @@ static int cifs_xattr_set(const struct xattr_handler *handler, · 17 unmodified lines
224225 cifs_remap(cifs_sb));
225226 #endif /* CONFIG_CIFS_POSIX */
226227 break;
228+#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
227229 }
228230
229231 out:
@@ -364,7 +366,7 @@ static int cifs_xattr_get(const struct xattr_handler *handler, · 134 unmodified lines
364366 }
365367 break;
366368 }
367−
369+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
368370 case XATTR_ACL_ACCESS:
369371 #ifdef CONFIG_CIFS_POSIX
370372 if (sb->s_flags & SB_POSIXACL)
@@ -384,6 +386,7 @@ static int cifs_xattr_get(const struct xattr_handler *handler, · 13 unmodified lines
384386 cifs_remap(cifs_sb));
385387 #endif /* CONFIG_CIFS_POSIX */
386388 break;
389+#endif /* ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
387390 }
388391
389392 /* We could add an additional check for streams ie