Skip to content

Commit 78a0cd6

Browse files
Leon Romanovskyjgunthorpe
Leon Romanovsky
authored andcommitted
RDMA/core: Add resource tracking for create and destroy QPs
Track create and destroy operations of QP objects. Reviewed-by: Mark Bloch <markb@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Reviewed-by: Steve Wise <swise@opengridcomputing.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 02d8883 commit 78a0cd6

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

drivers/infiniband/core/core_priv.h

+27
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,31 @@ struct ib_device *ib_device_get_by_index(u32 ifindex);
301301
/* RDMA device netlink */
302302
void nldev_init(void);
303303
void nldev_exit(void);
304+
305+
static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
306+
struct ib_pd *pd,
307+
struct ib_qp_init_attr *attr,
308+
struct ib_udata *udata)
309+
{
310+
struct ib_qp *qp;
311+
312+
qp = dev->create_qp(pd, attr, udata);
313+
if (IS_ERR(qp))
314+
return qp;
315+
316+
qp->device = dev;
317+
qp->pd = pd;
318+
/*
319+
* We don't track XRC QPs for now, because they don't have PD
320+
* and more importantly they are created internaly by driver,
321+
* see mlx5 create_dev_resources() as an example.
322+
*/
323+
if (attr->qp_type < IB_QPT_XRC_INI) {
324+
qp->res.type = RDMA_RESTRACK_QP;
325+
rdma_restrack_add(&qp->res);
326+
} else
327+
qp->res.valid = false;
328+
329+
return qp;
330+
}
304331
#endif /* _CORE_PRIV_H */

drivers/infiniband/core/uverbs_cmd.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ static int create_qp(struct ib_uverbs_file *file,
15141514
if (cmd->qp_type == IB_QPT_XRC_TGT)
15151515
qp = ib_create_qp(pd, &attr);
15161516
else
1517-
qp = device->create_qp(pd, &attr, uhw);
1517+
qp = _ib_create_qp(device, pd, &attr, uhw);
15181518

15191519
if (IS_ERR(qp)) {
15201520
ret = PTR_ERR(qp);
@@ -1527,7 +1527,6 @@ static int create_qp(struct ib_uverbs_file *file,
15271527
goto err_cb;
15281528

15291529
qp->real_qp = qp;
1530-
qp->device = device;
15311530
qp->pd = pd;
15321531
qp->send_cq = attr.send_cq;
15331532
qp->recv_cq = attr.recv_cq;

drivers/infiniband/core/verbs.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
882882
if (qp_init_attr->cap.max_rdma_ctxs)
883883
rdma_rw_init_qp(device, qp_init_attr);
884884

885-
qp = device->create_qp(pd, qp_init_attr, NULL);
885+
qp = _ib_create_qp(device, pd, qp_init_attr, NULL);
886886
if (IS_ERR(qp))
887887
return qp;
888888

@@ -892,7 +892,6 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
892892
return ERR_PTR(ret);
893893
}
894894

895-
qp->device = device;
896895
qp->real_qp = qp;
897896
qp->uobject = NULL;
898897
qp->qp_type = qp_init_attr->qp_type;
@@ -922,7 +921,6 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
922921
atomic_inc(&qp_init_attr->srq->usecnt);
923922
}
924923

925-
qp->pd = pd;
926924
qp->send_cq = qp_init_attr->send_cq;
927925
qp->xrcd = NULL;
928926

@@ -1538,6 +1536,7 @@ int ib_destroy_qp(struct ib_qp *qp)
15381536
if (!qp->uobject)
15391537
rdma_rw_cleanup_mrs(qp);
15401538

1539+
rdma_restrack_del(&qp->res);
15411540
ret = qp->device->destroy_qp(qp);
15421541
if (!ret) {
15431542
if (pd)

0 commit comments

Comments
 (0)