Skip to content

Commit 36e91a5

Browse files
Ryuwang3gregkh
authored andcommitted
RDMA/siw: publish QP after initialization
[ Upstream commit bb27fcc ] siw_create_qp() currently calls siw_qp_add() before the queues, CQ pointers, state, completion, and device list entry are ready. A QPN lookup can therefore reach a QP that is still being constructed. Move siw_qp_add() to the end of siw_create_qp(), after QP initialization and before adding the QP to the siw device list. Fixes: f29dd55 ("rdma/siw: queue pair methods") Link: https://patch.msgid.link/r/20260630060040.966461-1-ruoyuw560@gmail.com Suggested-by: Bernard Metzler <bernard.metzler@linux.dev> Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com> Acked-by: Bernard Metzler <bernard.metzler@linux.dev> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8bf7152 commit 36e91a5

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

drivers/infiniband/sw/siw/siw_verbs.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
302302
struct siw_ucontext *uctx =
303303
rdma_udata_to_drv_context(udata, struct siw_ucontext,
304304
base_ucontext);
305+
struct siw_uresp_create_qp uresp = {};
305306
unsigned long flags;
306307
int num_sqe, num_rqe, rv = 0;
307308
size_t length;
@@ -355,11 +356,6 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
355356
spin_lock_init(&qp->rq_lock);
356357
spin_lock_init(&qp->orq_lock);
357358

358-
rv = siw_qp_add(sdev, qp);
359-
if (rv)
360-
goto err_atomic;
361-
362-
363359
/* All queue indices are derived from modulo operations
364360
* on a free running 'get' (consumer) and 'put' (producer)
365361
* unsigned counter. Having queue sizes at power of two
@@ -377,14 +373,14 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
377373

378374
if (qp->sendq == NULL) {
379375
rv = -ENOMEM;
380-
goto err_out_xa;
376+
goto err_out;
381377
}
382378
if (attrs->sq_sig_type != IB_SIGNAL_REQ_WR) {
383379
if (attrs->sq_sig_type == IB_SIGNAL_ALL_WR)
384380
qp->attrs.flags |= SIW_SIGNAL_ALL_WR;
385381
else {
386382
rv = -EINVAL;
387-
goto err_out_xa;
383+
goto err_out;
388384
}
389385
}
390386
qp->pd = pd;
@@ -410,7 +406,7 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
410406

411407
if (qp->recvq == NULL) {
412408
rv = -ENOMEM;
413-
goto err_out_xa;
409+
goto err_out;
414410
}
415411
qp->attrs.rq_size = num_rqe;
416412
}
@@ -425,11 +421,8 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
425421
qp->attrs.state = SIW_QP_STATE_IDLE;
426422

427423
if (udata) {
428-
struct siw_uresp_create_qp uresp = {};
429-
430424
uresp.num_sqe = num_sqe;
431425
uresp.num_rqe = num_rqe;
432-
uresp.qp_id = qp_id(qp);
433426

434427
if (qp->sendq) {
435428
length = num_sqe * sizeof(struct siw_sqe);
@@ -438,7 +431,7 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
438431
length, &uresp.sq_key);
439432
if (!qp->sq_entry) {
440433
rv = -ENOMEM;
441-
goto err_out_xa;
434+
goto err_out;
442435
}
443436
}
444437

@@ -450,9 +443,23 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
450443
if (!qp->rq_entry) {
451444
uresp.sq_key = SIW_INVAL_UOBJ_KEY;
452445
rv = -ENOMEM;
453-
goto err_out_xa;
446+
goto err_out;
454447
}
455448
}
449+
}
450+
qp->tx_cpu = siw_get_tx_cpu(sdev);
451+
if (qp->tx_cpu < 0) {
452+
rv = -EINVAL;
453+
goto err_out;
454+
}
455+
init_completion(&qp->qp_free);
456+
457+
rv = siw_qp_add(sdev, qp);
458+
if (rv)
459+
goto err_out_tx;
460+
461+
if (udata) {
462+
uresp.qp_id = qp_id(qp);
456463

457464
if (udata->outlen < sizeof(uresp)) {
458465
rv = -EINVAL;
@@ -462,22 +469,19 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
462469
if (rv)
463470
goto err_out_xa;
464471
}
465-
qp->tx_cpu = siw_get_tx_cpu(sdev);
466-
if (qp->tx_cpu < 0) {
467-
rv = -EINVAL;
468-
goto err_out_xa;
469-
}
472+
470473
INIT_LIST_HEAD(&qp->devq);
471474
spin_lock_irqsave(&sdev->lock, flags);
472475
list_add_tail(&qp->devq, &sdev->qp_list);
473476
spin_unlock_irqrestore(&sdev->lock, flags);
474477

475-
init_completion(&qp->qp_free);
476-
477478
return 0;
478479

479480
err_out_xa:
480481
xa_erase(&sdev->qp_xa, qp_id(qp));
482+
err_out_tx:
483+
siw_put_tx_cpu(qp->tx_cpu);
484+
err_out:
481485
if (uctx) {
482486
rdma_user_mmap_entry_remove(qp->sq_entry);
483487
rdma_user_mmap_entry_remove(qp->rq_entry);

0 commit comments

Comments
 (0)