linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvme: fix Write Zeroes limitations
@ 2021-03-15  9:34 Christoph Hellwig
  2021-03-15 11:19 ` Klaus Jensen
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Christoph Hellwig @ 2021-03-15  9:34 UTC (permalink / raw)
  To: keith.busch, sagi; +Cc: linux-nvme

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: 6e02318eaea5 ("nvme: add support for the Write Zeroes command")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/nvme/host/core.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 82ad5eef9d0c30..1bd18d7f53b316 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1964,30 +1964,18 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
 		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
+ * 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
+ * limiting factors.
+ */
+static void nvme_config_write_zeroes(struct request_queue *q,
+		struct nvme_ctrl *ctrl)
 {
-	u64 max_blocks;
-
-	if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) ||
-	    (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)
-		max_blocks = (u64)USHRT_MAX + 1;
-	else
-		max_blocks = ns->ctrl->max_hw_sectors + 1;
-
-	blk_queue_max_write_zeroes_sectors(disk->queue,
-					   nvme_lba_to_sect(ns, max_blocks));
+	if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) &&
+	    !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES))
+		blk_queue_max_write_zeroes_sectors(q, ctrl->max_hw_sectors);
 }
 
 static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
@@ -2159,7 +2147,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
 	set_capacity_and_notify(disk, capacity);
 
 	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) ||
 		test_bit(NVME_NS_FORCE_RO, &ns->flags));
-- 
2.30.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvme: fix Write Zeroes limitations
  2021-03-15  9:34 [PATCH] nvme: fix Write Zeroes limitations Christoph Hellwig
@ 2021-03-15 11:19 ` Klaus Jensen
  2021-03-15 15:34 ` Keith Busch
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Klaus Jensen @ 2021-03-15 11:19 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: keith.busch, sagi, linux-nvme


[-- Attachment #1.1: Type: text/plain, Size: 2984 bytes --]

On Mar 15 10:34, Christoph Hellwig wrote:
> 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: 6e02318eaea5 ("nvme: add support for the Write Zeroes command")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  drivers/nvme/host/core.c | 36 ++++++++++++------------------------
>  1 file changed, 12 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 82ad5eef9d0c30..1bd18d7f53b316 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1964,30 +1964,18 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
>  		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
> + * 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
> + * limiting factors.
> + */
> +static void nvme_config_write_zeroes(struct request_queue *q,
> +		struct nvme_ctrl *ctrl)
>  {
> -	u64 max_blocks;
> -
> -	if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) ||
> -	    (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)
> -		max_blocks = (u64)USHRT_MAX + 1;
> -	else
> -		max_blocks = ns->ctrl->max_hw_sectors + 1;
> -
> -	blk_queue_max_write_zeroes_sectors(disk->queue,
> -					   nvme_lba_to_sect(ns, max_blocks));
> +	if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) &&
> +	    !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES))
> +		blk_queue_max_write_zeroes_sectors(q, ctrl->max_hw_sectors);
>  }
>  
>  static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
> @@ -2159,7 +2147,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
>  	set_capacity_and_notify(disk, capacity);
>  
>  	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) ||
>  		test_bit(NVME_NS_FORCE_RO, &ns->flags));
> -- 
> 2.30.1
> 

LGTM.

Tested-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 158 bytes --]

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvme: fix Write Zeroes limitations
  2021-03-15  9:34 [PATCH] nvme: fix Write Zeroes limitations Christoph Hellwig
  2021-03-15 11:19 ` Klaus Jensen
@ 2021-03-15 15:34 ` Keith Busch
  2021-03-16  3:42 ` Chaitanya Kulkarni
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Keith Busch @ 2021-03-15 15:34 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: keith.busch, sagi, linux-nvme

On Mon, Mar 15, 2021 at 10:34:38AM +0100, Christoph Hellwig wrote:
> 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: 6e02318eaea5 ("nvme: add support for the Write Zeroes command")
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good.

Reviewed-by: Keith Busch <kbusch@kernel.org>

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvme: fix Write Zeroes limitations
  2021-03-15  9:34 [PATCH] nvme: fix Write Zeroes limitations Christoph Hellwig
  2021-03-15 11:19 ` Klaus Jensen
  2021-03-15 15:34 ` Keith Busch
@ 2021-03-16  3:42 ` Chaitanya Kulkarni
  2021-03-16  6:26 ` Sagi Grimberg
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2021-03-16  3:42 UTC (permalink / raw)
  To: Christoph Hellwig, Keith Busch, sagi; +Cc: linux-nvme

