Skip to contentSkip to conversation

nvme: Fix nvme reset command timeout handling

PATCH New Keith Busch 4 participants 10 messages Jul 27, 2017 – Aug 10, 2017 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 nvme: Fix nvme reset command timeout handling

We need to return an error if a timeout occurs on any NVMe command during initialization. Without this, the nvme reset work will be stuck. A timeout will have a negative error code, meaning we need to stop initializing the controller. All postitive returns mean the controller is still usable.

bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=196325

Signed-off-by Keith Busch <keith.busch at intel.com>
Cc Martin Peres <martin.peres at intel.com>
---
 drivers/nvme/host/core.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/nvme/host/core.c +16 -7
index 0c27f1a..b150702 100644
@@ -1514,7 +1514,7 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
 	blk_queue_write_cache(q, vwc, vwc);
 }
 
-static void nvme_configure_apst(struct nvme_ctrl *ctrl)
+static int nvme_configure_apst(struct nvme_ctrl *ctrl)
 {
 	/*
 	 * APST (Autonomous Power State Transition) lets us program a
@@ -1543,16 +1543,16 @@ static void nvme_configure_apst(struct nvme_ctrl *ctrl)
 	 * then don't do anything.
 	 */
 	if (!ctrl->apsta)
-		return;
+		return 0;
 
 	if (ctrl->npss > 31) {
 		dev_warn(ctrl->device, "NPSS is invalid; not using APST\n");
-		return;
+		return 0;
 	}
 
 	table = kzalloc(sizeof(*table), GFP_KERNEL);
 	if (!table)
-		return;
+		return 0;
 
 	if (!ctrl->apst_enabled || ctrl->ps_max_latency_us == 0) {
 		/* Turn off APST. */
@@ -1634,6 +1634,7 @@ static void nvme_configure_apst(struct nvme_ctrl *ctrl)
 		dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret);
 
 	kfree(table);
+	return ret;
 }
 
 static void nvme_set_latency_tolerance(struct device *dev, s32 val)
@@ -1856,17 +1857,25 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 
 	kfree(id);
 
+	if (ret < 0)
+		return ret;
+
 	if (ctrl->apst_enabled && !prev_apst_enabled)
 		dev_pm_qos_expose_latency_tolerance(ctrl->device);
 	else if (!ctrl->apst_enabled && prev_apst_enabled)
 		dev_pm_qos_hide_latency_tolerance(ctrl->device);
 
-	nvme_configure_apst(ctrl);
-	nvme_configure_directives(ctrl);
+	ret = nvme_configure_apst(ctrl);
+	if (ret < 0)
+		return ret;
+
+	ret = nvme_configure_directives(ctrl);
+	if (ret < 0)
+		return ret;
 
 	ctrl->identified = true;
 
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(nvme_init_identify);
 
Signature · 1 line
2.5.5
#1 lore raw

PATCH 2/2 nvme: Provide option to disable ASPT feature

Similar to PCIe's APSM, the NVMe driver needs the ability to not use APST feature so that users have a way to prevent this feature from making their machines unusable. This patch makes that possible via module parameter "apst_off".

Signed-off-by Keith Busch <keith.busch at intel.com>
Cc Andy Lutomirski <luto at amacapital.net>
---
 drivers/nvme/host/core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +5 -1
index b150702..834913b 100644
@@ -64,6 +64,10 @@ static bool force_apst;
 module_param(force_apst, bool, 0644);
 MODULE_PARM_DESC(force_apst, "allow APST for newly enumerated devices even if quirked off");
 
+static bool apst_off;
+module_param(apst_off, bool, 0644);
+MODULE_PARM_DESC(apst_off, "Disable APST driver support");
+
 static bool streams;
 module_param(streams, bool, 0644);
 MODULE_PARM_DESC(streams, "turn on support for Streams write directives");
@@ -1542,7 +1546,7 @@ static int nvme_configure_apst(struct nvme_ctrl *ctrl)
 	 * If APST isn't supported or if we haven't been initialized yet,
 	 * then don't do anything.
 	 */
