diff options
author | Jason Gunthorpe <jgg@mellanox.com> | 2018-11-25 21:51:19 +0300 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2018-11-27 02:48:07 +0300 |
commit | 3a6532c9af1a7836da2d597f1aaca73cb16c3b97 (patch) | |
tree | 742c5de2458a3d10c0b49fb4afc9ca66161d0372 /drivers/infiniband/core/uverbs_main.c | |
parent | ef87df2c7a8f04d31cbf06f0b14b8dd5feafe473 (diff) | |
download | linux-3a6532c9af1a7836da2d597f1aaca73cb16c3b97.tar.xz |
RDMA/uverbs: Use uverbs_attr_bundle to pass udata for write
Now that we have metadata describing the command format the core code can
directly compute the udata pointers and all the really ugly
ib_uverbs_init_udata() calls can be removed from the handlers.
This means all the write() handlers are no longer sensitive to the layout
of the command buffer.
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Diffstat (limited to 'drivers/infiniband/core/uverbs_main.c')
-rw-r--r-- | drivers/infiniband/core/uverbs_main.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index fc8d3d1c7048..be049546cee2 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -693,8 +693,51 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, bundle.ufile = file; if (!method_elm->is_ex) { - ret = method_elm->handler(&bundle, buf, hdr.in_words * 4, - hdr.out_words * 4); + size_t in_len = hdr.in_words * 4 - sizeof(hdr); + size_t out_len = hdr.out_words * 4; + + if (method_elm->has_udata) { + bundle.driver_udata.inlen = + in_len - method_elm->req_size; + in_len = method_elm->req_size; + if (bundle.driver_udata.inlen) + bundle.driver_udata.inbuf = buf + in_len; + else + bundle.driver_udata.inbuf = NULL; + } else { + memset(&bundle.driver_udata, 0, + sizeof(bundle.driver_udata)); + } + + if (method_elm->has_resp) { + u64 response; + + /* + * The macros check that if has_resp is set + * then the command request structure starts + * with a '__aligned u64 response' member. + */ + ret = get_user(response, (const u64 *)buf); + if (ret) + goto out_unlock; + + if (method_elm->has_udata) { + bundle.driver_udata.outlen = + out_len - method_elm->resp_size; + out_len = method_elm->resp_size; + if (bundle.driver_udata.outlen) + bundle.driver_udata.outbuf = + u64_to_user_ptr(response + + out_len); + else + bundle.driver_udata.outbuf = NULL; + } + } else { + bundle.driver_udata.outlen = 0; + bundle.driver_udata.outbuf = NULL; + } + + ret = method_elm->handler(&bundle, buf, in_len, out_len); } else { struct ib_udata ucore; @@ -713,6 +756,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ret = method_elm->handler_ex(&bundle, &ucore); } +out_unlock: srcu_read_unlock(&file->device->disassociate_srcu, srcu_key); return (ret) ? : count; } |