Skip to content

Commit ad8a449

Browse files
monis410jgunthorpe
authored andcommitted
IB/uverbs: Add support to advise_mr
Add new ioctl method for the MR object - ADVISE_MR. This command can be used by users to give an advice or directions to the kernel about an address range that belongs to memory regions. A new ib_device callback, advise_mr(), is introduced here to suupport the new command. This command takes the following arguments: - pd: The protection domain to which all memory regions belong - advice: The type of the advice * IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH - Pre-fetch a range of an on-demand paging MR * IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH_WRITE - Pre-fetch a range of an on-demand paging MR with write intention - flags: The properties of the advice * IB_UVERBS_ADVISE_MR_FLAG_FLUSH - Operation must end before return to the caller - sg_list: The list of memory ranges - num_sge: The number of memory ranges in the list - attrs: More attributes to be parsed by the provider Signed-off-by: Moni Shoua <monis@mellanox.com> Reviewed-by: Guy Levi <guyle@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent cbfdd44 commit ad8a449

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

drivers/infiniband/core/uverbs_std_types_mr.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,42 @@ static int uverbs_free_mr(struct ib_uobject *uobject,
3939
return ib_dereg_mr((struct ib_mr *)uobject->object);
4040
}
4141

42+
static int UVERBS_HANDLER(UVERBS_METHOD_ADVISE_MR)(
43+
struct uverbs_attr_bundle *attrs)
44+
{
45+
struct ib_pd *pd =
46+
uverbs_attr_get_obj(attrs, UVERBS_ATTR_ADVISE_MR_PD_HANDLE);
47+
enum ib_uverbs_advise_mr_advice advice;
48+
struct ib_device *ib_dev = pd->device;
49+
struct ib_sge *sg_list;
50+
u32 num_sge;
51+
u32 flags;
52+
int ret;
53+
54+
/* FIXME: Extend the UAPI_DEF_OBJ_NEEDS_FN stuff.. */
55+
if (!ib_dev->ops.advise_mr)
56+
return -EOPNOTSUPP;
57+
58+
ret = uverbs_get_const(&advice, attrs, UVERBS_ATTR_ADVISE_MR_ADVICE);
59+
if (ret)
60+
return ret;
61+
62+
ret = uverbs_get_flags32(&flags, attrs, UVERBS_ATTR_ADVISE_MR_FLAGS,
63+
IB_UVERBS_ADVISE_MR_FLAG_FLUSH);
64+
if (ret)
65+
return ret;
66+
67+
num_sge = uverbs_attr_ptr_get_array_size(
68+
attrs, UVERBS_ATTR_ADVISE_MR_SGE_LIST, sizeof(struct ib_sge));
69+
if (num_sge < 0)
70+
return num_sge;
71+
72+
sg_list = uverbs_attr_get_alloced_ptr(attrs,
73+
UVERBS_ATTR_ADVISE_MR_SGE_LIST);
74+
return ib_dev->ops.advise_mr(pd, advice, flags, sg_list, num_sge,
75+
attrs);
76+
}
77+
4278
static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(
4379
struct uverbs_attr_bundle *attrs)
4480
{
@@ -114,6 +150,23 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(
114150
return ret;
115151
}
116152

153+
DECLARE_UVERBS_NAMED_METHOD(
154+
UVERBS_METHOD_ADVISE_MR,
155+
UVERBS_ATTR_IDR(UVERBS_ATTR_ADVISE_MR_PD_HANDLE,
156+
UVERBS_OBJECT_PD,
157+
UVERBS_ACCESS_READ,
158+
UA_MANDATORY),
159+
UVERBS_ATTR_CONST_IN(UVERBS_ATTR_ADVISE_MR_ADVICE,
160+
enum ib_uverbs_advise_mr_advice,
161+
UA_MANDATORY),
162+
UVERBS_ATTR_FLAGS_IN(UVERBS_ATTR_ADVISE_MR_FLAGS,
163+
enum ib_uverbs_advise_mr_flag,
164+
UA_MANDATORY),
165+
UVERBS_ATTR_PTR_IN(UVERBS_ATTR_ADVISE_MR_SGE_LIST,
166+
UVERBS_ATTR_MIN_SIZE(sizeof(struct ib_uverbs_sge)),
167+
UA_MANDATORY,
168+
UA_ALLOC_AND_COPY));
169+
117170
DECLARE_UVERBS_NAMED_METHOD(
118171
UVERBS_METHOD_DM_MR_REG,
119172
UVERBS_ATTR_IDR(UVERBS_ATTR_REG_DM_MR_HANDLE,
@@ -154,7 +207,8 @@ DECLARE_UVERBS_NAMED_OBJECT(
154207
UVERBS_OBJECT_MR,
155208
UVERBS_TYPE_ALLOC_IDR(uverbs_free_mr),
156209
&UVERBS_METHOD(UVERBS_METHOD_DM_MR_REG),
157-
&UVERBS_METHOD(UVERBS_METHOD_MR_DESTROY));
210+
&UVERBS_METHOD(UVERBS_METHOD_MR_DESTROY),
211+
&UVERBS_METHOD(UVERBS_METHOD_ADVISE_MR));
158212

159213
const struct uapi_definition uverbs_def_obj_mr[] = {
160214
UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_MR,

include/rdma/ib_verbs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,6 +2415,10 @@ struct ib_device_ops {
24152415
int (*dereg_mr)(struct ib_mr *mr);
24162416
struct ib_mr *(*alloc_mr)(struct ib_pd *pd, enum ib_mr_type mr_type,
24172417
u32 max_num_sg);
2418+
int (*advise_mr)(struct ib_pd *pd,
2419+
enum ib_uverbs_advise_mr_advice advice, u32 flags,
2420+
struct ib_sge *sg_list, u32 num_sge,
2421+
struct uverbs_attr_bundle *attrs);
24182422
int (*map_mr_sg)(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
24192423
unsigned int *sg_offset);
24202424
int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,

include/uapi/rdma/ib_user_ioctl_cmds.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,20 @@ enum uverbs_attrs_reg_dm_mr_cmd_attr_ids {
147147
enum uverbs_methods_mr {
148148
UVERBS_METHOD_DM_MR_REG,
149149
UVERBS_METHOD_MR_DESTROY,
150+
UVERBS_METHOD_ADVISE_MR,
150151
};
151152

152153
enum uverbs_attrs_mr_destroy_ids {
153154
UVERBS_ATTR_DESTROY_MR_HANDLE,
154155
};
155156

157+
enum uverbs_attrs_advise_mr_cmd_attr_ids {
158+
UVERBS_ATTR_ADVISE_MR_PD_HANDLE,
159+
UVERBS_ATTR_ADVISE_MR_ADVICE,
160+
UVERBS_ATTR_ADVISE_MR_FLAGS,
161+
UVERBS_ATTR_ADVISE_MR_SGE_LIST,
162+
};
163+
156164
enum uverbs_attrs_create_counters_cmd_attr_ids {
157165
UVERBS_ATTR_CREATE_COUNTERS_HANDLE,
158166
};

include/uapi/rdma/ib_user_ioctl_verbs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,13 @@ enum ib_uverbs_read_counters_flags {
157157
IB_UVERBS_READ_COUNTERS_PREFER_CACHED = 1 << 0,
158158
};
159159

160+
enum ib_uverbs_advise_mr_advice {
161+
IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH,
162+
IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH_WRITE,
163+
};
164+
165+
enum ib_uverbs_advise_mr_flag {
166+
IB_UVERBS_ADVISE_MR_FLAG_FLUSH = 1 << 0,
167+
};
168+
160169
#endif

0 commit comments

Comments
 (0)