Skip to content

Commit fccec5b

Browse files
Steve Wisedledford
authored andcommitted
RDMA/nldev: provide detailed MR information
Implement the RDMA nldev netlink interface for dumping detailed MR information. Signed-off-by: Steve Wise <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent e6f0330 commit fccec5b

File tree

7 files changed

+102
-13
lines changed

7 files changed

+102
-13
lines changed

drivers/infiniband/core/nldev.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
8585
[RDMA_NLDEV_ATTR_RES_CQE] = { .type = NLA_U32 },
8686
[RDMA_NLDEV_ATTR_RES_USECNT] = { .type = NLA_U64 },
8787
[RDMA_NLDEV_ATTR_RES_POLL_CTX] = { .type = NLA_U8 },
88+
[RDMA_NLDEV_ATTR_RES_MR] = { .type = NLA_NESTED },
89+
[RDMA_NLDEV_ATTR_RES_MR_ENTRY] = { .type = NLA_NESTED },
90+
[RDMA_NLDEV_ATTR_RES_RKEY] = { .type = NLA_U32 },
91+
[RDMA_NLDEV_ATTR_RES_LKEY] = { .type = NLA_U32 },
92+
[RDMA_NLDEV_ATTR_RES_IOVA] = { .type = NLA_U64 },
93+
[RDMA_NLDEV_ATTR_RES_MRLEN] = { .type = NLA_U64 },
8894
};
8995

9096
static int fill_nldev_handle(struct sk_buff *msg, struct ib_device *device)
@@ -197,6 +203,7 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device)
197203
[RDMA_RESTRACK_CQ] = "cq",
198204
[RDMA_RESTRACK_QP] = "qp",
199205
[RDMA_RESTRACK_CM_ID] = "cm_id",
206+
[RDMA_RESTRACK_MR] = "mr",
200207
};
201208

202209
struct rdma_restrack_root *res = &device->res;
@@ -397,6 +404,41 @@ static int fill_res_cq_entry(struct sk_buff *msg, struct netlink_callback *cb,
397404
return -EMSGSIZE;
398405
}
399406

407+
static int fill_res_mr_entry(struct sk_buff *msg, struct netlink_callback *cb,
408+
struct rdma_restrack_entry *res, uint32_t port)
409+
{
410+
struct ib_mr *mr = container_of(res, struct ib_mr, res);
411+
struct nlattr *entry_attr;
412+
413+
entry_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_RES_MR_ENTRY);
414+
if (!entry_attr)
415+
goto out;
416+
417+
if (netlink_capable(cb->skb, CAP_NET_ADMIN)) {
418+
if (nla_put_u32(msg, RDMA_NLDEV_ATTR_RES_RKEY, mr->rkey))
419+
goto err;
420+
if (nla_put_u32(msg, RDMA_NLDEV_ATTR_RES_LKEY, mr->lkey))
421+
goto err;
422+
if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_RES_IOVA,
423+
mr->iova, 0))
424+
goto err;
425+
}
426+
427+
if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_RES_MRLEN, mr->length, 0))
428+
goto err;
429+
430+
if (fill_res_name_pid(msg, res))
431+
goto err;
432+
433+
nla_nest_end(msg, entry_attr);
434+
return 0;
435+
436+
err:
437+
nla_nest_cancel(msg, entry_attr);
438+
out:
439+
return -EMSGSIZE;
440+
}
441+
400442
static int nldev_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
401443
struct netlink_ext_ack *extack)
402444
{
@@ -694,6 +736,11 @@ static const struct nldev_fill_res_entry fill_entries[RDMA_RESTRACK_MAX] = {
694736
.nldev_cmd = RDMA_NLDEV_CMD_RES_CQ_GET,
695737
.nldev_attr = RDMA_NLDEV_ATTR_RES_CQ,
696738
},
739+
[RDMA_RESTRACK_MR] = {
740+
.fill_res_func = fill_res_mr_entry,
741+
.nldev_cmd = RDMA_NLDEV_CMD_RES_MR_GET,
742+
.nldev_attr = RDMA_NLDEV_ATTR_RES_MR,
743+
},
697744
};
698745

