@@ -91,6 +91,10 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
91
91
[RDMA_NLDEV_ATTR_RES_LKEY ] = { .type = NLA_U32 },
92
92
[RDMA_NLDEV_ATTR_RES_IOVA ] = { .type = NLA_U64 },
93
93
[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 },
94
98
};
95
99
96
100
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,
439
443
return - EMSGSIZE ;
440
444
}
441
445
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
+
442
485
static int nldev_get_doit (struct sk_buff * skb , struct nlmsghdr * nlh ,
443
486
struct netlink_ext_ack * extack )
444
487
{
@@ -741,6 +784,11 @@ static const struct nldev_fill_res_entry fill_entries[RDMA_RESTRACK_MAX] = {
741
784
.nldev_cmd = RDMA_NLDEV_CMD_RES_MR_GET ,
742
785
.nldev_attr = RDMA_NLDEV_ATTR_RES_MR ,
743
786
},
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
+ },
744
792
};
745
793
746
794
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,
901
949
return res_get_common_dumpit (skb , cb , RDMA_RESTRACK_MR );
902
950
}
903
951
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
+
904
958
static const struct rdma_nl_cbs nldev_cb_table [RDMA_NLDEV_NUM_OPS ] = {
905
959
[RDMA_NLDEV_CMD_GET ] = {
906
960
.doit = nldev_get_doit ,
@@ -936,6 +990,9 @@ static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
936
990
[RDMA_NLDEV_CMD_RES_MR_GET ] = {
937
991
.dump = nldev_res_get_mr_dumpit ,
938
992
},
993
+ [RDMA_NLDEV_CMD_RES_PD_GET ] = {
994
+ .dump = nldev_res_get_pd_dumpit ,
995
+ },
939
996
};
940
997
941
998
void __init nldev_init (void )
0 commit comments