Skip to content

Commit

Permalink
IB/uverbs: Expose UAPI to query MR
Browse files Browse the repository at this point in the history
Expose UAPI to query MR, this will let user space application that
didn't allocate the MR but has access to by owning the matching command
FD to retrieve its information.

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Yishai Hadas <[email protected]>
Signed-off-by: Leon Romanovsky <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
  • Loading branch information
yishaih authored and jgunthorpe committed Jul 6, 2020
1 parent 05f71ef commit 6c01e6b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
52 changes: 51 additions & 1 deletion drivers/infiniband/core/uverbs_std_types_mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,36 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(
return ret;
}

static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_MR)(
struct uverbs_attr_bundle *attrs)
{
struct ib_mr *mr =
uverbs_attr_get_obj(attrs, UVERBS_ATTR_QUERY_MR_HANDLE);
int ret;

ret = uverbs_copy_to(attrs, UVERBS_ATTR_QUERY_MR_RESP_LKEY, &mr->lkey,
sizeof(mr->lkey));
if (ret)
return ret;

ret = uverbs_copy_to(attrs, UVERBS_ATTR_QUERY_MR_RESP_RKEY,
&mr->rkey, sizeof(mr->rkey));

if (ret)
return ret;

ret = uverbs_copy_to(attrs, UVERBS_ATTR_QUERY_MR_RESP_LENGTH,
&mr->length, sizeof(mr->length));

if (ret)
return ret;

ret = uverbs_copy_to(attrs, UVERBS_ATTR_QUERY_MR_RESP_IOVA,
&mr->iova, sizeof(mr->iova));

return IS_UVERBS_COPY_ERR(ret) ? ret : 0;
}

DECLARE_UVERBS_NAMED_METHOD(
UVERBS_METHOD_ADVISE_MR,
UVERBS_ATTR_IDR(UVERBS_ATTR_ADVISE_MR_PD_HANDLE,
Expand All @@ -165,6 +195,25 @@ DECLARE_UVERBS_NAMED_METHOD(
UA_MANDATORY,
UA_ALLOC_AND_COPY));

DECLARE_UVERBS_NAMED_METHOD(
UVERBS_METHOD_QUERY_MR,
UVERBS_ATTR_IDR(UVERBS_ATTR_QUERY_MR_HANDLE,
UVERBS_OBJECT_MR,
UVERBS_ACCESS_READ,
UA_MANDATORY),
UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_QUERY_MR_RESP_RKEY,
UVERBS_ATTR_TYPE(u32),
UA_MANDATORY),
UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_QUERY_MR_RESP_LKEY,
UVERBS_ATTR_TYPE(u32),
UA_MANDATORY),
UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_QUERY_MR_RESP_LENGTH,
UVERBS_ATTR_TYPE(u64),
UA_MANDATORY),
UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_QUERY_MR_RESP_IOVA,
UVERBS_ATTR_TYPE(u64),
UA_OPTIONAL));

DECLARE_UVERBS_NAMED_METHOD(
UVERBS_METHOD_DM_MR_REG,
UVERBS_ATTR_IDR(UVERBS_ATTR_REG_DM_MR_HANDLE,
Expand Down Expand Up @@ -206,7 +255,8 @@ DECLARE_UVERBS_NAMED_OBJECT(
UVERBS_TYPE_ALLOC_IDR(uverbs_free_mr),
&UVERBS_METHOD(UVERBS_METHOD_DM_MR_REG),
&UVERBS_METHOD(UVERBS_METHOD_MR_DESTROY),
&UVERBS_METHOD(UVERBS_METHOD_ADVISE_MR));
&UVERBS_METHOD(UVERBS_METHOD_ADVISE_MR),
&UVERBS_METHOD(UVERBS_METHOD_QUERY_MR));

const struct uapi_definition uverbs_def_obj_mr[] = {
UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_MR,
Expand Down
9 changes: 9 additions & 0 deletions include/uapi/rdma/ib_user_ioctl_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ enum uverbs_methods_mr {
UVERBS_METHOD_DM_MR_REG,
UVERBS_METHOD_MR_DESTROY,
UVERBS_METHOD_ADVISE_MR,
UVERBS_METHOD_QUERY_MR,
};

enum uverbs_attrs_mr_destroy_ids {
Expand All @@ -261,6 +262,14 @@ enum uverbs_attrs_advise_mr_cmd_attr_ids {
UVERBS_ATTR_ADVISE_MR_SGE_LIST,
};

enum uverbs_attrs_query_mr_cmd_attr_ids {
UVERBS_ATTR_QUERY_MR_HANDLE,
UVERBS_ATTR_QUERY_MR_RESP_LKEY,
UVERBS_ATTR_QUERY_MR_RESP_RKEY,
UVERBS_ATTR_QUERY_MR_RESP_LENGTH,
UVERBS_ATTR_QUERY_MR_RESP_IOVA,
};

enum uverbs_attrs_create_counters_cmd_attr_ids {
UVERBS_ATTR_CREATE_COUNTERS_HANDLE,
};
Expand Down

0 comments on commit 6c01e6b

Please sign in to comment.