A type-2 MW holds a reference to the QP that bound it. If the QP is destroyed while an MW is still bound, the MW keeps the QP alive and the responder can retain a stale QP association. Invalidate MWs bound to the QP before removing the QP from its pool. Fixes: 32a577b4c3a9 ("RDMA/rxe: Add support for bind MW work requests") Cc: stable@vger.kernel.org Signed-off-by: Dongliang Qin --- drivers/infiniband/sw/rxe/rxe_loc.h | 1 + drivers/infiniband/sw/rxe/rxe_mw.c | 21 +++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe_verbs.c | 2 ++ 3 files changed, 24 insertions(+) diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h index 5e95e5c5e32d6..5c648a5ef34b1 100644 --- a/drivers/infiniband/sw/rxe/rxe_loc.h +++ b/drivers/infiniband/sw/rxe/rxe_loc.h @@ -90,6 +90,7 @@ int rxe_alloc_mw(struct ib_mw *ibmw, struct ib_udata *udata); int rxe_dealloc_mw(struct ib_mw *ibmw); int rxe_bind_mw(struct rxe_qp *qp, struct rxe_send_wqe *wqe); int rxe_invalidate_mw(struct rxe_qp *qp, u32 rkey); +void rxe_invalidate_mws(struct rxe_qp *qp); struct rxe_mr *rxe_mw_get_mr(struct rxe_qp *qp, int access, u32 rkey, u64 *offset); void rxe_mw_cleanup(struct rxe_pool_elem *elem); diff --git a/drivers/infiniband/sw/rxe/rxe_mw.c b/drivers/infiniband/sw/rxe/rxe_mw.c index 82e9fef89b6c3..02d20ede1a789 100644 --- a/drivers/infiniband/sw/rxe/rxe_mw.c +++ b/drivers/infiniband/sw/rxe/rxe_mw.c @@ -298,6 +298,27 @@ int rxe_invalidate_mw(struct rxe_qp *qp, u32 rkey) return ret; } +void rxe_invalidate_mws(struct rxe_qp *qp) +{ + struct rxe_dev *rxe = to_rdev(qp->ibqp.device); + struct rxe_mw *mw; + unsigned long index; + + rcu_read_lock(); + xa_for_each(&rxe->mw_pool.xa, index, mw) { + if (!rxe_get(mw)) + continue; + + spin_lock_bh(&mw->lock); + if (mw->qp == qp) + rxe_do_invalidate_mw(mw); + spin_unlock_bh(&mw->lock); + + rxe_put(mw); + } + rcu_read_unlock(); +} + struct rxe_mr *rxe_mw_get_mr(struct rxe_qp *qp, int access, u32 rkey, u64 *offset) { diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c index 8553c8402c619..c0d77cad4906b 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.c +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c @@ -658,6 +658,8 @@ static int rxe_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) goto err_out; } + rxe_invalidate_mws(qp); + err = rxe_cleanup(qp); if (err) rxe_err_qp(qp, "cleanup failed, err = %d\n", err); -- 2.43.0