From patchwork Wed Nov 22 18:58:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 10070777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 92AFC601D5 for ; Wed, 22 Nov 2017 18:59:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86AD629D74 for ; Wed, 22 Nov 2017 18:59:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B00C29D99; Wed, 22 Nov 2017 18:59:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DD7729D74 for ; Wed, 22 Nov 2017 18:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752050AbdKVS7M (ORCPT ); Wed, 22 Nov 2017 13:59:12 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:59521 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751920AbdKVS7L (ORCPT ); Wed, 22 Nov 2017 13:59:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=aLDAOO/wM6exVMtW3Fg4S6YCBWclIhpYvoAgDJyzQpY=; b=AS7lJAZJ8oaE5bFsLSHwcm8ni kdnd2g7zMgwT3roBhOkTM3w1ShaniDr1/VeWtR5YTfCeiiQVA2fPTRL3SjogaZe9YkHvzvbHHiLLi tkfK8jNP4B9SXOlQrhJhKs8qtiu7eB8M14nAfIhz1VYcmi6IX24AYdmdu1tMBf7tCtFF27nGezV+2 TsMbpF7bAxkSh8XwRTZYRNnBrsnBq1EXttx6mXsDLpviGldznq+/TddP03J6Uhepn+He2KSiw0cO8 ZVjnvAwgMxsQ60iPySkCXWJDJoqJOrjeEHVcP3oliBCE/V+nIPGuYYVMKad0KXhbbqUb7kB9mCYqi Ege6rzSUA==; Received: from bzq-82-81-101-184.red.bezeqint.net ([82.81.101.184] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1eHaEk-0001dJ-Le; Wed, 22 Nov 2017 18:59:07 +0000 From: Sagi Grimberg To: linux-nvme@lists.infradead.org Cc: linux-rdma@vger.kernel.org, Christoph Hellwig , Max Gurtuvoy Subject: [PATCH v5 2/4] nvme-rdma: don't complete requests before a send work request has completed Date: Wed, 22 Nov 2017 20:58:36 +0200 Message-Id: <20171122185838.28855-3-sagi@grimberg.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171122185838.28855-1-sagi@grimberg.me> References: <20171122185838.28855-1-sagi@grimberg.me> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/nvme/host/rdma.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 85c98589a5e0..079150da9846 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -59,6 +59,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; @@ -1162,6 +1165,7 @@ static int nvme_rdma_map_data(struct nvme_rdma_queue *queue, req->num_sge = 1; req->inline_data = false; req->mr->need_inval = false; + refcount_set(&req->ref, 2); /* send and recv completions */ c->common.flags |= NVME_CMD_SGL_METABUF; @@ -1198,8 +1202,21 @@ static int nvme_rdma_map_data(struct nvme_rdma_queue *queue, static void nvme_rdma_send_done(struct ib_cq *cq, struct ib_wc *wc) { - if (unlikely(wc->status != IB_WC_SUCCESS)) + struct nvme_rdma_qe *qe; + struct nvme_rdma_request *req; + struct request *rq; + + if (unlikely(wc->status != IB_WC_SUCCESS)) { nvme_rdma_wr_error(cq, wc, "SEND"); + return; + } + + qe = container_of(wc->wr_cqe, struct nvme_rdma_qe, cqe); + req = container_of(qe, struct nvme_rdma_request, sqe); + rq = blk_mq_rq_from_pdu(req); + + if (refcount_dec_and_test(&req->ref)) + nvme_end_request(rq, req->status, req->result); } static int nvme_rdma_post_send(struct nvme_rdma_queue *queue, @@ -1318,14 +1335,19 @@ static int nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue *queue, } req = blk_mq_rq_to_pdu(rq); - if (rq->tag == tag) - ret = 1; + req->status = cqe->status; + req->result = cqe->result; if ((wc->wc_flags & IB_WC_WITH_INVALIDATE) && wc->ex.invalidate_rkey == req->mr->rkey) req->mr->need_inval = false; - nvme_end_request(rq, cqe->status, cqe->result); + if (refcount_dec_and_test(&req->ref)) { + if (rq->tag == tag) + ret = 1; + nvme_end_request(rq, req->status, req->result); + } + return ret; }