Skip to contentSkip to conversation

nvme-core: check id->mc before setting NVME_NS_METADATA_SUPPORTED

PATCH In review Irvin Cote 4 participants 6 messages Jun 24, 2023 – Jul 10, 2023 NVMe

lore
Share & tools
lore

Irvin Cote

author
#0 lore raw

PATCH 1/1 nvme-core: check id->mc before setting NVME_NS_METADATA_SUPPORTED

The NVM Command set Identify Namespace Data Structure defines the metadata capabilities field (mc) that determines support for metadata. Check for the value of this field before enabling the NVME_NS_METADATA_SUPPORTED in the nvme_ns data structure.

---
 drivers/nvme/host/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +3 -2
index 3ec38e2b9173..465206b5cf6f 100644
@@ -1841,7 +1841,8 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
 		 * 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(ns))
+		if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)
+				&& (id->mc & NVME_MC_EXTENDED_LBA))
 			ns->features |= NVME_NS_METADATA_SUPPORTED;
 	} else {
 		/*
@@ -1852,7 +1853,7 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
 		 */
 		if (id->flbas & NVME_NS_FLBAS_META_EXT)
 			ns->features |= NVME_NS_EXT_LBAS;
-		else
+		else if (id->mc & NVME_MC_METADATA_PTR)
 			ns->features |= NVME_NS_METADATA_SUPPORTED;
 	}
 }
Signature · 1 line
2.40.1
maintainer
#1 lore raw
Quoted 4 lines · Irvin Cote

The NVM Command set Identify Namespace Data Structure defines the metadata capabilities field (mc) that determines support for metadata. Check for the value of this field before enabling the NVME_NS_METADATA_SUPPORTED in the nvme_ns data structure.

The MC field is primarily for use when sending a format command to know what are valid possibilities. If the reported MS and FLBAS are out of sync with metadata capabilities, then the controller is broken.

#2 lore raw
In reply to Irvin Cote
Quoted 15 lines · Irvin Cote

The NVM Command set Identify Namespace Data Structure defines the metadata capabilities field (mc) that determines support for metadata. Check for the value of this field before enabling the NVME_NS_METADATA_SUPPORTED in the nvme_ns data structure.

---
  drivers/nvme/host/core.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +0 -0
index 3ec38e2b9173..465206b5cf6f 100644

drivers/nvme/host/core.c static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 1846

Quoted 7 lines
drivers/nvme/host/core.c +2 -1
@@ -1841,7 +1841,8 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
  		 * 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(ns))
+		if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)
+				&& (id->mc & NVME_MC_EXTENDED_LBA))
  			ns->features |= NVME_NS_METADATA_SUPPORTED;

this probably should go into the WARN_ON_ONCE above since it violate the spec.

drivers/nvme/host/core.c static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 1855

Quoted 6 lines
drivers/nvme/host/core.c +0 -0
  	} else {
  		/*
@@ -1852,7 +1853,7 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
  		 */
  		if (id->flbas & NVME_NS_FLBAS_META_EXT)
  			ns->features |= NVME_NS_EXT_LBAS;

we can check the NVME_MC_EXTENDED_LBA here and WARN_ON_ONCE if there is a spec violation.

drivers/nvme/host/core.c static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 1857

Quoted 3 lines
drivers/nvme/host/core.c +1 -1
-		else
+		else if (id->mc & NVME_MC_METADATA_PTR)
  			ns->features |= NVME_NS_METADATA_SUPPORTED;

same here.

Quoted 2 lines
drivers/nvme/host/core.c +0 -0
  	}
  }
author
#3 lore raw
Quoted 3 lines

The MC field is primarily for use when sending a format command to know what are valid possibilities. If the reported MS and FLBAS are out of sync with metadata capabilities, then the controller is broken.

Beware having MC and FLBAS out of sync does not necessarily mean we have a broken controller :
MC could be 0 (no metadata support at all) and FLBAS has no way to express that, it can only indicate which metadata type was selected by the user.
In such a case we could wrongfully signal metadata as supported when it is not

Quoted 48 lines · Max Gurtovoy
Quoted 15 lines · Irvin Cote

The NVM Command set Identify Namespace Data Structure defines the metadata capabilities field (mc) that determines support for metadata. Check for the value of this field before enabling the NVME_NS_METADATA_SUPPORTED in the nvme_ns data structure.

