[PATCH v4] nvme: change nvme_ns_has_pi() to nvme_ns_supports_pract()

Tokunori Ikegami ikegami.t at gmail.com
Wed Oct 23 03:08:36 PDT 2024


The PI is the first bytes or last bytes of the metadata.
So its size is not equal to the metadata size only but below also.
Then fix the function to check PI size if metadata size or below.

Signed-off-by: Tokunori Ikegami <ikegami.t at gmail.com>
---
Changes since v3 to v4:
- Change the function name nvme_ns_has_pi() to nvme_ns_supports_pract().

Changes since v2 to v3:
- Delete the nvme_submit_io() changes as only change the nvme_ns_has_pi().

Changes since v1:
- Fix the commit message spelling miss hte to the.

 drivers/nvme/host/core.c | 10 +++++-----
 drivers/nvme/host/nvme.h |  4 ++--
 drivers/nvme/host/rdma.c |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 84cb859a911d..37edd0ba423d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -915,7 +915,7 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
 	    (ns->head->features & NVME_NS_DEAC))
 		cmnd->write_zeroes.control |= cpu_to_le16(NVME_WZ_DEAC);
 
-	if (nvme_ns_has_pi(ns->head)) {
+	if (nvme_ns_supports_pract(ns->head)) {
 		cmnd->write_zeroes.control |= cpu_to_le16(NVME_RW_PRINFO_PRACT);
 
 		switch (ns->head->pi_type) {
@@ -999,7 +999,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
 		 * namespace capacity to zero to prevent any I/O.
 		 */
 		if (!blk_integrity_rq(req)) {
-			if (WARN_ON_ONCE(!nvme_ns_has_pi(ns->head)))
+			if (WARN_ON_ONCE(!nvme_ns_supports_pract(ns->head)))
 				return BLK_STS_NOTSUPP;
 			control |= NVME_RW_PRINFO_PRACT;
 		}
@@ -1766,7 +1766,7 @@ static bool nvme_init_integrity(struct nvme_ns_head *head,
 	 */
 	if (!IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ||
 	    !(head->features & NVME_NS_METADATA_SUPPORTED))
-		return nvme_ns_has_pi(head);
+		return nvme_ns_supports_pract(head);
 
 	switch (head->pi_type) {
 	case NVME_NS_DPS_PI_TYPE3:
@@ -1929,14 +1929,14 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl,
 
 		/*
 		 * The current fabrics transport drivers support namespace
-		 * metadata formats only if nvme_ns_has_pi() returns true.
+		 * metadata formats only if nvme_ns_supports_pract() returns true.
 		 * Suppress support for all other formats so the namespace will
 		 * have a 0 capacity and not be usable through the block stack.
 		 *
 		 * Note, this check will need to be modified if any drivers
 		 * gain the ability to use other metadata formats.
 		 */
-		if (ctrl->max_integrity_segments && nvme_ns_has_pi(head))
+		if (ctrl->max_integrity_segments && nvme_ns_supports_pract(head))
 			head->features |= NVME_NS_METADATA_SUPPORTED;
 	} else {
 		/*
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 093cb423f536..881418444a1a 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -540,9 +540,9 @@ struct nvme_ns {
 };
 
 /* NVMe ns supports metadata actions by the controller (generate/strip) */
-static inline bool nvme_ns_has_pi(struct nvme_ns_head *head)
+static inline bool nvme_ns_supports_pract(struct nvme_ns_head *head)
 {
-	return head->pi_type && head->ms == head->pi_size;
+	return head->pi_type && head->ms >= head->pi_size;
 }
 
 struct nvme_ctrl_ops {
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 24a2759798d0..e09fee1dd15c 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -2037,7 +2037,7 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
 	    queue->pi_support &&
 	    (c->common.opcode == nvme_cmd_write ||
 	     c->common.opcode == nvme_cmd_read) &&
-	    nvme_ns_has_pi(ns->head))
+	    nvme_ns_supports_pract(ns->head))
 		req->use_sig_mr = true;
 	else
 		req->use_sig_mr = false;
-- 
2.45.2




More information about the Linux-nvme mailing list