Skip to content

Commit 12137c5

Browse files
Stefan RoscherRoland Dreier
authored andcommitted
IB/ehca: Wait for async events to finish before destroying QP
This is necessary because, in a multicore environment, a race between uverbs async handler and destroy QP could occur. Signed-off-by: Stefan Roscher <stefan.roscher at de.ibm.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
1 parent ab69b3c commit 12137c5

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎drivers/infiniband/hw/ehca/ehca_classes.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ struct ehca_qp {
192192
int mtu_shift;
193193
u32 message_count;
194194
u32 packet_count;
195+
atomic_t nr_events; /* events seen */
196+
wait_queue_head_t wait_completion;
195197
};
196198

197199
#define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)

‎drivers/infiniband/hw/ehca/ehca_irq.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ static void qp_event_callback(struct ehca_shca *shca, u64 eqe,
204204

205205
read_lock(&ehca_qp_idr_lock);
206206
qp = idr_find(&ehca_qp_idr, token);
207+
if (qp)
208+
atomic_inc(&qp->nr_events);
207209
read_unlock(&ehca_qp_idr_lock);
208210

209211
if (!qp)
@@ -223,6 +225,8 @@ static void qp_event_callback(struct ehca_shca *shca, u64 eqe,
223225
if (fatal && qp->ext_type == EQPT_SRQBASE)
224226
dispatch_qp_event(shca, qp, IB_EVENT_QP_LAST_WQE_REACHED);
225227

228+
if (atomic_dec_and_test(&qp->nr_events))
229+
wake_up(&qp->wait_completion);
226230
return;
227231
}
228232

‎drivers/infiniband/hw/ehca/ehca_qp.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ static struct ehca_qp *internal_create_qp(
566566
return ERR_PTR(-ENOMEM);
567567
}
568568

569+
atomic_set(&my_qp->nr_events, 0);
570+
init_waitqueue_head(&my_qp->wait_completion);
569571
spin_lock_init(&my_qp->spinlock_s);
570572
spin_lock_init(&my_qp->spinlock_r);
571573
my_qp->qp_type = qp_type;
@@ -1934,6 +1936,9 @@ static int internal_destroy_qp(struct ib_device *dev, struct ehca_qp *my_qp,
19341936
idr_remove(&ehca_qp_idr, my_qp->token);
19351937
write_unlock_irqrestore(&ehca_qp_idr_lock, flags);
19361938

1939+
/* now wait until all pending events have completed */
1940+
wait_event(my_qp->wait_completion, !atomic_read(&my_qp->nr_events));
1941+
19371942
h_ret = hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
19381943
if (h_ret != H_SUCCESS) {
19391944
ehca_err(dev, "hipz_h_destroy_qp() failed h_ret=%li "

0 commit comments

Comments
 (0)