Skip to content

Commit f7cc25d

Browse files
Kumar Sanghvirolandd
authored andcommitted
RDMA/cxgb3: Serialize calls to CQ's comp_handler
iw_cxgb3 has a potential problem where a CQ's comp_handler can get called simultaneously from different places in iw_cxgb3 driver. This does not comply with Documentation/infiniband/core_locking.txt, which states that at a given point of time, there should be only one callback per CQ should be active. Such problem was reported by Parav Pandit <Parav.Pandit@Emulex.Com> for iw_cxgb4 driver. Based on discussion between Parav Pandit and Steve Wise, this patch fixes the above problem by serializing the calls to a CQ's comp_handler using a spin_lock. Signed-off-by: Kumar Sanghvi <kumaras@chelsio.com> Acked-by: Steve Wise <swise@opengridcomputing.com> Signed-off-by: Roland Dreier <roland@purestorage.com>
1 parent 976d167 commit f7cc25d

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎drivers/infiniband/hw/cxgb3/iwch_ev.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
4646
struct ib_event event;
4747
struct iwch_qp_attributes attrs;
4848
struct iwch_qp *qhp;
49+
unsigned long flag;
4950

5051
spin_lock(&rnicp->lock);
5152
qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
@@ -94,7 +95,9 @@ static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
9495
if (qhp->ibqp.event_handler)
9596
(*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
9697

98+
spin_lock_irqsave(&chp->comp_handler_lock, flag);
9799
(*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
100+
spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
98101

99102
if (atomic_dec_and_test(&qhp->refcnt))
100103
wake_up(&qhp->wait);
@@ -107,6 +110,7 @@ void iwch_ev_dispatch(struct cxio_rdev *rdev_p, struct sk_buff *skb)
107110
struct iwch_cq *chp;
108111
struct iwch_qp *qhp;
109112
u32 cqid = RSPQ_CQID(rsp_msg);
113+
unsigned long flag;
110114

111115
rnicp = (struct iwch_dev *) rdev_p->ulp;
112116
spin_lock(&rnicp->lock);
@@ -170,7 +174,9 @@ void iwch_ev_dispatch(struct cxio_rdev *rdev_p, struct sk_buff *skb)
170174
*/
171175
if (qhp->ep && SQ_TYPE(rsp_msg->cqe))
172176
dst_confirm(qhp->ep->dst);
177+
spin_lock_irqsave(&chp->comp_handler_lock, flag);
173178
(*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
179+
spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
174180
break;
175181

176182
case TPT_ERR_STAG:

‎drivers/infiniband/hw/cxgb3/iwch_provider.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ static struct ib_cq *iwch_create_cq(struct ib_device *ibdev, int entries, int ve
190190
chp->rhp = rhp;
191191
chp->ibcq.cqe = 1 << chp->cq.size_log2;
192192
spin_lock_init(&chp->lock);
193+
spin_lock_init(&chp->comp_handler_lock);
193194
atomic_set(&chp->refcnt, 1);
194195
init_waitqueue_head(&chp->wait);
195196
if (insert_handle(rhp, &rhp->cqidr, chp, chp->cq.cqid)) {

‎drivers/infiniband/hw/cxgb3/iwch_provider.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct iwch_cq {
103103
struct iwch_dev *rhp;
104104
struct t3_cq cq;
105105
spinlock_t lock;
106+
spinlock_t comp_handler_lock;
106107
atomic_t refcnt;
107108
wait_queue_head_t wait;
108109
u32 __user *user_rptr_addr;

‎drivers/infiniband/hw/cxgb3/iwch_qp.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,11 @@ static void __flush_qp(struct iwch_qp *qhp, struct iwch_cq *rchp,
822822
flushed = cxio_flush_rq(&qhp->wq, &rchp->cq, count);
823823
spin_unlock(&qhp->lock);
824824
spin_unlock_irqrestore(&rchp->lock, *flag);
825-
if (flushed)
825+
if (flushed) {
826+
spin_lock_irqsave(&rchp->comp_handler_lock, *flag);
826827
(*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
828+
spin_unlock_irqrestore(&rchp->comp_handler_lock, *flag);
829+
}
827830

828831
/* locking hierarchy: cq lock first, then qp lock. */
829832
spin_lock_irqsave(&schp->lock, *flag);
@@ -833,8 +836,11 @@ static void __flush_qp(struct iwch_qp *qhp, struct iwch_cq *rchp,
833836
flushed = cxio_flush_sq(&qhp->wq, &schp->cq, count);
834837
spin_unlock(&qhp->lock);
835838
spin_unlock_irqrestore(&schp->lock, *flag);
836-
if (flushed)
839+
if (flushed) {
840+
spin_lock_irqsave(&schp->comp_handler_lock, *flag);
837841
(*schp->ibcq.comp_handler)(&schp->ibcq, schp->ibcq.cq_context);
842+
spin_unlock_irqrestore(&schp->comp_handler_lock, *flag);
843+
}
838844

839845
/* deref */
840846
if (atomic_dec_and_test(&qhp->refcnt))
@@ -853,11 +859,15 @@ static void flush_qp(struct iwch_qp *qhp, unsigned long *flag)
853859
if (qhp->ibqp.uobject) {
854860
cxio_set_wq_in_error(&qhp->wq);
855861
cxio_set_cq_in_error(&rchp->cq);
862+
spin_lock_irqsave(&rchp->comp_handler_lock, *flag);
856863
(*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
864+
spin_unlock_irqrestore(&rchp->comp_handler_lock, *flag);
857865
if (schp != rchp) {
858866
cxio_set_cq_in_error(&schp->cq);
867+
spin_lock_irqsave(&schp->comp_handler_lock, *flag);
859868
(*schp->ibcq.comp_handler)(&schp->ibcq,
860869
schp->ibcq.cq_context);
870+
spin_unlock_irqrestore(&schp->comp_handler_lock, *flag);
861871
}
862872
return;
863873
}

0 commit comments

Comments
 (0)