public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* two more nvme fixes for Linux 4.15
@ 2018-01-17 21:04 Christoph Hellwig
  2018-01-17 21:04 ` [PATCH 1/2] nvme-pci: check segement valid for SGL use Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christoph Hellwig @ 2018-01-17 21:04 UTC (permalink / raw)
  To: axboe; +Cc: keith.busch, linux-block, sagi, linux-nvme

Hi Jens,

below are the two fixes for the new SGL support in 4.15 as a patch
series due to the issues with the git server.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] nvme-pci: check segement valid for SGL use
  2018-01-17 21:04 two more nvme fixes for Linux 4.15 Christoph Hellwig
@ 2018-01-17 21:04 ` Christoph Hellwig
  2018-01-17 21:04 ` [PATCH 2/2] nvme-pci: take sglist coalescing in dma_map_sg into account Christoph Hellwig
  2018-01-17 21:05 ` two more nvme fixes for Linux 4.15 Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2018-01-17 21:04 UTC (permalink / raw)
  To: axboe; +Cc: keith.busch, linux-block, sagi, linux-nvme

From: Keith Busch <keith.busch@intel.com>

The driver needs to verify there is a payload with a command before
seeing if it should use SGLs to map it.

Fixes: 955b1b5a00ba ("nvme-pci: move use_sgl initialization to nvme_init_iod()")
Reported-by: Paul Menzel <pmenzel+linux-nvme@molgen.mpg.de>
Reviewed-by: Paul Menzel <pmenzel+linux-nvme@molgen.mpg.de>
Signed-off-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/nvme/host/pci.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index d53550e612bc..a7e94cc3c70e 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -451,10 +451,13 @@ static void **nvme_pci_iod_list(struct request *req)
 static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req)
 {
 	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
+	int nseg = blk_rq_nr_phys_segments(req);
 	unsigned int avg_seg_size;
 
-	avg_seg_size = DIV_ROUND_UP(blk_rq_payload_bytes(req),
-			blk_rq_nr_phys_segments(req));
+	if (nseg == 0)
+		return false;
+
+	avg_seg_size = DIV_ROUND_UP(blk_rq_payload_bytes(req), nseg);
 
 	if (!(dev->ctrl.sgls & ((1 << 0) | (1 << 1))))
 		return false;
-- 
2.14.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] nvme-pci: take sglist coalescing in dma_map_sg into account
  2018-01-17 21:04 two more nvme fixes for Linux 4.15 Christoph Hellwig
  2018-01-17 21:04 ` [PATCH 1/2] nvme-pci: check segement valid for SGL use Christoph Hellwig
@ 2018-01-17 21:04 ` Christoph Hellwig
  2018-01-17 21:05 ` two more nvme fixes for Linux 4.15 Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2018-01-17 21:04 UTC (permalink / raw)
  To: axboe; +Cc: keith.busch, linux-block, sagi, linux-nvme

Some iommu implementations can merge physically and/or virtually
contiguous segments inside sg_map_dma.  The NVMe SGL support does not take
this into account and will warn because of falling off a loop.  Pass the
number of mapped segments to nvme_pci_setup_sgls so that the SGL setup
can take the number of mapped segments into account.

Reported-by: Fangjian (Turing) <f.fangjian@huawei.com>
Fixes: a7a7cbe3 ("nvme-pci: add SGL support")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Sagi Grimberg <sagi@rimberg.me>
---
 drivers/nvme/host/pci.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index a7e94cc3c70e..4276ebfff22b 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -725,20 +725,19 @@ static void nvme_pci_sgl_set_seg(struct nvme_sgl_desc *sge,
 }
 
 static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev,
-		struct request *req, struct nvme_rw_command *cmd)
+		struct request *req, struct nvme_rw_command *cmd, int entries)
 {
 	struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
-	int length = blk_rq_payload_bytes(req);
 	struct dma_pool *pool;
 	struct nvme_sgl_desc *sg_list;
 	struct scatterlist *sg = iod->sg;
-	int entries = iod->nents, i = 0;
 	dma_addr_t sgl_dma;
+	int i = 0;
 
 	/* setting the transfer type as SGL */
 	cmd->flags = NVME_CMD_SGL_METABUF;
 
-	if (length == sg_dma_len(sg)) {
+	if (entries == 1) {
 		nvme_pci_sgl_set_data(&cmd->dptr.sgl, sg);
 		return BLK_STS_OK;
 	}
@@ -778,13 +777,9 @@ static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev,
 		}
 
 		nvme_pci_sgl_set_data(&sg_list[i++], sg);
-
-		length -= sg_dma_len(sg);
 		sg = sg_next(sg);
-		entries--;
-	} while (length > 0);
+	} while (--entries > 0);
 
-	WARN_ON(entries > 0);
 	return BLK_STS_OK;
 }
 
@@ -796,6 +791,7 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
 	enum dma_data_direction dma_dir = rq_data_dir(req) ?
 			DMA_TO_DEVICE : DMA_FROM_DEVICE;
 	blk_status_t ret = BLK_STS_IOERR;
+	int nr_mapped;
 
 	sg_init_table(iod->sg, blk_rq_nr_phys_segments(req));
 	iod->nents = blk_rq_map_sg(q, req, iod->sg);
@@ -803,12 +799,13 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
 		goto out;
 
 	ret = BLK_STS_RESOURCE;
-	if (!dma_map_sg_attrs(dev->dev, iod->sg, iod->nents, dma_dir,
-				DMA_ATTR_NO_WARN))
+	nr_mapped = dma_map_sg_attrs(dev->dev, iod->sg, iod->nents, dma_dir,
+			DMA_ATTR_NO_WARN);
+	if (!nr_mapped)
 		goto out;
 
 	if (iod->use_sgl)
-		ret = nvme_pci_setup_sgls(dev, req, &cmnd->rw);
+		ret = nvme_pci_setup_sgls(dev, req, &cmnd->rw, nr_mapped);
 	else
 		ret = nvme_pci_setup_prps(dev, req, &cmnd->rw);
 
-- 
2.14.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: two more nvme fixes for Linux 4.15
  2018-01-17 21:04 two more nvme fixes for Linux 4.15 Christoph Hellwig
  2018-01-17 21:04 ` [PATCH 1/2] nvme-pci: check segement valid for SGL use Christoph Hellwig
  2018-01-17 21:04 ` [PATCH 2/2] nvme-pci: take sglist coalescing in dma_map_sg into account Christoph Hellwig
@ 2018-01-17 21:05 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2018-01-17 21:05 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: keith.busch, linux-block, sagi, linux-nvme

On 1/17/18 2:04 PM, Christoph Hellwig wrote:
> Hi Jens,
> 
> below are the two fixes for the new SGL support in 4.15 as a patch
> series due to the issues with the git server.

Applied, thanks.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-17 21:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-17 21:04 two more nvme fixes for Linux 4.15 Christoph Hellwig
2018-01-17 21:04 ` [PATCH 1/2] nvme-pci: check segement valid for SGL use Christoph Hellwig
2018-01-17 21:04 ` [PATCH 2/2] nvme-pci: take sglist coalescing in dma_map_sg into account Christoph Hellwig
2018-01-17 21:05 ` two more nvme fixes for Linux 4.15 Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox