Skip to content

Commit 29cf135

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

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

drivers/infiniband/core/nldev.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
9191
[RDMA_NLDEV_ATTR_RES_LKEY] = { .type = NLA_U32 },
9292
[RDMA_NLDEV_ATTR_RES_IOVA] = { .type = NLA_U64 },
9393
[RDMA_NLDEV_ATTR_RES_MRLEN] = { .type = NLA_U64 },
94+
[RDMA_NLDEV_ATTR_RES_PD] = { .type = NLA_NESTED },
95+
[RDMA_NLDEV_ATTR_RES_PD_ENTRY] = { .type = NLA_NESTED },
96+
[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY] = { .type = NLA_U32 },
97+
[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY] = { .type = NLA_U32 },
9498
};
9599

96100
static int fill_nldev_handle(struct sk_buff *msg, struct ib_device *device)
@@ -439,6 +443,45 @@ static int fill_res_mr_entry(struct sk_buff *msg, struct netlink_callback *cb,
439443
return -EMSGSIZE;
440444
}
441445

446+
static int fill_res_pd_entry(struct sk_buff *msg, struct netlink_callback *cb,
447+
struct rdma_restrack_entry *res, uint32_t port)
448+
{
449+
struct ib_pd *pd = container_of(res, struct ib_pd, res);
450+
struct nlattr *entry_attr;
451+
452+
entry_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_RES_PD_ENTRY);
453+
if (!entry_attr)
454+
goto out;
455+
456+
if (netlink_capable(cb->skb, CAP_NET_ADMIN)) {
457+
if (nla_put_u32(msg, RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY,
458+
pd->local_dma_lkey))
459+
goto err;
460+
if ((pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY) &&
461+
nla_put_u32(msg, RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY,
462+
pd->unsafe_global_rkey))
463+
goto err;
464+
}
465+
if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_RES_USECNT,
466+
atomic_read(&pd->usecnt), 0))
467+
goto err;
468+
if ((pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY) &&
469+
nla_put_u32(msg, RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY,
470+
pd->unsafe_global_rkey))
471+
goto err;
472+
473+
if (fill_res_name_pid(msg, res))
474+
goto err;
475+
476+
nla_nest_end(msg, entry_attr);
477+
return 0;
478+
479+
err:
480+
nla_nest_cancel(msg, entry_attr);
481+
out:
482+
return -EMSGSIZE;
483+
}
484+
442485
static int nldev_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
443486
struct netlink_ext_ack *extack)
444487
{
@@ -741,6 +784,11 @@ static const struct nldev_fill_res_entry fill_entries[RDMA_RESTRACK_MAX] = {
741784
.nldev_cmd = RDMA_NLDEV_CMD_RES_MR_GET,
742785
.nldev_attr = RDMA_NLDEV_ATTR_RES_MR,
743786
},
787+
[RDMA_RESTRACK_PD] = {
788+
.fill_res_func = fill_res_pd_entry,
789+
.nldev_cmd = RDMA_NLDEV_CMD_RES_PD_GET,
790+
.nldev_attr = RDMA_NLDEV_ATTR_RES_PD,
791+
},
744792
};
745793

746794
static int res_get_common_dumpit(struct sk_buff *skb,
@@ -901,6 +949,12 @@ static int nldev_res_get_mr_dumpit(struct sk_buff *skb,
901949
return res_get_common_dumpit(skb, cb, RDMA_RESTRACK_MR);
902950
}
903951

952+
static int nldev_res_get_pd_dumpit(struct sk_buff *skb,
953+
struct netlink_callback *cb)
954+
{
955+
return res_get_common_dumpit(skb, cb, RDMA_RESTRACK_PD);
956+
}
957+
904958
static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
905959
[RDMA_NLDEV_CMD_GET] = {
906960
.doit = nldev_get_doit,
@@ -936,6 +990,9 @@ static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
936990
[RDMA_NLDEV_CMD_RES_MR_GET] = {
937991
.dump = nldev_res_get_mr_dumpit,
938992
},
993+
[RDMA_NLDEV_CMD_RES_PD_GET] = {
994+
.dump = nldev_res_get_pd_dumpit,
995+
},
939996
};
940997

941998
void __init nldev_init(void)

include/uapi/rdma/rdma_netlink.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ enum rdma_nldev_command {
244244

245245
RDMA_NLDEV_CMD_RES_MR_GET, /* can dump */
246246

247+
RDMA_NLDEV_CMD_RES_PD_GET, /* can dump */
248+
247249
RDMA_NLDEV_NUM_OPS
248250
};
249251

@@ -381,6 +383,11 @@ enum rdma_nldev_attr {
381383
RDMA_NLDEV_ATTR_RES_IOVA, /* u64 */
382384
RDMA_NLDEV_ATTR_RES_MRLEN, /* u64 */
383385

386+
RDMA_NLDEV_ATTR_RES_PD, /* nested table */
387+
RDMA_NLDEV_ATTR_RES_PD_ENTRY, /* nested table */
388+
RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY, /* u32 */
389+
RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY, /* u32 */
390+
384391
RDMA_NLDEV_ATTR_MAX
385392
};
386393
#endif /* _UAPI_RDMA_NETLINK_H */

0 commit comments

Comments
 (0)