On 3/15/21 02:45, Christoph Hellwig wrote:
> 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: 6e02318eaea5 ("nvme: add support for the Write Zeroes command")
> Signed-off-by: Christoph Hellwig <hch@lst.de>

My bad, thanks for fixing this.

Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvme: fix Write Zeroes limitations
  2021-03-15  9:34 [PATCH] nvme: fix Write Zeroes limitations Christoph Hellwig
                   ` (2 preceding siblings ...)
  2021-03-16  3:42 ` Chaitanya Kulkarni
@ 2021-03-16  6:26 ` Sagi Grimberg
  2021-03-16 14:29 ` Max Gurtovoy
  2021-03-17 21:23 ` Himanshu Madhani
  5 siblings, 0 replies; 7+ messages in thread
From: Sagi Grimberg @ 2021-03-16  6:26 UTC (permalink / raw)
  To: Christoph Hellwig, keith.busch; +Cc: linux-nvme

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvme: fix Write Zeroes limitations
  2021-03-15  9:34 [PATCH] nvme: fix Write Zeroes limitations Christoph Hellwig
                   ` (3 preceding siblings ...)
  2021-03-16  6:26 ` Sagi Grimberg
@ 2021-03-16 14:29 ` Max Gurtovoy
  2021-03-17 21:23 ` Himanshu Madhani
  5 siblings, 0 replies; 7+ messages in thread
From: Max Gurtovoy @ 2021-03-16 14:29 UTC (permalink / raw)
  To: Christoph Hellwig, keith.busch, sagi; +Cc: linux-nvme


On 3/15/2021 11:34 AM, Christoph Hellwig wrote:
> 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: 6e02318eaea5 ("nvme: add support for the Write Zeroes command")
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good,

Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com>


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvme: fix Write Zeroes limitations
  2021-03-15  9:34 [PATCH] nvme: fix Write Zeroes limitations Christoph Hellwig
                   ` (4 preceding siblings ...)
  2021-03-16 14:29 ` Max Gurtovoy
@ 2021-03-17 21:23 ` Himanshu Madhani
  5 siblings, 0 replies; 7+ messages in thread
From: Himanshu Madhani @ 2021-03-17 21:23 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: keith.busch, sagi, linux-nvme



> On Mar 15, 2021, at 4:34 AM, Christoph Hellwig <hch@lst.de> wrote:
> 
> 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: 6e02318eaea5 ("nvme: add support for the Write Zeroes command")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/nvme/host/core.c | 36 ++++++++++++------------------------
> 1 file changed, 12 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 82ad5eef9d0c30..1bd18d7f53b316 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1964,30 +1964,18 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
> 		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
> + * 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
> + * limiting factors.
> + */
> +static void nvme_config_write_zeroes(struct request_queue *q,
> +		struct nvme_ctrl *ctrl)
> {
> -	u64 max_blocks;
> -
> -	if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) ||
> -	    (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)
> -		max_blocks = (u64)USHRT_MAX + 1;
> -	else
> -		max_blocks = ns->ctrl->max_hw_sectors + 1;
> -
> -	blk_queue_max_write_zeroes_sectors(disk->queue,
> -					   nvme_lba_to_sect(ns, max_blocks));
> +	if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) &&
> +	    !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES))
> +		blk_queue_max_write_zeroes_sectors(q, ctrl->max_hw_sectors);
> }
> 
> static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
> @@ -2159,7 +2147,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
> 	set_capacity_and_notify(disk, capacity);
> 
> 	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) ||
> 		test_bit(NVME_NS_FORCE_RO, &ns->flags));
> -- 
> 2.30.1
> 
> 
> _______________________________________________
> Linux-nvme mailing list
> Linux-nvme@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-nvme

Looks Good. 

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>

--
Himanshu Madhani	 Oracle Linux Engineering


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

end of thread, other threads:[~2021-03-17 21:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15  9:34 [PATCH] nvme: fix Write Zeroes limitations Christoph Hellwig
2021-03-15 11:19 ` Klaus Jensen
2021-03-15 15:34 ` Keith Busch
2021-03-16  3:42 ` Chaitanya Kulkarni
2021-03-16  6:26 ` Sagi Grimberg
2021-03-16 14:29 ` Max Gurtovoy
2021-03-17 21:23 ` Himanshu Madhani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).