Received: by 10.213.65.68 with SMTP id h4csp1689086imn; Thu, 29 Mar 2018 09:10:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+EERw3TxDJQk9XOxwfkT8QRzVOMay58lTF4YAseGYaGat5+3usiWv6Ql4ouQtBB7HRQq7y X-Received: by 2002:a17:902:8a93:: with SMTP id p19-v6mr8804659plo.285.1522339842249; Thu, 29 Mar 2018 09:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522339842; cv=none; d=google.com; s=arc-20160816; b=TWOAVrMpwefwm9jTvQbN81A6h6nqyeOpGPo9MX91RGuEy5Fc3UxdMnuSJNFv13aZcf eM+M0LC1HoYMQYR4s5nHYi5W60aad3BEXFFAaw/ybleUl1mN5njrtd8JoDdce00OIkUz jvJUDiLl6K/PfjMJdqjovWq+c8ITfc0OonKoxmmfUwjWbhf12Pkf5x//m27UvX02SiPv mBSIr/Z58tCoHhYd0soazrnxLJTWJqZAVeqmPdPrI00nd1B6T+O/8Nd7+grI4uCa1Jt0 NbbAAUFD9LEbzGs+5mF2mn9vkeE/yP+wNvMnYWpNa2VSCLMZ2sTCh76aCnXu//XM5CCY Y4UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=GPQKWAsFng0zzpg51BRCytZ5bw4WBSS85xFv+GVCjCw=; b=hPAQC4OdVGATfkhDv4M2IAcHSancEU+MH4rhuiRfJtI3rKazB51PieqoXTg1F0kKrQ eHWs5PNJGZ6O/4MCJId42BPHjSYxvYV9q2Le0OdFutSiwJvIqpIj70uv91pEH9+uzSdL FkdBP/cy5rXhorgpBFSaanx4wezq5Cm+FQYULaDBZz4DG0PN46Ix+hKo6VI26MTBv+kE DDVUYRVr4zfBxmvTla9hpj2MPOkAzcWx8Z8/o+4cJxCANS47Fi/oTBe875YmDCRx5UzZ qAsaJ/s6ukNg9nqA3hb92ySAcEIda6crCkiUXQqXFwteZd4eTdrRnAMyY26wa1Qi/xic 9dMQ== 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 i12-v6si6127480plk.508.2018.03.29.09.10.28; Thu, 29 Mar 2018 09:10:42 -0700 (PDT) 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 S1752618AbeC2QHz (ORCPT + 99 others); Thu, 29 Mar 2018 12:07:55 -0400 Received: from ale.deltatee.com ([207.54.116.67]:46342 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750820AbeC2QHf (ORCPT ); Thu, 29 Mar 2018 12:07:35 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1f1a5K-0005mh-OA; Thu, 29 Mar 2018 10:07:34 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1f1a5J-0001EY-6J; Thu, 29 Mar 2018 10:07:29 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org Cc: Christoph Hellwig , Sagi Grimberg , James Smart , Logan Gunthorpe Date: Thu, 29 Mar 2018 10:07:20 -0600 Message-Id: <20180329160721.4691-4-logang@deltatee.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180329160721.4691-1-logang@deltatee.com> References: <20180329160721.4691-1-logang@deltatee.com> X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, hch@lst.de, sagi@grimberg.me, james.smart@broadcom.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_NO_TEXT,T_RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 Subject: [PATCH 3/4] nvmet-fc: Don't use the count returned by the dma_map_sg call X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When allocating an SGL, the fibre channel target uses the number of entities mapped as the number of entities in a given scatter gather list. This is incorrect. The DMA-API-HOWTO document gives this note: The 'nents' argument to the dma_unmap_sg call must be the _same_ one you passed into the dma_map_sg call, it should _NOT_ be the 'count' value _returned_ from the dma_map_sg call. The fc code only stores the count value returned form the dma_map_sg() call and uses that value in the call to dma_unmap_sg(). The dma_map_sg() call will return a lower count than nents when multiple SG entries were merged into one. This implies that there will be fewer DMA address and length entries but the original number of page entries in the SGL. So if this occurs, when the SGL reaches nvmet_execute_rw(), a bio would be created with fewer than the total number of entries. As odd as it sounds, and as far as I can tell, the number of SG entries mapped does not appear to be used anywhere in the fc driver and therefore there's no current need to store it. Signed-off-by: Logan Gunthorpe Cc: James Smart Cc: Christoph Hellwig Cc: Sagi Grimberg Fixes: c53432030d8642 ("nvme-fabrics: Add target support for FC transport") --- drivers/nvme/target/fc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 9b39a6cb1935..9f2f8ab83158 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1698,6 +1698,7 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod) { struct scatterlist *sg; unsigned int nent; + int ret; sg = sgl_alloc(fod->req.transfer_len, GFP_KERNEL, &nent); if (!sg) @@ -1705,10 +1706,12 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod) fod->data_sg = sg; fod->data_sg_cnt = nent; - fod->data_sg_cnt = fc_dma_map_sg(fod->tgtport->dev, sg, nent, - ((fod->io_dir == NVMET_FCP_WRITE) ? - DMA_FROM_DEVICE : DMA_TO_DEVICE)); - /* note: write from initiator perspective */ + ret = fc_dma_map_sg(fod->tgtport->dev, sg, nent, + ((fod->io_dir == NVMET_FCP_WRITE) ? + DMA_FROM_DEVICE : DMA_TO_DEVICE)); + /* note: write from initiator perspective */ + if (!ret) + goto out; return 0; -- 2.11.0