Skip to contentSkip to conversation

nvme-core: checking nlbaf when retrieving lbaf index

PATCH In review Irvin Cote 2 participants 2 messages Jun 21, 2023 – Jun 27, 2023 NVMe

lore
Share & tools
lore

Irvin Cote

author
#0 lore raw

PATCH 1/1 nvme-core: checking nlbaf when retrieving lbaf index

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

---
 drivers/nvme/host/core.c |  4 ++--
 include/linux/nvme.h     | 11 ++++++++---
 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/nvme/host/core.c +2 -2
index 3ec38e2b9173..cbabed94b4c7 100644
@@ -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);
 
include/linux/nvme.h +8 -3
index 779507ac750b..edfb6140a063 100644
@@ -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): */
Signature · 1 line
2.40.1
maintainer
#1 lore raw
Quoted 3 lines · Irvin Cote

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

They're reserved bits in 1.0 and:

"A reserved bit, byte, word, field, property, or register shall be
cleared to 0h"

So we don't need to validate prior to using these bits unless a controller is breaking spec.