-	if (!ctrl->apsta)
+	if (!ctrl->apsta || apst_off)
 		return 0;
 
 	if (ctrl->npss > 31) {
Signature · 1 line
2.5.5
#2 lore raw

PATCH 2/2 nvme: Provide option to disable ASPT feature

Quoted 8 lines · Keith Busch

Similar to PCIe's APSM, the NVMe driver needs the ability to not use APST feature so that users have a way to prevent this feature from making their machines unusable. This patch makes that possible via module parameter "apst_off".

Isn't this redundant with default_ps_max_latency=0?

Quoted 34 lines
Signed-off-by Keith Busch <keith.busch at intel.com>
Cc Andy Lutomirski <luto at amacapital.net>

---
drivers/nvme/host/core.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +5 -1
index b150702..834913b 100644
@@ -64,6 +64,10 @@ static bool force_apst;
 module_param(force_apst, bool, 0644);
 MODULE_PARM_DESC(force_apst, "allow APST for newly enumerated devices even if quirked off");
 
+static bool apst_off;
+module_param(apst_off, bool, 0644);
+MODULE_PARM_DESC(apst_off, "Disable APST driver support");
+
 static bool streams;
 module_param(streams, bool, 0644);
 MODULE_PARM_DESC(streams, "turn on support for Streams write directives");
@@ -1542,7 +1546,7 @@ static int nvme_configure_apst(struct nvme_ctrl *ctrl)
    * If APST isn't supported or if we haven't been initialized yet,
    * then don't do anything.
    */
-    if (!ctrl->apsta)
+    if (!ctrl->apsta || apst_off)
       return 0;
 
   if (ctrl->npss > 31) {
Signature · 1 line
2.5.5
#3 lore raw

PATCH 2/2 nvme: Provide option to disable ASPT feature

Quoted 10 lines · Andy Lutomirski
Quoted 8 lines · Keith Busch

Similar to PCIe's APSM, the NVMe driver needs the ability to not use APST feature so that users have a way to prevent this feature from making their machines unusable. This patch makes that possible via module parameter "apst_off".

Isn't this redundant with default_ps_max_latency=0?

Ah, thanks, so it is. I thought this wasn't considered through nvme_init_identify, but ctrl->ps_max_latency_us would be 0.

This patch isn't needed, but we still need patch 1 in this series.

#4 lore raw

PATCH 1/2 nvme: Fix nvme reset command timeout handling

In reply to Keith Busch

Review int nvme_init_identify(struct nvme_ctrl *ctrl) · line 1862

Quoted 8 lines · Keith Busch

static void nvme_set_latency_tolerance(struct device *dev, s32 val)

(quoted diff) +3 -0
@@ -1856,17 +1857,25 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 
 	kfree(id);
 
+	if (ret < 0)
+		return ret;
+

This is a bit confusing IMHO, how about this?

drivers/nvme/host/core.c +8 -1
index 3b77cfe5aa1e..71a97db3ce91 100644
@@ -1835,13 +1835,16 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 		 * In fabrics we need to verify the cntlid matches the
 		 * admin connect
 		 */
-		if (ctrl->cntlid != le16_to_cpu(id->cntlid))
+		if (ctrl->cntlid != le16_to_cpu(id->cntlid)) {
 			ret = -EINVAL;
+			goto free_id;
+		}
 
 		if (!ctrl->opts->discovery_nqn && !ctrl->kas) {
 			dev_err(ctrl->device,
 				"keep-alive support is mandatory for fabrics\n");
 			ret = -EINVAL;
+			goto free_id;
 		}
 	} else {
 		ctrl->cntlid = le16_to_cpu(id->cntlid);
@@ -1862,6 +1865,10 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 	ctrl->identified = true;
 
 	return ret;
+
+free_id:
+	kfree(id);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(nvme_init_identify);
 

Or ditch the goto and do a kfree(id); return ret; directly in the if blocks?

Byte,
Johannes

Signature · 6 lines
Johannes Thumshirn                                          Storage
jthumshirn at suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#5 lore raw

PATCH 1/2 nvme: Fix nvme reset command timeout handling

Quoted 11 lines · Johannes Thumshirn

Review int nvme_init_identify(struct nvme_ctrl *ctrl) · line 1862

Quoted 8 lines · Keith Busch

static void nvme_set_latency_tolerance(struct device *dev, s32 val)

(quoted diff) +3 -0
@@ -1856,17 +1857,25 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 
 	kfree(id);
 
+	if (ret < 0)
+		return ret;
+

This is a bit confusing IMHO, how about this?

Agreed.

We probably should get this series into 4.13, so other comments would be welcome.

#6 lore raw

PATCH 1/2 nvme: Fix nvme reset command timeout handling

Quoted 4 lines · Christoph Hellwig

Agreed.

We probably should get this series into 4.13, so other comments would be welcome.

So with my proposed change I'm fine with it, so
Reviewed-by: Johannes Thumshirn <jthumshirn at suse.de> IFF the change is made.

Patch 2 is unneeded as Luto stated.

Thanks,
Johannes

Signature · 6 lines
Johannes Thumshirn                                          Storage
jthumshirn at suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#7 lore raw

PATCH 1/2 nvme: Fix nvme reset command timeout handling

Quoted 9 lines · Johannes Thumshirn
Quoted 4 lines · Christoph Hellwig

Agreed.

We probably should get this series into 4.13, so other comments would be welcome.

So with my proposed change I'm fine with it, so
Reviewed-by: Johannes Thumshirn <jthumshirn at suse.de> IFF the change is made.

Given that you're awake now: can you resend a full patch with your proposed changes included so that it can be tested when the Americans get up? :)

#8 lore raw

PATCH 1/2 nvme: Fix nvme reset command timeout handling

Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Johannes Thumshirn
Quoted 4 lines · Christoph Hellwig

Agreed.

We probably should get this series into 4.13, so other comments would be welcome.

Quoted 7 lines
Quoted 3 lines

So with my proposed change I'm fine with it, so
Reviewed-by: Johannes Thumshirn <jthumshirn at suse.de> IFF the change is made.

Given that you're awake now: can you resend a full patch with your proposed changes included so that it can be tested when the Americans get up? :)

It was originally Keith's patch, but sure, if you want me to.

Signature · 6 lines
Johannes Thumshirn                                          Storage
jthumshirn at suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#9 lore raw

PATCH 1/2 nvme: Fix nvme reset command timeout handling

In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Johannes Thumshirn
Quoted 4 lines · Christoph Hellwig

Agreed.

We probably should get this series into 4.13, so other comments would be welcome.

Quoted 7 lines
Quoted 3 lines

So with my proposed change I'm fine with it, so
Reviewed-by: Johannes Thumshirn <jthumshirn at suse.de> IFF the change is made.

Given that you're awake now: can you resend a full patch with your proposed changes included so that it can be tested when the Americans get up? :)

I'm back in America now! A typhoon caused some trouble for Pacific air travel, and I lost 1.5 days as a result. Back to normalcy, and thank you for resending the fixed up patch. :)