]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
RDMA/core: Allow drivers to disable restrack DB
authorLeon Romanovsky <leonro@mellanox.com>
Tue, 17 Nov 2020 07:01:47 +0000 (09:01 +0200)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 27 Nov 2020 15:38:46 +0000 (11:38 -0400)
Driver QP types are special case with no IBTA restrictions. For example,
EFA implemented creation of this QP type as regular one, while mlx5
separated create to two step: create and modify. That separation causes to
the situation where DC QP (mlx5) is always added to the same xarray index
zero.

This change allows to drivers like mlx5 simply disable restrack DB
tracking, but it doesn't disable kref on the memory.

Fixes: 52e0a118a203 ("RDMA/restrack: Track driver QP types in resource tracker")
Link: https://lore.kernel.org/r/20201117070148.1974114-3-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/counters.c
drivers/infiniband/core/restrack.c
drivers/infiniband/hw/mlx4/qp.c
drivers/infiniband/hw/mlx5/qp.c
include/rdma/restrack.h

index 2c67ba6a272579712347fc9ef6240ff62f14a32c..92745522250e4a701cae83167de4a44a98f8af0f 100644 (file)
@@ -285,7 +285,7 @@ int rdma_counter_bind_qp_auto(struct ib_qp *qp, u8 port)
        struct rdma_counter *counter;
        int ret;
 
-       if (!qp->res.valid || rdma_is_kernel_res(&qp->res))
+       if (!rdma_restrack_is_tracked(&qp->res) || rdma_is_kernel_res(&qp->res))
                return 0;
 
        if (!rdma_is_port_valid(dev, port))
index a123b22b454a3cc8242fd0d35e11e1511e7d5162..e0a41c8670023a4ef2df594248353fbfef4e28cb 100644 (file)
@@ -221,11 +221,14 @@ void rdma_restrack_add(struct rdma_restrack_entry *res)
 {
        struct ib_device *dev = res_to_dev(res);
        struct rdma_restrack_root *rt;
-       int ret;
+       int ret = 0;
 
        if (!dev)
                return;
 
+       if (res->no_track)
+               goto out;
+
        rt = &dev->res[res->type];
 
        if (res->type == RDMA_RESTRACK_QP) {
@@ -253,6 +256,7 @@ void rdma_restrack_add(struct rdma_restrack_entry *res)
                                      &rt->next_id, GFP_KERNEL);
        }
 
+out:
        if (!ret)
                res->valid = true;
 }
@@ -325,6 +329,9 @@ void rdma_restrack_del(struct rdma_restrack_entry *res)
                return;
        }
 
+       if (res->no_track)
+               goto out;
+
        dev = res_to_dev(res);
        if (WARN_ON(!dev))
                return;
@@ -335,8 +342,9 @@ void rdma_restrack_del(struct rdma_restrack_entry *res)
        if (res->type == RDMA_RESTRACK_MR || res->type == RDMA_RESTRACK_QP)
                return;
        WARN_ON(old != res);
-       res->valid = false;
 
+out:
+       res->valid = false;
        rdma_restrack_put(res);
        wait_for_completion(&res->comp);
 }
index 7636e7f1485892355eff475a2078b5d94256caf1..651785bd57f2de0c1913fd7924eb36b896cbb378 100644 (file)
@@ -1561,6 +1561,11 @@ static int _mlx4_ib_create_qp(struct ib_pd *pd, struct mlx4_ib_qp *qp,
                if (err)
                        return err;
 
+               if (init_attr->create_flags &
+                   (MLX4_IB_SRIOV_SQP | MLX4_IB_SRIOV_TUNNEL_QP))
+                       /* Internal QP created with ib_create_qp */
+                       rdma_restrack_no_track(&qp->ibqp.res);
+
                qp->port        = init_attr->port_num;
                qp->ibqp.qp_num = init_attr->qp_type == IB_QPT_SMI ? 0 :
                        init_attr->create_flags & MLX4_IB_QP_CREATE_ROCE_V2_GSI ? sqpn : 1;
index 8d40c929b2f414efbc5495840df9334696bc8e42..9d32f31732316e7e389b74cd767f104263129efe 100644 (file)
@@ -2410,7 +2410,7 @@ static int create_dct(struct mlx5_ib_dev *dev, struct ib_pd *pd,
        }
 
        qp->state = IB_QPS_RESET;
-
+       rdma_restrack_no_track(&qp->ibqp.res);
        return 0;
 }
 
index d3a1cc5be7bcefbaad22b60d2be95d44d2235065..05e18839eaffcdf1fa626481237c1deca7a1d7ce 100644 (file)
@@ -68,6 +68,14 @@ struct rdma_restrack_entry {
         * As an example for that, see mlx5 QPs with type MLX5_IB_QPT_HW_GSI
         */
        bool                    valid;
+       /**
+        * @no_track: don't add this entry to restrack DB
+        *
+        * This field is used to mark an entry that doesn't need to be added to
+        * internal restrack DB and presented later to the users at the nldev
+        * query stage.
+        */
+       u8                      no_track : 1;
        /*
         * @kref: Protect destroy of the resource
         */
@@ -145,4 +153,20 @@ int rdma_nl_stat_hwcounter_entry(struct sk_buff *msg, const char *name,
 struct rdma_restrack_entry *rdma_restrack_get_byid(struct ib_device *dev,
                                                   enum rdma_restrack_type type,
                                                   u32 id);
+
+/**
+ * rdma_restrack_no_track() - don't add resource to the DB
+ * @res: resource entry
+ *
+ * Every user of thie API should be cross examined.
+ * Probaby you don't need to use this function.
+ */
+static inline void rdma_restrack_no_track(struct rdma_restrack_entry *res)
+{
+       res->no_track = true;
+}
+static inline bool rdma_restrack_is_tracked(struct rdma_restrack_entry *res)
+{
+       return !res->no_track;
+}
 #endif /* _RDMA_RESTRACK_H_ */