[PATCH] nvme-core: checking nlbaf when retrieving lbaf index

Irvin Cote irvincoteg at gmail.com
Wed Jun 21 02:22:58 PDT 2023


As per NVM-Express-NVM-Command-Set-Specification-1.0c
ignore the two most significant bits of flbas if nlbaf
is inferior or equal to 16

Signed-off-by: Irvin Cote <irvincoteg at gmail.com>
---
 drivers/nvme/host/core.c |  4 ++--
 include/linux/nvme.h     | 11 ++++++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 3ec38e2b9173..cbabed94b4c7 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1753,7 +1753,7 @@ static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b)
 static int nvme_init_ms(struct nvme_ns *ns, struct nvme_id_ns *id)
 {
 	bool first = id->dps & NVME_NS_DPS_PI_FIRST;
-	unsigned lbaf = nvme_lbaf_index(id->flbas);
+	unsigned lbaf = nvme_lbaf_index(id);
 	struct nvme_ctrl *ctrl = ns->ctrl;
 	struct nvme_command c = { };
 	struct nvme_id_ns_nvm *nvm;
@@ -2024,7 +2024,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
 		return ret;
 
 	blk_mq_freeze_queue(ns->disk->queue);
-	lbaf = nvme_lbaf_index(id->flbas);
+	lbaf = nvme_lbaf_index(id);
 	ns->lba_shift = id->lbaf[lbaf].ds;
 	nvme_set_queue_limits(ns->ctrl, ns->queue);
 
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 779507ac750b..edfb6140a063 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -569,10 +569,15 @@ enum {
 	NVME_NVM_NS_64B_GUARD	= 2,
 };
 
-static inline __u8 nvme_lbaf_index(__u8 flbas)
+static inline __u8 nvme_lbaf_index(struct nvme_id_ns *id)
 {
-	return (flbas & NVME_NS_FLBAS_LBA_MASK) |
-		((flbas & NVME_NS_FLBAS_LBA_UMASK) >> NVME_NS_FLBAS_LBA_SHIFT);
+	__u8 lbaf_index = id->flbas & NVME_NS_FLBAS_LBA_MASK;
+
+	if (id->nlbaf > 16)
+		lbaf_index |= ((id->flbas & NVME_NS_FLBAS_LBA_UMASK) >> NVME_NS_FLBAS_LBA_SHIFT);
+
+	return lbaf_index;
+
 }
 
 /* Identify Namespace Metadata Capabilities (MC): */
-- 
2.40.1




More information about the Linux-nvme mailing list