]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
nvme: fix max_segments integer truncation
authorAshok Vairavan <ashok.vairavan@oracle.com>
Thu, 27 Oct 2016 19:31:52 +0000 (12:31 -0700)
committerChuck Anderson <chuck.anderson@oracle.com>
Fri, 28 Oct 2016 00:51:49 +0000 (17:51 -0700)
The block layer uses an unsigned short for max_segments.  The way we
calculate the value for NVMe tends to generate very large 32-bit values,
which after integer truncation may lead to a zero value instead of
the desired outcome.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reported-by: Jeff Lien <Jeff.Lien@hgst.com>
Tested-by: Jeff Lien <Jeff.Lien@hgst.com>
Reviewed-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Orabug: 24928835
Cherry picked commit: 45686b6198bd824f083ff5293f191d78db9d708a
Conflicts:
UEK4 QU2 nvme module doesn't have core.c file. All the functions
resides in pci.c. Hence, this patch is manually ported to the respective
function in pci.c
drivers/nvme/host/core.c

Signed-off-by: Ashok Vairavan <ashok.vairavan@oracle.com>
drivers/nvme/host/pci.c

index fd0879823856f82d856c7709ea17ed245fa04cab..6369a6280dd47b04caa100c97429a6a8480e7f88 100644 (file)
@@ -2153,9 +2153,11 @@ static void nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid)
 
        blk_queue_logical_block_size(ns->queue, 1 << ns->lba_shift);
        if (dev->max_hw_sectors) {
+               u32 max_segments =
+                       (dev->max_hw_sectors / (dev->page_size >> 9)) + 1;
+
                blk_queue_max_hw_sectors(ns->queue, dev->max_hw_sectors);
-               blk_queue_max_segments(ns->queue,
-                       (dev->max_hw_sectors / (dev->page_size >> 9)) + 1);
+               blk_queue_max_segments(ns->queue, min_t(u32, max_segments, USHRT_MAX));
        }
        if (dev->stripe_size)
                blk_queue_chunk_sectors(ns->queue, dev->stripe_size >> 9);