[PATCH v3] nvme: fix interpretation of dmrsl

Keith Busch kbusch at kernel.org
Thu Apr 28 10:18:00 PDT 2022


On Fri, Apr 29, 2022 at 12:50:51AM +0800, Tom Yan wrote:
> @@ -1606,6 +1606,7 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
>  	struct nvme_ctrl *ctrl = ns->ctrl;
>  	struct request_queue *queue = disk->queue;
>  	u32 size = queue_logical_block_size(queue);
> +	int lts_shift = ilog2(size) - 9;
>  
>  	if (ctrl->max_discard_sectors == 0) {
>  		blk_queue_flag_clear(QUEUE_FLAG_DISCARD, queue);
> @@ -1622,6 +1623,9 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
>  	if (blk_queue_flag_test_and_set(QUEUE_FLAG_DISCARD, queue))
>  		return;
>  
> +	if (ctrl->dmrsl && ctrl->dmrsl <= UINT_MAX >> lts_shift)
> +		ctrl->max_discard_sectors = ctrl->dmrsl << lts_shift;
> +
>  	blk_queue_max_discard_sectors(queue, ctrl->max_discard_sectors);

I think the only change you really need is just changing the above line to:

  	blk_queue_max_discard_sectors(queue, nvme_lba_to_sect(ns, ctrl->max_discard_sectors));



More information about the Linux-nvme mailing list