CIFS: Implement SMBDirect
Subsystems (3)
v4 cover CIFS: Implement SMBDirect
From: Long Li <[email protected]>
Starting with SMB2 dialect 3.0, Microsoft introduced SMBDirect transport protocol for transferring upper layer (SMB2) payload over RDMA via Infiniband, RoCE or iWARP. The prococol is published in [MS-SMBD]
(https://msdn.microsoft.com/en-us/library/hh536346.aspx).
Patch v2 added RDMA read/write via memory registration, and addressed feedbacks on v1.
Patch v3 improved performance by introducing an additional queue for handling empty packets and reducing lock contention on IRQ path. Also added light weight profiling by reading TSC and addressed feedbacks on v2.
Patch v4 fixed connectivity issues with iWAPR devices and addressed comments.
Long Li (22):
CIFS: SMBD: Add SMBDirect protocol initial values and constants
CIFS: SMBD: Establish SMBDirect connection
CIFS: SMBD: export protocol initial values
CIFS: SMBD: Add rdma mount option
CIFS: SMBD: Implement function to create a SMBDirect connection
CIFS: SMBD: Upper layer connects to SMBDirect session
CIFS: SMBD: Implement function to reconnect to a SMBDirect transport
CIFS: SMBD: Upper layer reconnects to SMBDirect session
CIFS: SMBD: Implement function to destroy a SMBDirect connection
CIFS: SMBD: Upper layer destroys SMBDirect session on shutdown or
umount
CIFS: SMBD: Set SMBDirect maximum read or write size for I/O
CIFS: SMBD: Implement function to receive data via RDMA receive
CIFS: SMBD: Upper layer receives data via RDMA receive
CIFS: SMBD: Implement function to send data via RDMA send
CIFS: SMBD: Upper layer sends data via RDMA send
CIFS: SMBD: Fix the definition for SMB2_CHANNEL_RDMA_V1_INVALIDATE
CIFS: SMBD: Implement RDMA memory registration
CIFS: SMBD: Upper layer performs SMB write via RDMA read through
memory registration
CIFS: SMBD: Add parameter rdata to smb2_new_read_req
CIFS: SMBD: Read correct returned data length for RDMA write (SMB
read) I/O
CIFS: SMBD: Upper layer performs SMB read via RDMA write through
memory registration
CIFS: SMBD: Add SMBDirect debug counters
fs/cifs/Makefile | 2 +- fs/cifs/cifs_debug.c | 159 +++ fs/cifs/cifsfs.c | 2 + fs/cifs/cifsglob.h | 17 +- fs/cifs/cifssmb.c | 10 +- fs/cifs/connect.c | 46 +- fs/cifs/file.c | 10 + fs/cifs/smb1ops.c | 2 +- fs/cifs/smb2ops.c | 21 +- fs/cifs/smb2pdu.c | 114 ++- fs/cifs/smb2pdu.h | 2 +- fs/cifs/smbdirect.c | 2651 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smbdirect.h | 325 +++++++ fs/cifs/transport.c | 7 + 14 files changed, 3348 insertions(+), 20 deletions(-) create mode 100644 fs/cifs/smbdirect.c create mode 100644 fs/cifs/smbdirect.h
Signature · 1 line
2.7.4
PATCH v4 1/22 CIFS: SMBD: Add SMBDirect protocol initial values and constants
From: Long Li <[email protected]>
To prepare for protocol implementation, add constants and user-configurable values in the SMBDirect protocol.
--- fs/cifs/smbdirect.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smbdirect.h | 21 +++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 fs/cifs/smbdirect.c create mode 100644 fs/cifs/smbdirect.h
fs/cifs/smbdirect.c new file +77 -0
@@ -0,0 +1,77 @@ +/* +* Copyright (C) 2017, Microsoft Corporation. +* +* Author(s): Long Li <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +*/ +#include "smbdirect.h" + +/* SMBD version number */ +#define SMBD_V1 0x0100 + +/* Port numbers for SMBD transport */ +#define SMB_PORT 445 +#define SMBD_PORT 5445 + +/* Address lookup and resolve timeout in ms */ +#define RDMA_RESOLVE_TIMEOUT 5000 + +/* SMBD negotiation timeout in seconds */ +#define SMBD_NEGOTIATE_TIMEOUT 120 + +/* SMBD minimum receive size and fragmented sized defined in [MS-SMBD] */ +#define SMBD_MIN_RECEIVE_SIZE 128 +#define SMBD_MIN_FRAGMENTED_SIZE 131072 + +/* +* Default maximum number of RDMA read/write outstanding on this connection +* This value is possibly decreased during QP creation on hardware limit +*/ +#define SMBD_CM_RESPONDER_RESOURCES 32 + +/* Maximum number of retries on data transfer operations */ +#define SMBD_CM_RETRY 6 +/* No need to retry on Receiver Not Ready since SMBD manages credits */ +#define SMBD_CM_RNR_RETRY 0 + +/* +* User configurable initial values per SMBD transport connection +* as defined in [MS-SMBD] 3.1.1.1 +* Those may change after a SMBD negotiation +*/ +/* The local peer's maximum number of credits to grant to the peer */ +int smbd_receive_credit_max =255 ; + +/* The remote peer's credit request of local peer */ +int smbd_send_credit_target =255 ; + +/* The maximum single message size can be sent to remote peer */ +int smbd_max_send_size =1364 ; + +/* The maximum fragmented upper-layer payload receive size supported */ +int smbd_max_fragmented_recv_size =1024 *1024 ; + +/* The maximum single-message size which can be received */ +int smbd_max_receive_size =8192 ; + +/* The timeout to initiate send of a keepalive message on idle */ +int smbd_keep_alive_interval =120 ; + +/* +* User configurable initial values for RDMA transport +* The actual values used may be lower and are limited to hardware capabilities +*/ +/* Default maximum number of SGEs in a RDMA write/read */ +int smbd_max_frmr_depth =2048 ; + +/* If payload is less than this byte, use RDMA send/recv not read/write */ +int rdma_readwrite_threshold =4096 ;
fs/cifs/smbdirect.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* Copyright (C) 2017, Microsoft Corporation. +* +* Author(s): Long Li <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +*/ +#ifndef _SMBDIRECT_H +#define _SMBDIRECT_H + +/* Default maximum number of SGEs in a RDMA send/recv */ +#define SMBDIRECT_MAX_SGE 16 +#endif
Signature · 1 line
2.7.4
PATCH v4 2/22 CIFS: SMBD: Establish SMBDirect connection
In reply to Long LiFrom: Long Li <[email protected]>
Add code to implement the core functions to establish a SMBDirect connection.
1. Establish an RDMA connection to SMB server.
2. Negotiate and setup SMBDirect protocol.
3. Implement idle connection timer and credit management.
Add to Makefile.
--- fs/cifs/Makefile | 2 +- fs/cifs/smbdirect.c | 1600 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smbdirect.h | 229 ++++++++ 3 files changed, 1830 insertions(+), 1 deletion(-)
fs/cifs/Makefile +1 -1
@@ -8,7 +8,7 @@ cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \ cifs_unicode.o nterr.o cifsencrypt.o \ readdir.o ioctl.o sess.o export.o smb1ops.o winucase.o \ smb2ops.o smb2maperror.o smb2transport.o \ - smb2misc.o smb2pdu.o smb2inode.o smb2file.o + smb2misc.o smb2pdu.o smb2inode.o smb2file.o smbdirect.o cifs-$(CONFIG_CIFS_XATTR) += xattr.o cifs-$(CONFIG_CIFS_ACL) += cifsacl.o
fs/cifs/smbdirect.c +1600 -0
1,610 lines not on this page · raw message
fs/cifs/smbdirect.h +229 -0
235 lines not on this page · raw message
Signature · 1 line
2.7.4
kbuild test robot
build botRe: [Patch v4 02/22] CIFS: SMBD: Establish SMBDirect connection
reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…
Hi Long,
[auto build test ERROR on cifs/for-next]
[also build test ERROR on v4.14-rc3 next-20170929]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Long-Li/CIFS-Implement-SMBDirect/20171004-165915 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: ia64-defconfig (attached as .config) compiler: ia64-linux-gcc (GCC) 6.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=ia64
All errors (new ones prefixed by >>):
>> fs//cifs/smbdirect.c:19:21: fatal error: asm/msr.h: No such file or directory
#include <asm/msr.h>
^compilation terminated.
vim +19 fs//cifs/smbdirect.c
> 19 #include <asm/msr.h>
20 ---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v4 3/22 CIFS: SMBD: export protocol initial values
In reply to Long LiFrom: Long Li <[email protected]>
Those values can be configured by user. Export them to /proc/fs/cifs.
--- fs/cifs/cifs_debug.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)
fs/cifs/cifs_debug.c +70 -0
@@ -369,6 +369,52 @@ static const struct file_operations cifs_stats_proc_fops = { };#endif /* STATS */ +#define PROC_FILE_DEFINE (name) \ +static ssize_t name##_write(struct file *file, const char __user *buffer, \ + size_t count, loff_t *ppos) \ +{ \ + int rc; \ + rc = kstrtoint_from_user(buffer, count, 10, & name ); \ + if (rc) \ + return rc; \ + return count; \ +} \ +static int name##_proc_show(struct seq_file *m, void *v) \ +{ \ + seq_printf(m, "%d\n", name ); \ + return 0; \ +} \ +static int name##_open(struct inode *inode, struct file *file) \ +{ \ + return single_open(file, name##_proc_show, NULL); \ +} \ +\ +static const struct file_operations cifs_##name##_proc_fops = { \ + .open = name##_open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ + .write = name##_write, \ +} + +extern int rdma_readwrite_threshold; +extern int smbd_max_frmr_depth; +extern int smbd_keep_alive_interval; +extern int smbd_max_receive_size; +extern int smbd_max_fragmented_recv_size; +extern int smbd_max_send_size; +extern int smbd_send_credit_target; +extern int smbd_receive_credit_max; + +PROC_FILE_DEFINE (rdma_readwrite_threshold); +PROC_FILE_DEFINE (smbd_max_frmr_depth); +PROC_FILE_DEFINE (smbd_keep_alive_interval); +PROC_FILE_DEFINE (smbd_max_receive_size); +PROC_FILE_DEFINE (smbd_max_fragmented_recv_size); +PROC_FILE_DEFINE (smbd_max_send_size); +PROC_FILE_DEFINE (smbd_send_credit_target); +PROC_FILE_DEFINE (smbd_receive_credit_max); +static struct proc_dir_entry *proc_fs_cifs;static const struct file_operations cifsFYI_proc_fops;static const struct file_operations cifs_lookup_cache_proc_fops;
@@ -396,6 +442,22 @@ cifs_proc_init(void) &cifs_security_flags_proc_fops);proc_create ("LookupCacheEnabled" ,0 , proc_fs_cifs, &cifs_lookup_cache_proc_fops); +proc_create ("rdma_readwrite_threshold" ,0 , proc_fs_cifs, + &cifs_rdma_readwrite_threshold_proc_fops); +proc_create ("smbd_max_frmr_depth" ,0 , proc_fs_cifs, + &cifs_smbd_max_frmr_depth_proc_fops); +proc_create ("smbd_keep_alive_interval" ,0 , proc_fs_cifs, + &cifs_smbd_keep_alive_interval_proc_fops); +proc_create ("smbd_max_receive_size" ,0 , proc_fs_cifs, + &cifs_smbd_max_receive_size_proc_fops); +proc_create ("smbd_max_fragmented_recv_size" ,0 , proc_fs_cifs, + &cifs_smbd_max_fragmented_recv_size_proc_fops); +proc_create ("smbd_max_send_size" ,0 , proc_fs_cifs, + &cifs_smbd_max_send_size_proc_fops); +proc_create ("smbd_send_credit_target" ,0 , proc_fs_cifs, + &cifs_smbd_send_credit_target_proc_fops); +proc_create ("smbd_receive_credit_max" ,0 , proc_fs_cifs, + &cifs_smbd_receive_credit_max_proc_fops); }void
@@ -413,6 +475,14 @@ cifs_proc_clean(void)remove_proc_entry ("SecurityFlags" , proc_fs_cifs);remove_proc_entry ("LinuxExtensionsEnabled" , proc_fs_cifs);remove_proc_entry ("LookupCacheEnabled" , proc_fs_cifs); +remove_proc_entry ("rdma_readwrite_threshold" , proc_fs_cifs); +remove_proc_entry ("smbd_max_frmr_depth" , proc_fs_cifs); +remove_proc_entry ("smbd_keep_alive_interval" , proc_fs_cifs); +remove_proc_entry ("smbd_max_receive_size" , proc_fs_cifs); +remove_proc_entry ("smbd_max_fragmented_recv_size" , proc_fs_cifs); +remove_proc_entry ("smbd_max_send_size" , proc_fs_cifs); +remove_proc_entry ("smbd_send_credit_target" , proc_fs_cifs); +remove_proc_entry ("smbd_receive_credit_max" , proc_fs_cifs);remove_proc_entry ("fs/cifs" ,NULL ); }
Signature · 1 line
2.7.4
PATCH v4 4/22 CIFS: SMBD: Add rdma mount option
In reply to Long LiFrom: Long Li <[email protected]>
Add "rdma" to CIFS mount options to connect to SMB Direct. Add checks to validate this is used on SMB 3.X dialects.
To connect to SMBDirect, use "mount.cifs -o rdma,vers=3.x". At the time of this patch, 3.x can be 3.0, 3.02 or 3.1.1.
--- fs/cifs/cifs_debug.c | 2 ++ fs/cifs/cifsfs.c | 2 ++ fs/cifs/cifsglob.h | 5 +++++ fs/cifs/connect.c | 15 ++++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-)
fs/cifs/cifs_debug.c +2 -0
@@ -171,6 +171,8 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v) ses->ses_count, ses->serverOS, ses->serverNOS, ses->capabilities, ses->status); } +if (server->rdma) +seq_printf (m,"RDMA\n\t" ); seq_printf(m, "TCP status: %d\n\tLocal Users To " "Server: %d SecMode: 0x%x Req On Wire: %d", server->tcpStatus, server->srv_count,
fs/cifs/cifsfs.c +2 -0
@@ -327,6 +327,8 @@ cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)default :seq_puts (s,"(unknown)" ); } +if (server->rdma) +seq_puts (s,",rdma" ); } static void
fs/cifs/cifsglob.h +5 -0
@@ -530,6 +530,7 @@ struct smb_vol { bool nopersistent:1; bool resilient:1; /* noresilient not required since not fored for CA */ bool domainauto:1; + bool rdma:1;unsigned int rsize;unsigned int wsize; bool sockopt_tcp_nodelay:1;
@@ -646,6 +647,10 @@ struct TCP_Server_Info {bool sec_kerberos;/* supports plain Kerberos */ bool sec_mskerberos;/* supports legacy MS Kerberos */ bool large_buf;/* is current buffer large? */ +/* use SMBD connection instead of socket */ +bool rdma; +/* point to the SMBD connection if RDMA is used instead of socket */ +struct smbd_connection *smbd_conn;struct delayed_work echo;/* echo ping workqueue job */ char *smallbuf;/* pointer to current "small" buffer */ char *bigbuf;/* pointer to current "big" buffer */
fs/cifs/connect.c +14 -1
@@ -92,7 +92,7 @@ enum { Opt_multiuser, Opt_sloppy, Opt_nosharesock, Opt_persistent, Opt_nopersistent, Opt_resilient, Opt_noresilient, - Opt_domainauto, + Opt_domainauto, Opt_rdma,/* Mount options which take numeric value */ Opt_backupuid, Opt_backupgid, Opt_uid,
@@ -183,6 +183,7 @@ static const match_table_t cifs_mount_option_tokens = { { Opt_resilient, "resilienthandles"}, { Opt_noresilient, "noresilienthandles"}, { Opt_domainauto, "domainauto"}, + { Opt_rdma, "rdma"}, { Opt_backupuid, "backupuid=%s" }, { Opt_backupgid, "backupgid=%s" },
@@ -1538,6 +1539,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,case Opt_domainauto: vol->domainauto = true;break ; +case Opt_rdma: + vol->rdma = true; +break ;/* Numeric Values */ case Opt_backupuid:
@@ -1928,6 +1932,11 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, goto cifs_parse_mount_err; } +if (vol->rdma && vol->vals->protocol_id <SMB30_PROT_ID ) { +cifs_dbg (VFS ,"SMB Direct requires Version >=3.0\n" ); + goto cifs_parse_mount_err; + } +#ifndef CONFIG_KEYS /* Muliuser mounts require CONFIG_KEYS support */ if (vol->multiuser) {
@@ -2131,6 +2140,9 @@ static int match_server(struct TCP_Server_Info *server, struct smb_vol *vol)if (server->echo_interval != vol->echo_interval *HZ )return 0 ; +if (server->rdma != vol->rdma) +return 0 ; +return 1 ; }
@@ -2229,6 +2241,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) tcp_ses->noblocksnd = volume_info->noblocksnd; tcp_ses->noautotune = volume_info->noautotune; tcp_ses->tcp_nodelay = volume_info->sockopt_tcp_nodelay; + tcp_ses->rdma = volume_info->rdma; tcp_ses->in_flight =0 ; tcp_ses->credits =1 ;init_waitqueue_head (&tcp_ses->response_q);
Signature · 1 line
2.7.4
PATCH v4 5/22 CIFS: SMBD: Implement function to create a SMBDirect connection
In reply to Long LiFrom: Long Li <[email protected]>
The upper layer calls this function to connect to peer through SMBDirect. Each SMBDirect connection is based on a RC Queue Pair.
--- fs/cifs/smbdirect.c | 17 +++++++++++++++++ fs/cifs/smbdirect.h | 4 ++++ 2 files changed, 21 insertions(+)
fs/cifs/smbdirect.c +17 -0
@@ -1675,3 +1675,20 @@ struct smbd_connection *_smbd_get_connection(kfree (info);return NULL ; } + +struct smbd_connection *smbd_get_connection ( +struct TCP_Server_Info *server,struct sockaddr *dstaddr) +{ +struct smbd_connection *ret; +int port =SMBD_PORT ; + +try_again: + ret =_smbd_get_connection (server, dstaddr, port); + +/* Try SMB_PORT if SMBD_PORT doesn't work */ +if (!ret && port ==SMBD_PORT ) { + port =SMB_PORT ; + goto try_again; + } +return ret; +}
fs/cifs/smbdirect.h +4 -0
@@ -245,6 +245,10 @@ struct smbd_response { u8 packet[]; }; +/* Create a SMBDirect session */ +struct smbd_connection *smbd_get_connection ( +struct TCP_Server_Info *server,struct sockaddr *dstaddr); +void profiling_display_histogram (struct seq_file *m,unsigned long long array[]);#endif
Signature · 1 line
2.7.4
PATCH v4 6/22 CIFS: SMBD: Upper layer connects to SMBDirect session
In reply to Long LiFrom: Long Li <[email protected]>
When "rdma" is specified in the mount option, CIFS attempts to connect to SMBDirect instead of TCP socket.
--- fs/cifs/connect.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
fs/cifs/connect.c +15 -0
@@ -45,6 +45,7 @@#include <linux/parser.h> #include <linux/bvec.h> +#include "smbdirect.h" #include "cifspdu.h" #include "cifsglob.h" #include "cifsproto.h"
@@ -2280,12 +2281,26 @@ cifs_get_tcp_session(struct smb_vol *volume_info)else tcp_ses->echo_interval =SMB_ECHO_INTERVAL_DEFAULT *HZ ; +if (tcp_ses->rdma) { + tcp_ses->smbd_conn =smbd_get_connection ( + tcp_ses, (struct sockaddr *)&volume_info->dstaddr); +if (tcp_ses->smbd_conn) { +cifs_dbg (VFS ,"RDMA transport established\n" ); + rc =0 ; + goto connected; + }else { + rc = -ENOENT ; + goto out_err_crypto_release; + } + } + rc =ip_connect (tcp_ses);if (rc <0 ) {cifs_dbg (VFS ,"Error connecting to socket. Aborting operation.\n" ); goto out_err_crypto_release; } +connected:/* * since we're in a cifs function already, we know that * this will succeed. No need for try_module_get().
Signature · 1 line
2.7.4
PATCH v4 7/22 CIFS: SMBD: Implement function to reconnect to a SMBDirect transport
In reply to Long LiFrom: Long Li <[email protected]>
Add function to implement a reconnect to SMBDirect. This involves tearing down the current connection and establishing/negotiating a new connection.
--- fs/cifs/smbdirect.c | 36 ++++++++++++++++++++++++++++++++++++ fs/cifs/smbdirect.h | 3 +++ 2 files changed, 39 insertions(+)
fs/cifs/smbdirect.c +36 -0
@@ -1416,6 +1416,42 @@ static void idle_connection_timer(struct work_struct *work) info->keep_alive_interval*HZ); } +/* +* Reconnect this SMBD connection, called from upper layer +* return value: 0 on success, or actual error code +*/ +int smbd_reconnect (struct TCP_Server_Info *server) +{ +log_rdma_event (INFO ,"reconnecting rdma session\n" ); + +if (!server->smbd_conn) { +log_rdma_event (ERR ,"rdma session already destroyed\n" ); +return -EINVAL ; + } + +/* +* This is possible if transport is disconnected and we haven't received +* notification from RDMA, but upper layer has detected timeout +*/ +if (server->smbd_conn->transport_status ==SMBD_CONNECTED ) { +log_rdma_event (INFO ,"disconnecting transport\n" ); +smbd_disconnect_rdma_connection (server->smbd_conn); + } + +/* wait until the transport is destroyed */ +wait_event (server->smbd_conn->wait_destroy, + server->smbd_conn->transport_status ==SMBD_DESTROYED ); + +destroy_workqueue (server->smbd_conn->workqueue); +kfree (server->smbd_conn); + +log_rdma_event (INFO ,"creating rdma session\n" ); + server->smbd_conn =smbd_get_connection ( + server, (struct sockaddr *) &server->dstaddr); + +return server->smbd_conn ?0 : -ENOENT ; +} +static void destroy_caches_and_workqueue (struct smbd_connection *info) {destroy_receive_buffers (info);
fs/cifs/smbdirect.h +3 -0
@@ -249,6 +249,9 @@ struct smbd_response {struct smbd_connection *smbd_get_connection (struct TCP_Server_Info *server,struct sockaddr *dstaddr); +/* Reconnect SMBDirect session */ +int smbd_reconnect (struct TCP_Server_Info *server); +void profiling_display_histogram (struct seq_file *m,unsigned long long array[]);#endif
Signature · 1 line
2.7.4
PATCH v4 8/22 CIFS: SMBD: Upper layer reconnects to SMBDirect session
In reply to Long LiFrom: Long Li <[email protected]>
Do a reconnect on SMBDirect when it is used as the connection. Reconnect can happen for many reasons and it's mostly the decision of upper layer SMB2.
--- fs/cifs/connect.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/cifs/connect.c +5 -1
@@ -405,7 +405,11 @@ cifs_reconnect(struct TCP_Server_Info *server)/* we should try only the port we connected to before */ mutex_lock (&server->srv_mutex); - rc =generic_ip_connect (server); +if (server->rdma) + rc =smbd_reconnect (server); +else + rc =generic_ip_connect (server); +if (rc) {cifs_dbg (FYI ,"reconnect error %d\n" , rc);mutex_unlock (&server->srv_mutex);
Signature · 1 line
2.7.4
PATCH v4 9/22 CIFS: SMBD: Implement function to destroy a SMBDirect connection
In reply to Long LiFrom: Long Li <[email protected]>
Add function to tear down a SMBDirect connection. This is used by upper layer to free all SMBDirect connection and transport resources.
--- fs/cifs/smbdirect.c | 16 ++++++++++++++++ fs/cifs/smbdirect.h | 3 +++ 2 files changed, 19 insertions(+)
fs/cifs/smbdirect.c +16 -0
@@ -1416,6 +1416,22 @@ static void idle_connection_timer(struct work_struct *work) info->keep_alive_interval*HZ); } +/* Destroy this SMBD connection, called from upper layer */ +void smbd_destroy (struct smbd_connection *info) +{ +log_rdma_event (INFO ,"destroying rdma session\n" ); + +/* Kick off the disconnection process */ +smbd_disconnect_rdma_connection (info); + +log_rdma_event (INFO ,"wait for transport being destroyed\n" ); +wait_event (info->wait_destroy, + info->transport_status ==SMBD_DESTROYED ); + +destroy_workqueue (info->workqueue); +kfree (info); +} +/* * Reconnect this SMBD connection, called from upper layer * return value: 0 on success, or actual error code
fs/cifs/smbdirect.h +3 -0
@@ -252,6 +252,9 @@ struct smbd_connection *smbd_get_connection(/* Reconnect SMBDirect session */ int smbd_reconnect (struct TCP_Server_Info *server); +/* Destroy SMBDirect session */ +void smbd_destroy (struct smbd_connection *info); +void profiling_display_histogram (struct seq_file *m,unsigned long long array[]);#endif
Signature · 1 line
2.7.4
PATCH v4 10/22 CIFS: SMBD: Upper layer destroys SMBDirect session on shutdown or umount
In reply to Long LiFrom: Long Li <[email protected]>
When CIFS wants to umount, call shutdown on transport when SMBDirect is used.
--- fs/cifs/connect.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/cifs/connect.c +5 -0
@@ -704,6 +704,11 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)/* give those requests time to exit */ msleep (125 ); +if (server->smbd_conn) { +smbd_destroy (server->smbd_conn); + server->smbd_conn =NULL ; + } +if (server->ssocket) {sock_release (server->ssocket); server->ssocket =NULL ;
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 11/22 CIFS: SMBD: Set SMBDirect maximum read or write size for I/O
In reply to Long LiFrom: Long Li <[email protected]>
When connecting over SMBDirect, the transport negotiates its maximum I/O sizes with the server and determines how to choose to do RDMA send/recv vs read/write. Expose these maximum I/O sizes to upper layer so we will get the correct sized payloads.
--- fs/cifs/smb2ops.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
fs/cifs/smb2ops.c +11 -2
@@ -32,6 +32,7 @@#include "smb2status.h" #include "smb2glob.h" #include "cifs_ioctl.h" +#include "smbdirect.h" static int change_conf (struct TCP_Server_Info *server)
@@ -249,7 +250,11 @@ smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)/* start with specified wsize, or default */ wsize = volume_info->wsize ? volume_info->wsize :CIFS_DEFAULT_IOSIZE ; - wsize = min_t(unsigned int, wsize, server->max_write); +if (server->rdma) + wsize = min_t(unsigned int, + wsize, server->smbd_conn->max_readwrite_size); +else + wsize = min_t(unsigned int, wsize, server->max_write);if (!(server->capabilities &SMB2_GLOBAL_CAP_LARGE_MTU )) wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
@@ -265,7 +270,11 @@ smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)/* start with specified rsize, or default */ rsize = volume_info->rsize ? volume_info->rsize :CIFS_DEFAULT_IOSIZE ; - rsize = min_t(unsigned int, rsize, server->max_read); +if (server->rdma) + rsize = min_t(unsigned int, + rsize, server->smbd_conn->max_readwrite_size); +else + rsize = min_t(unsigned int, rsize, server->max_read);if (!(server->capabilities &SMB2_GLOBAL_CAP_LARGE_MTU )) rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
Signature · 1 line
2.7.4
PATCH v4 12/22 CIFS: SMBD: Implement function to receive data via RDMA receive
In reply to Long LiFrom: Long Li <[email protected]>
On the receive path, the transport maintains receive buffers and a reassembly queue for transferring payload via RDMA recv. There is data copy in the transport on recv when it copies the payload to upper layer.
The transport recognizes the RFC1002 header length use in the SMB upper layer payloads in CIFS. Because this length is mainly used for TCP and not applicable to RDMA, it is handled as a out-of-band information and is never sent over the wire, and the trasnport behaves like TCP to upper layer by processing and exposing the length correctly on data payloads.
--- fs/cifs/smbdirect.c | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smbdirect.h | 6 ++ 2 files changed, 235 insertions(+)
fs/cifs/smbdirect.c +229 -0
@@ -200,6 +200,8 @@ static void smbd_destroy_rdma_work(struct work_struct *work)log_rdma_event (INFO ,"wait for all recv to finish\n" );wake_up_interruptible (&info->wait_reassembly_queue); +wait_event (info->wait_smbd_recv_pending, + info->smbd_recv_pending ==0 );log_rdma_event (INFO ,"wait for all send posted to IB to finish\n" ); wait_event(info->wait_send_pending,
@@ -1678,6 +1680,9 @@ struct smbd_connection *_smbd_get_connection(queue_delayed_work (info->workqueue, &info->idle_timer_work, info->keep_alive_interval*HZ ); +init_waitqueue_head (&info->wait_smbd_recv_pending); + info->smbd_recv_pending =0 ; +init_waitqueue_head (&info->wait_send_pending);atomic_set (&info->send_pending,0 );
@@ -1744,3 +1749,227 @@ struct smbd_connection *smbd_get_connection( }return ret; } + +/* +* Receive data from receive reassembly queue +* All the incoming data packets are placed in reassembly queue +* buf: the buffer to read data into +* size: the length of data to read +* return value: actual data read +* Note: this implementation copies the data from reassebmly queue to receive +* buffers used by upper layer. This is not the optimal code path. A better way +* to do it is to not have upper layer allocate its receive buffers but rather +* borrow the buffer from reassembly queue, and return it after data is +* consumed. But this will require more changes to upper layer code, and also +* need to consider packet boundaries while they still being reassembled. +*/ +int smbd_recv_buf (struct smbd_connection *info,char *buf,unsigned int size) +{ +struct smbd_response *response; +struct smbd_data_transfer *data_transfer; +int to_copy, to_read, data_read, offset; +u32 data_length, remaining_data_length, data_offset; +int rc; +unsigned long flags; + +again: +if (info->transport_status !=SMBD_CONNECTED ) { +log_read (ERR ,"disconnected\n" ); +return -ENODEV ; + } + +/* +* No need to hold the reassembly queue lock all the time as we are +* the only one reading from the front of the queue. The transport +* may add more entries to the back of the queeu at the same time +*/ +log_read (INFO ,"size=%d info->reassembly_data_length=%d\n" , size, + info->reassembly_data_length); +if (info->reassembly_data_length >= size) { +unsigned long long t1 =rdtsc (); +int queue_length; +int queue_removed =0 ; + +/* +* Need to make sure reassembly_data_length is read before +* reading reassembly_queue_length and calling +* _get_first_reassembly. This call is lock free +* as we never read at the end of the queue which are being +* updated in SOFTIRQ as more data is received +*/ +virt_rmb (); + queue_length = info->reassembly_queue_length; + data_read =0 ; + to_read = size; + offset = info->first_entry_offset; +while (data_read < size) { + response =_get_first_reassembly (info); + data_transfer =smbd_response_payload (response); + data_length =le32_to_cpu (data_transfer->data_length); + remaining_data_length = +le32_to_cpu ( + data_transfer->remaining_data_length); + data_offset =le32_to_cpu (data_transfer->data_offset); + +/* +* The upper layer expects RFC1002 length at the +* beginning of the payload. Return it to indicate +* the total length of the packet. This minimize the +* change to upper layer packet processing logic. This +* will be eventually remove when an intermediate +* transport layer is added +*/ +if (response->first_segment && size ==4 ) { +unsigned int rfc1002_len = + data_length + remaining_data_length; + *((__be32 *)buf) =cpu_to_be32 (rfc1002_len); + data_read =4 ; + response->first_segment = false; +log_read (INFO ,"returning rfc1002 length %d\n" , + rfc1002_len); + goto read_rfc1002_done; + } + + to_copy =min_t (int, data_length - offset, to_read); +memcpy ( + buf + data_read, + (char *)data_transfer + data_offset + offset, + to_copy); + +/* move on to the next buffer? */ +if (to_copy == data_length - offset) { + queue_length--; +/* +* No need to lock if we are not at the +* end of the queue +*/ +if (!queue_length) +spin_lock_irqsave ( + &info->reassembly_queue_lock, + flags); +list_del (&response->list); + queue_removed++; +if (!queue_length) +spin_unlock_irqrestore ( + &info->reassembly_queue_lock, + flags); + + info->count_reassembly_queue--; + info->count_dequeue_reassembly_queue++; +put_receive_buffer (info, response, true); + offset =0 ; +log_read (INFO ,"put_receive_buffer offset=0\n" ); + }else + offset += to_copy; + + to_read -= to_copy; + data_read += to_copy; + +log_read (INFO ,"_get_first_reassembly memcpy %d bytes " +"data_transfer_length-offset=%d after that " +"to_read=%d data_read=%d offset=%d\n" , + to_copy, data_length - offset, + to_read, data_read, offset); + } + +spin_lock_irqsave (&info->reassembly_queue_lock, flags); + info->reassembly_data_length -= data_read; + info->reassembly_queue_length -= queue_removed; +spin_unlock_irqrestore (&info->reassembly_queue_lock, flags); + + info->first_entry_offset = offset; +log_read (INFO ,"returning to thread data_read=%d " +"reassembly_data_length=%d first_entry_offset=%d\n" , + data_read, info->reassembly_data_length, + info->first_entry_offset); +read_rfc1002_done: +profiling_add_histogram (rdtsc () - t1, info->smbd_recv_cycles); +return data_read; + } + +log_read (INFO ,"wait_event on more data\n" ); + rc =wait_event_interruptible ( + info->wait_reassembly_queue, + info->reassembly_data_length >= size || + info->transport_status !=SMBD_CONNECTED ); +/* Don't return any data if interrupted */ +if (rc) +return -ENODEV ; + + goto again; +} + +/* +* Receive a page from receive reassembly queue +* page: the page to read data into +* to_read: the length of data to read +* return value: actual data read +*/ +int smbd_recv_page (struct smbd_connection *info, +struct page *page,unsigned int to_read) +{ +int ret; +char *to_address; + +/* make sure we have the page ready for read */ + ret =wait_event_interruptible ( + info->wait_reassembly_queue, + info->reassembly_data_length >= to_read || + info->transport_status !=SMBD_CONNECTED ); +if (ret) +return 0 ; + +/* now we can read from reassembly queue and not sleep */ + to_address =kmap_atomic (page); + +log_read (INFO ,"reading from page=%p address=%p to_read=%d\n" , + page, to_address, to_read); + + ret =smbd_recv_buf (info, to_address, to_read); +kunmap_atomic (to_address); + +return ret; +} + +/* +* Receive data from transport +* msg: a msghdr point to the buffer, can be ITER_KVEC or ITER_BVEC +* return: total bytes read, or 0. SMB Direct will not do partial read. +*/ +int smbd_recv (struct smbd_connection *info,struct msghdr *msg) +{ +char *buf; +struct page *page; +unsigned int to_read; +int rc; + + info->smbd_recv_pending++; + +switch (msg->msg_iter.type) { +case READ |ITER_KVEC : + buf = msg->msg_iter.kvec->iov_base; + to_read = msg->msg_iter.kvec->iov_len; + rc =smbd_recv_buf (info, buf, to_read); +break ; + +case READ |ITER_BVEC : + page = msg->msg_iter.bvec->bv_page; + to_read = msg->msg_iter.bvec->bv_len; + rc =smbd_recv_page (info, page, to_read); +break ; + +default : +/* It's a bug in upper layer to get there */ +cifs_dbg (VFS ,"CIFS: invalid msg type %d\n" , + msg->msg_iter.type); + rc = -EIO ; + } + + info->smbd_recv_pending--; +wake_up (&info->wait_smbd_recv_pending); + +/* SMBDirect will read it all or nothing */ +if (rc >0 ) + msg->msg_iter.count =0 ; +return rc; +}
fs/cifs/smbdirect.h +6 -0
@@ -88,6 +88,9 @@ struct smbd_connection {int fragment_reassembly_remaining;/* Activity accoutning */ +/* Pending reqeusts issued from upper layer */ +int smbd_recv_pending; +wait_queue_head_t wait_smbd_recv_pending;atomic_t send_pending;wait_queue_head_t wait_send_pending;
@@ -255,6 +258,9 @@ int smbd_reconnect(struct TCP_Server_Info *server);/* Destroy SMBDirect session */ void smbd_destroy (struct smbd_connection *info); +/* Interface for carrying upper layer I/O through send/recv */ +int smbd_recv (struct smbd_connection *info,struct msghdr *msg); +void profiling_display_histogram (struct seq_file *m,unsigned long long array[]);#endif
Signature · 1 line
2.7.4
kbuild test robot
build botRe: [Patch v4 12/22] CIFS: SMBD: Implement function to receive data via RDMA receive
reproduce:
Hi Long,
[auto build test ERROR on cifs/for-next]
[also build test ERROR on v4.14-rc3 next-20170929]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Long-Li/CIFS-Implement-SMBDirect/20171004-165915 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: i386-randconfig-x005-201740 (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=i386
All error/warnings (new ones prefixed by >>):
fs/cifs/smbdirect.c: In function 'smbd_recv_page':
>> fs/cifs/smbdirect.c:1923:15: error: implicit declaration of function 'kmap_atomic' [-Werror=implicit-function-declaration]
to_address = kmap_atomic(page);
^~~~~~~~~~~
>> fs/cifs/smbdirect.c:1923:13: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
to_address = kmap_atomic(page);
^
>> fs/cifs/smbdirect.c:1929:2: error: implicit declaration of function 'kunmap_atomic' [-Werror=implicit-function-declaration]
kunmap_atomic(to_address);
^~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +/kmap_atomic +1923 fs/cifs/smbdirect.c
1901
1902 /*
1903 * Receive a page from receive reassembly queue
1904 * page: the page to read data into
1905 * to_read: the length of data to read
1906 * return value: actual data read
1907 */
1908 int smbd_recv_page(struct smbd_connection *info,
1909 struct page *page, unsigned int to_read)
1910 {
1911 int ret;
1912 char *to_address;
1913
1914 /* make sure we have the page ready for read */
1915 ret = wait_event_interruptible(
1916 info->wait_reassembly_queue,
1917 info->reassembly_data_length >= to_read ||
1918 info->transport_status != SMBD_CONNECTED);
1919 if (ret)
1920 return 0;
1921
1922 /* now we can read from reassembly queue and not sleep */
> 1923 to_address = kmap_atomic(page); 1924 1925 log_read(INFO, "reading from page=%p address=%p to_read=%d\n", 1926 page, to_address, to_read); 1927 1928 ret = smbd_recv_buf(info, to_address, to_read); > 1929 kunmap_atomic(to_address);
1930
1931 return ret;
1932 }
1933
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v4 13/22 CIFS: SMBD: Upper layer receives data via RDMA receive
In reply to Long LiFrom: Long Li <[email protected]>
With SMBDirect connected, use it for receiving data via RDMA receive.
--- fs/cifs/connect.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/cifs/connect.c +4 -1
@@ -542,7 +542,10 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg)if (server_unresponsive (server))return -ECONNABORTED ; - length =sock_recvmsg (server->ssocket, smb_msg,0 ); +if (server->smbd_conn) + length =smbd_recv (server->smbd_conn, smb_msg); +else + length =sock_recvmsg (server->ssocket, smb_msg,0 );if (server->tcpStatus == CifsExiting)return -ESHUTDOWN ;
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 14/22 CIFS: SMBD: Implement function to send data via RDMA send
In reply to Long LiFrom: Long Li <[email protected]>
The transport doesn't maintain send buffers or send queue for transferring payload via RDMA send. There is no data copy in the transport on send.
--- fs/cifs/smbdirect.c | 248 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smbdirect.h | 4 + 2 files changed, 252 insertions(+)
fs/cifs/smbdirect.c +248 -0
@@ -42,6 +42,12 @@ static int smbd_post_recv( struct smbd_response *response);static int smbd_post_send_empty (struct smbd_connection *info); +static int smbd_post_send_data ( +struct smbd_connection *info, +struct kvec *iov,int n_vec,int remaining_data_length); +static int smbd_post_send_page (struct smbd_connection *info, +struct page *page,unsigned long offset, +size_t size,int remaining_data_length);/* SMBD version number */ #define SMBD_V1 0x0100
@@ -198,6 +204,10 @@ static void smbd_destroy_rdma_work(struct work_struct *work)log_rdma_event (INFO ,"cancelling send immediate work\n" );cancel_delayed_work_sync (&info->send_immediate_work); +log_rdma_event (INFO ,"wait for all send to finish\n" ); +wait_event (info->wait_smbd_send_pending, + info->smbd_send_pending ==0 ); +log_rdma_event (INFO ,"wait for all recv to finish\n" );wake_up_interruptible (&info->wait_reassembly_queue); wait_event(info->wait_smbd_recv_pending,
@@ -1103,6 +1113,24 @@ static int smbd_post_send_sgl(struct smbd_connection *info, }/* +* Send a page +* page: the page to send +* offset: offset in the page to send +* size: length in the page to send +* remaining_data_length: remaining data to send in this payload +*/ +static int smbd_post_send_page (struct smbd_connection *info,struct page *page, +unsigned long offset,size_t size,int remaining_data_length) +{ +struct scatterlist sgl; + +sg_init_table (&sgl,1 ); +sg_set_page (&sgl, page, size, offset); + +return smbd_post_send_sgl (info, &sgl, size, remaining_data_length); +} + +/* * Send an empty message * Empty message is used to extend credits to peer to for keep live * while there is no upper layer payload to send at the time
@@ -1114,6 +1142,35 @@ static int smbd_post_send_empty(struct smbd_connection *info) }/* +* Send a data buffer +* iov: the iov array describing the data buffers +* n_vec: number of iov array +* remaining_data_length: remaining data to send following this packet +* in segmented SMBD packet +*/ +static int smbd_post_send_data ( +struct smbd_connection *info,struct kvec *iov,int n_vec, +int remaining_data_length) +{ +int i; +u32 data_length =0 ; +struct scatterlist sgl[SMBDIRECT_MAX_SGE ]; + +if (n_vec >SMBDIRECT_MAX_SGE ) { +cifs_dbg (VFS ,"Can't fit data to SGL, n_vec=%d\n" , n_vec); +return -ENOMEM ; + } + +sg_init_table (sgl, n_vec); +for (i =0 ; i < n_vec; i++) { + data_length += iov[i].iov_len; +sg_set_buf (&sgl[i], iov[i].iov_base, iov[i].iov_len); + } + +return smbd_post_send_sgl (info, sgl, data_length, remaining_data_length); +} + +/* * Post a receive request to the transport * The remote peer can only send data when a receive request is posted * The interaction is controlled by send/receive credit system
@@ -1680,6 +1737,9 @@ struct smbd_connection *_smbd_get_connection(queue_delayed_work (info->workqueue, &info->idle_timer_work, info->keep_alive_interval*HZ ); +init_waitqueue_head (&info->wait_smbd_send_pending); + info->smbd_send_pending =0 ; +init_waitqueue_head (&info->wait_smbd_recv_pending); info->smbd_recv_pending =0 ;
@@ -1973,3 +2033,191 @@ int smbd_recv(struct smbd_connection *info, struct msghdr *msg) msg->msg_iter.count =0 ;return rc; } + +/* +* Send data to transport +* Each rqst is transported as a SMBDirect payload +* rqst: the data to write +* return value: 0 if successfully write, otherwise error code +*/ +int smbd_send (struct smbd_connection *info,struct smb_rqst *rqst) +{ +struct kvec vec; +int nvecs; +int size; +int buflen =0 , remaining_data_length; +int start, i, j; +int max_iov_size = + info->max_send_size -sizeof (struct smbd_data_transfer ); +struct kvec iov[SMBDIRECT_MAX_SGE ]; +int rc; +unsigned long long t1 =rdtsc (); + + info->smbd_send_pending++; +if (info->transport_status !=SMBD_CONNECTED ) { + rc = -ENODEV ; + goto done; + } + +/* +* This usually means a configuration error +* We use RDMA read/write for packet size > rdma_readwrite_threshold +* as long as it's properly configured we should never get into this +* situation +*/ +if (rqst->rq_nvec + rqst->rq_npages >SMBDIRECT_MAX_SGE ) { +log_write (ERR ,"maximum send segment %x exceeding %x\n" , + rqst->rq_nvec + rqst->rq_npages,SMBDIRECT_MAX_SGE ); + rc = -EINVAL ; + goto done; + } + +/* +* Remove the RFC1002 length defined in MS-SMB2 section 2.1 +* It is used only for TCP transport +* In future we may want to add a transport layer under protocol +* layer so this will only be issued to TCP transport +*/ + iov[0 ].iov_base = (char *)rqst->rq_iov[0 ].iov_base +4 ; + iov[0 ].iov_len = rqst->rq_iov[0 ].iov_len -4 ; + buflen += iov[0 ].iov_len; + +/* total up iov array first */ +for (i =1 ; i < rqst->rq_nvec; i++) { + iov[i].iov_base = rqst->rq_iov[i].iov_base; + iov[i].iov_len = rqst->rq_iov[i].iov_len; + buflen += iov[i].iov_len; + } + +/* add in the page array if there is one */ +if (rqst->rq_npages) { + buflen += rqst->rq_pagesz * (rqst->rq_npages -1 ); + buflen += rqst->rq_tailsz; + } + +if (buflen +sizeof (struct smbd_data_transfer ) > + info->max_fragmented_send_size) { +log_write (ERR ,"payload size %d > max size %d\n" , + buflen, info->max_fragmented_send_size); + rc = -EINVAL ; + goto done; + } + + remaining_data_length = buflen; + +log_write (INFO ,"rqst->rq_nvec=%d rqst->rq_npages=%d rq_pagesz=%d " +"rq_tailsz=%d buflen=%d\n" , + rqst->rq_nvec, rqst->rq_npages, rqst->rq_pagesz, + rqst->rq_tailsz, buflen); + + start = i = iov[0 ].iov_len ?0 :1 ; + buflen =0 ; +while (true) { + buflen += iov[i].iov_len; +if (buflen > max_iov_size) { +if (i > start) { + remaining_data_length -= + (buflen-iov[i].iov_len); +log_write (INFO ,"sending iov[] from start=%d " +"i=%d nvecs=%d " +"remaining_data_length=%d\n" , + start, i, i-start, + remaining_data_length); + rc =smbd_post_send_data ( + info, &iov[start], i-start, + remaining_data_length); +if (rc) + goto done; + }else { +/* iov[start] is too big, break it */ + nvecs = (buflen+max_iov_size-1 )/max_iov_size; +log_write (INFO ,"iov[%d] iov_base=%p buflen=%d" +" break to %d vectors\n" , + start, iov[start].iov_base, + buflen, nvecs); +for (j =0 ; j < nvecs; j++) { + vec.iov_base = + (char *)iov[start].iov_base + + j*max_iov_size; + vec.iov_len = max_iov_size; +if (j == nvecs-1 ) + vec.iov_len = + buflen - + max_iov_size*(nvecs-1 ); + remaining_data_length -= vec.iov_len; +log_write (INFO , +"sending vec j=%d iov_base=%p" +" iov_len=%lu " +"remaining_data_length=%d\n" , + j, vec.iov_base, vec.iov_len, + remaining_data_length); + rc =smbd_post_send_data ( + info, &vec,1 , + remaining_data_length); +if (rc) + goto done; + } + i++; + } + start = i; + buflen =0 ; + }else { + i++; +if (i == rqst->rq_nvec) { +/* send out all remaining vecs */ + remaining_data_length -= buflen; +log_write (INFO , +"sending iov[] from start=%d i=%d " +"nvecs=%d remaining_data_length=%d\n" , + start, i, i-start, + remaining_data_length); + rc =smbd_post_send_data (info, &iov[start], + i-start, remaining_data_length); +if (rc) + goto done; +break ; + } + } +log_write (INFO ,"looping i=%d buflen=%d\n" , i, buflen); + } + +/* now sending pages if there are any */ +for (i =0 ; i < rqst->rq_npages; i++) { + buflen = (i == rqst->rq_npages-1 ) ? + rqst->rq_tailsz : rqst->rq_pagesz; + nvecs = (buflen + max_iov_size -1 ) / max_iov_size; +log_write (INFO ,"sending pages buflen=%d nvecs=%d\n" , + buflen, nvecs); +for (j =0 ; j < nvecs; j++) { + size = max_iov_size; +if (j == nvecs-1 ) + size = buflen - j*max_iov_size; + remaining_data_length -= size; +log_write (INFO ,"sending pages i=%d offset=%d size=%d" +" remaining_data_length=%d\n" , + i, j*max_iov_size, size, remaining_data_length); + rc =smbd_post_send_page ( + info, rqst->rq_pages[i], j*max_iov_size, + size, remaining_data_length); +if (rc) + goto done; + } + } + +done: +/* +* As an optimization, we don't wait for individual I/O to finish +* before sending the next one. +* Send them all and wait for pending send count to get to 0 +* that means all the I/Os have been out and we are good to return +*/ + +wait_event (info->wait_send_payload_pending, +atomic_read (&info->send_payload_pending) ==0 ); + + info->smbd_send_pending--; +wake_up (&info->wait_smbd_send_pending); +profiling_add_histogram (rdtsc ()-t1, info->smbd_write_cycles); + +return rc; +}
fs/cifs/smbdirect.h +4 -0
@@ -89,6 +89,9 @@ struct smbd_connection {/* Activity accoutning */ /* Pending reqeusts issued from upper layer */ +int smbd_send_pending; +wait_queue_head_t wait_smbd_send_pending; +int smbd_recv_pending;wait_queue_head_t wait_smbd_recv_pending;
@@ -260,6 +263,7 @@ void smbd_destroy(struct smbd_connection *info);/* Interface for carrying upper layer I/O through send/recv */ int smbd_recv (struct smbd_connection *info,struct msghdr *msg); +int smbd_send (struct smbd_connection *info,struct smb_rqst *rqst);void profiling_display_histogram (struct seq_file *m,unsigned long long array[]);
Signature · 1 line
2.7.4
kbuild test robot
build botRe: [Patch v4 14/22] CIFS: SMBD: Implement function to send data via RDMA send
reproduce:
Hi Long,
[auto build test WARNING on cifs/for-next]
[also build test WARNING on v4.14-rc3]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Long-Li/CIFS-Implement-SMBDirect/20171004-165915 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: i386-randconfig-x001-201740 (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=i386
All warnings (new ones prefixed by >>):
In file included from include/linux/kernel.h:13:0,
from include/linux/list.h:8, from include/linux/module.h:9, from fs/cifs/smbdirect.c:16:
fs/cifs/smbdirect.c: In function 'smbd_send':
>> fs/cifs/cifs_debug.h:55:24: warning: format '%lu' expects argument of type 'long unsigned int', but argument 8 has type 'size_t {aka unsigned int}' [-Wformat=]
pr_debug_ratelimited("%s: " \
^
include/linux/printk.h:285:21: note: in definition of macro 'pr_fmt'
#define pr_fmt(fmt) fmt
^~~
>> fs/cifs/cifs_debug.h:55:3: note: in expansion of macro 'pr_debug_ratelimited'
pr_debug_ratelimited("%s: " \
^~~~~~~~~~~~~~~~~~~~
>> fs/cifs/smbdirect.c:143:3: note: in expansion of macro 'cifs_dbg'
cifs_dbg(VFS, "%s:%d " fmt, __func__, __LINE__, ##args);\
^~~~~~~~
>> fs/cifs/smbdirect.c:151:40: note: in expansion of macro 'log_rdma'
#define log_write(level, fmt, args...) log_rdma(level, LOG_WRITE, fmt, ##args)
^~~~~~~~
>> fs/cifs/smbdirect.c:2148:6: note: in expansion of macro 'log_write'
log_write(INFO,
^~~~~~~~~
In file included from fs/cifs/smbdirect.c:18:0:
>> fs/cifs/smbdirect.c:143:17: warning: format '%lu' expects argument of type 'long unsigned int', but argument 6 has type 'size_t {aka unsigned int}' [-Wformat=]
cifs_dbg(VFS, "%s:%d " fmt, __func__, __LINE__, ##args);\
^
fs/cifs/cifs_debug.h:58:16: note: in definition of macro 'cifs_dbg'
cifs_vfs_err(fmt, ##__VA_ARGS__); \
^~~
>> fs/cifs/smbdirect.c:151:40: note: in expansion of macro 'log_rdma'
#define log_write(level, fmt, args...) log_rdma(level, LOG_WRITE, fmt, ##args)
^~~~~~~~
>> fs/cifs/smbdirect.c:2148:6: note: in expansion of macro 'log_write'
log_write(INFO,
^~~~~~~~~
In file included from include/linux/kernel.h:13:0,
from include/linux/list.h:8,
from include/linux/module.h:9,
from fs/cifs/smbdirect.c:16:
fs/cifs/smbdirect.c:143:17: warning: format '%lu' expects argument of type 'long unsigned int', but argument 7 has type 'size_t {aka unsigned int}' [-Wformat=]
cifs_dbg(VFS, "%s:%d " fmt, __func__, __LINE__, ##args);\
^
include/linux/printk.h:285:21: note: in definition of macro 'pr_fmt'
#define pr_fmt(fmt) fmt
^~~
fs/cifs/cifs_debug.h:60:3: note: in expansion of macro 'pr_debug_ratelimited'
pr_debug_ratelimited(fmt, ##__VA_ARGS__); \
^~~~~~~~~~~~~~~~~~~~
>> fs/cifs/smbdirect.c:143:3: note: in expansion of macro 'cifs_dbg'
cifs_dbg(VFS, "%s:%d " fmt, __func__, __LINE__, ##args);\
^~~~~~~~
>> fs/cifs/smbdirect.c:151:40: note: in expansion of macro 'log_rdma'
#define log_write(level, fmt, args...) log_rdma(level, LOG_WRITE, fmt, ##args)
^~~~~~~~
>> fs/cifs/smbdirect.c:2148:6: note: in expansion of macro 'log_write'
log_write(INFO,
^~~~~~~~~vim +/cifs_dbg +143 fs/cifs/smbdirect.c
056f27d3 Long Li 2017-10-01 112
056f27d3 Long Li 2017-10-01 113 /* Transport logging functions
056f27d3 Long Li 2017-10-01 114 * Logging are defined as classes. They can be OR'ed to define the actual
056f27d3 Long Li 2017-10-01 115 * logging level via module parameter smbd_logging_class
056f27d3 Long Li 2017-10-01 116 * e.g. cifs.smbd_logging_class=0x500 will log all log_rdma_recv() and
056f27d3 Long Li 2017-10-01 117 * log_rdma_event()
056f27d3 Long Li 2017-10-01 118 */
056f27d3 Long Li 2017-10-01 119 #define LOG_OUTGOING 0x1
056f27d3 Long Li 2017-10-01 120 #define LOG_INCOMING 0x2
056f27d3 Long Li 2017-10-01 121 #define LOG_READ 0x4
056f27d3 Long Li 2017-10-01 122 #define LOG_WRITE 0x8
056f27d3 Long Li 2017-10-01 123 #define LOG_RDMA_SEND 0x10
056f27d3 Long Li 2017-10-01 124 #define LOG_RDMA_RECV 0x20
056f27d3 Long Li 2017-10-01 125 #define LOG_KEEP_ALIVE 0x40
056f27d3 Long Li 2017-10-01 126 #define LOG_RDMA_EVENT 0x80
056f27d3 Long Li 2017-10-01 127 #define LOG_RDMA_MR 0x100
056f27d3 Long Li 2017-10-01 128 static unsigned int smbd_logging_class = 0;
056f27d3 Long Li 2017-10-01 129 module_param(smbd_logging_class, uint, 0644);
056f27d3 Long Li 2017-10-01 130 MODULE_PARM_DESC(smbd_logging_class,
056f27d3 Long Li 2017-10-01 131 "Logging class for SMBD transport 0x0 to 0x100");
056f27d3 Long Li 2017-10-01 132
056f27d3 Long Li 2017-10-01 133 #define ERR 0x0
056f27d3 Long Li 2017-10-01 134 #define INFO 0x1
056f27d3 Long Li 2017-10-01 135 static unsigned int smbd_logging_level = ERR;
056f27d3 Long Li 2017-10-01 136 module_param(smbd_logging_level, uint, 0644);
056f27d3 Long Li 2017-10-01 137 MODULE_PARM_DESC(smbd_logging_level,
056f27d3 Long Li 2017-10-01 138 "Logging level for SMBD transport, 0 (default): error, 1: info");
056f27d3 Long Li 2017-10-01 139
056f27d3 Long Li 2017-10-01 140 #define log_rdma(level, class, fmt, args...) \
056f27d3 Long Li 2017-10-01 141 do { \
056f27d3 Long Li 2017-10-01 142 if (level <= smbd_logging_level || class & smbd_logging_class) \
056f27d3 Long Li 2017-10-01 @143 cifs_dbg(VFS, "%s:%d " fmt, __func__, __LINE__, ##args);\
056f27d3 Long Li 2017-10-01 144 } while (0)
056f27d3 Long Li 2017-10-01 145
056f27d3 Long Li 2017-10-01 146 #define log_outgoing(level, fmt, args...) \
056f27d3 Long Li 2017-10-01 147 log_rdma(level, LOG_OUTGOING, fmt, ##args)
056f27d3 Long Li 2017-10-01 148 #define log_incoming(level, fmt, args...) \
056f27d3 Long Li 2017-10-01 149 log_rdma(level, LOG_INCOMING, fmt, ##args)
056f27d3 Long Li 2017-10-01 150 #define log_read(level, fmt, args...) log_rdma(level, LOG_READ, fmt, ##args)
056f27d3 Long Li 2017-10-01 @151 #define log_write(level, fmt, args...) log_rdma(level, LOG_WRITE, fmt, ##args)
056f27d3 Long Li 2017-10-01 152 #define log_rdma_send(level, fmt, args...) \
056f27d3 Long Li 2017-10-01 153 log_rdma(level, LOG_RDMA_SEND, fmt, ##args)
056f27d3 Long Li 2017-10-01 154 #define log_rdma_recv(level, fmt, args...) \
056f27d3 Long Li 2017-10-01 155 log_rdma(level, LOG_RDMA_RECV, fmt, ##args)
056f27d3 Long Li 2017-10-01 156 #define log_keep_alive(level, fmt, args...) \
056f27d3 Long Li 2017-10-01 157 log_rdma(level, LOG_KEEP_ALIVE, fmt, ##args)
056f27d3 Long Li 2017-10-01 158 #define log_rdma_event(level, fmt, args...) \
056f27d3 Long Li 2017-10-01 159 log_rdma(level, LOG_RDMA_EVENT, fmt, ##args)
056f27d3 Long Li 2017-10-01 160 #define log_rdma_mr(level, fmt, args...) \
056f27d3 Long Li 2017-10-01 161 log_rdma(level, LOG_RDMA_MR, fmt, ##args)056f27d3 Long Li 2017-10-01 162
:::::: The code at line 143 was first introduced by commit
:::::: 056f27d3b5a46aa10b0e23437c46d1c5a9fab431 CIFS: SMBD: Establish SMBDirect connection
:::::: TO: Long Li <[email protected]> :::::: CC: 0day robot <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [Patch v4 14/22] CIFS: SMBD: Implement function to send data via RDMA send
In reply to Long Lireproduce:
Hi Long,
[auto build test WARNING on cifs/for-next]
[also build test WARNING on v4.14-rc3 next-20170929]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Long-Li/CIFS-Implement-SMBDirect/20171004-165915 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: i386-randconfig-x005-201740 (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=i386
All warnings (new ones prefixed by >>):
fs/cifs/smbdirect.c: In function 'smbd_recv_page':
fs/cifs/smbdirect.c:1983:15: error: implicit declaration of function 'kmap_atomic' [-Werror=implicit-function-declaration]
to_address = kmap_atomic(page);
^~~~~~~~~~~
fs/cifs/smbdirect.c:1983:13: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
to_address = kmap_atomic(page);
^
fs/cifs/smbdirect.c:1989:2: error: implicit declaration of function 'kunmap_atomic' [-Werror=implicit-function-declaration]
kunmap_atomic(to_address);
^~~~~~~~~~~~~
In file included from include/linux/kernel.h:13:0,
from include/linux/list.h:8,
from include/linux/module.h:9,
from fs/cifs/smbdirect.c:16:
fs/cifs/smbdirect.c: In function 'smbd_send':
>> include/linux/kern_levels.h:4:18: warning: format '%lu' expects argument of type 'long unsigned int', but argument 6 has type 'size_t {aka unsigned int}' [-Wformat=]
#define KERN_SOH "\001" /* ASCII Start Of Header */
^
include/linux/printk.h:136:11: note: in definition of macro 'no_printk'
printk(fmt, ##__VA_ARGS__); \
^~~
include/linux/kern_levels.h:14:20: note: in expansion of macro 'KERN_SOH'
#define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
^~~~~~~~
include/linux/printk.h:339:12: note: in expansion of macro 'KERN_DEBUG'
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
^~~~~~~~~~
>> fs/cifs/cifs_debug.h:72:3: note: in expansion of macro 'pr_debug'
pr_debug(fmt, ##__VA_ARGS__); \
^~~~~~~~
fs/cifs/smbdirect.c:143:3: note: in expansion of macro 'cifs_dbg'
cifs_dbg(VFS, "%s:%d " fmt, __func__, __LINE__, ##args);\
^~~~~~~~
fs/cifs/smbdirect.c:151:40: note: in expansion of macro 'log_rdma'
#define log_write(level, fmt, args...) log_rdma(level, LOG_WRITE, fmt, ##args)
^~~~~~~~
fs/cifs/smbdirect.c:2148:6: note: in expansion of macro 'log_write'
log_write(INFO,
^~~~~~~~~cc1: some warnings being treated as errors
vim +4 include/linux/kern_levels.h
314ba352 Joe Perches 2012-07-30 304d2c8c8 Joe Perches 2012-07-30 @4 #define KERN_SOH "\001" /* ASCII Start Of Header */04d2c8c8 Joe Perches 2012-07-30 5 #define KERN_SOH_ASCII '\001'04d2c8c8 Joe Perches 2012-07-30 6
:::::: The code at line 4 was first introduced by commit
:::::: 04d2c8c83d0e3ac5f78aeede51babb3236200112 printk: convert the format for KERN_<LEVEL> to a 2 byte pattern
:::::: TO: Joe Perches <[email protected]> :::::: CC: Linus Torvalds <torvalds-de/[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v4 15/22 CIFS: SMBD: Upper layer sends data via RDMA send
In reply to Long LiFrom: Long Li <[email protected]>
With SMBDirect connected, use it for sending data via RDMA send.
--- fs/cifs/transport.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/cifs/transport.c +7 -0
@@ -37,6 +37,7 @@#include "cifsglob.h" #include "cifsproto.h" #include "cifs_debug.h" +#include "smbdirect.h" void cifs_wake_up_task (struct mid_q_entry *mid)
@@ -230,6 +231,11 @@ __smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)struct msghdr smb_msg;int val =1 ; +if (server->smbd_conn) { + rc =smbd_send (server->smbd_conn, rqst); + goto done; + } +if (ssocket ==NULL )return -ENOTSOCK ;
@@ -299,6 +305,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) server->tcpStatus = CifsNeedReconnect; } +done:if (rc <0 && rc != -EINTR )cifs_dbg (VFS ,"Error %d sending data on socket to server\n" , rc);
Signature · 1 line
2.7.4
PATCH v4 16/22 CIFS: SMBD: Fix the definition for SMB2_CHANNEL_RDMA_V1_INVALIDATE
In reply to Long LiFrom: Long Li <[email protected]>
The channel value for requesting server remote invalidating local memory registration should be 0x00000002
--- fs/cifs/smb2pdu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2pdu.h +1 -1
@@ -832,7 +832,7 @@ struct smb2_flush_rsp {/* Channel field for read and write: exactly one of following flags can be set*/ #define SMB2_CHANNEL_NONE 0x00000000#define SMB2_CHANNEL_RDMA_V1 0x00000001/* SMB3 or later */ -#define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000001/* SMB3.02 or later */ +#define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000002/* SMB3.02 or later */ /* SMB2 read request without RFC1001 length at the beginning */ struct smb2_read_plain_req {
Signature · 1 line
2.7.4
Re: [Patch v4 16/22] CIFS: SMBD: Fix the definition for SMB2_CHANNEL_RDMA_V1_INVALIDATE
Good catch - merged into cifs-2.6.git for-next
Quoted 30 lines · Long Li
From: Long Li <[email protected]>
The channel value for requesting server remote invalidating local memory registration should be
0x00000002Signed-off-by Long Li <[email protected]>--- fs/cifs/smb2pdu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/cifs/smb2pdu.h +1
-2@@ -832,7 +832,7 @@ struct smb2_flush_rsp {/* Channel field for read and write: exactly one of following flags can be set*/ #define SMB2_CHANNEL_NONE 0x00000000#define SMB2_CHANNEL_RDMA_V1 0x00000001/* SMB3 or later */ -#define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000001/* SMB3.02 or later */ +#define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000002/* SMB3.02 or later */ /* SMB2 read request without RFC1001 length at the beginning */ struct smb2_read_plain_req { --2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Thanks, Steve
PATCH v4 17/22 CIFS: SMBD: Implement RDMA memory registration
In reply to Long LiFrom: Long Li <[email protected]>
Memory registration is used for transferring payload via RDMA read or write. After I/O is done, memory registrations are recovered and reused. This process can be time consuming and is done in a work queue.
--- fs/cifs/smbdirect.c | 428 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smbdirect.h | 55 +++++++ 2 files changed, 483 insertions(+)
fs/cifs/smbdirect.c +428 -0
@@ -49,6 +49,9 @@ static int smbd_post_send_page(struct smbd_connection *info, struct page *page, unsigned long offset, size_t size, int remaining_data_length); +static void destroy_mr_list (struct smbd_connection *info); +static int allocate_mr_list (struct smbd_connection *info); +/* SMBD version number */ #define SMBD_V1 0x0100
@@ -219,6 +222,12 @@ static void smbd_destroy_rdma_work(struct work_struct *work)wait_event (info->wait_send_payload_pending,atomic_read (&info->send_payload_pending) ==0 ); +log_rdma_event (INFO ,"freeing mr list\n" ); +wake_up_interruptible_all (&info->wait_mr); +wait_event (info->wait_for_mr_cleanup, +atomic_read (&info->mr_used_count) ==0 ); +destroy_mr_list (info); +/* It's not posssible for upper layer to get to reassembly */ log_rdma_event (INFO ,"drain the reassembly queue\n" ); do {
@@ -475,6 +484,16 @@ static bool process_negotiation_response( } info->max_fragmented_send_size =le32_to_cpu (packet->max_fragmented_size); + info->rdma_readwrite_threshold = + rdma_readwrite_threshold > info->max_fragmented_send_size ? + info->max_fragmented_send_size : + rdma_readwrite_threshold; + + + info->max_readwrite_size =min_t (u32, +le32_to_cpu (packet->max_readwrite_size), + info->max_frmr_depth *PAGE_SIZE ); + info->max_frmr_depth = info->max_readwrite_size /PAGE_SIZE ;return true; }
@@ -773,6 +792,12 @@ static int smbd_ia_open( rc = -EPROTONOSUPPORT ; goto out2; } + info->max_frmr_depth =min_t (int, + smbd_max_frmr_depth, + info->id->device->attrs.max_fast_reg_page_list_len); + info->mr_type =IB_MR_TYPE_MEM_REG ; +if (info->id->device->attrs.device_cap_flags &IB_DEVICE_SG_GAPS_REG ) + info->mr_type =IB_MR_TYPE_SG_GAPS ; info->pd =ib_alloc_pd (info->id->device,0 );if (IS_ERR (info->pd)) {
@@ -1610,6 +1635,8 @@ struct smbd_connection *_smbd_get_connection(struct rdma_conn_param conn_param;struct ib_qp_init_attr qp_attr;struct sockaddr_in *addr_in = (struct sockaddr_in *) dstaddr; +struct ib_port_immutable port_immutable; +u32 ird_ord_hdr[2 ]; info =kzalloc (sizeof (struct smbd_connection ),GFP_KERNEL );if (!info)
@@ -1698,6 +1725,28 @@ struct smbd_connection *_smbd_get_connection(memset (&conn_param,0 ,sizeof (conn_param)); conn_param.initiator_depth =0 ; + conn_param.responder_resources = + info->id->device->attrs.max_qp_rd_atom + <SMBD_CM_RESPONDER_RESOURCES ? + info->id->device->attrs.max_qp_rd_atom : +SMBD_CM_RESPONDER_RESOURCES ; + info->responder_resources = conn_param.responder_resources; +log_rdma_mr (INFO ,"responder_resources=%d\n" , + info->responder_resources); + +/* Need to send IRD/ORD in private data for iWARP */ + info->id->device->get_port_immutable ( + info->id->device, info->id->port_num, &port_immutable); +if (port_immutable.core_cap_flags &RDMA_CORE_PORT_IWARP ) { + ird_ord_hdr[0 ] = info->responder_resources; + ird_ord_hdr[1 ] =1 ; + conn_param.private_data = ird_ord_hdr; + conn_param.private_data_len =sizeof (ird_ord_hdr); + }else { + conn_param.private_data =NULL ; + conn_param.private_data_len =0 ; + } + conn_param.retry_count =SMBD_CM_RETRY ; conn_param.rnr_retry_count =SMBD_CM_RNR_RETRY ; conn_param.flow_control =0 ;
@@ -1762,8 +1811,19 @@ struct smbd_connection *_smbd_get_connection( goto negotiation_failed; } + rc =allocate_mr_list (info); +if (rc) { +log_rdma_mr (ERR ,"memory registration allocation failed\n" ); + goto allocate_mr_failed; + } +return info; +allocate_mr_failed: +/* At this point, need to a full transport shutdown */ +smbd_destroy (info); +return NULL ; + negotiation_failed:cancel_delayed_work_sync (&info->idle_timer_work);destroy_caches_and_workqueue (info);
@@ -2221,3 +2281,371 @@ int smbd_send(struct smbd_connection *info, struct smb_rqst *rqst)return rc; } + +static void register_mr_done (struct ib_cq *cq,struct ib_wc *wc) +{ +struct smbd_mr *mr; +struct ib_cqe *cqe; + +if (wc->status) { +log_rdma_mr (ERR ,"status=%d\n" , wc->status); + cqe = wc->wr_cqe; + mr = container_of(cqe, struct smbd_mr, cqe); +smbd_disconnect_rdma_connection (mr->conn); + } +} + +/* +* The work queue function that recovers MRs +* We need to call ib_dereg_mr() and ib_alloc_mr() before this MR can be used +* again. Both calls are slow, so finish them in a workqueue. This will not +* block I/O path. +* There is one workqueue that recovers MRs, there is no need to lock as the +* I/O requests calling smbd_register_mr will never update the links in the +* mr_list. +*/ +static void smbd_mr_recovery_work (struct work_struct *work) +{ +struct smbd_connection *info = + container_of(work, struct smbd_connection, mr_recovery_work); +struct smbd_mr *smbdirect_mr; +int rc; + +list_for_each_entry (smbdirect_mr, &info->mr_list, list) { +if (smbdirect_mr->state ==MR_INVALIDATED || + smbdirect_mr->state ==MR_ERROR ) { + +if (smbdirect_mr->state ==MR_INVALIDATED ) { +ib_dma_unmap_sg ( + info->id->device, smbdirect_mr->sgl, + smbdirect_mr->sgl_count, + smbdirect_mr->dir); + smbdirect_mr->state =MR_READY ; + }else if (smbdirect_mr->state ==MR_ERROR ) { + +/* recover this MR entry */ + rc =ib_dereg_mr (smbdirect_mr->mr); +if (rc) { +log_rdma_mr (ERR , +"ib_dereg_mr faield rc=%x\n" , + rc); +smbd_disconnect_rdma_connection (info); + } + + smbdirect_mr->mr =ib_alloc_mr ( + info->pd, info->mr_type, + info->max_frmr_depth); +if (IS_ERR (smbdirect_mr->mr)) { +log_rdma_mr (ERR , +"ib_alloc_mr failed mr_type=%x " +"max_frmr_depth=%x\n" , + info->mr_type, + info->max_frmr_depth); +smbd_disconnect_rdma_connection (info); + } + + smbdirect_mr->state =MR_READY ; + } +/* smbdirect_mr->state is updated by this function +* and is read and updated by I/O issuing CPUs trying +* to get a MR, the call to atomic_inc_return +* implicates a memory barrier and guarantees this +* value is updated before waking up any calls to +* get_mr() from the I/O issuing CPUs +*/ +if (atomic_inc_return (&info->mr_ready_count) ==1 ) +wake_up_interruptible (&info->wait_mr); + } + } +} + +static void destroy_mr_list (struct smbd_connection *info) +{ +struct smbd_mr *mr, *tmp; + +cancel_work_sync (&info->mr_recovery_work); +list_for_each_entry_safe (mr, tmp, &info->mr_list, list) { +if (mr->state ==MR_INVALIDATED ) +ib_dma_unmap_sg (info->id->device, mr->sgl, + mr->sgl_count, mr->dir); +ib_dereg_mr (mr->mr); +kfree (mr->sgl); +kfree (mr); + } +} + +/* +* Allocate MRs used for RDMA read/write +* The number of MRs will not exceed hardware capability in responder_resources +* All MRs are kept in mr_list. The MR can be recovered after it's used +* Recovery is done in smbd_mr_recovery_work. The content of list entry changes +* as MRs are used and recovered for I/O, but the list links will not change +*/ +static int allocate_mr_list (struct smbd_connection *info) +{ +int i; +struct smbd_mr *smbdirect_mr, *tmp; + +INIT_LIST_HEAD (&info->mr_list); +init_waitqueue_head (&info->wait_mr); +spin_lock_init (&info->mr_list_lock); +atomic_set (&info->mr_ready_count,0 ); +atomic_set (&info->mr_used_count,0 ); +init_waitqueue_head (&info->wait_for_mr_cleanup); +/* Allocate more MRs (2x) than hardware responder_resources */ +for (i =0 ; i < info->responder_resources *2 ; i++) { + smbdirect_mr =kzalloc (sizeof (*smbdirect_mr),GFP_KERNEL ); +if (!smbdirect_mr) + goto out; + smbdirect_mr->mr =ib_alloc_mr (info->pd, info->mr_type, + info->max_frmr_depth); +if (IS_ERR (smbdirect_mr->mr)) { +log_rdma_mr (ERR ,"ib_alloc_mr failed mr_type=%x " +"max_frmr_depth=%x\n" , + info->mr_type, info->max_frmr_depth); + goto out; + } + smbdirect_mr->sgl =kcalloc ( + info->max_frmr_depth, +sizeof (struct scatterlist ), +GFP_KERNEL ); +if (!smbdirect_mr->sgl) { +log_rdma_mr (ERR ,"failed to allocate sgl\n" ); +ib_dereg_mr (smbdirect_mr->mr); + goto out; + } + smbdirect_mr->state =MR_READY ; + smbdirect_mr->conn = info; + +list_add_tail (&smbdirect_mr->list, &info->mr_list); +atomic_inc (&info->mr_ready_count); + } +INIT_WORK (&info->mr_recovery_work, smbd_mr_recovery_work); +return 0 ; + +out: +kfree (smbdirect_mr); + +list_for_each_entry_safe (smbdirect_mr, tmp, &info->mr_list, list) { +ib_dereg_mr (smbdirect_mr->mr); +kfree (smbdirect_mr->sgl); +kfree (smbdirect_mr); + } +return -ENOMEM ; +} + +/* +* Get a MR from mr_list. This function waits until there is at least one +* MR available in the list. It may access the list while the +* smbd_mr_recovery_work is recovering the MR list. This doesn't need a lock +* as they never modify the same places. However, there may be several CPUs +* issueing I/O trying to get MR at the same time, mr_list_lock is used to +* protect this situation. +*/ +static struct smbd_mr *get_mr (struct smbd_connection *info) +{ +struct smbd_mr *ret; +int rc; +again: + rc =wait_event_interruptible (info->wait_mr, +atomic_read (&info->mr_ready_count) || + info->transport_status !=SMBD_CONNECTED ); +if (rc) { +log_rdma_mr (ERR ,"wait_event_interruptible rc=%x\n" , rc); +return NULL ; + } + +if (info->transport_status !=SMBD_CONNECTED ) { +log_rdma_mr (ERR ,"info->transport_status=%x\n" , + info->transport_status); +return NULL ; + } + +spin_lock (&info->mr_list_lock); +list_for_each_entry (ret, &info->mr_list, list) { +if (ret->state ==MR_READY ) { + ret->state =MR_REGISTERED ; +spin_unlock (&info->mr_list_lock); +atomic_dec (&info->mr_ready_count); +atomic_inc (&info->mr_used_count); +return ret; + } + } + +spin_unlock (&info->mr_list_lock); +/* +* It is possible that we can get a MR because other processes may try +* to acquire a MR at the same time. If this is the case, retry it. +*/ + goto again; +} + +/* +* Register memory for RDMA read/write +* pages[]: the list of pages to register memory with +* num_pages: the number of pages to register +* tailsz: if non-zero, the bytes to register in the last page +* writing: true if this is a RDMA write (SMB read), false for RDMA read +* need_invalidate: true if this MR needs to be locally invalidated after I/O +* return value: the MR registered, NULL if failed. +*/ +struct smbd_mr *smbd_register_mr ( +struct smbd_connection *info,struct page *pages[],int num_pages, +int tailsz,bool writing,bool need_invalidate) +{ +struct smbd_mr *smbdirect_mr; +int rc, i; +enum dma_data_direction dir; +struct ib_reg_wr *reg_wr; +struct ib_send_wr *bad_wr; +unsigned long long t1 =rdtsc (); + +if (num_pages > info->max_frmr_depth) { +log_rdma_mr (ERR ,"num_pages=%d max_frmr_depth=%d\n" , + num_pages, info->max_frmr_depth); +return NULL ; + } + + smbdirect_mr =get_mr (info); +if (!smbdirect_mr) { +log_rdma_mr (ERR ,"get_mr returning NULL\n" ); +return NULL ; + } + smbdirect_mr->need_invalidate = need_invalidate; + smbdirect_mr->sgl_count = num_pages; +sg_init_table (smbdirect_mr->sgl, num_pages); + +for (i =0 ; i < num_pages -1 ; i++) +sg_set_page (&smbdirect_mr->sgl[i], pages[i],PAGE_SIZE ,0 ); + +sg_set_page (&smbdirect_mr->sgl[i], pages[i], + tailsz ? tailsz :PAGE_SIZE ,0 ); + + dir = writing ?DMA_FROM_DEVICE :DMA_TO_DEVICE ; + smbdirect_mr->dir = dir; + rc =ib_dma_map_sg (info->id->device, smbdirect_mr->sgl, num_pages, dir); +if (!rc) { +log_rdma_mr (INFO ,"ib_dma_map_sg num_pages=%x dir=%x rc=%x\n" , + num_pages, dir, rc); + goto dma_map_error; + } + + rc =ib_map_mr_sg (smbdirect_mr->mr, smbdirect_mr->sgl, num_pages, +NULL ,PAGE_SIZE ); +if (rc != num_pages) { +log_rdma_mr (INFO , +"ib_map_mr_sg failed rc = %x num_pages = %x\n" , + rc, num_pages); + goto map_mr_error; + } + +ib_update_fast_reg_key (smbdirect_mr->mr, +ib_inc_rkey (smbdirect_mr->mr->rkey)); + reg_wr = &smbdirect_mr->wr; + reg_wr->wr.opcode =IB_WR_REG_MR ; + smbdirect_mr->cqe.done = register_mr_done; + reg_wr->wr.wr_cqe = &smbdirect_mr->cqe; + reg_wr->wr.num_sge =0 ; + reg_wr->wr.send_flags =IB_SEND_SIGNALED ; + reg_wr->mr = smbdirect_mr->mr; + reg_wr->key = smbdirect_mr->mr->rkey; + reg_wr->access = writing ? +IB_ACCESS_REMOTE_WRITE |IB_ACCESS_LOCAL_WRITE : +IB_ACCESS_REMOTE_READ ; + +/* +* There is no need for waiting for complemtion on ib_post_send +* on IB_WR_REG_MR. Hardware enforces a barrier and order of execution +* on the next ib_post_send when we actaully send I/O to remote peer +*/ + rc =ib_post_send (info->id->qp, ®_wr->wr, &bad_wr); +if (!rc) { +profiling_add_histogram ( +rdtsc ()-t1, info->smbd_register_mr_cycles); +return smbdirect_mr; + } + +log_rdma_mr (ERR ,"ib_post_send failed rc=%x reg_wr->key=%x\n" , + rc, reg_wr->key); + +/* If all failed, attempt to recover this MR by setting it MR_ERROR*/ +map_mr_error: +ib_dma_unmap_sg (info->id->device, smbdirect_mr->sgl, + smbdirect_mr->sgl_count, smbdirect_mr->dir); + +dma_map_error: + smbdirect_mr->state =MR_ERROR ; +if (atomic_dec_and_test (&info->mr_used_count)) +wake_up (&info->wait_for_mr_cleanup); + +return NULL ; +} + +static void local_inv_done (struct ib_cq *cq,struct ib_wc *wc) +{ +struct smbd_mr *smbdirect_mr; +struct ib_cqe *cqe; + + cqe = wc->wr_cqe; + smbdirect_mr = container_of(cqe, struct smbd_mr, cqe); + smbdirect_mr->state =MR_INVALIDATED ; +if (wc->status !=IB_WC_SUCCESS ) { +log_rdma_mr (ERR ,"invalidate failed status=%x\n" , wc->status); + smbdirect_mr->state =MR_ERROR ; + } +complete (&smbdirect_mr->invalidate_done); +} + +/* +* Deregister a MR after I/O is done +* This function may wait if remote invalidation is not used +* and we have to locally invalidate the buffer to prevent data is being +* modified by remote peer after upper layer consumes it +*/ +int smbd_deregister_mr (struct smbd_mr *smbdirect_mr) +{ +struct ib_send_wr *wr, *bad_wr; +struct smbd_connection *info = smbdirect_mr->conn; +int rc =0 ; +unsigned long long t1 =rdtsc (); + +if (smbdirect_mr->need_invalidate) { +/* Need to finish local invalidation before returning */ + wr = &smbdirect_mr->inv_wr; + wr->opcode =IB_WR_LOCAL_INV ; + smbdirect_mr->cqe.done = local_inv_done; + wr->wr_cqe = &smbdirect_mr->cqe; + wr->num_sge =0 ; + wr->ex.invalidate_rkey = smbdirect_mr->mr->rkey; + wr->send_flags =IB_SEND_SIGNALED ; + +init_completion (&smbdirect_mr->invalidate_done); + rc =ib_post_send (info->id->qp, wr, &bad_wr); +if (rc) { +log_rdma_mr (ERR ,"ib_post_send failed rc=%x\n" , rc); +smbd_disconnect_rdma_connection (info); + goto done; + } +wait_for_completion (&smbdirect_mr->invalidate_done); + smbdirect_mr->need_invalidate = false; + }else +/* +* For remote invalidation, just set it to MR_INVALIDATED +* and defer to mr_recovery_work to recover the MR for next use +*/ + smbdirect_mr->state =MR_INVALIDATED ; + +/* +* Schedule the work to do MR recovery for future I/Os +* MR recovery is slow and we don't want it to block the current I/O +*/ +queue_work (info->workqueue, &info->mr_recovery_work); + +profiling_add_histogram (rdtsc ()-t1, info->smbd_deregister_mr_cycles); + +done: +if (atomic_dec_and_test (&info->mr_used_count)) +wake_up (&info->wait_for_mr_cleanup); + +return rc; +}
fs/cifs/smbdirect.h +55 -0
73 lines not on this page · raw message
Signature · 1 line
2.7.4
kbuild test robot
build botRe: [Patch v4 17/22] CIFS: SMBD: Implement RDMA memory registration
reproduce:
Hi Long,
[auto build test ERROR on cifs/for-next]
[also build test ERROR on v4.14-rc3 next-20170929]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Long-Li/CIFS-Implement-SMBDirect/20171004-165915 base: git://git.samba.org/sfrench/cifs-2.6.git for-next config: x86_64-acpi-redef (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
fs/cifs/smbdirect.o: In function `smbd_qp_async_error_upcall':
smbdirect.c:(.text+0xb2f): undefined reference to ib_event_msg' fs/cifs/smbdirect.o: In function smbd_mr_recovery_work':
>> smbdirect.c:(.text+0xca4): undefined reference to `ib_dereg_mr' >> smbdirect.c:(.text+0xce7): undefined reference to `ib_alloc_mr' fs/cifs/smbdirect.o: In function `smbd_disconnect_rdma_work': smbdirect.c:(.text+0xed0): undefined reference to `rdma_disconnect' fs/cifs/smbdirect.o: In function `smbd_destroy_rdma_work': smbdirect.c:(.text+0x1625): undefined reference to `ib_drain_qp' smbdirect.c:(.text+0x1631): undefined reference to `rdma_destroy_qp' smbdirect.c:(.text+0x19de): undefined reference to `ib_dereg_mr' smbdirect.c:(.text+0x1b65): undefined reference to `ib_free_cq' smbdirect.c:(.text+0x1b71): undefined reference to `ib_free_cq' smbdirect.c:(.text+0x1b7d): undefined reference to `ib_dealloc_pd' smbdirect.c:(.text+0x1b89): undefined reference to `rdma_destroy_id' fs/cifs/smbdirect.o: In function `_smbd_get_connection': smbdirect.c:(.text+0x1f86): undefined reference to `rdma_create_id' smbdirect.c:(.text+0x2008): undefined reference to `rdma_resolve_addr' smbdirect.c:(.text+0x2075): undefined reference to `rdma_resolve_route' smbdirect.c:(.text+0x20d6): undefined reference to `rdma_destroy_id' smbdirect.c:(.text+0x214c): undefined reference to `__ib_alloc_pd' smbdirect.c:(.text+0x217e): undefined reference to `rdma_destroy_id' smbdirect.c:(.text+0x22d7): undefined reference to `ib_alloc_cq' smbdirect.c:(.text+0x2313): undefined reference to `ib_alloc_cq' smbdirect.c:(.text+0x23a8): undefined reference to `rdma_create_qp' smbdirect.c:(.text+0x2521): undefined reference to `rdma_connect' smbdirect.c:(.text+0x3003): undefined reference to `rdma_destroy_qp' smbdirect.c:(.text+0x3014): undefined reference to `ib_free_cq' smbdirect.c:(.text+0x3025): undefined reference to `ib_free_cq' smbdirect.c:(.text+0x302e): undefined reference to `ib_dealloc_pd' smbdirect.c:(.text+0x3037): undefined reference to `rdma_destroy_id' smbdirect.c:(.text+0x31b4): undefined reference to `rdma_disconnect' smbdirect.c:(.text+0x32c6): undefined reference to `ib_alloc_mr' smbdirect.c:(.text+0x3341): undefined reference to `ib_dereg_mr' smbdirect.c:(.text+0x3410): undefined reference to `ib_dereg_mr' fs/cifs/smbdirect.o: In function `smbd_register_mr': >> smbdirect.c:(.text+0x45e8): undefined reference to `ib_map_mr_sg'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v4 18/22 CIFS: SMBD: Upper layer performs SMB write via RDMA read through memory registration
In reply to Long LiFrom: Long Li <[email protected]>
When sending I/O, if size is larger than rdma_readwrite_threshold we prepare to send SMB write packet for a RDMA read via memory registration. The actual I/O is done by remote peer through local RDMA hardware. Modify the relevant fields in the packet accordingly, and append a smbd_buffer_descriptor_v1 to the end of the SMB write packet.
On write I/O finish, deregister the memory region if this was for a RDMA read. If remote invalidation is not used, the call to smbd_deregister_mr will do local invalidation and possibly wait. Memory region is normally deregistered in MID callback as soon as it's used. There are situations where the MID may not be created on I/O failure, under which memory region is deregistered when write data context is released.
--- fs/cifs/cifsglob.h | 1 + fs/cifs/cifssmb.c | 6 ++++++ fs/cifs/smb2pdu.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-)
fs/cifs/cifsglob.h +1 -0
@@ -1168,6 +1168,7 @@ struct cifs_writedata {pid_t pid;unsigned int bytes;int result; +struct smbd_mr *mr;unsigned int pagesz;unsigned int tailsz;unsigned int credits;
fs/cifs/cifssmb.c +6 -0
@@ -43,6 +43,7 @@#include "cifs_unicode.h" #include "cifs_debug.h" #include "fscache.h" +#include "smbdirect.h" #ifdef CONFIG_CIFS_POSIX static struct {
@@ -1912,6 +1913,11 @@ cifs_writedata_release(struct kref *refcount)struct cifs_writedata *wdata =container_of (refcount, struct cifs_writedata, refcount); +if (wdata->mr) { +smbd_deregister_mr (wdata->mr); + wdata->mr =NULL ; + } +if (wdata->cfile)cifsFileInfo_put (wdata->cfile);
fs/cifs/smb2pdu.c +56 -1
84 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 19/22 CIFS: SMBD: Add parameter rdata to smb2_new_read_req
In reply to Long LiFrom: Long Li <[email protected]>
This patch is for preparing upper layer for doing SMB read via RDMA write.
When we assemble the SMB read packet header, we need to know the I/O layout if this request is to use a RDMA write. rdata has all the information we need for memory registration. Add rdata to smb2_new_read_req.
--- fs/cifs/smb2pdu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
fs/cifs/smb2pdu.c +9 -5
@@ -2351,18 +2351,21 @@ SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,*/ static int smb2_new_read_req (void **buf,unsigned int *total_len, -struct cifs_io_parms *io_parms,unsigned int remaining_bytes, -int request_type) +struct cifs_io_parms *io_parms,struct cifs_readdata *rdata, +unsigned int remaining_bytes,int request_type) {int rc = -EACCES ;struct smb2_read_plain_req *req =NULL ;struct smb2_sync_hdr *shdr; +struct TCP_Server_Info *server; rc =smb2_plain_req_init (SMB2_READ , io_parms->tcon, (void **) &req, total_len);if (rc)return rc; -if (io_parms->tcon->ses->server ==NULL ) + + server = io_parms->tcon->ses->server; +if (server ==NULL )return -ECONNABORTED ; shdr = &req->sync_hdr;
@@ -2490,7 +2493,8 @@ smb2_async_readv(struct cifs_readdata *rdata) server = io_parms.tcon->ses->server; - rc =smb2_new_read_req ((void **) &buf, &total_len, &io_parms,0 ,0 ); + rc =smb2_new_read_req ( + (void **) &buf, &total_len, &io_parms, rdata,0 ,0 );if (rc) {if (rc == -EAGAIN && rdata->credits) {/* credits was reset by reconnect */
@@ -2558,7 +2562,7 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,struct cifs_ses *ses = io_parms->tcon->ses; *nbytes =0 ; - rc =smb2_new_read_req ((void **)&req, &total_len, io_parms,0 ,0 ); + rc =smb2_new_read_req ((void **)&req, &total_len, io_parms,NULL ,0 ,0 );if (rc)return rc;
Signature · 1 line
2.7.4
PATCH v4 20/22 CIFS: SMBD: Read correct returned data length for RDMA write (SMB read) I/O
In reply to Long LiFrom: Long Li <[email protected]>
This patch is for preparing upper layer for doing SMB read via RDMA write.
When RDMA write is used for SMB read, the returned data length is in DataRemaining in the response packet. Reading it properly by adding a parameter to specifiy where the returned data length is.
--- fs/cifs/cifsglob.h | 10 ++++++++-- fs/cifs/cifssmb.c | 4 ++-- fs/cifs/smb1ops.c | 2 +- fs/cifs/smb2ops.c | 8 ++++++-- 4 files changed, 17 insertions(+), 7 deletions(-)
fs/cifs/cifsglob.h +8 -2
@@ -228,8 +228,14 @@ struct smb_version_operations {__u64 (*get_next_mid)(struct TCP_Server_Info *);/* data offset from read response message */ unsigned int (*read_data_offset)(char *); -/* data length from read response message */ -unsigned int (*read_data_length)(char *); +/* +* Data length from read response message +* When in_remaining is true, the returned data length is in +* message field DataRemaining for out-of-band data read (e.g through +* Memory Registration RDMA write in SMBD). +* Otherwise, the returned data length is in message field DataLength. +*/ +unsigned int (*read_data_length)(char *,bool in_remaining);/* map smb to linux error */ int (*map_error)(char *,bool );/* find mid corresponding to the response message */
fs/cifs/cifssmb.c +2 -2
@@ -1531,8 +1531,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) rdata->iov[0].iov_base, server->total_read);/* how much data is in the response? */ - data_len = server->ops->read_data_length (buf); -if (data_offset + data_len > buflen) { + data_len = server->ops->read_data_length (buf, rdata->mr); +if (!rdata->mr && (data_offset + data_len > buflen)) {/* data_len is corrupt -- discard frame */ rdata->result = -EIO ;return cifs_readv_discard (server, mid);
fs/cifs/smb1ops.c +1 -1
@@ -87,7 +87,7 @@ cifs_read_data_offset(char *buf) }static unsigned int -cifs_read_data_length (char *buf) +cifs_read_data_length (char *buf,bool in_remaining) {READ_RSP *rsp = (READ_RSP *)buf; return (le16_to_cpu(rsp->DataLengthHigh) << 16) +
fs/cifs/smb2ops.c +6 -2
@@ -935,9 +935,13 @@ smb2_read_data_offset(char *buf) }static unsigned int -smb2_read_data_length (char *buf) +smb2_read_data_length (char *buf,bool in_remaining) {struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; + +if (in_remaining) +return le32_to_cpu (rsp->DataRemaining); +return le32_to_cpu (rsp->DataLength); }
@@ -2446,7 +2450,7 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, } data_offset = server->ops->read_data_offset (buf) +4 ; - data_len = server->ops->read_data_length (buf); + data_len = server->ops->read_data_length (buf, rdata->mr);if (data_offset < server->vals->read_rsp_size) {/*
Signature · 1 line
2.7.4
PATCH v4 21/22 CIFS: SMBD: Upper layer performs SMB read via RDMA write through memory registration
In reply to Long LiFrom: Long Li <[email protected]>
If I/O size is larger than rdma_readwrite_threshold, use RDMA write for SMB read by specifying channel SMB2_CHANNEL_RDMA_V1 or SMB2_CHANNEL_RDMA_V1_INVALIDATE in the SMB packet, depending on SMB dialect used. Append a smbd_buffer_descriptor_v1 to the end of the SMB packet and fill in other values to indicate this SMB read uses RDMA write.
There is no need to read from the transport for incoming payload. At the time SMB read response comes back, the data is already transfered and placed in the pages by RDMA hardware.
When SMB read is finished, deregister the memory regions if RDMA write is used for this SMB read. smbd_deregister_mr may need to do local invalidation and sleep, if server remote invalidation is not used.
There are situations where the MID may not be created on I/O failure, under which memory region is deregistered when read data context is released.
--- fs/cifs/cifsglob.h | 1 + fs/cifs/file.c | 10 ++++++++++ fs/cifs/smb2pdu.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+)
fs/cifs/cifsglob.h +1 -0
@@ -1152,6 +1152,7 @@ struct cifs_readdata {struct cifs_readdata *rdata, struct iov_iter *iter);struct kvec iov[2 ]; +struct smbd_mr *mr;unsigned int pagesz;unsigned int tailsz;unsigned int credits;
fs/cifs/file.c +10 -0
@@ -42,6 +42,7 @@#include "cifs_debug.h" #include "cifs_fs_sb.h" #include "fscache.h" +#include "smbdirect.h" static inline int cifs_convert_flags (unsigned int flags)
@@ -2909,6 +2910,11 @@ cifs_readdata_release(struct kref *refcount)struct cifs_readdata *rdata =container_of (refcount, struct cifs_readdata, refcount); +if (rdata->mr) { +smbd_deregister_mr (rdata->mr); + rdata->mr =NULL ; + } +if (rdata->cfile)cifsFileInfo_put (rdata->cfile);
@@ -3037,6 +3043,8 @@ uncached_fill_pages(struct TCP_Server_Info *server, }if (iter) result =copy_page_from_iter (page,0 , n, iter); +else if (rdata->mr) + result = n;else result =cifs_read_page_from_socket (server, page, n);if (result <0 )
@@ -3606,6 +3614,8 @@ readpages_fill_pages(struct TCP_Server_Info *server,if (iter) result =copy_page_from_iter (page,0 , n, iter); +else if (rdata->mr) + result = n;else result =cifs_read_page_from_socket (server, page, n);if (result <0 )
fs/cifs/smb2pdu.c +43 -0
55 lines not on this page · raw message
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 22/22 CIFS: SMBD: Add SMBDirect debug counters
In reply to Long LiFrom: Long Li <[email protected]>
Export SMBDirect debug counters to /proc/fs/cifs/DebugData.
Those are used for debugging, troubleshooting and profiling.
--- fs/cifs/cifs_debug.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
fs/cifs/cifs_debug.c +87 -0
@@ -30,6 +30,7 @@#include "cifsproto.h" #include "cifs_debug.h" #include "cifsfs.h" +#include "smbdirect.h" void cifs_dump_mem (char *label,void *data,int length)
@@ -152,6 +153,92 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)list_for_each (tmp1, &cifs_tcp_ses_list) { server = list_entry(tmp1, struct TCP_Server_Info, tcp_ses_list); + +if (!server->rdma) + goto skip_rdma; + +seq_printf (m,"\nSMBDirect (in hex) protocol version: %x " +"transport status: %x" , + server->smbd_conn->protocol, + server->smbd_conn->transport_status); +seq_printf (m,"\nConn receive_credit_max: %x " +"send_credit_target: %x max_send_size: %x" , + server->smbd_conn->receive_credit_max, + server->smbd_conn->send_credit_target, + server->smbd_conn->max_send_size); +seq_printf (m,"\nConn max_fragmented_recv_size: %x " +"max_fragmented_send_size: %x max_receive_size:%x" , + server->smbd_conn->max_fragmented_recv_size, + server->smbd_conn->max_fragmented_send_size, + server->smbd_conn->max_receive_size); +seq_printf (m,"\nConn keep_alive_interval: %x " +"max_readwrite_size: %x rdma_readwrite_threshold: %x" , + server->smbd_conn->keep_alive_interval, + server->smbd_conn->max_readwrite_size, + server->smbd_conn->rdma_readwrite_threshold); +seq_printf (m,"\nDebug count_get_receive_buffer: %x " +"count_put_receive_buffer: %x count_send_empty: %x" , + server->smbd_conn->count_get_receive_buffer, + server->smbd_conn->count_put_receive_buffer, + server->smbd_conn->count_send_empty); +seq_printf (m,"\nRead Queue count_reassembly_queue: %x " +"count_enqueue_reassembly_queue: %x " +"count_dequeue_reassembly_queue: %x " +"fragment_reassembly_remaining: %x " +"reassembly_data_length: %x " +"reassembly_queue_length: %x" , + server->smbd_conn->count_reassembly_queue, + server->smbd_conn->count_enqueue_reassembly_queue, + server->smbd_conn->count_dequeue_reassembly_queue, + server->smbd_conn->fragment_reassembly_remaining, + server->smbd_conn->reassembly_data_length, + server->smbd_conn->reassembly_queue_length); +seq_printf (m,"\nCurrent Credits send_credits: %x " +"receive_credits: %x receive_credit_target: %x" , +atomic_read (&server->smbd_conn->send_credits), +atomic_read (&server->smbd_conn->receive_credits), + server->smbd_conn->receive_credit_target); +seq_printf (m,"\nPending send_pending: %x send_payload_pending:" +" %x smbd_send_pending: %x smbd_recv_pending: %x" , +atomic_read (&server->smbd_conn->send_pending), +atomic_read (&server->smbd_conn->send_payload_pending), + server->smbd_conn->smbd_send_pending, + server->smbd_conn->smbd_recv_pending); +seq_printf (m,"\nReceive buffers count_receive_queue: %x " +"count_empty_packet_queue: %x" , + server->smbd_conn->count_receive_queue, + server->smbd_conn->count_empty_packet_queue); +seq_printf (m,"\nMR responder_resources: %x " +"max_frmr_depth: %x mr_type: %x" , + server->smbd_conn->responder_resources, + server->smbd_conn->max_frmr_depth, + server->smbd_conn->mr_type); +seq_printf (m,"\nMR mr_ready_count: %x mr_used_count: %x" , +atomic_read (&server->smbd_conn->mr_ready_count), +atomic_read (&server->smbd_conn->mr_used_count)); + +seq_printf (m,"\nTSC cycle histogram in I/O path: " +"(the number of most significant bits)" ); +seq_printf (m,"\nsmbd_register_mr cycles [1/10000]: " ); +profiling_display_histogram ( + m, server->smbd_conn->smbd_register_mr_cycles); + +seq_printf (m,"\nsmbd_deregister_mr cycles [1/10000]: " ); +profiling_display_histogram ( + m, server->smbd_conn->smbd_deregister_mr_cycles); + +seq_printf (m,"\nsmbd_send cycles [1/10000]: " ); +profiling_display_histogram ( + m, server->smbd_conn->smbd_write_cycles); + +seq_printf (m,"\nsmbd_recv cycles [1/10000]: " ); +profiling_display_histogram ( + m, server->smbd_conn->smbd_recv_cycles); + +seq_printf (m,"\nrecv_done cycles [1/10000]: " ); +profiling_display_histogram ( + m, server->smbd_conn->recv_done_cycles); +skip_rdma:seq_printf (m,"\nNumber of credits: %d" , server->credits); i++;list_for_each (tmp2, &server->smb_ses_list) {
Signature · 1 line
2.7.4