From: Yuval Shaia <yuval.shaia@xxxxxxxxxx> To keep track of shared object life time add ref count to ib_mr Signed-off-by: Yuval Shaia <yuval.shaia@xxxxxxxxxx> --- drivers/infiniband/core/uverbs_cmd.c | 2 ++ include/rdma/ib_verbs.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index dc1ffcf44ee5..229fc8e48391 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -768,8 +768,10 @@ static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs) atomic_inc(&pd->usecnt); mr->res.type = RDMA_RESTRACK_MR; rdma_restrack_uadd(&mr->res); + atomic_set(&mr->refcnt, 1); uobj->object = mr; + uobj->refcnt = &mr->refcnt; memset(&resp, 0, sizeof resp); resp.lkey = mr->lkey; diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 0ff2732794c9..01be29a71d90 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -1742,6 +1742,9 @@ struct ib_mr { * Implementation details of the RDMA core, don't use in drivers: */ struct rdma_restrack_entry res; + + /* number of uobj using this ib_pd */ + atomic_t refcnt; }; struct ib_mw { -- 2.20.1