RDMA/restrack: Simplify restrack tracking in kernel flows
authorLeon Romanovsky <leonro@mellanox.com>
Tue, 22 Sep 2020 09:11:05 +0000 (12:11 +0300)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 22 Sep 2020 22:47:35 +0000 (19:47 -0300)
Have a single rdma_restrack_add() that adds an entry, there is no reason
to split the user/kernel here, the rdma_restrack_set_task() is responsible
for this difference.

This patch prepares the code to the future requirement of making restrack
is mandatory for managing ib objects.

Link: https://lore.kernel.org/r/20200922091106.2152715-5-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/cma.c
drivers/infiniband/core/core_priv.h
drivers/infiniband/core/counters.c
drivers/infiniband/core/cq.c
drivers/infiniband/core/restrack.c
drivers/infiniband/core/restrack.h
drivers/infiniband/core/verbs.c
include/rdma/restrack.h

index 568ad223d40f49d055ed8a3dad205050e66d9899..99a8d61bcbb26b5c93aa75f527e4ae59afb594b7 100644 (file)
@@ -454,7 +454,7 @@ static void _cma_attach_to_dev(struct rdma_id_private *id_priv,
                rdma_node_get_transport(cma_dev->device->node_type);
        list_add_tail(&id_priv->list, &cma_dev->id_list);
        if (id_priv->res.kern_name)
-               rdma_restrack_kadd(&id_priv->res);
+               rdma_restrack_add(&id_priv->res);
        else
                rdma_restrack_uadd(&id_priv->res);
        trace_cm_id_attach(id_priv, cma_dev->device);
index 2ad276cd9781bb75e1e4e0ff2216f241358f4432..cf5a50cefa3955a3bfa15c660a8394ea7311bb8a 100644 (file)
@@ -363,8 +363,10 @@ static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
        if ((qp_type < IB_QPT_MAX && !is_xrc) || qp_type == IB_QPT_DRIVER) {
                if (uobj)
                        rdma_restrack_uadd(&qp->res);
-               else
-                       rdma_restrack_kadd(&qp->res);
+               else {
+                       rdma_restrack_set_task(&qp->res, pd->res.kern_name);
+                       rdma_restrack_add(&qp->res);
+               }
        } else
                qp->res.valid = false;
 
index c059de99d19c59dee8fca57af14bf38499d8c8f5..e13c500a9ec0029b2b9fe1fa4aca4f98459a5b87 100644 (file)
@@ -252,7 +252,7 @@ static void rdma_counter_res_add(struct rdma_counter *counter,
 {
        if (rdma_is_kernel_res(&qp->res)) {
                rdma_restrack_set_task(&counter->res, qp->res.kern_name);
-               rdma_restrack_kadd(&counter->res);
+               rdma_restrack_add(&counter->res);
        } else {
                rdma_restrack_attach_task(&counter->res, qp->res.task);
                rdma_restrack_uadd(&counter->res);
index 2c3ff8dda717d8a30eb77739eb73118a80e3a051..620cf7c2696dd6247dd7c6fca457517cbb639c24 100644 (file)
@@ -267,7 +267,7 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, int nr_cqe,
                goto out_destroy_cq;
        }
 
-       rdma_restrack_kadd(&cq->res);
+       rdma_restrack_add(&cq->res);
        trace_cq_alloc(cq, nr_cqe, comp_vector, poll_ctx);
        return cq;
 
index 22c658e8c157ffed30c4e43da9cb69421c34218f..88d3852676a963a3b0dccf0903476084ce118f89 100644 (file)
@@ -123,32 +123,6 @@ int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type)
 }
 EXPORT_SYMBOL(rdma_restrack_count);
 
-static void set_kern_name(struct rdma_restrack_entry *res)
-{
-       struct ib_pd *pd;
-
-       switch (res->type) {
-       case RDMA_RESTRACK_QP:
-               pd = container_of(res, struct ib_qp, res)->pd;
-               if (!pd) {
-                       WARN_ONCE(true, "XRC QPs are not supported\n");
-                       /* Survive, despite the programmer's error */
-                       res->kern_name = " ";
-               }
-               break;
-       case RDMA_RESTRACK_MR:
-               pd = container_of(res, struct ib_mr, res)->pd;
-               break;
-       default:
-               /* Other types set kern_name directly */
-               pd = NULL;
-               break;
-       }
-
-       if (pd)
-               res->kern_name = pd->res.kern_name;
-}
-
 static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
 {
        switch (res->type) {
@@ -217,7 +191,11 @@ void rdma_restrack_new(struct rdma_restrack_entry *res,
 }
 EXPORT_SYMBOL(rdma_restrack_new);
 
-static void rdma_restrack_add(struct rdma_restrack_entry *res)
+/**
+ * rdma_restrack_add() - add object to the reource tracking database
+ * @res:  resource entry
+ */
+void rdma_restrack_add(struct rdma_restrack_entry *res)
 {
        struct ib_device *dev = res_to_dev(res);
        struct rdma_restrack_root *rt;
@@ -249,19 +227,7 @@ static void rdma_restrack_add(struct rdma_restrack_entry *res)
        if (!ret)
                res->valid = true;
 }
-
-/**
- * rdma_restrack_kadd() - add kernel object to the reource tracking database
- * @res:  resource entry
- */
-void rdma_restrack_kadd(struct rdma_restrack_entry *res)
-{
-       res->task = NULL;
-       set_kern_name(res);
-       res->user = false;
-       rdma_restrack_add(res);
-}
-EXPORT_SYMBOL(rdma_restrack_kadd);
+EXPORT_SYMBOL(rdma_restrack_add);
 
 /**
  * rdma_restrack_uadd() - add user object to the reource tracking database
index 16006a5e7408e689787faa9fdf86aff4acab4f0d..d35c4c41d2ffcf7b126bffd52475b037201c0123 100644 (file)
@@ -25,6 +25,7 @@ struct rdma_restrack_root {
 
 int rdma_restrack_init(struct ib_device *dev);
 void rdma_restrack_clean(struct ib_device *dev);
+void rdma_restrack_add(struct rdma_restrack_entry *res);
 void rdma_restrack_del(struct rdma_restrack_entry *res);
 void rdma_restrack_new(struct rdma_restrack_entry *res,
                       enum rdma_restrack_type type);
index 2607c410b09f6b77a1f3a45d978f23fa5c404cb9..8117e551a86694ac7cbeb8e09c0ecc1693f81892 100644 (file)
@@ -281,7 +281,7 @@ struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
                kfree(pd);
                return ERR_PTR(ret);
        }
-       rdma_restrack_kadd(&pd->res);
+       rdma_restrack_add(&pd->res);
 
        if (device->attrs.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY)
                pd->local_dma_lkey = device->local_dma_lkey;
@@ -2008,7 +2008,7 @@ struct ib_cq *__ib_create_cq(struct ib_device *device,
                return ERR_PTR(ret);
        }
 
-       rdma_restrack_kadd(&cq->res);
+       rdma_restrack_add(&cq->res);
        return cq;
 }
 EXPORT_SYMBOL(__ib_create_cq);
@@ -2081,7 +2081,8 @@ struct ib_mr *ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
        atomic_inc(&pd->usecnt);
 
        rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
-       rdma_restrack_kadd(&mr->res);
+       rdma_restrack_set_task(&mr->res, pd->res.kern_name);
+       rdma_restrack_add(&mr->res);
 
        return mr;
 }
@@ -2164,7 +2165,8 @@ struct ib_mr *ib_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
        mr->sig_attrs = NULL;
 
        rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
-       rdma_restrack_kadd(&mr->res);
+       rdma_restrack_set_task(&mr->res, pd->res.kern_name);
+       rdma_restrack_add(&mr->res);
 out:
        trace_mr_alloc(pd, mr_type, max_num_sg, mr);
        return mr;
@@ -2224,7 +2226,8 @@ struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
        mr->sig_attrs = sig_attrs;
 
        rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
-       rdma_restrack_kadd(&mr->res);
+       rdma_restrack_set_task(&mr->res, pd->res.kern_name);
+       rdma_restrack_add(&mr->res);
 out:
        trace_mr_integ_alloc(pd, max_num_data_sg, max_num_meta_sg, mr);
        return mr;
index d7c16623793912ec73a5acafa6a2d6fb7af5db83..db59e208f5e8efb6db48c2dc3afb031f681b212d 100644 (file)
@@ -107,7 +107,6 @@ struct rdma_restrack_entry {
 int rdma_restrack_count(struct ib_device *dev,
                        enum rdma_restrack_type type);
 
-void rdma_restrack_kadd(struct rdma_restrack_entry *res);
 void rdma_restrack_uadd(struct rdma_restrack_entry *res);
 
 /**