Commit 08f294a1 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Jason Gunthorpe

RDMA/core: Add resource tracking for create and destroy CQs

Track create and destroy operations of CQ objects.
Reviewed-by: default avatarMark Bloch <markb@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Reviewed-by: default avatarSteve Wise <swise@opengridcomputing.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 78a0cd64
...@@ -159,6 +159,10 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, ...@@ -159,6 +159,10 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private,
if (!cq->wc) if (!cq->wc)
goto out_destroy_cq; goto out_destroy_cq;
cq->res.type = RDMA_RESTRACK_CQ;
cq->res.kern_name = caller;
rdma_restrack_add(&cq->res);
switch (cq->poll_ctx) { switch (cq->poll_ctx) {
case IB_POLL_DIRECT: case IB_POLL_DIRECT:
cq->comp_handler = ib_cq_completion_direct; cq->comp_handler = ib_cq_completion_direct;
...@@ -183,6 +187,7 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, ...@@ -183,6 +187,7 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private,
out_free_wc: out_free_wc:
kfree(cq->wc); kfree(cq->wc);
rdma_restrack_del(&cq->res);
out_destroy_cq: out_destroy_cq:
cq->device->destroy_cq(cq); cq->device->destroy_cq(cq);
return ERR_PTR(ret); return ERR_PTR(ret);
...@@ -214,6 +219,7 @@ void ib_free_cq(struct ib_cq *cq) ...@@ -214,6 +219,7 @@ void ib_free_cq(struct ib_cq *cq)
} }
kfree(cq->wc); kfree(cq->wc);
rdma_restrack_del(&cq->res);
ret = cq->device->destroy_cq(cq); ret = cq->device->destroy_cq(cq);
WARN_ON_ONCE(ret); WARN_ON_ONCE(ret);
} }
......
...@@ -1033,6 +1033,8 @@ static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file, ...@@ -1033,6 +1033,8 @@ static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file,
goto err_cb; goto err_cb;
uobj_alloc_commit(&obj->uobject); uobj_alloc_commit(&obj->uobject);
cq->res.type = RDMA_RESTRACK_CQ;
rdma_restrack_add(&cq->res);
return obj; return obj;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <rdma/ib_verbs.h> #include <rdma/ib_verbs.h>
#include <linux/bug.h> #include <linux/bug.h>
#include <linux/file.h> #include <linux/file.h>
#include <rdma/restrack.h>
#include "rdma_core.h" #include "rdma_core.h"
#include "uverbs.h" #include "uverbs.h"
...@@ -319,6 +320,8 @@ static int uverbs_create_cq_handler(struct ib_device *ib_dev, ...@@ -319,6 +320,8 @@ static int uverbs_create_cq_handler(struct ib_device *ib_dev,
obj->uobject.object = cq; obj->uobject.object = cq;
obj->uobject.user_handle = user_handle; obj->uobject.user_handle = user_handle;
atomic_set(&cq->usecnt, 0); atomic_set(&cq->usecnt, 0);
cq->res.type = RDMA_RESTRACK_CQ;
rdma_restrack_add(&cq->res);
ret = uverbs_copy_to(attrs, CREATE_CQ_RESP_CQE, &cq->cqe); ret = uverbs_copy_to(attrs, CREATE_CQ_RESP_CQE, &cq->cqe);
if (ret) if (ret)
......
...@@ -1579,6 +1579,8 @@ struct ib_cq *ib_create_cq(struct ib_device *device, ...@@ -1579,6 +1579,8 @@ struct ib_cq *ib_create_cq(struct ib_device *device,
cq->event_handler = event_handler; cq->event_handler = event_handler;
cq->cq_context = cq_context; cq->cq_context = cq_context;
atomic_set(&cq->usecnt, 0); atomic_set(&cq->usecnt, 0);
cq->res.type = RDMA_RESTRACK_CQ;
rdma_restrack_add(&cq->res);
} }
return cq; return cq;
...@@ -1597,6 +1599,7 @@ int ib_destroy_cq(struct ib_cq *cq) ...@@ -1597,6 +1599,7 @@ int ib_destroy_cq(struct ib_cq *cq)
if (atomic_read(&cq->usecnt)) if (atomic_read(&cq->usecnt))
return -EBUSY; return -EBUSY;
rdma_restrack_del(&cq->res);
return cq->device->destroy_cq(cq); return cq->device->destroy_cq(cq);
} }
EXPORT_SYMBOL(ib_destroy_cq); EXPORT_SYMBOL(ib_destroy_cq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment