From: Shamir Rabinovitch <shamir.rabinovitch@xxxxxxxxxx> Implementation of new verb which enable to import ib_pd object. Signed-off-by: Shamir Rabinovitch <shamir.rabinovitch@xxxxxxxxxx> Signed-off-by: Shamir Rabinovitch <srabinov7@xxxxxxxxx> --- drivers/infiniband/core/uverbs_cmd.c | 95 ++++++++++++++++++++++++++++ include/uapi/rdma/ib_user_verbs.h | 14 ++++ 2 files changed, 109 insertions(+) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index 5800d7e0992a..08f39adb3a9d 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -3867,6 +3867,96 @@ static void ib_uverbs_import_unlock(struct ib_uobject *uobj, fput(filep); } +static void ib_uverbs_clone_ib_pd(union ib_uverbs_import_fr_fd_resp *resp, + struct ib_pd *pd, + __u32 handle) +{ + resp->alloc_pd.pd_handle = handle; +} + +static int ib_uverbs_import_ib_pd(struct uverbs_attr_bundle *attrs) +{ + union ib_uverbs_import_fr_fd_resp resp = {0}; + struct ib_uobject *src_uobj = NULL; + struct ib_uobject *dst_uobj = NULL; + struct ib_uverbs_import_fr_fd cmd; + struct ib_uverbs_file *src_file; + struct ib_device *ibdev; + struct ib_pd *pd; + struct file *filep; + int ret; + + ret = uverbs_request(attrs, &cmd, sizeof(cmd)); + if (ret) + return ret; + + ret = ib_uverbs_import_lock(attrs, cmd.fd, UVERBS_OBJECT_PD, + cmd.handle, &src_uobj, &filep, + &src_file); + if (ret) + return ret; + + pd = src_uobj->object; + + dst_uobj = uobj_alloc(UVERBS_OBJECT_PD, attrs, &ibdev); + if (IS_ERR(dst_uobj)) { + ret = -ENOMEM; + goto uobj; + } + + if (!ibdev->ops.clone_ib_pd) { + ret = -EINVAL; + goto uobj; + } + + dst_uobj->object = src_uobj->object; + dst_uobj->refcnt = src_uobj->refcnt; + + if (WARN_ON(!atomic_inc_not_zero(src_uobj->refcnt))) { + ret = -EINVAL; + goto uobj; + } + + ret = ibdev->ops.clone_ib_pd(&attrs->driver_udata, pd); + if (ret) + goto uobj; + + ib_uverbs_clone_ib_pd(&resp, dst_uobj->object, dst_uobj->id); + + ret = uverbs_response(attrs, &resp, sizeof(resp)); + if (ret) + goto uobj; + + ret = uobj_alloc_commit(dst_uobj, attrs); + + ib_uverbs_import_unlock(src_uobj, filep); + + return ret; + +uobj: + if (!IS_ERR_OR_NULL(dst_uobj)) + uobj_alloc_abort(dst_uobj, attrs); + + return ret; +} + +static int ib_uverbs_import_fr_fd(struct uverbs_attr_bundle *attrs) +{ + struct ib_uverbs_import_fr_fd cmd; + int ret; + + ret = uverbs_request(attrs, &cmd, sizeof(cmd)); + if (ret) + return ret; + + switch (cmd.type) { + case UVERBS_OBJECT_PD: + return ib_uverbs_import_ib_pd(attrs); + } + + return -EINVAL; +} + /* * Describe the input structs for write(). Some write methods have an input * only struct, most have an input and output. If the struct has an output then @@ -3999,6 +4089,11 @@ const struct uapi_definition uverbs_def_write_intf[] = { UAPI_DEF_WRITE_IO(struct ib_uverbs_query_port, struct ib_uverbs_query_port_resp), UAPI_DEF_METHOD_NEEDS_FN(query_port)), + DECLARE_UVERBS_WRITE( + IB_USER_VERBS_CMD_IMPORT_FR_FD, + ib_uverbs_import_fr_fd, + UAPI_DEF_WRITE_IO(struct ib_uverbs_import_fr_fd, + union ib_uverbs_import_fr_fd_resp)), DECLARE_UVERBS_WRITE_EX( IB_USER_VERBS_EX_CMD_QUERY_DEVICE, ib_uverbs_ex_query_device, diff --git a/include/uapi/rdma/ib_user_verbs.h b/include/uapi/rdma/ib_user_verbs.h index 0474c7400268..4274c40bcff8 100644 --- a/include/uapi/rdma/ib_user_verbs.h +++ b/include/uapi/rdma/ib_user_verbs.h @@ -88,6 +88,7 @@ enum ib_uverbs_write_cmds { IB_USER_VERBS_CMD_CLOSE_XRCD, IB_USER_VERBS_CMD_CREATE_XSRQ, IB_USER_VERBS_CMD_OPEN_QP, + IB_USER_VERBS_CMD_IMPORT_FR_FD, }; enum { @@ -1299,6 +1300,19 @@ struct ib_uverbs_ex_modify_cq { __u32 reserved; }; +/* object sharing support */ +struct ib_uverbs_import_fr_fd { + __u64 response; + __u32 fd; + __u32 handle; + __u16 type; + __u8 reserved[6]; +}; + +union ib_uverbs_import_fr_fd_resp { + struct ib_uverbs_alloc_pd_resp alloc_pd; +}; + #define IB_DEVICE_NAME_MAX 64 #endif /* IB_USER_VERBS_H */ -- 2.20.1