]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
nvme: fix max_segments integer truncation
authorChristoph Hellwig <hch@lst.de>
Fri, 3 Jun 2016 13:42:16 +0000 (07:42 -0600)
committerKamal Mostafa <kamal@canonical.com>
Fri, 10 Jun 2016 13:32:25 +0000 (06:32 -0700)
BugLink: http://bugs.launchpad.net/bugs/1588449
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>
(cherry picked from commit 45686b6198bd824f083ff5293f191d78db9d708a)
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
drivers/nvme/host/core.c

index fde3b4a4e03c23a981bfb0a246de6e7bdd3240cf..6ab452d931b27a2207b30ba759e77b33a5ea2df6 100644 (file)
@@ -839,9 +839,11 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
                struct request_queue *q)
 {
        if (ctrl->max_hw_sectors) {
+               u32 max_segments =
+                       (ctrl->max_hw_sectors / (ctrl->page_size >> 9)) + 1;
+
                blk_queue_max_hw_sectors(q, ctrl->max_hw_sectors);
-               blk_queue_max_segments(q,
-                       (ctrl->max_hw_sectors / (ctrl->page_size >> 9)) + 1);
+               blk_queue_max_segments(q, min_t(u32, max_segments, USHRT_MAX));
        }
        if (ctrl->stripe_size)
                blk_queue_chunk_sectors(q, ctrl->stripe_size >> 9);