xref: /linux/fs/smb/client/cifs_debug.c (revision c5ec7f49b480db0dfc83f395755b1c2a7c979920)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *
4  *   Copyright (C) International Business Machines  Corp., 2000,2005
5  *
6  *   Modified by Steve French (sfrench@us.ibm.com)
7  */
8 #include <linux/fs.h>
9 #include <linux/string.h>
10 #include <linux/ctype.h>
11 #include <linux/kstrtox.h>
12 #include <linux/module.h>
13 #include <linux/proc_fs.h>
14 #include <linux/uaccess.h>
15 #include <uapi/linux/ethtool.h>
16 #include "cifspdu.h"
17 #include "cifsglob.h"
18 #include "cifsproto.h"
19 #include "cifs_debug.h"
20 #include "cifsfs.h"
21 #include "fs_context.h"
22 #ifdef CONFIG_CIFS_DFS_UPCALL
23 #include "dfs_cache.h"
24 #endif
25 #ifdef CONFIG_CIFS_SMB_DIRECT
26 #include "smbdirect.h"
27 #endif
28 #include "cifs_swn.h"
29 #include "cached_dir.h"
30 
31 void
32 cifs_dump_mem(char *label, void *data, int length)
33 {
34 	pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
35 	print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
36 		       data, length, true);
37 }
38 
39 void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
40 {
41 #ifdef CONFIG_CIFS_DEBUG2
42 	struct smb_hdr *smb = buf;
43 
44 	cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d Wct: %d\n",
45 		 smb->Command, smb->Status.CifsError, smb->Flags,
46 		 smb->Flags2, smb->Mid, smb->Pid, smb->WordCount);
47 	if (!server->ops->check_message(buf, server->total_read, server)) {
48 		cifs_dbg(VFS, "smb buf %p len %u\n", smb,
49 			 server->ops->calc_smb_size(smb));
50 	}
51 #endif /* CONFIG_CIFS_DEBUG2 */
52 }
53 
54 void cifs_dump_mids(struct TCP_Server_Info *server)
55 {
56 #ifdef CONFIG_CIFS_DEBUG2
57 	struct mid_q_entry *mid_entry;
58 
59 	if (server == NULL)
60 		return;
61 
62 	cifs_dbg(VFS, "Dump pending requests:\n");
63 	spin_lock(&server->mid_lock);
64 	list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
65 		cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
66 			 mid_entry->mid_state,
67 			 le16_to_cpu(mid_entry->command),
68 			 mid_entry->pid,
69 			 mid_entry->callback_data,
70 			 mid_entry->mid);
71 #ifdef CONFIG_CIFS_STATS2
72 		cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
73 			 mid_entry->large_buf,
74 			 mid_entry->resp_buf,
75 			 mid_entry->when_received,
76 			 jiffies);
77 #endif /* STATS2 */
78 		cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
79 			 mid_entry->multiRsp, mid_entry->multiEnd);
80 		if (mid_entry->resp_buf) {
81 			cifs_dump_detail(mid_entry->resp_buf, server);
82 			cifs_dump_mem("existing buf: ",
83 				mid_entry->resp_buf, 62);
84 		}
85 	}
86 	spin_unlock(&server->mid_lock);
87 #endif /* CONFIG_CIFS_DEBUG2 */
88 }
89 
90 #ifdef CONFIG_PROC_FS
91 static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
92 {
93 	__u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
94 
95 	seq_printf(m, "%s Mounts: %d ", tcon->tree_name, tcon->tc_count);
96 	if (tcon->nativeFileSystem)
97 		seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
98 	seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
99 		   le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
100 		   le32_to_cpu(tcon->fsAttrInfo.Attributes),
101 		   le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
102 		   tcon->status);
103 	if (dev_type == FILE_DEVICE_DISK)
104 		seq_puts(m, " type: DISK ");
105 	else if (dev_type == FILE_DEVICE_CD_ROM)
106 		seq_puts(m, " type: CDROM ");
107 	else
108 		seq_printf(m, " type: %d ", dev_type);
109 
110 	seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
111 
112 	if ((tcon->seal) ||
113 	    (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
114 	    (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
115 		seq_puts(m, " encrypted");
116 	if (tcon->nocase)
117 		seq_printf(m, " nocase");
118 	if (tcon->unix_ext)
119 		seq_printf(m, " POSIX Extensions");
120 	if (tcon->ses->server->ops->dump_share_caps)
121 		tcon->ses->server->ops->dump_share_caps(m, tcon);
122 	if (tcon->use_witness)
123 		seq_puts(m, " Witness");
124 	if (tcon->broken_sparse_sup)
125 		seq_puts(m, " nosparse");
126 	if (tcon->need_reconnect)
127 		seq_puts(m, "\tDISCONNECTED ");
128 	spin_lock(&tcon->tc_lock);
129 	if (tcon->origin_fullpath) {
130 		seq_printf(m, "\n\tDFS origin fullpath: %s",
131 			   tcon->origin_fullpath);
132 	}
133 	spin_unlock(&tcon->tc_lock);
134 	seq_putc(m, '\n');
135 }
136 
137 static void
138 cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan)
139 {
140 	struct TCP_Server_Info *server = chan->server;
141 
142 	if (!server) {
143 		seq_printf(m, "\n\n\t\tChannel: %d DISABLED", i+1);
144 		return;
145 	}
146 
147 	seq_printf(m, "\n\n\t\tChannel: %d ConnectionId: 0x%llx"
148 		   "\n\t\tNumber of credits: %d,%d,%d Dialect 0x%x"
149 		   "\n\t\tTCP status: %d Instance: %d"
150 		   "\n\t\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d"
151 		   "\n\t\tIn Send: %d In MaxReq Wait: %d",
152 		   i+1, server->conn_id,
153 		   server->credits,
154 		   server->echo_credits,
155 		   server->oplock_credits,
156 		   server->dialect,
157 		   server->tcpStatus,
158 		   server->reconnect_instance,
159 		   server->srv_count,
160 		   server->sec_mode,
161 		   in_flight(server),
162 		   atomic_read(&server->in_send),
163 		   atomic_read(&server->num_waiters));
164 #ifdef CONFIG_NET_NS
165 	if (server->net)
166 		seq_printf(m, " Net namespace: %u ", server->net->ns.inum);
167 #endif /* NET_NS */
168 
169 }
170 
171 static inline const char *smb_speed_to_str(size_t bps)
172 {
173 	size_t mbps = bps / 1000 / 1000;
174 
175 	switch (mbps) {
176 	case SPEED_10:
177 		return "10Mbps";
178 	case SPEED_100:
179 		return "100Mbps";
180 	case SPEED_1000:
181 		return "1Gbps";
182 	case SPEED_2500:
183 		return "2.5Gbps";
184 	case SPEED_5000:
185 		return "5Gbps";
186 	case SPEED_10000:
187 		return "10Gbps";
188 	case SPEED_14000:
189 		return "14Gbps";
190 	case SPEED_20000:
191 		return "20Gbps";
192 	case SPEED_25000:
193 		return "25Gbps";
194 	case SPEED_40000:
195 		return "40Gbps";
196 	case SPEED_50000:
197 		return "50Gbps";
198 	case SPEED_56000:
199 		return "56Gbps";
200 	case SPEED_100000:
201 		return "100Gbps";
202 	case SPEED_200000:
203 		return "200Gbps";
204 	case SPEED_400000:
205 		return "400Gbps";
206 	case SPEED_800000:
207 		return "800Gbps";
208 	default:
209 		return "Unknown";
210 	}
211 }
212 
213 static void
214 cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
215 {
216 	struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
217 	struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
218 
219 	seq_printf(m, "\tSpeed: %s\n", smb_speed_to_str(iface->speed));
220 	seq_puts(m, "\t\tCapabilities: ");
221 	if (iface->rdma_capable)
222 		seq_puts(m, "rdma ");
223 	if (iface->rss_capable)
224 		seq_puts(m, "rss ");
225 	if (!iface->rdma_capable && !iface->rss_capable)
226 		seq_puts(m, "None");
227 	seq_putc(m, '\n');
228 	if (iface->sockaddr.ss_family == AF_INET)
229 		seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
230 	else if (iface->sockaddr.ss_family == AF_INET6)
231 		seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
232 	if (!iface->is_active)
233 		seq_puts(m, "\t\t[for-cleanup]\n");
234 }
235 
236 static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
237 {
238 	struct TCP_Server_Info *server;
239 	struct cifs_ses *ses;
240 	struct cifs_tcon *tcon;
241 	struct cifsFileInfo *cfile;
242 
243 	seq_puts(m, "# Version:1\n");
244 	seq_puts(m, "# Format:\n");
245 	seq_puts(m, "# <tree id> <ses id> <persistent fid> <flags> <count> <pid> <uid>");
246 #ifdef CONFIG_CIFS_DEBUG2
247 	seq_printf(m, " <filename> <mid>\n");
248 #else
249 	seq_printf(m, " <filename>\n");
250 #endif /* CIFS_DEBUG2 */
251 	spin_lock(&cifs_tcp_ses_lock);
252 	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
253 		list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
254 			if (cifs_ses_exiting(ses))
255 				continue;
256 			list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
257 				spin_lock(&tcon->open_file_lock);
258 				list_for_each_entry(cfile, &tcon->openFileList, tlist) {
259 					seq_printf(m,
260 						"0x%x 0x%llx 0x%llx 0x%x %d %d %d %pd",
261 						tcon->tid,
262 						ses->Suid,
263 						cfile->fid.persistent_fid,
264 						cfile->f_flags,
265 						cfile->count,
266 						cfile->pid,
267 						from_kuid(&init_user_ns, cfile->uid),
268 						cfile->dentry);
269 #ifdef CONFIG_CIFS_DEBUG2
270 					seq_printf(m, " %llu\n", cfile->fid.mid);
271 #else
272 					seq_printf(m, "\n");
273 #endif /* CIFS_DEBUG2 */
274 				}
275 				spin_unlock(&tcon->open_file_lock);
276 			}
277 		}
278 	}
279 	spin_unlock(&cifs_tcp_ses_lock);
280 	seq_putc(m, '\n');
281 	return 0;
282 }
283 
284 static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)
285 {
286 	struct list_head *stmp, *tmp, *tmp1;
287 	struct TCP_Server_Info *server;
288 	struct cifs_ses *ses;
289 	struct cifs_tcon *tcon;
290 	struct cached_fids *cfids;
291 	struct cached_fid *cfid;
292 	LIST_HEAD(entry);
293 
294 	seq_puts(m, "# Version:1\n");
295 	seq_puts(m, "# Format:\n");
296 	seq_puts(m, "# <tree id> <sess id> <persistent fid> <path>\n");
297 
298 	spin_lock(&cifs_tcp_ses_lock);
299 	list_for_each(stmp, &cifs_tcp_ses_list) {
300 		server = list_entry(stmp, struct TCP_Server_Info,
301 				    tcp_ses_list);
302 		list_for_each(tmp, &server->smb_ses_list) {
303 			ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
304 			list_for_each(tmp1, &ses->tcon_list) {
305 				tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
306 				cfids = tcon->cfids;
307 				spin_lock(&cfids->cfid_list_lock); /* check lock ordering */
308 				seq_printf(m, "Num entries: %d\n", cfids->num_entries);
309 				list_for_each_entry(cfid, &cfids->entries, entry) {
310 					seq_printf(m, "0x%x 0x%llx 0x%llx     %s",
311 						tcon->tid,
312 						ses->Suid,
313 						cfid->fid.persistent_fid,
314 						cfid->path);
315 					if (cfid->file_all_info_is_valid)
316 						seq_printf(m, "\tvalid file info");
317 					if (cfid->dirents.is_valid)
318 						seq_printf(m, ", valid dirents");
319 					seq_printf(m, "\n");
320 				}
321 				spin_unlock(&cfids->cfid_list_lock);
322 
323 
324 			}
325 		}
326 	}
327 	spin_unlock(&cifs_tcp_ses_lock);
328 	seq_putc(m, '\n');
329 	return 0;
330 }
331 
332 static __always_inline const char *compression_alg_str(__le16 alg)
333 {
334 	switch (alg) {
335 	case SMB3_COMPRESS_NONE:
336 		return "NONE";
337 	case SMB3_COMPRESS_LZNT1:
338 		return "LZNT1";
339 	case SMB3_COMPRESS_LZ77:
340 		return "LZ77";
341 	case SMB3_COMPRESS_LZ77_HUFF:
342 		return "LZ77-Huffman";
343 	case SMB3_COMPRESS_PATTERN:
344 		return "Pattern_V1";
345 	default:
346 		return "invalid";
347 	}
348 }
349 
350 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
351 {
352 	struct mid_q_entry *mid_entry;
353 	struct TCP_Server_Info *server;
354 	struct TCP_Server_Info *chan_server;
355 	struct cifs_ses *ses;
356 	struct cifs_tcon *tcon;
357 	struct cifs_server_iface *iface;
358 	size_t iface_weight = 0, iface_min_speed = 0;
359 	struct cifs_server_iface *last_iface = NULL;
360 	int c, i, j;
361 
362 	seq_puts(m,
363 		    "Display Internal CIFS Data Structures for Debugging\n"
364 		    "---------------------------------------------------\n");
365 	seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
366 	seq_printf(m, "Features:");
367 #ifdef CONFIG_CIFS_DFS_UPCALL
368 	seq_printf(m, " DFS");
369 #endif
370 #ifdef CONFIG_CIFS_FSCACHE
371 	seq_printf(m, ",FSCACHE");
372 #endif
373 #ifdef CONFIG_CIFS_SMB_DIRECT
374 	seq_printf(m, ",SMB_DIRECT");
375 #endif
376 #ifdef CONFIG_CIFS_STATS2
377 	seq_printf(m, ",STATS2");
378 #else
379 	seq_printf(m, ",STATS");
380 #endif
381 #ifdef CONFIG_CIFS_DEBUG2
382 	seq_printf(m, ",DEBUG2");
383 #elif defined(CONFIG_CIFS_DEBUG)
384 	seq_printf(m, ",DEBUG");
385 #endif
386 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
387 	seq_printf(m, ",ALLOW_INSECURE_LEGACY");
388 #endif
389 #ifdef CONFIG_CIFS_POSIX
390 	seq_printf(m, ",CIFS_POSIX");
391 #endif
392 #ifdef CONFIG_CIFS_UPCALL
393 	seq_printf(m, ",UPCALL(SPNEGO)");
394 #endif
395 #ifdef CONFIG_CIFS_XATTR
396 	seq_printf(m, ",XATTR");
397 #endif
398 	seq_printf(m, ",ACL");
399 #ifdef CONFIG_CIFS_SWN_UPCALL
400 	seq_puts(m, ",WITNESS");
401 #endif
402 #ifdef CONFIG_CIFS_COMPRESSION
403 	seq_puts(m, ",COMPRESSION");
404 #endif
405 	seq_putc(m, '\n');
406 	seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
407 	seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
408 
409 	seq_printf(m, "\nServers: ");
410 
411 	c = 0;
412 	spin_lock(&cifs_tcp_ses_lock);
413 	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
414 #ifdef CONFIG_CIFS_SMB_DIRECT
415 		struct smbdirect_socket_parameters *sp;
416 #endif
417 
418 		/* channel info will be printed as a part of sessions below */
419 		if (SERVER_IS_CHAN(server))
420 			continue;
421 
422 		c++;
423 		seq_printf(m, "\n%d) ConnectionId: 0x%llx ",
424 			c, server->conn_id);
425 
426 		spin_lock(&server->srv_lock);
427 		if (server->hostname)
428 			seq_printf(m, "Hostname: %s ", server->hostname);
429 		seq_printf(m, "\nClientGUID: %pUL", server->client_guid);
430 		spin_unlock(&server->srv_lock);
431 #ifdef CONFIG_CIFS_SMB_DIRECT
432 		if (!server->rdma)
433 			goto skip_rdma;
434 
435 		if (!server->smbd_conn) {
436 			seq_printf(m, "\nSMBDirect transport not available");
437 			goto skip_rdma;
438 		}
439 		sp = &server->smbd_conn->socket.parameters;
440 
441 		seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
442 			"transport status: %x",
443 			server->smbd_conn->protocol,
444 			server->smbd_conn->socket.status);
445 		seq_printf(m, "\nConn receive_credit_max: %x "
446 			"send_credit_target: %x max_send_size: %x",
447 			sp->recv_credit_max,
448 			sp->send_credit_target,
449 			sp->max_send_size);
450 		seq_printf(m, "\nConn max_fragmented_recv_size: %x "
451 			"max_fragmented_send_size: %x max_receive_size:%x",
452 			sp->max_fragmented_recv_size,
453 			sp->max_fragmented_send_size,
454 			sp->max_recv_size);
455 		seq_printf(m, "\nConn keep_alive_interval: %x "
456 			"max_readwrite_size: %x rdma_readwrite_threshold: %x",
457 			sp->keepalive_interval_msec * 1000,
458 			sp->max_read_write_size,
459 			server->smbd_conn->rdma_readwrite_threshold);
460 		seq_printf(m, "\nDebug count_get_receive_buffer: %x "
461 			"count_put_receive_buffer: %x count_send_empty: %x",
462 			server->smbd_conn->count_get_receive_buffer,
463 			server->smbd_conn->count_put_receive_buffer,
464 			server->smbd_conn->count_send_empty);
465 		seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
466 			"count_enqueue_reassembly_queue: %x "
467 			"count_dequeue_reassembly_queue: %x "
468 			"fragment_reassembly_remaining: %x "
469 			"reassembly_data_length: %x "
470 			"reassembly_queue_length: %x",
471 			server->smbd_conn->count_reassembly_queue,
472 			server->smbd_conn->count_enqueue_reassembly_queue,
473 			server->smbd_conn->count_dequeue_reassembly_queue,
474 			server->smbd_conn->fragment_reassembly_remaining,
475 			server->smbd_conn->reassembly_data_length,
476 			server->smbd_conn->reassembly_queue_length);
477 		seq_printf(m, "\nCurrent Credits send_credits: %x "
478 			"receive_credits: %x receive_credit_target: %x",
479 			atomic_read(&server->smbd_conn->send_credits),
480 			atomic_read(&server->smbd_conn->receive_credits),
481 			server->smbd_conn->receive_credit_target);
482 		seq_printf(m, "\nPending send_pending: %x ",
483 			atomic_read(&server->smbd_conn->send_pending));
484 		seq_printf(m, "\nReceive buffers count_receive_queue: %x "
485 			"count_empty_packet_queue: %x",
486 			server->smbd_conn->count_receive_queue,
487 			server->smbd_conn->count_empty_packet_queue);
488 		seq_printf(m, "\nMR responder_resources: %x "
489 			"max_frmr_depth: %x mr_type: %x",
490 			server->smbd_conn->responder_resources,
491 			server->smbd_conn->max_frmr_depth,
492 			server->smbd_conn->mr_type);
493 		seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
494 			atomic_read(&server->smbd_conn->mr_ready_count),
495 			atomic_read(&server->smbd_conn->mr_used_count));
496 skip_rdma:
497 #endif
498 		seq_printf(m, "\nNumber of credits: %d,%d,%d Dialect 0x%x",
499 			server->credits,
500 			server->echo_credits,
501 			server->oplock_credits,
502 			server->dialect);
503 		if (server->sign)
504 			seq_printf(m, " signed");
505 		if (server->posix_ext_supported)
506 			seq_printf(m, " posix");
507 		if (server->nosharesock)
508 			seq_printf(m, " nosharesock");
509 
510 		seq_printf(m, "\nServer capabilities: 0x%x", server->capabilities);
511 
512 		if (server->rdma)
513 			seq_printf(m, "\nRDMA ");
514 		seq_printf(m, "\nTCP status: %d Instance: %d"
515 				"\nLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
516 				server->tcpStatus,
517 				server->reconnect_instance,
518 				server->srv_count,
519 				server->sec_mode, in_flight(server));
520 #ifdef CONFIG_NET_NS
521 		if (server->net)
522 			seq_printf(m, " Net namespace: %u ", server->net->ns.inum);
523 #endif /* NET_NS */
524 
525 		seq_printf(m, "\nIn Send: %d In MaxReq Wait: %d",
526 				atomic_read(&server->in_send),
527 				atomic_read(&server->num_waiters));
528 
529 		if (server->leaf_fullpath) {
530 			seq_printf(m, "\nDFS leaf full path: %s",
531 				   server->leaf_fullpath);
532 		}
533 
534 		seq_puts(m, "\nCompression: ");
535 		if (!IS_ENABLED(CONFIG_CIFS_COMPRESSION))
536 			seq_puts(m, "no built-in support");
537 		else if (!server->compression.requested)
538 			seq_puts(m, "disabled on mount");
539 		else if (server->compression.enabled)
540 			seq_printf(m, "enabled (%s)", compression_alg_str(server->compression.alg));
541 		else
542 			seq_puts(m, "disabled (not supported by this server)");
543 
544 		seq_printf(m, "\n\n\tSessions: ");
545 		i = 0;
546 		list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
547 			spin_lock(&ses->ses_lock);
548 			if (ses->ses_status == SES_EXITING) {
549 				spin_unlock(&ses->ses_lock);
550 				continue;
551 			}
552 			i++;
553 			if ((ses->serverDomain == NULL) ||
554 				(ses->serverOS == NULL) ||
555 				(ses->serverNOS == NULL)) {
556 				seq_printf(m, "\n\t%d) Address: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
557 					i, ses->ip_addr, ses->ses_count,
558 					ses->capabilities, ses->ses_status);
559 				if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
560 					seq_printf(m, "Guest ");
561 				else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
562 					seq_printf(m, "Anonymous ");
563 			} else {
564 				seq_printf(m,
565 				    "\n\t%d) Name: %s  Domain: %s Uses: %d OS: %s "
566 				    "\n\tNOS: %s\tCapability: 0x%x"
567 					"\n\tSMB session status: %d ",
568 				i, ses->ip_addr, ses->serverDomain,
569 				ses->ses_count, ses->serverOS, ses->serverNOS,
570 				ses->capabilities, ses->ses_status);
571 			}
572 			if (ses->expired_pwd)
573 				seq_puts(m, "password no longer valid ");
574 			spin_unlock(&ses->ses_lock);
575 
576 			seq_printf(m, "\n\tSecurity type: %s ",
577 				get_security_type_str(server->ops->select_sectype(server, ses->sectype)));
578 
579 			/* dump session id helpful for use with network trace */
580 			seq_printf(m, " SessionId: 0x%llx", ses->Suid);
581 			if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) {
582 				seq_puts(m, " encrypted");
583 				/* can help in debugging to show encryption type */
584 				if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)
585 					seq_puts(m, "(gcm256)");
586 			}
587 			if (ses->sign)
588 				seq_puts(m, " signed");
589 
590 			seq_printf(m, "\n\tUser: %d Cred User: %d",
591 				   from_kuid(&init_user_ns, ses->linux_uid),
592 				   from_kuid(&init_user_ns, ses->cred_uid));
593 
594 			if (ses->dfs_root_ses) {
595 				seq_printf(m, "\n\tDFS root session id: 0x%llx",
596 					   ses->dfs_root_ses->Suid);
597 			}
598 
599 			spin_lock(&ses->chan_lock);
600 			if (CIFS_CHAN_NEEDS_RECONNECT(ses, 0))
601 				seq_puts(m, "\tPrimary channel: DISCONNECTED ");
602 			if (CIFS_CHAN_IN_RECONNECT(ses, 0))
603 				seq_puts(m, "\t[RECONNECTING] ");
604 
605 			if (ses->chan_count > 1) {
606 				seq_printf(m, "\n\n\tExtra Channels: %zu ",
607 					   ses->chan_count-1);
608 				for (j = 1; j < ses->chan_count; j++) {
609 					cifs_dump_channel(m, j, &ses->chans[j]);
610 					if (CIFS_CHAN_NEEDS_RECONNECT(ses, j))
611 						seq_puts(m, "\tDISCONNECTED ");
612 					if (CIFS_CHAN_IN_RECONNECT(ses, j))
613 						seq_puts(m, "\t[RECONNECTING] ");
614 				}
615 			}
616 			spin_unlock(&ses->chan_lock);
617 
618 			seq_puts(m, "\n\n\tShares: ");
619 			j = 0;
620 
621 			seq_printf(m, "\n\t%d) IPC: ", j);
622 			if (ses->tcon_ipc)
623 				cifs_debug_tcon(m, ses->tcon_ipc);
624 			else
625 				seq_puts(m, "none\n");
626 
627 			list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
628 				++j;
629 				seq_printf(m, "\n\t%d) ", j);
630 				cifs_debug_tcon(m, tcon);
631 			}
632 
633 			spin_lock(&ses->iface_lock);
634 			if (ses->iface_count)
635 				seq_printf(m, "\n\n\tServer interfaces: %zu"
636 					   "\tLast updated: %lu seconds ago",
637 					   ses->iface_count,
638 					   (jiffies - ses->iface_last_update) / HZ);
639 
640 			last_iface = list_last_entry(&ses->iface_list,
641 						     struct cifs_server_iface,
642 						     iface_head);
643 			iface_min_speed = last_iface->speed;
644 
645 			j = 0;
646 			list_for_each_entry(iface, &ses->iface_list,
647 						 iface_head) {
648 				seq_printf(m, "\n\t%d)", ++j);
649 				cifs_dump_iface(m, iface);
650 
651 				iface_weight = iface->speed / iface_min_speed;
652 				seq_printf(m, "\t\tWeight (cur,total): (%zu,%zu)"
653 					   "\n\t\tAllocated channels: %u\n",
654 					   iface->weight_fulfilled,
655 					   iface_weight,
656 					   iface->num_channels);
657 
658 				if (is_ses_using_iface(ses, iface))
659 					seq_puts(m, "\t\t[CONNECTED]\n");
660 			}
661 			spin_unlock(&ses->iface_lock);
662 
663 			seq_puts(m, "\n\n\tMIDs: ");
664 			spin_lock(&ses->chan_lock);
665 			for (j = 0; j < ses->chan_count; j++) {
666 				chan_server = ses->chans[j].server;
667 				if (!chan_server)
668 					continue;
669 
670 				if (list_empty(&chan_server->pending_mid_q))
671 					continue;
672 
673 				seq_printf(m, "\n\tServer ConnectionId: 0x%llx",
674 					   chan_server->conn_id);
675 				spin_lock(&chan_server->mid_lock);
676 				list_for_each_entry(mid_entry, &chan_server->pending_mid_q, qhead) {
677 					seq_printf(m, "\n\t\tState: %d com: %d pid: %d cbdata: %p mid %llu",
678 						   mid_entry->mid_state,
679 						   le16_to_cpu(mid_entry->command),
680 						   mid_entry->pid,
681 						   mid_entry->callback_data,
682 						   mid_entry->mid);
683 				}
684 				spin_unlock(&chan_server->mid_lock);
685 			}
686 			spin_unlock(&ses->chan_lock);
687 			seq_puts(m, "\n--\n");
688 		}
689 		if (i == 0)
690 			seq_printf(m, "\n\t\t[NONE]");
691 	}
692 	if (c == 0)
693 		seq_printf(m, "\n\t[NONE]");
694 
695 	spin_unlock(&cifs_tcp_ses_lock);
696 	seq_putc(m, '\n');
697 	cifs_swn_dump(m);
698 
699 	/* BB add code to dump additional info such as TCP session info now */
700 	return 0;
701 }
702 
703 static ssize_t cifs_stats_proc_write(struct file *file,
704 		const char __user *buffer, size_t count, loff_t *ppos)
705 {
706 	bool bv;
707 	int rc;
708 	struct TCP_Server_Info *server;
709 	struct cifs_ses *ses;
710 	struct cifs_tcon *tcon;
711 
712 	rc = kstrtobool_from_user(buffer, count, &bv);
713 	if (rc == 0) {
714 #ifdef CONFIG_CIFS_STATS2
715 		int i;
716 
717 		atomic_set(&total_buf_alloc_count, 0);
718 		atomic_set(&total_small_buf_alloc_count, 0);
719 #endif /* CONFIG_CIFS_STATS2 */
720 		atomic_set(&tcpSesReconnectCount, 0);
721 		atomic_set(&tconInfoReconnectCount, 0);
722 
723 		spin_lock(&GlobalMid_Lock);
724 		GlobalMaxActiveXid = 0;
725 		GlobalCurrentXid = 0;
726 		spin_unlock(&GlobalMid_Lock);
727 		spin_lock(&cifs_tcp_ses_lock);
728 		list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
729 			server->max_in_flight = 0;
730 #ifdef CONFIG_CIFS_STATS2
731 			for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
732 				atomic_set(&server->num_cmds[i], 0);
733 				atomic_set(&server->smb2slowcmd[i], 0);
734 				server->time_per_cmd[i] = 0;
735 				server->slowest_cmd[i] = 0;
736 				server->fastest_cmd[0] = 0;
737 			}
738 #endif /* CONFIG_CIFS_STATS2 */
739 			list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
740 				if (cifs_ses_exiting(ses))
741 					continue;
742 				list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
743 					atomic_set(&tcon->num_smbs_sent, 0);
744 					spin_lock(&tcon->stat_lock);
745 					tcon->bytes_read = 0;
746 					tcon->bytes_written = 0;
747 					tcon->stats_from_time = ktime_get_real_seconds();
748 					spin_unlock(&tcon->stat_lock);
749 					if (server->ops->clear_stats)
750 						server->ops->clear_stats(tcon);
751 				}
752 			}
753 		}
754 		spin_unlock(&cifs_tcp_ses_lock);
755 	} else {
756 		return rc;
757 	}
758 
759 	return count;
760 }
761 
762 static int cifs_stats_proc_show(struct seq_file *m, void *v)
763 {
764 	int i;
765 #ifdef CONFIG_CIFS_STATS2
766 	int j;
767 #endif /* STATS2 */
768 	struct TCP_Server_Info *server;
769 	struct cifs_ses *ses;
770 	struct cifs_tcon *tcon;
771 
772 	seq_printf(m, "Resources in use\nCIFS Session: %d\n",
773 			sesInfoAllocCount.counter);
774 	seq_printf(m, "Share (unique mount targets): %d\n",
775 			tconInfoAllocCount.counter);
776 	seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
777 			buf_alloc_count.counter,
778 			cifs_min_rcv + tcpSesAllocCount.counter);
779 	seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
780 			small_buf_alloc_count.counter, cifs_min_small);
781 #ifdef CONFIG_CIFS_STATS2
782 	seq_printf(m, "Total Large %d Small %d Allocations\n",
783 				atomic_read(&total_buf_alloc_count),
784 				atomic_read(&total_small_buf_alloc_count));
785 #endif /* CONFIG_CIFS_STATS2 */
786 
787 	seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&mid_count));
788 	seq_printf(m,
789 		"\n%d session %d share reconnects\n",
790 		tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
791 
792 	seq_printf(m,
793 		"Total vfs operations: %d maximum at one time: %d\n",
794 		GlobalCurrentXid, GlobalMaxActiveXid);
795 
796 	i = 0;
797 	spin_lock(&cifs_tcp_ses_lock);
798 	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
799 		seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
800 #ifdef CONFIG_CIFS_STATS2
801 		seq_puts(m, "\nTotal time spent processing by command. Time ");
802 		seq_printf(m, "units are jiffies (%d per second)\n", HZ);
803 		seq_puts(m, "  SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
804 		seq_puts(m, "  --------\t------\t----------\t-------\t-------\n");
805 		for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
806 			seq_printf(m, "  %d\t\t%d\t%llu\t\t%u\t%u\n", j,
807 				atomic_read(&server->num_cmds[j]),
808 				server->time_per_cmd[j],
809 				server->fastest_cmd[j],
810 				server->slowest_cmd[j]);
811 		for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
812 			if (atomic_read(&server->smb2slowcmd[j])) {
813 				spin_lock(&server->srv_lock);
814 				seq_printf(m, "  %d slow responses from %s for command %d\n",
815 					atomic_read(&server->smb2slowcmd[j]),
816 					server->hostname, j);
817 				spin_unlock(&server->srv_lock);
818 			}
819 #endif /* STATS2 */
820 		list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
821 			if (cifs_ses_exiting(ses))
822 				continue;
823 			list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
824 				i++;
825 				seq_printf(m, "\n%d) %s", i, tcon->tree_name);
826 				if (tcon->need_reconnect)
827 					seq_puts(m, "\tDISCONNECTED ");
828 				seq_printf(m, "\nSMBs: %d since %ptTs UTC",
829 					   atomic_read(&tcon->num_smbs_sent),
830 					   &tcon->stats_from_time);
831 				if (server->ops->print_stats)
832 					server->ops->print_stats(m, tcon);
833 			}
834 		}
835 	}
836 	spin_unlock(&cifs_tcp_ses_lock);
837 
838 	seq_putc(m, '\n');
839 	return 0;
840 }
841 
842 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
843 {
844 	return single_open(file, cifs_stats_proc_show, NULL);
845 }
846 
847 static const struct proc_ops cifs_stats_proc_ops = {
848 	.proc_open	= cifs_stats_proc_open,
849 	.proc_read	= seq_read,
850 	.proc_lseek	= seq_lseek,
851 	.proc_release	= single_release,
852 	.proc_write	= cifs_stats_proc_write,
853 };
854 
855 #ifdef CONFIG_CIFS_SMB_DIRECT
856 #define PROC_FILE_DEFINE(name) \
857 static ssize_t name##_write(struct file *file, const char __user *buffer, \
858 	size_t count, loff_t *ppos) \
859 { \
860 	int rc; \
861 	rc = kstrtoint_from_user(buffer, count, 10, &name); \
862 	if (rc) \
863 		return rc; \
864 	return count; \
865 } \
866 static int name##_proc_show(struct seq_file *m, void *v) \
867 { \
868 	seq_printf(m, "%d\n", name); \
869 	return 0; \
870 } \
871 static int name##_open(struct inode *inode, struct file *file) \
872 { \
873 	return single_open(file, name##_proc_show, NULL); \
874 } \
875 \
876 static const struct proc_ops cifs_##name##_proc_fops = { \
877 	.proc_open	= name##_open, \
878 	.proc_read	= seq_read, \
879 	.proc_lseek	= seq_lseek, \
880 	.proc_release	= single_release, \
881 	.proc_write	= name##_write, \
882 }
883 
884 PROC_FILE_DEFINE(rdma_readwrite_threshold);
885 PROC_FILE_DEFINE(smbd_max_frmr_depth);
886 PROC_FILE_DEFINE(smbd_keep_alive_interval);
887 PROC_FILE_DEFINE(smbd_max_receive_size);
888 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
889 PROC_FILE_DEFINE(smbd_max_send_size);
890 PROC_FILE_DEFINE(smbd_send_credit_target);
891 PROC_FILE_DEFINE(smbd_receive_credit_max);
892 #endif
893 
894 static struct proc_dir_entry *proc_fs_cifs;
895 static const struct proc_ops cifsFYI_proc_ops;
896 static const struct proc_ops cifs_lookup_cache_proc_ops;
897 static const struct proc_ops traceSMB_proc_ops;
898 static const struct proc_ops cifs_security_flags_proc_ops;
899 static const struct proc_ops cifs_linux_ext_proc_ops;
900 static const struct proc_ops cifs_mount_params_proc_ops;
901 
902 void
903 cifs_proc_init(void)
904 {
905 	proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
906 	if (proc_fs_cifs == NULL)
907 		return;
908 
909 	proc_create_single("DebugData", 0, proc_fs_cifs,
910 			cifs_debug_data_proc_show);
911 
912 	proc_create_single("open_files", 0400, proc_fs_cifs,
913 			cifs_debug_files_proc_show);
914 
915 	proc_create_single("open_dirs", 0400, proc_fs_cifs,
916 			cifs_debug_dirs_proc_show);
917 
918 	proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
919 	proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
920 	proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
921 	proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
922 		    &cifs_linux_ext_proc_ops);
923 	proc_create("SecurityFlags", 0644, proc_fs_cifs,
924 		    &cifs_security_flags_proc_ops);
925 	proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
926 		    &cifs_lookup_cache_proc_ops);
927 
928 	proc_create("mount_params", 0444, proc_fs_cifs, &cifs_mount_params_proc_ops);
929 
930 #ifdef CONFIG_CIFS_DFS_UPCALL
931 	proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
932 #endif
933 
934 #ifdef CONFIG_CIFS_SMB_DIRECT
935 	proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
936 		&cifs_rdma_readwrite_threshold_proc_fops);
937 	proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
938 		&cifs_smbd_max_frmr_depth_proc_fops);
939 	proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
940 		&cifs_smbd_keep_alive_interval_proc_fops);
941 	proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
942 		&cifs_smbd_max_receive_size_proc_fops);
943 	proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
944 		&cifs_smbd_max_fragmented_recv_size_proc_fops);
945 	proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
946 		&cifs_smbd_max_send_size_proc_fops);
947 	proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
948 		&cifs_smbd_send_credit_target_proc_fops);
949 	proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
950 		&cifs_smbd_receive_credit_max_proc_fops);
951 #endif
952 }
953 
954 void
955 cifs_proc_clean(void)
956 {
957 	if (proc_fs_cifs == NULL)
958 		return;
959 
960 	remove_proc_entry("DebugData", proc_fs_cifs);
961 	remove_proc_entry("open_files", proc_fs_cifs);
962 	remove_proc_entry("open_dirs", proc_fs_cifs);
963 	remove_proc_entry("cifsFYI", proc_fs_cifs);
964 	remove_proc_entry("traceSMB", proc_fs_cifs);
965 	remove_proc_entry("Stats", proc_fs_cifs);
966 	remove_proc_entry("SecurityFlags", proc_fs_cifs);
967 	remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
968 	remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
969 	remove_proc_entry("mount_params", proc_fs_cifs);
970 
971 #ifdef CONFIG_CIFS_DFS_UPCALL
972 	remove_proc_entry("dfscache", proc_fs_cifs);
973 #endif
974 #ifdef CONFIG_CIFS_SMB_DIRECT
975 	remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
976 	remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
977 	remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
978 	remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
979 	remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
980 	remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
981 	remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
982 	remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
983 #endif
984 	remove_proc_entry("fs/cifs", NULL);
985 }
986 
987 static int cifsFYI_proc_show(struct seq_file *m, void *v)
988 {
989 	seq_printf(m, "%d\n", cifsFYI);
990 	return 0;
991 }
992 
993 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
994 {
995 	return single_open(file, cifsFYI_proc_show, NULL);
996 }
997 
998 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
999 		size_t count, loff_t *ppos)
1000 {
1001 	char c[2] = { '\0' };
1002 	bool bv;
1003 	int rc;
1004 
1005 	rc = get_user(c[0], buffer);
1006 	if (rc)
1007 		return rc;
1008 	if (kstrtobool(c, &bv) == 0)
1009 		cifsFYI = bv;
1010 	else if ((c[0] > '1') && (c[0] <= '9'))
1011 		cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
1012 	else
1013 		return -EINVAL;
1014 
1015 	return count;
1016 }
1017 
1018 static const struct proc_ops cifsFYI_proc_ops = {
1019 	.proc_open	= cifsFYI_proc_open,
1020 	.proc_read	= seq_read,
1021 	.proc_lseek	= seq_lseek,
1022 	.proc_release	= single_release,
1023 	.proc_write	= cifsFYI_proc_write,
1024 };
1025 
1026 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
1027 {
1028 	seq_printf(m, "%d\n", linuxExtEnabled);
1029 	return 0;
1030 }
1031 
1032 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
1033 {
1034 	return single_open(file, cifs_linux_ext_proc_show, NULL);
1035 }
1036 
1037 static ssize_t cifs_linux_ext_proc_write(struct file *file,
1038 		const char __user *buffer, size_t count, loff_t *ppos)
1039 {
1040 	int rc;
1041 
1042 	rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
1043 	if (rc)
1044 		return rc;
1045 
1046 	return count;
1047 }
1048 
1049 static const struct proc_ops cifs_linux_ext_proc_ops = {
1050 	.proc_open	= cifs_linux_ext_proc_open,
1051 	.proc_read	= seq_read,
1052 	.proc_lseek	= seq_lseek,
1053 	.proc_release	= single_release,
1054 	.proc_write	= cifs_linux_ext_proc_write,
1055 };
1056 
1057 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
1058 {
1059 	seq_printf(m, "%d\n", lookupCacheEnabled);
1060 	return 0;
1061 }
1062 
1063 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
1064 {
1065 	return single_open(file, cifs_lookup_cache_proc_show, NULL);
1066 }
1067 
1068 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
1069 		const char __user *buffer, size_t count, loff_t *ppos)
1070 {
1071 	int rc;
1072 
1073 	rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
1074 	if (rc)
1075 		return rc;
1076 
1077 	return count;
1078 }
1079 
1080 static const struct proc_ops cifs_lookup_cache_proc_ops = {
1081 	.proc_open	= cifs_lookup_cache_proc_open,
1082 	.proc_read	= seq_read,
1083 	.proc_lseek	= seq_lseek,
1084 	.proc_release	= single_release,
1085 	.proc_write	= cifs_lookup_cache_proc_write,
1086 };
1087 
1088 static int traceSMB_proc_show(struct seq_file *m, void *v)
1089 {
1090 	seq_printf(m, "%d\n", traceSMB);
1091 	return 0;
1092 }
1093 
1094 static int traceSMB_proc_open(struct inode *inode, struct file *file)
1095 {
1096 	return single_open(file, traceSMB_proc_show, NULL);
1097 }
1098 
1099 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
1100 		size_t count, loff_t *ppos)
1101 {
1102 	int rc;
1103 
1104 	rc = kstrtobool_from_user(buffer, count, &traceSMB);
1105 	if (rc)
1106 		return rc;
1107 
1108 	return count;
1109 }
1110 
1111 static const struct proc_ops traceSMB_proc_ops = {
1112 	.proc_open	= traceSMB_proc_open,
1113 	.proc_read	= seq_read,
1114 	.proc_lseek	= seq_lseek,
1115 	.proc_release	= single_release,
1116 	.proc_write	= traceSMB_proc_write,
1117 };
1118 
1119 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
1120 {
1121 	seq_printf(m, "0x%x\n", global_secflags);
1122 	return 0;
1123 }
1124 
1125 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
1126 {
1127 	return single_open(file, cifs_security_flags_proc_show, NULL);
1128 }
1129 
1130 /*
1131  * Ensure that if someone sets a MUST flag, that we disable all other MAY
1132  * flags except for the ones corresponding to the given MUST flag. If there are
1133  * multiple MUST flags, then try to prefer more secure ones.
1134  */
1135 static void
1136 cifs_security_flags_handle_must_flags(unsigned int *flags)
1137 {
1138 	unsigned int signflags = *flags & (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL);
1139 
1140 	if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
1141 		*flags = CIFSSEC_MUST_KRB5;
1142 	else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
1143 		*flags = CIFSSEC_MUST_NTLMSSP;
1144 	else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
1145 		*flags = CIFSSEC_MUST_NTLMV2;
1146 
1147 	*flags |= signflags;
1148 }
1149 
1150 static ssize_t cifs_security_flags_proc_write(struct file *file,
1151 		const char __user *buffer, size_t count, loff_t *ppos)
1152 {
1153 	int rc;
1154 	unsigned int flags;
1155 	char flags_string[12];
1156 	bool bv;
1157 
1158 	if ((count < 1) || (count > 11))
1159 		return -EINVAL;
1160 
1161 	memset(flags_string, 0, sizeof(flags_string));
1162 
1163 	if (copy_from_user(flags_string, buffer, count))
1164 		return -EFAULT;
1165 
1166 	if (count < 3) {
1167 		/* single char or single char followed by null */
1168 		if (kstrtobool(flags_string, &bv) == 0) {
1169 			global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
1170 			return count;
1171 		} else if (!isdigit(flags_string[0])) {
1172 			cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
1173 					flags_string);
1174 			return -EINVAL;
1175 		}
1176 	}
1177 
1178 	/* else we have a number */
1179 	rc = kstrtouint(flags_string, 0, &flags);
1180 	if (rc) {
1181 		cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
1182 				flags_string);
1183 		return rc;
1184 	}
1185 
1186 	cifs_dbg(FYI, "sec flags 0x%x\n", flags);
1187 
1188 	if (flags == 0)  {
1189 		cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
1190 		return -EINVAL;
1191 	}
1192 
1193 	if (flags & ~CIFSSEC_MASK) {
1194 		cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
1195 			 flags & ~CIFSSEC_MASK);
1196 		return -EINVAL;
1197 	}
1198 
1199 	cifs_security_flags_handle_must_flags(&flags);
1200 
1201 	/* flags look ok - update the global security flags for cifs module */
1202 	global_secflags = flags;
1203 	if (global_secflags & CIFSSEC_MUST_SIGN) {
1204 		/* requiring signing implies signing is allowed */
1205 		global_secflags |= CIFSSEC_MAY_SIGN;
1206 		cifs_dbg(FYI, "packet signing now required\n");
1207 	} else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
1208 		cifs_dbg(FYI, "packet signing disabled\n");
1209 	}
1210 	/* BB should we turn on MAY flags for other MUST options? */
1211 	return count;
1212 }
1213 
1214 static const struct proc_ops cifs_security_flags_proc_ops = {
1215 	.proc_open	= cifs_security_flags_proc_open,
1216 	.proc_read	= seq_read,
1217 	.proc_lseek	= seq_lseek,
1218 	.proc_release	= single_release,
1219 	.proc_write	= cifs_security_flags_proc_write,
1220 };
1221 
1222 /* To make it easier to debug, can help to show mount params */
1223 static int cifs_mount_params_proc_show(struct seq_file *m, void *v)
1224 {
1225 	const struct fs_parameter_spec *p;
1226 	const char *type;
1227 
1228 	for (p = smb3_fs_parameters; p->name; p++) {
1229 		/* cannot use switch with pointers... */
1230 		if (!p->type) {
1231 			if (p->flags == fs_param_neg_with_no)
1232 				type = "noflag";
1233 			else
1234 				type = "flag";
1235 		} else if (p->type == fs_param_is_bool)
1236 			type = "bool";
1237 		else if (p->type == fs_param_is_u32)
1238 			type = "u32";
1239 		else if (p->type == fs_param_is_u64)
1240 			type = "u64";
1241 		else if (p->type == fs_param_is_string)
1242 			type = "string";
1243 		else
1244 			type = "unknown";
1245 
1246 		seq_printf(m, "%s:%s\n", p->name, type);
1247 	}
1248 
1249 	return 0;
1250 }
1251 
1252 static int cifs_mount_params_proc_open(struct inode *inode, struct file *file)
1253 {
1254 	return single_open(file, cifs_mount_params_proc_show, NULL);
1255 }
1256 
1257 static const struct proc_ops cifs_mount_params_proc_ops = {
1258 	.proc_open	= cifs_mount_params_proc_open,
1259 	.proc_read	= seq_read,
1260 	.proc_lseek	= seq_lseek,
1261 	.proc_release	= single_release,
1262 	/* No need for write for now */
1263 	/* .proc_write	= cifs_mount_params_proc_write, */
1264 };
1265 
1266 #else
1267 inline void cifs_proc_init(void)
1268 {
1269 }
1270 
1271 inline void cifs_proc_clean(void)
1272 {
1273 }
1274 #endif /* PROC_FS */
1275