ksmbd: smbd: handle multiple Buffer Decriptors
Subsystems (2)
PATCH 1/1 ksmbd: smbd: handle multiple Buffer Decriptors
Make ksmbd handle multiple buffer descriptors
when reading and writing files using SMB direct:
- Change the prototype of transport's operations to accept a pointer and length of descriptors.
- Post the work requests of rdma_rw_ctx for RDMA r/w in smb_direct_rdma_xmit(), and the work request for the READ/WRITE response with a remote invaliation in smb_direct_writev().
- SMB2_READ/WRITE request needs the number of rw credits, (the pages the request wants to transfer / the maximum pages which can be registered with one MR) to read and write a file.
- Allocate enough RDMA resources for the maximum number of rw credits allowed by ksmbd.
--- fs/ksmbd/connection.c | 32 ++-- fs/ksmbd/connection.h | 32 ++-- fs/ksmbd/ksmbd_work.h | 4 +- fs/ksmbd/smb2pdu.c | 77 ++++----- fs/ksmbd/transport_rdma.c | 344 ++++++++++++++++++++++---------------- fs/ksmbd/transport_tcp.c | 5 +- 6 files changed, 278 insertions(+), 216 deletions(-)
fs/ksmbd/connection.c +18 -14
@@ -191,10 +191,10 @@ int ksmbd_conn_write(struct ksmbd_work *work) }ksmbd_conn_lock (conn); - sent = conn->transport->ops->writev (conn->transport, &iov[0 ], - iov_idx, len, - work->need_invalidate_rkey, - work->remote_key); + sent = conn->transport->ops->writev (conn->transport, + &iov[0 ], iov_idx, len, + work->need_invalidate_rkey, + work->remote_key);ksmbd_conn_unlock (conn);if (sent <0 ) {
@@ -205,31 +205,35 @@ int ksmbd_conn_write(struct ksmbd_work *work)return 0 ; } -int ksmbd_conn_rdma_read (struct ksmbd_conn *conn,void *buf, -unsigned int buflen,u32 remote_key,u64 remote_offset, -u32 remote_len) +int ksmbd_conn_rdma_read (struct ksmbd_conn *conn, +void *buf,unsigned int buflen, +struct smb2_buffer_desc_v1 *desc, +unsigned int desc_len) {int ret = -EINVAL ; +ksmbd_conn_lock (conn);if (conn->transport->ops->rdma_read) ret = conn->transport->ops->rdma_read (conn->transport, buf, buflen, - remote_key, remote_offset, - remote_len); + desc, desc_len); +ksmbd_conn_unlock (conn);return ret; } -int ksmbd_conn_rdma_write (struct ksmbd_conn *conn,void *buf, -unsigned int buflen,u32 remote_key, -u64 remote_offset,u32 remote_len) +int ksmbd_conn_rdma_write (struct ksmbd_conn *conn, +void *buf,unsigned int buflen, +struct smb2_buffer_desc_v1 *desc, +unsigned int desc_len) {int ret = -EINVAL ; +ksmbd_conn_lock (conn);if (conn->transport->ops->rdma_write) ret = conn->transport->ops->rdma_write (conn->transport, buf, buflen, - remote_key, remote_offset, - remote_len); + desc, desc_len); +ksmbd_conn_unlock (conn);return ret; }
fs/ksmbd/connection.h +19 -13
@@ -119,14 +119,18 @@ struct ksmbd_transport_ops {void (*disconnect)(struct ksmbd_transport *t);void (*shutdown)(struct ksmbd_transport *t);int (*read)(struct ksmbd_transport *t,char *buf,unsigned int size); -int (*writev)(struct ksmbd_transport *t,struct kvec *iovs,int niov, -int size,bool need_invalidate_rkey, +int (*writev)(struct ksmbd_transport *t, +struct kvec *iovs,int niov,int size, +bool need_invalidate,unsigned int remote_key); -int (*rdma_read)(struct ksmbd_transport *t,void *buf,unsigned int len, -u32 remote_key,u64 remote_offset,u32 remote_len); -int (*rdma_write)(struct ksmbd_transport *t,void *buf, -unsigned int len,u32 remote_key,u64 remote_offset, -u32 remote_len); +int (*rdma_read)(struct ksmbd_transport *t, +void *buf,unsigned int len, +struct smb2_buffer_desc_v1 *desc, +unsigned int desc_len); +int (*rdma_write)(struct ksmbd_transport *t, +void *buf,unsigned int len, +struct smb2_buffer_desc_v1 *desc, +unsigned int desc_len); };struct ksmbd_transport {
@@ -148,12 +152,14 @@ struct ksmbd_conn *ksmbd_conn_alloc(void);void ksmbd_conn_free (struct ksmbd_conn *conn);bool ksmbd_conn_lookup_dialect (struct ksmbd_conn *c);int ksmbd_conn_write (struct ksmbd_work *work); -int ksmbd_conn_rdma_read (struct ksmbd_conn *conn,void *buf, -unsigned int buflen,u32 remote_key,u64 remote_offset, -u32 remote_len); -int ksmbd_conn_rdma_write (struct ksmbd_conn *conn,void *buf, -unsigned int buflen,u32 remote_key,u64 remote_offset, -u32 remote_len); +int ksmbd_conn_rdma_read (struct ksmbd_conn *conn, +void *buf,unsigned int buflen, +struct smb2_buffer_desc_v1 *desc, +unsigned int desc_len); +int ksmbd_conn_rdma_write (struct ksmbd_conn *conn, +void *buf,unsigned int buflen, +struct smb2_buffer_desc_v1 *desc, +unsigned int desc_len);void ksmbd_conn_enqueue_request (struct ksmbd_work *work);int ksmbd_conn_try_dequeue_request (struct ksmbd_work *work);void ksmbd_conn_init_server_callbacks (struct ksmbd_conn_ops *ops);
fs/ksmbd/ksmbd_work.h +2 -2
@@ -69,9 +69,9 @@ struct ksmbd_work { bool encrypted:1;/* Is this SYNC or ASYNC ksmbd_work */ bool syncronous:1; - bool need_invalidate_rkey:1; + bool need_invalidate_rkey:1; -unsigned int remote_key; +unsigned int remote_key;/* cancel works */ int async_id;void **cancel_argv;
fs/ksmbd/smb2pdu.c +36 -41
142 lines not on this page · raw message
fs/ksmbd/transport_rdma.c +200 -144
547 lines not on this page · raw message
fs/ksmbd/transport_tcp.c +3 -2
@@ -352,8 +352,9 @@ static int ksmbd_tcp_read(struct ksmbd_transport *t, char *buf, unsigned int to_return ksmbd_tcp_readv (TCP_TRANS (t), &iov,1 , to_read); } -static int ksmbd_tcp_writev (struct ksmbd_transport *t,struct kvec *iov, -int nvecs,int size,bool need_invalidate, +static int ksmbd_tcp_writev (struct ksmbd_transport *t, +struct kvec *iov,int nvecs,int size, +bool need_invalidate,unsigned int remote_key) {
Signature · 1 line
2.25.1
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi Hyunchul,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.18-rc1 next-20220401]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Hyunchul-Lee/ksmbd-smbd-handle-multiple-Buffer-Decriptors/20220404-073255 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git be2d3ecedd9911fbfd7e55cc9ceac5f8b79ae4cf config: mips-randconfig-s032-20220404 (https://download.01.org/0day-ci/archive/20220404/[email protected]/config) compiler: mips-linux-gcc (GCC) 11.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/intel-lab-lkp/linux/commit/3b3063c454ee836c82afc4a47004165038971cc4
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Hyunchul-Lee/ksmbd-smbd-handle-multiple-Buffer-Decriptors/20220404-073255
git checkout 3b3063c454ee836c82afc4a47004165038971cc4
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=mips SHELL=/bin/bash fs/ksmbd/
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
command-line: note: in included file:
builtin:1:9: sparse: sparse: preprocessor token __ATOMIC_ACQUIRE redefined builtin:0:0: sparse: this was the original definition builtin:1:9: sparse: sparse: preprocessor token __ATOMIC_SEQ_CST redefined builtin:0:0: sparse: this was the original definition builtin:1:9: sparse: sparse: preprocessor token __ATOMIC_ACQ_REL redefined builtin:0:0: sparse: this was the original definition builtin:1:9: sparse: sparse: preprocessor token __ATOMIC_RELEASE redefined builtin:0:0: sparse: this was the original definition
>> fs/ksmbd/smb2pdu.c:6193:40: sparse: sparse: cast to restricted __le32 >> fs/ksmbd/smb2pdu.c:6193:40: sparse: sparse: cast from restricted __le16
fs/ksmbd/smb2pdu.c:6195:21: sparse: sparse: cast to restricted __le32 fs/ksmbd/smb2pdu.c:6195:21: sparse: sparse: cast from restricted __le16
vim +6193 fs/ksmbd/smb2pdu.c
6164
6165 /**
6166 * smb2_read() - handler for smb2 read from file
6167 * @work: smb work containing read command buffer
6168 *
6169 * Return: 0 on success, otherwise error
6170 */
6171 int smb2_read(struct ksmbd_work *work)
6172 {
6173 struct ksmbd_conn *conn = work->conn;
6174 struct smb2_read_req *req;
6175 struct smb2_read_rsp *rsp;
6176 struct ksmbd_file *fp = NULL;
6177 loff_t offset;
6178 size_t length, mincount;
6179 ssize_t nbytes = 0, remain_bytes = 0;
6180 int err = 0;
6181
6182 WORK_BUFFERS(work, req, rsp);
6183
6184 if (test_share_config_flag(work->tcon->share_conf,
6185 KSMBD_SHARE_FLAG_PIPE)) {
6186 ksmbd_debug(SMB, "IPC pipe read request\n");
6187 return smb2_read_pipe(work);
6188 }
6189
6190 if (req->Channel == SMB2_CHANNEL_RDMA_V1_INVALIDATE ||
6191 req->Channel == SMB2_CHANNEL_RDMA_V1) {
6192 struct smb2_buffer_desc_v1 *descs = (struct smb2_buffer_desc_v1 *)
> 6193 ((char *)req + le32_to_cpu(req->ReadChannelInfoOffset));
6194
6195 if (le32_to_cpu(req->ReadChannelInfoOffset) <
6196 offsetof(struct smb2_read_req, Buffer)) {
6197 err = -EINVAL;
6198 goto out;
6199 }
6200
6201 err = smb2_validate_rdma_buffer_descs(work,
6202 descs,
6203 req->Channel,
6204 req->ReadChannelInfoOffset,
6205 req->ReadChannelInfoLength); 6206 if (err)
6207 goto out;
6208 }
6209
6210 fp = ksmbd_lookup_fd_slow(work, req->VolatileFileId, req->PersistentFileId);
6211 if (!fp) {
6212 err = -ENOENT;
6213 goto out;
6214 }
6215
6216 if (!(fp->daccess & (FILE_READ_DATA_LE | FILE_READ_ATTRIBUTES_LE))) {
6217 pr_err("Not permitted to read : 0x%x\n", fp->daccess);
6218 err = -EACCES;
6219 goto out;
6220 }
6221
6222 offset = le64_to_cpu(req->Offset);
6223 length = le32_to_cpu(req->Length);
6224 mincount = le32_to_cpu(req->MinimumCount);
6225
6226 if (length > conn->vals->max_read_size) {
6227 ksmbd_debug(SMB, "limiting read size to max size(%u)\n",
6228 conn->vals->max_read_size);
6229 err = -EINVAL;
6230 goto out;
6231 }
6232
6233 ksmbd_debug(SMB, "filename %pd, offset %lld, len %zu\n",
6234 fp->filp->f_path.dentry, offset, length);
6235
6236 work->aux_payload_buf = kvmalloc(length, GFP_KERNEL | __GFP_ZERO);
6237 if (!work->aux_payload_buf) {
6238 err = -ENOMEM;
6239 goto out;
6240 }
6241
6242 nbytes = ksmbd_vfs_read(work, fp, length, &offset);
6243 if (nbytes < 0) {
6244 err = nbytes;
6245 goto out;
6246 }
6247
6248 if ((nbytes == 0 && length != 0) || nbytes < mincount) {
6249 kvfree(work->aux_payload_buf);
6250 work->aux_payload_buf = NULL;
6251 rsp->hdr.Status = STATUS_END_OF_FILE;
6252 smb2_set_err_rsp(work);
6253 goto out;
6254 }
6255
6256 ksmbd_debug(SMB, "nbytes %zu, offset %lld mincount %zu\n",
6257 nbytes, offset, mincount);
6258
6259 if (req->Channel == SMB2_CHANNEL_RDMA_V1_INVALIDATE ||
6260 req->Channel == SMB2_CHANNEL_RDMA_V1) {
6261 /* write data to the client using rdma channel */
6262 remain_bytes = smb2_read_rdma_channel(work, req,
6263 work->aux_payload_buf,
6264 nbytes);
6265 kvfree(work->aux_payload_buf);
6266 work->aux_payload_buf = NULL;
6267
6268 nbytes = 0;
6269 if (remain_bytes < 0) {
6270 err = (int)remain_bytes;
6271 goto out;
6272 }
6273 }
6274
6275 rsp->StructureSize = cpu_to_le16(17);
6276 rsp->DataOffset = 80;
6277 rsp->Reserved = 0;
6278 rsp->DataLength = cpu_to_le32(nbytes);
6279 rsp->DataRemaining = cpu_to_le32(remain_bytes);
6280 rsp->Flags = 0;
6281 inc_rfc1001_len(work->response_buf, 16);
6282 work->resp_hdr_sz = get_rfc1002_len(work->response_buf) + 4;
6283 work->aux_payload_sz = nbytes;
6284 inc_rfc1001_len(work->response_buf, nbytes);
6285 ksmbd_fd_put(work, fp);
6286 return 0;
6287
6288 out:
6289 if (err) {
6290 if (err == -EISDIR)
6291 rsp->hdr.Status = STATUS_INVALID_DEVICE_REQUEST;
6292 else if (err == -EAGAIN)
6293 rsp->hdr.Status = STATUS_FILE_LOCK_CONFLICT;
6294 else if (err == -ENOENT)
6295 rsp->hdr.Status = STATUS_FILE_CLOSED;
6296 else if (err == -EACCES)
6297 rsp->hdr.Status = STATUS_ACCESS_DENIED;
6298 else if (err == -ESHARE)
6299 rsp->hdr.Status = STATUS_SHARING_VIOLATION;
6300 else if (err == -EINVAL)
6301 rsp->hdr.Status = STATUS_INVALID_PARAMETER;
6302 else
6303 rsp->hdr.Status = STATUS_INVALID_HANDLE;
6304
6305 smb2_set_err_rsp(work);
6306 }
6307 ksmbd_fd_put(work, fp);
6308 return err;
6309 }
6310
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp