Skip to contentSkip to conversation

nvme: verify MNAN value if ANA is enabled

PATCH Superseded Daniel Wagner 4 participants 4 messages May 31, 2021 – Jun 3, 2021 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: verify MNAN value if ANA is enabled

The controller is required to have a non-zero MNAN value if it supports ANA:

If the controller supports Asymmetric Namespace Access Reporting, then this field shall be set to a non-zero value that is less than or equal to the NN value.

---
This is a follow up to the discussion in

https://lore.kernel.org/linux-nvme/[email protected]/

 drivers/nvme/host/core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/nvme/host/core.c +10 -0
index cb1a76a3d42a..4c412adc9e14 100644
@@ -2972,6 +2972,16 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
 	if (ret < 0)
 		goto out_free;
 
+#ifdef CONFIG_NVME_MULTIPATH
+	if (ctrl->ana_log_buf && (!ctrl->max_namespaces ||
+				  ctrl->max_namespaces > le32_to_cpu(id->nn))) {
+		dev_err(ctrl->device,
+			"Invalid MNAN value %u\n", ctrl->max_namespaces);
+		ret = -EINVAL;
+		goto out_free;
+	}
+#endif
+
 	if (ctrl->apst_enabled && !prev_apst_enabled)
 		dev_pm_qos_expose_latency_tolerance(ctrl->device);
 	else if (!ctrl->apst_enabled && prev_apst_enabled)
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Daniel Wagner

The controller is required to have a non-zero MNAN value if it supports ANA:

If the controller supports Asymmetric Namespace Access Reporting, then this field shall be set to a non-zero value that is less than or equal to the NN value.

---
This is a follow up to the discussion in

https://lore.kernel.org/linux-nvme/[email protected]/

 drivers/nvme/host/core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/nvme/host/core.c +3 -0
index cb1a76a3d42a..4c412adc9e14 100644
@@ -2972,6 +2972,16 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
 	if (ret < 0)
 		goto out_free;
 
+#ifdef CONFIG_NVME_MULTIPATH
+	if (ctrl->ana_log_buf && (!ctrl->max_namespaces ||
+				  ctrl->max_namespaces > le32_to_cpu(id->nn))) {

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl) · line 2987

Quoted 10 lines
drivers/nvme/host/core.c +7 -0
+		dev_err(ctrl->device,
+			"Invalid MNAN value %u\n", ctrl->max_namespaces);
+		ret = -EINVAL;
+		goto out_free;
+	}
+#endif
+
 	if (ctrl->apst_enabled && !prev_apst_enabled)
 		dev_pm_qos_expose_latency_tolerance(ctrl->device);
 	else if (!ctrl->apst_enabled && prev_apst_enabled)

Cheers,

Hannes

Signature · 9 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#3 lore raw
In reply to Daniel Wagner

drivers/nvme/host/core.c static int nvme_init_identify(struct nvme_ctrl *ctrl) · line 2983

Quoted 13 lines
drivers/nvme/host/core.c +9 -0
@@ -2972,6 +2972,16 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
 	if (ret < 0)
 		goto out_free;
 
+#ifdef CONFIG_NVME_MULTIPATH
+	if (ctrl->ana_log_buf && (!ctrl->max_namespaces ||
+				  ctrl->max_namespaces > le32_to_cpu(id->nn))) {
+		dev_err(ctrl->device,
+			"Invalid MNAN value %u\n", ctrl->max_namespaces);
+		ret = -EINVAL;
+		goto out_free;
+	}
+#endif

Please move the check into nvme_mpath_init_identify, where we can avoid the ifdef and the ana_log_buf check, which won't trigger for the first initialization.