Commit b94e8cd2 authored by Christoph Hellwig's avatar Christoph Hellwig

nvme: fix Write Zeroes limitations

We voluntarily limit the Write Zeroes sizes to the MDTS value provided by
the hardware, but currently get the units wrong, so fix that.

Fixes: 6e02318e ("nvme: add support for the Write Zeroes command")
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarKeith Busch <kbusch@kernel.org>
Tested-by: default avatarKlaus Jensen <k.jensen@samsung.com>
Reviewed-by: default avatarKlaus Jensen <k.jensen@samsung.com>
Reviewed-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
parent 985c5a32
...@@ -1954,30 +1954,18 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) ...@@ -1954,30 +1954,18 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
blk_queue_max_write_zeroes_sectors(queue, UINT_MAX); blk_queue_max_write_zeroes_sectors(queue, UINT_MAX);
} }
static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) /*
{ * Even though NVMe spec explicitly states that MDTS is not applicable to the
u64 max_blocks; * write-zeroes, we are cautious and limit the size to the controllers
* max_hw_sectors value, which is based on the MDTS field and possibly other
if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) || * limiting factors.
(ns->ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES))
return;
/*
* Even though NVMe spec explicitly states that MDTS is not
* applicable to the write-zeroes:- "The restriction does not apply to
* commands that do not transfer data between the host and the
* controller (e.g., Write Uncorrectable ro Write Zeroes command).".
* In order to be more cautious use controller's max_hw_sectors value
* to configure the maximum sectors for the write-zeroes which is
* configured based on the controller's MDTS field in the
* nvme_init_identify() if available.
*/ */
if (ns->ctrl->max_hw_sectors == UINT_MAX) static void nvme_config_write_zeroes(struct request_queue *q,
max_blocks = (u64)USHRT_MAX + 1; struct nvme_ctrl *ctrl)
else {
max_blocks = ns->ctrl->max_hw_sectors + 1; if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) &&
!(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES))
blk_queue_max_write_zeroes_sectors(disk->queue, blk_queue_max_write_zeroes_sectors(q, ctrl->max_hw_sectors);
nvme_lba_to_sect(ns, max_blocks));
} }
static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids) static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
...@@ -2149,7 +2137,7 @@ static void nvme_update_disk_info(struct gendisk *disk, ...@@ -2149,7 +2137,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
set_capacity_and_notify(disk, capacity); set_capacity_and_notify(disk, capacity);
nvme_config_discard(disk, ns); nvme_config_discard(disk, ns);
nvme_config_write_zeroes(disk, ns); nvme_config_write_zeroes(disk->queue, ns->ctrl);
set_disk_ro(disk, (id->nsattr & NVME_NS_ATTR_RO) || set_disk_ro(disk, (id->nsattr & NVME_NS_ATTR_RO) ||
test_bit(NVME_NS_FORCE_RO, &ns->flags)); test_bit(NVME_NS_FORCE_RO, &ns->flags));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment