Return-Path: From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Sagi Grimberg , Christoph Hellwig , "Sasha Levin" Subject: [PATCH AUTOSEL for 4.14 037/100] nvme-rdma: don't complete requests before a send work request has completed Date: Wed, 24 Jan 2018 04:14:42 +0000 Message-ID: <20180124041414.32065-37-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: From: Sagi Grimberg [ Upstream commit 4af7f7ff92a42b6c713293c99e7982bcfcf51a70 ] In order to guarantee that the HCA will never get an access violation (either from invalidated rkey or from iommu) when retrying a send operation we must complete a request only when both send completion and the nvme cqe has arrived. We need to set the send/recv completions flags atomically because we might have more than a single context accessing the request concurrently (one is cq irq-poll context and the other is user-polling used in IOCB_HIPRI). Only then we are safe to invalidate the rkey (if needed), unmap the host buffers, and complete the IO. Signed-off-by: Sagi Grimberg Reviewed-by: Max Gurtovoy Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/rdma.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 6de163e6c9eb..33d4431c2b4b 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -67,6 +67,9 @@ struct nvme_rdma_request { struct nvme_request req; struct ib_mr *mr; struct nvme_rdma_qe sqe; + union nvme_result result; + __le16 status; + refcount_t ref; struct ib_sge sge[1 + NVME_RDMA_MAX_INLINE_SEGMENTS]; u32 num_sge; int nents; @@ -1177,6 +1180,7 @@ static int nvme_rdma_map_data(struct nvme_rdma_queue = *queue, req->num_sge =3D 1; req->inline_data =3D false; req->mr->need_inval =3D false; + refcount_set(&req->ref, 2); /* send and recv completions */ =20 c->common.flags |=3D NVME_CMD_SGL_METABUF; =20 @@ -1213,8 +1217,19 @@ static int nvme_rdma_map_data(struct nvme_rdma_queue= *queue, =20 static void nvme_rdma_send_done(struct ib_cq *cq, struct ib_wc *wc) { - if (unlikely(wc->status !=3D IB_WC_SUCCESS)) + struct nvme_rdma_qe *qe =3D + container_of(wc->wr_cqe, struct nvme_rdma_qe, cqe); + struct nvme_rdma_request *req =3D + container_of(qe, struct nvme_rdma_request, sqe); + struct request *rq =3D blk_mq_rq_from_pdu(req); + + if (unlikely(wc->status !=3D IB_WC_SUCCESS)) { nvme_rdma_wr_error(cq, wc, "SEND"); + return; + } + + if (refcount_dec_and_test(&req->ref)) + nvme_end_request(rq, req->status, req->result); } =20 /* @@ -1359,14 +1374,19 @@ static int nvme_rdma_process_nvme_rsp(struct nvme_r= dma_queue *queue, } req =3D blk_mq_rq_to_pdu(rq); =20 - if (rq->tag =3D=3D tag) - ret =3D 1; + req->status =3D cqe->status; + req->result =3D cqe->result; =20 if ((wc->wc_flags & IB_WC_WITH_INVALIDATE) && wc->ex.invalidate_rkey =3D=3D req->mr->rkey) req->mr->need_inval =3D false; =20 - nvme_end_request(rq, cqe->status, cqe->result); + if (refcount_dec_and_test(&req->ref)) { + if (rq->tag =3D=3D tag) + ret =3D 1; + nvme_end_request(rq, req->status, req->result); + } + return ret; } =20 --=20 2.11.0