Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RDMA/nldev: Return context information

Extend the RDMA nldev return a context information, like ctx number and
process ID that created that context. This functionality is helpful to
find orphan contexts that are not closed for some reason.

Sample output:

$ rdma res show ctx
dev ibp8s0f0 ctxn 0 pid 980 comm ibv_rc_pingpong
dev ibp8s0f0 ctxn 1 pid 981 comm ibv_rc_pingpong
dev ibp8s0f0 ctxn 2 pid 992 comm ibv_rc_pingpong
dev ibp8s0f1 ctxn 0 pid 984 comm ibv_rc_pingpong
dev ibp8s0f1 ctxn 1 pid 987 comm ibv_rc_pingpong

$ rdma res show ctx dev ibp8s0f1
dev ibp8s0f1 ctxn 0 pid 984 comm ibv_rc_pingpong
dev ibp8s0f1 ctxn 1 pid 987 comm ibv_rc_pingpong

Link: https://lore.kernel.org/r/5c956acfeac4e9d532988575f3da7d64cb449374.1618753110.git.leonro@nvidia.com
Signed-off-by: Neta Ostrovsky <netao@nvidia.com>
Reviewed-by: Mark Zhang <markzhang@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Neta Ostrovsky and committed by
Jason Gunthorpe
12ce208f cb5cd0ea

+32
+27
drivers/infiniband/core/nldev.c
··· 92 92 [RDMA_NLDEV_ATTR_RES_CQE] = { .type = NLA_U32 }, 93 93 [RDMA_NLDEV_ATTR_RES_CQN] = { .type = NLA_U32 }, 94 94 [RDMA_NLDEV_ATTR_RES_CQ_ENTRY] = { .type = NLA_NESTED }, 95 + [RDMA_NLDEV_ATTR_RES_CTX] = { .type = NLA_NESTED }, 95 96 [RDMA_NLDEV_ATTR_RES_CTXN] = { .type = NLA_U32 }, 97 + [RDMA_NLDEV_ATTR_RES_CTX_ENTRY] = { .type = NLA_NESTED }, 96 98 [RDMA_NLDEV_ATTR_RES_DST_ADDR] = { 97 99 .len = sizeof(struct __kernel_sockaddr_storage) }, 98 100 [RDMA_NLDEV_ATTR_RES_IOVA] = { .type = NLA_U64 }, ··· 705 703 err: return -EMSGSIZE; 706 704 } 707 705 706 + static int fill_res_ctx_entry(struct sk_buff *msg, bool has_cap_net_admin, 707 + struct rdma_restrack_entry *res, uint32_t port) 708 + { 709 + struct ib_ucontext *ctx = container_of(res, struct ib_ucontext, res); 710 + 711 + if (rdma_is_kernel_res(res)) 712 + return 0; 713 + 714 + if (nla_put_u32(msg, RDMA_NLDEV_ATTR_RES_CTXN, ctx->res.id)) 715 + return -EMSGSIZE; 716 + 717 + return fill_res_name_pid(msg, res); 718 + } 719 + 708 720 static int fill_stat_counter_mode(struct sk_buff *msg, 709 721 struct rdma_counter *counter) 710 722 { ··· 1252 1236 .entry = RDMA_NLDEV_ATTR_STAT_COUNTER_ENTRY, 1253 1237 .id = RDMA_NLDEV_ATTR_STAT_COUNTER_ID, 1254 1238 }, 1239 + [RDMA_RESTRACK_CTX] = { 1240 + .nldev_attr = RDMA_NLDEV_ATTR_RES_CTX, 1241 + .flags = NLDEV_PER_DEV, 1242 + .entry = RDMA_NLDEV_ATTR_RES_CTX_ENTRY, 1243 + .id = RDMA_NLDEV_ATTR_RES_CTXN, 1244 + }, 1255 1245 }; 1256 1246 1257 1247 static int res_get_common_doit(struct sk_buff *skb, struct nlmsghdr *nlh, ··· 1498 1476 RES_GET_FUNCS(mr, RDMA_RESTRACK_MR); 1499 1477 RES_GET_FUNCS(mr_raw, RDMA_RESTRACK_MR); 1500 1478 RES_GET_FUNCS(counter, RDMA_RESTRACK_COUNTER); 1479 + RES_GET_FUNCS(ctx, RDMA_RESTRACK_CTX); 1501 1480 1502 1481 static LIST_HEAD(link_ops); 1503 1482 static DECLARE_RWSEM(link_ops_rwsem); ··· 2161 2138 [RDMA_NLDEV_CMD_RES_PD_GET] = { 2162 2139 .doit = nldev_res_get_pd_doit, 2163 2140 .dump = nldev_res_get_pd_dumpit, 2141 + }, 2142 + [RDMA_NLDEV_CMD_RES_CTX_GET] = { 2143 + .doit = nldev_res_get_ctx_doit, 2144 + .dump = nldev_res_get_ctx_dumpit, 2164 2145 }, 2165 2146 [RDMA_NLDEV_CMD_SYS_GET] = { 2166 2147 .doit = nldev_sys_get_doit,
+5
include/uapi/rdma/rdma_netlink.h
··· 293 293 294 294 RDMA_NLDEV_CMD_RES_MR_GET_RAW, 295 295 296 + RDMA_NLDEV_CMD_RES_CTX_GET, /* can dump */ 297 + 296 298 RDMA_NLDEV_NUM_OPS 297 299 }; 298 300 ··· 534 532 RDMA_NLDEV_ATTR_DEV_DIM, /* u8 */ 535 533 536 534 RDMA_NLDEV_ATTR_RES_RAW, /* binary */ 535 + 536 + RDMA_NLDEV_ATTR_RES_CTX, /* nested table */ 537 + RDMA_NLDEV_ATTR_RES_CTX_ENTRY, /* nested table */ 537 538 538 539 /* 539 540 * Always the end