linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] nvme: implement the DEAC bit for the Write Zeroes command
@ 2022-11-07 16:21 Christoph Hellwig
  2022-11-07 16:30 ` Keith Busch
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christoph Hellwig @ 2022-11-07 16:21 UTC (permalink / raw)
  To: kbusch, sagi; +Cc: linux-nvme

While the specification allows devices to either deallocate data
or to actually write zeroes on any Write Zeroes command, many SSDs
only do the sensible thing and deallocate data when the DEAC bit
is specific.  Set it when it is suppored and the caller doesn't
explicitly opt out of deallocation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---

Changes since v1:
 - add a sanity check that deallocate returns zeroes

 drivers/nvme/host/core.c | 13 ++++++++++++-
 drivers/nvme/host/nvme.h |  1 +
 include/linux/nvme.h     |  1 +
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f94b05c585cbc..1a87a072fbed3 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -850,8 +850,11 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
 	cmnd->write_zeroes.length =
 		cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1);
 
+	if (!(req->cmd_flags & REQ_NOUNMAP) && (ns->features & NVME_NS_DEAC))
+		cmnd->write_zeroes.control |= cpu_to_le16(NVME_WZ_DEAC);
+
 	if (nvme_ns_has_pi(ns)) {
-		cmnd->write_zeroes.control = cpu_to_le16(NVME_RW_PRINFO_PRACT);
+		cmnd->write_zeroes.control |= cpu_to_le16(NVME_RW_PRINFO_PRACT);
 
 		switch (ns->pi_type) {
 		case NVME_NS_DPS_PI_TYPE1:
@@ -2003,6 +2006,14 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 		}
 	}
 
+	/*
+	 * Only set the DEAC bit if the device guarantees that reads from
+	 * deallocated data return zeroes.  While the DEAC bit does not
+	 * require that, it must be a no-op if reads from deallocated data
+	 * do not return zeroes.
+	 */
+	if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3)))
+		ns->features |= NVME_NS_DEAC;
 	set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info));
 	set_bit(NVME_NS_READY, &ns->flags);
 	blk_mq_unfreeze_queue(ns->disk->queue);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index f9df10653f3c5..16b34a4914959 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -455,6 +455,7 @@ static inline bool nvme_ns_head_multipath(struct nvme_ns_head *head)
 enum nvme_ns_features {
 	NVME_NS_EXT_LBAS = 1 << 0, /* support extended LBA format */
 	NVME_NS_METADATA_SUPPORTED = 1 << 1, /* support getting generated md */
+	NVME_NS_DEAC,		/* DEAC bit in Write Zeores supported */
 };
 
 struct nvme_ns {
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 050d7d0cd81b0..c96930b2c28fe 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -963,6 +963,7 @@ enum {
 	NVME_RW_PRINFO_PRCHK_GUARD	= 1 << 12,
 	NVME_RW_PRINFO_PRACT		= 1 << 13,
 	NVME_RW_DTYPE_STREAMS		= 1 << 4,
+	NVME_WZ_DEAC			= 1 << 9,
 };
 
 struct nvme_dsm_cmd {
-- 
2.30.2



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

* Re: [PATCH v2] nvme: implement the DEAC bit for the Write Zeroes command
  2022-11-07 16:21 [PATCH v2] nvme: implement the DEAC bit for the Write Zeroes command Christoph Hellwig
@ 2022-11-07 16:30 ` Keith Busch
  2022-11-07 17:10 ` Martin K. Petersen
  2022-11-08  3:54 ` Chaitanya Kulkarni
  2 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2022-11-07 16:30 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sagi, linux-nvme

Looks good.

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


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

* Re: [PATCH v2] nvme: implement the DEAC bit for the Write Zeroes command
  2022-11-07 16:21 [PATCH v2] nvme: implement the DEAC bit for the Write Zeroes command Christoph Hellwig
  2022-11-07 16:30 ` Keith Busch
@ 2022-11-07 17:10 ` Martin K. Petersen
  2022-11-08  3:54 ` Chaitanya Kulkarni
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-11-07 17:10 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: kbusch, sagi, linux-nvme


Christoph,

> While the specification allows devices to either deallocate data or to
> actually write zeroes on any Write Zeroes command, many SSDs only do
> the sensible thing and deallocate data when the DEAC bit is specific.
> Set it when it is suppored and the caller doesn't explicitly opt out

supported

> of deallocation.

Looks good.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>

-- 
Martin K. Petersen	Oracle Linux Engineering


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

* Re: [PATCH v2] nvme: implement the DEAC bit for the Write Zeroes command
  2022-11-07 16:21 [PATCH v2] nvme: implement the DEAC bit for the Write Zeroes command Christoph Hellwig
  2022-11-07 16:30 ` Keith Busch
  2022-11-07 17:10 ` Martin K. Petersen
@ 2022-11-08  3:54 ` Chaitanya Kulkarni
  2 siblings, 0 replies; 4+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-08  3:54 UTC (permalink / raw)
  To: Christoph Hellwig, kbusch, sagi; +Cc: linux-nvme

On 11/7/22 08:21, Christoph Hellwig wrote:
> While the specification allows devices to either deallocate data
> or to actually write zeroes on any Write Zeroes command, many SSDs
> only do the sensible thing and deallocate data when the DEAC bit
> is specific.  Set it when it is suppored and the caller doesn't
> explicitly opt out of deallocation.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> 

with Martin's suggested commit log fix ...

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck


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

end of thread, other threads:[~2022-11-08  3:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 16:21 [PATCH v2] nvme: implement the DEAC bit for the Write Zeroes command Christoph Hellwig
2022-11-07 16:30 ` Keith Busch
2022-11-07 17:10 ` Martin K. Petersen
2022-11-08  3:54 ` Chaitanya Kulkarni

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).