---
  drivers/nvme/host/core.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +0 -0
index 3ec38e2b9173..465206b5cf6f 100644

drivers/nvme/host/core.c static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 1846

Quoted 7 lines
drivers/nvme/host/core.c +2 -1
@@ -1841,7 +1841,8 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
               * 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(ns))
+             if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)
+                             && (id->mc & NVME_MC_EXTENDED_LBA))
                      ns->features |= NVME_NS_METADATA_SUPPORTED;

this probably should go into the WARN_ON_ONCE above since it violate the spec.

drivers/nvme/host/core.c static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 1855

Quoted 6 lines
drivers/nvme/host/core.c +0 -0
      } else {
              /*
@@ -1852,7 +1853,7 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
               */
              if (id->flbas & NVME_NS_FLBAS_META_EXT)
                      ns->features |= NVME_NS_EXT_LBAS;

we can check the NVME_MC_EXTENDED_LBA here and WARN_ON_ONCE if there is a spec violation.

drivers/nvme/host/core.c static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 1857

Quoted 3 lines
drivers/nvme/host/core.c +1 -1
-             else
+             else if (id->mc & NVME_MC_METADATA_PTR)
                      ns->features |= NVME_NS_METADATA_SUPPORTED;

same here.

Quoted 2 lines
drivers/nvme/host/core.c +0 -0
      }
  }
author
#4 lore raw

Apologies I understand now, no need to check MC if both FLBAS and MS are checked,
Thanks

Quoted 61 lines · irvin cote
Quoted 4 lines

The MC field is primarily for use when sending a format command to know what are valid possibilities. If the reported MS and FLBAS are out of sync with metadata capabilities, then the controller is broken.

Beware having MC and FLBAS out of sync does not necessarily mean we have a broken controller :
MC could be 0 (no metadata support at all) and FLBAS has no way to express that, it can only indicate which metadata type was selected by the user.
In such a case we could wrongfully signal metadata as supported when it is not

Quoted 48 lines · Max Gurtovoy
Quoted 15 lines · Irvin Cote

The NVM Command set Identify Namespace Data Structure defines the metadata capabilities field (mc) that determines support for metadata. Check for the value of this field before enabling the NVME_NS_METADATA_SUPPORTED in the nvme_ns data structure.

---
  drivers/nvme/host/core.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +0 -0
index 3ec38e2b9173..465206b5cf6f 100644

drivers/nvme/host/core.c static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 1846

Quoted 7 lines
drivers/nvme/host/core.c +2 -1
@@ -1841,7 +1841,8 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
               * 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(ns))
+             if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)
+                             && (id->mc & NVME_MC_EXTENDED_LBA))
                      ns->features |= NVME_NS_METADATA_SUPPORTED;

this probably should go into the WARN_ON_ONCE above since it violate the spec.

drivers/nvme/host/core.c static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 1855

Quoted 6 lines
drivers/nvme/host/core.c +0 -0
      } else {
              /*
@@ -1852,7 +1853,7 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
               */
              if (id->flbas & NVME_NS_FLBAS_META_EXT)
                      ns->features |= NVME_NS_EXT_LBAS;

we can check the NVME_MC_EXTENDED_LBA here and WARN_ON_ONCE if there is a spec violation.

drivers/nvme/host/core.c static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) · line 1857

Quoted 3 lines
drivers/nvme/host/core.c +1 -1
-             else
+             else if (id->mc & NVME_MC_METADATA_PTR)
                      ns->features |= NVME_NS_METADATA_SUPPORTED;

same here.

Quoted 2 lines
drivers/nvme/host/core.c +0 -0
      }
  }
#5 lore raw
In reply to irvin cote
Quoted 10 lines · irvin cote
Quoted 3 lines

The MC field is primarily for use when sending a format command to know what are valid possibilities. If the reported MS and FLBAS are out of sync with metadata capabilities, then the controller is broken.

Beware having MC and FLBAS out of sync does not necessarily mean we have a broken controller :
MC could be 0 (no metadata support at all) and FLBAS has no way to express that, it can only indicate which metadata type was selected by the user.
In such a case we could wrongfully signal metadata as supported when it is not

The LBA Format Data Structure indicates the metadata size for any given format.