Skip to content

Commit d3d72d9

Browse files
Sean Heftyrolandd
authored andcommitted
RDMA/verbs: Cleanup XRC TGT QPs when destroying XRCD
XRC TGT QPs are intended to be shared among multiple users and processes. Allow the destruction of an XRC TGT QP to be done explicitly through ib_destroy_qp() or when the XRCD is destroyed. To support destroying an XRC TGT QP, we need to track TGT QPs with the XRCD. When the XRCD is destroyed, all tracked XRC TGT QPs are also cleaned up. To avoid stale reference issues, if a user is holding a reference on a TGT QP, we increment a reference count on the QP. The user releases the reference by calling ib_release_qp. This releases any access to the QP from a user above verbs, but allows the QP to continue to exist until destroyed by the XRCD. Signed-off-by: Sean Hefty <sean.hefty@intel.com> Signed-off-by: Roland Dreier <roland@purestorage.com>
1 parent b42b63c commit d3d72d9

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

‎drivers/infiniband/core/verbs.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,20 @@ EXPORT_SYMBOL(ib_destroy_srq);
316316

317317
/* Queue pairs */
318318

319+
static void __ib_insert_xrcd_qp(struct ib_xrcd *xrcd, struct ib_qp *qp)
320+
{
321+
mutex_lock(&xrcd->tgt_qp_mutex);
322+
list_add(&qp->xrcd_list, &xrcd->tgt_qp_list);
323+
mutex_unlock(&xrcd->tgt_qp_mutex);
324+
}
325+
326+
static void __ib_remove_xrcd_qp(struct ib_xrcd *xrcd, struct ib_qp *qp)
327+
{
328+
mutex_lock(&xrcd->tgt_qp_mutex);
329+
list_del(&qp->xrcd_list);
330+
mutex_unlock(&xrcd->tgt_qp_mutex);
331+
}
332+
319333
struct ib_qp *ib_create_qp(struct ib_pd *pd,
320334
struct ib_qp_init_attr *qp_init_attr)
321335
{
@@ -334,6 +348,7 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
334348
qp->srq = NULL;
335349
qp->xrcd = qp_init_attr->xrcd;
336350
atomic_inc(&qp_init_attr->xrcd->usecnt);
351+
__ib_insert_xrcd_qp(qp_init_attr->xrcd, qp);
337352
} else {
338353
if (qp_init_attr->qp_type == IB_QPT_XRC_INI) {
339354
qp->recv_cq = NULL;
@@ -730,6 +745,8 @@ int ib_destroy_qp(struct ib_qp *qp)
730745
rcq = qp->recv_cq;
731746
srq = qp->srq;
732747
xrcd = qp->xrcd;
748+
if (xrcd)
749+
__ib_remove_xrcd_qp(xrcd, qp);
733750

734751
ret = qp->device->destroy_qp(qp);
735752
if (!ret) {
@@ -743,12 +760,30 @@ int ib_destroy_qp(struct ib_qp *qp)
743760
atomic_dec(&srq->usecnt);
744761
if (xrcd)
745762
atomic_dec(&xrcd->usecnt);
763+
} else if (xrcd) {
764+
__ib_insert_xrcd_qp(xrcd, qp);
746765
}
747766

748767
return ret;
749768
}
750769
EXPORT_SYMBOL(ib_destroy_qp);
751770

771+
int ib_release_qp(struct ib_qp *qp)
772+
{
773+
unsigned long flags;
774+
775+
if (qp->qp_type != IB_QPT_XRC_TGT)
776+
return -EINVAL;
777+
778+
spin_lock_irqsave(&qp->device->event_handler_lock, flags);
779+
qp->event_handler = NULL;
780+
spin_unlock_irqrestore(&qp->device->event_handler_lock, flags);
781+
782+
atomic_dec(&qp->xrcd->usecnt);
783+
return 0;
784+
}
785+
EXPORT_SYMBOL(ib_release_qp);
786+
752787
/* Completion queues */
753788

754789
struct ib_cq *ib_create_cq(struct ib_device *device,
@@ -1062,6 +1097,8 @@ struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device)
10621097
if (!IS_ERR(xrcd)) {
10631098
xrcd->device = device;
10641099
atomic_set(&xrcd->usecnt, 0);
1100+
mutex_init(&xrcd->tgt_qp_mutex);
1101+
INIT_LIST_HEAD(&xrcd->tgt_qp_list);
10651102
}
10661103

10671104
return xrcd;
@@ -1070,9 +1107,19 @@ EXPORT_SYMBOL(ib_alloc_xrcd);
10701107

10711108
int ib_dealloc_xrcd(struct ib_xrcd *xrcd)
10721109
{
1110+
struct ib_qp *qp;
1111+
int ret;
1112+
10731113
if (atomic_read(&xrcd->usecnt))
10741114
return -EBUSY;
10751115

1116+
while (!list_empty(&xrcd->tgt_qp_list)) {
1117+
qp = list_entry(xrcd->tgt_qp_list.next, struct ib_qp, xrcd_list);
1118+
ret = ib_destroy_qp(qp);
1119+
if (ret)
1120+
return ret;
1121+
}
1122+
10761123
return xrcd->device->dealloc_xrcd(xrcd);
10771124
}
10781125
EXPORT_SYMBOL(ib_dealloc_xrcd);

‎include/rdma/ib_verbs.h‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,10 @@ struct ib_pd {
880880

881881
struct ib_xrcd {
882882
struct ib_device *device;
883-
atomic_t usecnt; /* count all resources */
883+
atomic_t usecnt; /* count all exposed resources */
884+
885+
struct mutex tgt_qp_mutex;
886+
struct list_head tgt_qp_list;
884887
};
885888

886889
struct ib_ah {
@@ -926,6 +929,7 @@ struct ib_qp {
926929
struct ib_cq *recv_cq;
927930
struct ib_srq *srq;
928931
struct ib_xrcd *xrcd; /* XRC TGT QPs only */
932+
struct list_head xrcd_list;
929933
struct ib_uobject *uobject;
930934
void (*event_handler)(struct ib_event *, void *);
931935
void *qp_context;
@@ -1481,6 +1485,17 @@ int ib_query_qp(struct ib_qp *qp,
14811485
*/
14821486
int ib_destroy_qp(struct ib_qp *qp);
14831487

1488+
/**
1489+
* ib_release_qp - Release an external reference to a QP.
1490+
* @qp: The QP handle to release
1491+
*
1492+
* The specified QP handle is released by the caller. If the QP is
1493+
* referenced internally, it is not destroyed until all internal
1494+
* references are released. After releasing the qp, the caller
1495+
* can no longer access it and all events on the QP are discarded.
1496+
*/
1497+
int ib_release_qp(struct ib_qp *qp);
1498+
14841499
/**
14851500
* ib_post_send - Posts a list of work requests to the send queue of
14861501
* the specified QP.

0 commit comments

Comments
 (0)