Received: by 10.223.176.5 with SMTP id f5csp987973wra; Fri, 2 Feb 2018 09:18:04 -0800 (PST) X-Google-Smtp-Source: AH8x225HG1pyLuzajw+u/ftAeWZIUTzJmuipfsjMkU++SIgakX6dligca3PJrixHSnHMBtYM+aDi X-Received: by 10.99.108.7 with SMTP id h7mr31741150pgc.292.1517591884838; Fri, 02 Feb 2018 09:18:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517591884; cv=none; d=google.com; s=arc-20160816; b=B/pWa+xoQ+lS/j9LupGMnpTRUtLaKSp5qKcSNhp3iLz+MSx5OyIJhPu8cEyU69mKpY wSVXqCptfAkSh04kMI2c+PfH3p2UaB3FcWhx0I9lKnEgj9s01J0hOcFv3cFDZqK8ly1I vFosUqWL8/mPh3rMyIgbBd+RIogsBXXJTgpcPEar4/YSXtKTkPETnC5JUDdbs7JuwMTn Qo/b2nl/yPPx8G9wg0ArUF+Q1MUu1o6rQNlE4jjtmZBjDdS0cFqTFKsKYTVabskHArvw FaxewNpwSRVY1e6+WNN11MxRL4IrupJJb6elpl6kUSblmm9Bk3MYhb4qokNjyOYiOVXT oxPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rfT31DRsrLOQRY3XyBN77dAWWs6ODFGifoG9DYjSYFE=; b=s3QkedZ/e35cmvk0SibOi94dVIWU6nJUu31iMFFrKG00BvoZANvEGnbRZg3uK9LCWS 0C60mIPy9vP4FNyFapUckRjj7DqYo7sYlFu/QQfuh1ZXlpAVmcUOpDbxMa165QzEo/Ux 11Tr1dtA4CBRlcQacc9z9XmzLaXnql3uextm6x9aZe6tRj59GqcZ1NYn/6DIw7TKAsZh qEjp3HR1cEYusWmHWpxpZQczze9Mjasxfi7qAV9vMC9sKDF8ajbfhuIUCPPfFQEuCpkl 6pdDWbYiX2fgNjD6y/28GrjAftc18dioIEAD7dUqWcmKrhUEXyIWVIuqlrjxphlfSabD U15w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t12si1705607pgf.370.2018.02.02.09.17.50; Fri, 02 Feb 2018 09:18:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753827AbeBBRQO (ORCPT + 99 others); Fri, 2 Feb 2018 12:16:14 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:38086 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752773AbeBBRKC (ORCPT ); Fri, 2 Feb 2018 12:10:02 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 72CBEE27; Fri, 2 Feb 2018 17:10:01 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sagi Grimberg , Max Gurtovoy , Christoph Hellwig , Sasha Levin Subject: [PATCH 4.14 066/156] nvme-rdma: dont complete requests before a send work request has completed Date: Fri, 2 Feb 2018 17:57:27 +0100 Message-Id: <20180202140843.274307950@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/host/rdma.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) --- 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 nvm 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; @@ -1213,8 +1217,19 @@ static int nvme_rdma_map_data(struct nvm 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 = + container_of(wc->wr_cqe, struct nvme_rdma_qe, cqe); + struct nvme_rdma_request *req = + container_of(qe, struct nvme_rdma_request, sqe); + struct request *rq = blk_mq_rq_from_pdu(req); + + if (unlikely(wc->status != 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); } /* @@ -1359,14 +1374,19 @@ static int nvme_rdma_process_nvme_rsp(st } 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; }