699746
static int res_get_common_dumpit(struct sk_buff *skb,
@@ -848,6 +895,12 @@ static int nldev_res_get_cq_dumpit(struct sk_buff *skb,
848895
return res_get_common_dumpit(skb, cb, RDMA_RESTRACK_CQ);
849896
}
850897

898+
static int nldev_res_get_mr_dumpit(struct sk_buff *skb,
899+
struct netlink_callback *cb)
900+
{
901+
return res_get_common_dumpit(skb, cb, RDMA_RESTRACK_MR);
902+
}
903+
851904
static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
852905
[RDMA_NLDEV_CMD_GET] = {
853906
.doit = nldev_get_doit,
@@ -880,6 +933,9 @@ static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
880933
[RDMA_NLDEV_CMD_RES_CQ_GET] = {
881934
.dump = nldev_res_get_cq_dumpit,
882935
},
936+
[RDMA_NLDEV_CMD_RES_MR_GET] = {
937+
.dump = nldev_res_get_mr_dumpit,
938+
},
883939
};
884940

885941
void __init nldev_init(void)

drivers/infiniband/core/restrack.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,28 @@ EXPORT_SYMBOL(rdma_restrack_count);
4343

4444
static void set_kern_name(struct rdma_restrack_entry *res)
4545
{
46-
enum rdma_restrack_type type = res->type;
47-
struct ib_qp *qp;
46+
struct ib_pd *pd;
4847

49-
if (type != RDMA_RESTRACK_QP)
50-
/* Other types already have this name embedded in */
51-
return;
52-
53-
qp = container_of(res, struct ib_qp, res);
54-
if (!qp->pd) {
55-
WARN_ONCE(true, "XRC QPs are not supported\n");
56-
/* Survive, despite the programmer's error */
57-
res->kern_name = " ";
58-
return;
48+
switch (res->type) {
49+
case RDMA_RESTRACK_QP:
50+
pd = container_of(res, struct ib_qp, res)->pd;
51+
if (!pd) {
52+
WARN_ONCE(true, "XRC QPs are not supported\n");
53+
/* Survive, despite the programmer's error */
54+
res->kern_name = " ";
55+
}
56+
break;
57+
case RDMA_RESTRACK_MR:
58+
pd = container_of(res, struct ib_mr, res)->pd;
59+
break;
60+
default:
61+
/* Other types set kern_name directly */
62+
pd = NULL;
63+
break;
5964
}
6065

61-
res->kern_name = qp->pd->res.kern_name;
66+
if (pd)
67+
res->kern_name = pd->res.kern_name;
6268
}
6369

6470
static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
@@ -73,6 +79,8 @@ static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
7379
case RDMA_RESTRACK_CM_ID:
7480
return container_of(res, struct rdma_id_private,
7581
res)->id.device;
82+
case RDMA_RESTRACK_MR:
83+
return container_of(res, struct ib_mr, res)->device;
7684
default:
7785
WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type);
7886
return NULL;
@@ -90,6 +98,8 @@ static bool res_is_user(struct rdma_restrack_entry *res)
9098
return container_of(res, struct ib_qp, res)->uobject;
9199
case RDMA_RESTRACK_CM_ID:
92100
return !res->kern_name;
101+
case RDMA_RESTRACK_MR:
102+
return container_of(res, struct ib_mr, res)->pd->uobject;
93103
default:
94104
WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type);
95105
return false;

drivers/infiniband/core/uverbs_cmd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
693693
mr->pd = pd;
694694
mr->uobject = uobj;
695695
atomic_inc(&pd->usecnt);
696+
mr->res.type = RDMA_RESTRACK_MR;
697+
rdma_restrack_add(&mr->res);
696698

697699
uobj->object = mr;
698700

drivers/infiniband/core/verbs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ int ib_dereg_mr(struct ib_mr *mr)
16221622
struct ib_pd *pd = mr->pd;
16231623
int ret;
16241624

1625+
rdma_restrack_del(&mr->res);
16251626
ret = mr->device->dereg_mr(mr);
16261627
if (!ret)
16271628
atomic_dec(&pd->usecnt);
@@ -1658,6 +1659,8 @@ struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
16581659
mr->uobject = NULL;
16591660
atomic_inc(&pd->usecnt);
16601661
mr->need_inval = false;
1662+
mr->res.type = RDMA_RESTRACK_MR;
1663+
rdma_restrack_add(&mr->res);
16611664
}
16621665

16631666
return mr;

include/rdma/ib_verbs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,11 @@ struct ib_mr {
17721772
struct ib_uobject *uobject; /* user */
17731773
struct list_head qp_entry; /* FR */
17741774
};
1775+
1776+
/*
1777+
* Implementation details of the RDMA core, don't use in drivers:
1778+
*/
1779+
struct rdma_restrack_entry res;
17751780
};
17761781

17771782
struct ib_mw {

include/rdma/restrack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ enum rdma_restrack_type {
3333
* @RDMA_RESTRACK_CM_ID: Connection Manager ID (CM_ID)
3434
*/
3535
RDMA_RESTRACK_CM_ID,
36+
/**
37+
* @RDMA_RESTRACK_MR: Memory Region (MR)
38+
*/
39+
RDMA_RESTRACK_MR,
3640
/**
3741
* @RDMA_RESTRACK_MAX: Last entry, used for array dclarations
3842
*/

include/uapi/rdma/rdma_netlink.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ enum rdma_nldev_command {
242242

243243
RDMA_NLDEV_CMD_RES_CQ_GET, /* can dump */
244244

245+
RDMA_NLDEV_CMD_RES_MR_GET, /* can dump */
246+
245247
RDMA_NLDEV_NUM_OPS
246248
};
247249

@@ -372,6 +374,13 @@ enum rdma_nldev_attr {
372374
RDMA_NLDEV_ATTR_RES_USECNT, /* u64 */
373375
RDMA_NLDEV_ATTR_RES_POLL_CTX, /* u8 */
374376

377+
RDMA_NLDEV_ATTR_RES_MR, /* nested table */
378+
RDMA_NLDEV_ATTR_RES_MR_ENTRY, /* nested table */
379+
RDMA_NLDEV_ATTR_RES_RKEY, /* u32 */
380+
RDMA_NLDEV_ATTR_RES_LKEY, /* u32 */
381+
RDMA_NLDEV_ATTR_RES_IOVA, /* u64 */
382+
RDMA_NLDEV_ATTR_RES_MRLEN, /* u64 */
383+
375384
RDMA_NLDEV_ATTR_MAX
376385
};
377386
#endif /* _UAPI_RDMA_NETLINK_H */

0 commit comments

Comments
 (0)