Skip to content

Commit ad61a4c

Browse files
Steve Wisedledford
authored andcommitted
iw_cxgb4: don't block in destroy_qp awaiting the last deref
Blocking in c4iw_destroy_qp() causes a deadlock when apps destroy a qp or disconnect a cm_id from their cm event handler function. There is no need to block here anyway, so just replace the refcnt atomic with a kref object and free the memory on the last put. Signed-off-by: Steve Wise <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 1b1a889 commit ad61a4c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

drivers/infiniband/hw/cxgb4/iw_cxgb4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ struct c4iw_qp {
475475
struct t4_wq wq;
476476
spinlock_t lock;
477477
struct mutex mutex;
478-
atomic_t refcnt;
478+
struct kref kref;
479479
wait_queue_head_t wait;
480480
struct timer_list timer;
481481
int sq_sig_all;

drivers/infiniband/hw/cxgb4/qp.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -683,17 +683,25 @@ static int build_inv_stag(union t4_wr *wqe, struct ib_send_wr *wr,
683683
return 0;
684684
}
685685

686+
void _free_qp(struct kref *kref)
687+
{
688+
struct c4iw_qp *qhp;
689+
690+
qhp = container_of(kref, struct c4iw_qp, kref);
691+
PDBG("%s qhp %p\n", __func__, qhp);
692+
kfree(qhp);
693+
}
694+
686695
void c4iw_qp_add_ref(struct ib_qp *qp)
687696
{
688697
PDBG("%s ib_qp %p\n", __func__, qp);
689-
atomic_inc(&(to_c4iw_qp(qp)->refcnt));
698+
kref_get(&to_c4iw_qp(qp)->kref);
690699
}
691700

692701
void c4iw_qp_rem_ref(struct ib_qp *qp)
693702
{
694703
PDBG("%s ib_qp %p\n", __func__, qp);
695-
if (atomic_dec_and_test(&(to_c4iw_qp(qp)->refcnt)))
696-
wake_up(&(to_c4iw_qp(qp)->wait));
704+
kref_put(&to_c4iw_qp(qp)->kref, _free_qp);
697705
}
698706

699707
static void add_to_fc_list(struct list_head *head, struct list_head *entry)
@@ -1594,8 +1602,6 @@ int c4iw_destroy_qp(struct ib_qp *ib_qp)
15941602
wait_event(qhp->wait, !qhp->ep);
15951603

15961604
remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid);
1597-
atomic_dec(&qhp->refcnt);
1598-
wait_event(qhp->wait, !atomic_read(&qhp->refcnt));
15991605

16001606
spin_lock_irq(&rhp->lock);
16011607
if (!list_empty(&qhp->db_fc_entry))
@@ -1608,8 +1614,9 @@ int c4iw_destroy_qp(struct ib_qp *ib_qp)
16081614
destroy_qp(&rhp->rdev, &qhp->wq,
16091615
ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
16101616

1617+
c4iw_qp_rem_ref(ib_qp);
1618+
16111619
PDBG("%s ib_qp %p qpid 0x%0x\n", __func__, ib_qp, qhp->wq.sq.qid);
1612-
kfree(qhp);
16131620
return 0;
16141621
}
16151622

@@ -1706,7 +1713,7 @@ struct ib_qp *c4iw_create_qp(struct ib_pd *pd, struct ib_qp_init_attr *attrs,
17061713
init_completion(&qhp->rq_drained);
17071714
mutex_init(&qhp->mutex);
17081715
init_waitqueue_head(&qhp->wait);
1709-
atomic_set(&qhp->refcnt, 1);
1716+
kref_init(&qhp->kref);
17101717

17111718
ret = insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.sq.qid);
17121719
if (ret)

0 commit comments

Comments
 (0)