All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 0/1] nvme: Add verbose error logging
@ 2021-12-23 21:57 Alan Adamson
  2021-12-23 21:57 ` [PATCH V2 1/1] " Alan Adamson
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Adamson @ 2021-12-23 21:57 UTC (permalink / raw)
  To: linux-nvme; +Cc: alan.adamson, kbusch, hch, sagi

V2:
- Change nvme_errors[] to a sparse array where the status is used as an index into the array.

- Change pr_err() to pr_err_ratelimited().

- By enabling CONFIG_NVME_VERBOSE_ERRORS, the verbose status error is displayed.  If it is not
enabled, then a message will still be displayed, but without the verbose status.

- Remove call to nvme_error_status() when determining whether to call nvme_error_log().  Speeds
up the fast path just a bit.


This patch improves logging for NVMe errors.  Currently, we only get a
a vague idea as to why commands fail since only the block layer status
is captured on error. This patch allows us to see why a command was failed
by the controller. This is very useful when debugging problems in the field.

An example of an improved logged error:

[ 4652.812867] nvme0n1: Read @ LBA 1536, 1 blocks, Unrecovered Read Error (sct 0x2 / sc 0x81) DNR 

Alan Adamson (1):
  nvme: Add verbose error logging

 drivers/nvme/host/Kconfig  |   8 ++
 drivers/nvme/host/Makefile |   2 +-
 drivers/nvme/host/core.c   |   3 +
 drivers/nvme/host/errors.c | 202 +++++++++++++++++++++++++++++++++++++
 drivers/nvme/host/nvme.h   |   2 +
 include/linux/nvme.h       |   1 +
 6 files changed, 217 insertions(+), 1 deletion(-)
 create mode 100644 drivers/nvme/host/errors.c

-- 
2.27.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 1/1] nvme: Add verbose error logging
  2021-12-23 21:57 [PATCH V2 0/1] nvme: Add verbose error logging Alan Adamson
@ 2021-12-23 21:57 ` Alan Adamson
  2021-12-27 16:07   ` Keith Busch
  2022-01-17 13:52   ` Hannes Reinecke
  0 siblings, 2 replies; 6+ messages in thread
From: Alan Adamson @ 2021-12-23 21:57 UTC (permalink / raw)
  To: linux-nvme; +Cc: alan.adamson, kbusch, hch, sagi

Improves logging of NVMe errors.  If NVME_VERBOSE_ERRORS is configured,
a verbose description of the error is logged, otherwise only status codes/bits
is logged.

Verbose logging example:
nvme0n1: Read @ LBA 2304, 1 blocks, Unrecovered Read Error (sct 0x2 / sc 0x81) DNR

Non-verbose logging example:
nvme0n1: Read @ LBA 2304, 1 blocks, NVME Error (sct 0x2 / sc 0x81) DNR

Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Alan Adamson <alan.adamson@oracle.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
---
 drivers/nvme/host/Kconfig  |   8 ++
 drivers/nvme/host/Makefile |   2 +-
 drivers/nvme/host/core.c   |   3 +
 drivers/nvme/host/errors.c | 202 +++++++++++++++++++++++++++++++++++++
 drivers/nvme/host/nvme.h   |   2 +
 include/linux/nvme.h       |   1 +
 6 files changed, 217 insertions(+), 1 deletion(-)
 create mode 100644 drivers/nvme/host/errors.c

diff --git a/drivers/nvme/host/Kconfig b/drivers/nvme/host/Kconfig
index dc0450ca23a3..d6d056963c06 100644
--- a/drivers/nvme/host/Kconfig
+++ b/drivers/nvme/host/Kconfig
@@ -24,6 +24,14 @@ config NVME_MULTIPATH
 	   /dev/nvmeXnY device will show up for each NVMe namespace,
 	   even if it is accessible through multiple controllers.
 
+config NVME_VERBOSE_ERRORS
+	bool "NVMe verbose error reporting"
+	depends on NVME_CORE
+	help
+	   This option enables verbose reporting for NVMe errors. The
+	   error translation table will grow the kernel image size by
+	   about 4 KB.
+
 config NVME_HWMON
 	bool "NVMe hardware monitoring"
 	depends on (NVME_CORE=y && HWMON=y) || (NVME_CORE=m && HWMON)
diff --git a/drivers/nvme/host/Makefile b/drivers/nvme/host/Makefile
index dfaacd472e5d..ea3d702feb51 100644
--- a/drivers/nvme/host/Makefile
+++ b/drivers/nvme/host/Makefile
@@ -9,7 +9,7 @@ obj-$(CONFIG_NVME_RDMA)			+= nvme-rdma.o
 obj-$(CONFIG_NVME_FC)			+= nvme-fc.o
 obj-$(CONFIG_NVME_TCP)			+= nvme-tcp.o
 
-nvme-core-y				:= core.o ioctl.o
+nvme-core-y				:= core.o ioctl.o errors.o
 nvme-core-$(CONFIG_TRACING)		+= trace.o
 nvme-core-$(CONFIG_NVME_MULTIPATH)	+= multipath.o
 nvme-core-$(CONFIG_BLK_DEV_ZONED)	+= zns.o
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 1af8a4513708..fda029a55436 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -354,6 +354,9 @@ void nvme_complete_rq(struct request *req)
 
 	switch (nvme_decide_disposition(req)) {
 	case COMPLETE:
+		if (unlikely(nvme_req(req)->status != NVME_SC_SUCCESS))
+			nvme_error_log(req);
+
 		nvme_end_req(req);
 		return;
 	case RETRY:
diff --git a/drivers/nvme/host/errors.c b/drivers/nvme/host/errors.c
new file mode 100644
index 000000000000..3183b2e728d4
--- /dev/null
+++ b/drivers/nvme/host/errors.c
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * NVM Express device driver verbose errors
+ * Copyright (c) 2021, Oracle and/or its affiliates
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include <linux/blkdev.h>
+#include "nvme.h"
+
+struct nvme_string_table {
+	unsigned int code;
+	const unsigned char *string;
+};
+
+static const struct nvme_string_table nvme_ops[] = {
+	{ REQ_OP_READ,			"Read" },
+	{ REQ_OP_WRITE,			"Write" },
+	{ REQ_OP_FLUSH,			"Flush" },
+	{ REQ_OP_DISCARD,		"Deallocate (DSM)" },
+	{ REQ_OP_WRITE_ZEROES,		"Write Zeroes" },
+	{ REQ_OP_ZONE_RESET_ALL,	"Zone Reset All" },
+	{ REQ_OP_ZONE_RESET,		"Zone Reset" },
+	{ REQ_OP_ZONE_OPEN,		"Zone Open" },
+	{ REQ_OP_ZONE_CLOSE,		"Zone Close" },
+	{ REQ_OP_ZONE_FINISH,		"Zone Finish" },
+	{ REQ_OP_ZONE_APPEND,		"Zone Append" },
+};
+#define NVME_OPS_SIZE ARRAY_SIZE(nvme_ops)
+
+#ifdef CONFIG_NVME_VERBOSE_ERRORS
+#define TEN_NULLS	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+
+static const char * const nvme_errors[] = {
+	"Success",
+	"Invalid Command Opcode",
+	"Invalid Field in Command",
+	"Command ID Conflict",
+	"Data Transfer Error",
+	"Commands Aborted due to Power Loss Notification",
+	"Internal Error",
+	"Command Abort Requested",
+	"Command Aborted due to SQ Deletion",
+	"Command Aborted due to Failed Fused Command",
+	"Command Aborted due to Missing Fused Command",
+	"Invalid Namespace or Format",
+	"Command Sequence Error",
+	"Invalid SGL Segment Descriptor",
+	"Invalid Number of SGL Descriptors",
+	"Data SGL Length Invalid",
+	"Metadata SGL Length Invalid",
+	"SGL Descriptor Type Invalid",
+	"Invalid Use of Controller Memory Buffer",
+	"PRP Offset Invalid",
+	"Atomic Write Unit Exceeded",
+	"Operation Denied",
+	"SGL Offset Invalid",
+	"Reserved",
+	"Host Identifier Inconsistent Format",
+	"Keep Alive Timeout Expired",
+	"Keep Alive Timeout Invalid",
+	"Command Aborted due to Preempt and Abort",
+	"Sanitize Failed",
+	"Sanitize In Progress",
+	"SGL Data Block Granularity Invalid",
+	"Command Not Supported for Queue in CMB",
+	"Namespace is Write Protected",
+	"Command Interrupted",
+	"Transient Transport Error",
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	"Invalid IO Command Set",
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS, TEN_NULLS, TEN_NULLS,
+	NULL, NULL, NULL,
+	"LBA Out of Range",
+	"Capacity Exceeded",
+	"Namespace Not Ready",
+	"Reservation Conflict",
+	"Format In Progress",
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS, TEN_NULLS, TEN_NULLS,
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, NULL, NULL, NULL,
+	"Completion Queue Invalid",
+	"Invalid Queue Identifier",
+	"Invalid Queue Size",
+	"Abort Command Limit Exceeded",
+	"Reserved",
+	"Asynchronous Event Request Limit Exceeded",
+	"Invalid Firmware Slot",
+	"Invalid Firmware Image",
+	"Invalid Interrupt Vector",
+	"Invalid Log Page",
+	"Invalid Format",
+	"Firmware Activation Requires Conventional Reset",
+	"Invalid Queue Deletion",
+	"Feature Identifier Not Saveable",
+	"Feature Not Changeable",
+	"Feature Not Namespace Specific",
+	"Firmware Activation Requires NVM Subsystem Reset",
+	"Firmware Activation Requires Reset",
+	"Firmware Activation Requires Maximum Time Violation",
+	"Firmware Activation Prohibited",
+	"Overlapping Range",
+	"Namespace Insufficient Capacity",
+	"Namespace Identifier Unavailable",
+	NULL,
+	"Namespace Already Attached",
+	"Namespace Is Private",
+	"Namespace Not Attached",
+	"Thin Provisioning Not Supported",
+	"Controller List Invalid",
+	"Device Self-test In Progress",
+	"Boot Partition Write Prohibited",
+	"Invalid Controller Identifier",
+	"Invalid Secondary Controller State",
+	"Invalid Number of Controller Resources",
+	"Invalid Resource Identifier",
+	"Sanitize Prohibited",
+	"ANA Group Identifier Invalid",
+	"ANA Attach Failed",
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
+	TEN_NULLS, TEN_NULLS, TEN_NULLS,
+	"Conflicting Attributes",
+	"Invalid Protection Information",
+	"Attempted Write to Read Only Range",
+	"ONCS Not Supported",
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, NULL, NULL,
+	"Zoned Boundary Error",
+	"Zone Is Full",
+	"Zone Is Read Only",
+	"Zone Is Offline",
+	"Zone Invalid Write",
+	"Too Many Active Zones",
+	"Too Many Open Zones",
+	"Invalid Zone State Transition",
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
+	TEN_NULLS, NULL, NULL,
+	"Write Fault",
+	"Unrecovered Read Error",
+	"End-to-end Guard Check Error",
+	"End-to-end Application Tag Check Error",
+	"End-to-end Reference Tag Check Error",
+	"Compare Failure",
+	"Access Denied",
+	"Deallocated or Unwritten Logical Block",
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
+	NULL,
+	"Asymmetric Access Persistent Loss",
+	"Asymmetric Access Inaccessible",
+	"Asymmetric Access Transition",
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
+	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	"Host Pathing Error",
+};
+#define NVME_ERRORS_SIZE ARRAY_SIZE(nvme_errors)
+#endif /* CONFIG_NVME_VERBOSE_ERRORS */
+
+void nvme_error_log(struct request *req)
+{
+	struct nvme_ns *ns = req->q->queuedata;
+	struct nvme_request *nr = nvme_req(req);
+	const struct nvme_string_table *entry;
+	const unsigned char *op_str  = "Unknown";
+	const unsigned char *err_str = NULL;
+	unsigned int i;
+
+	if (!ns)
+		return;
+
+	for (i = 0, entry = nvme_ops ; i < NVME_OPS_SIZE ; i++)
+		if (entry[i].code == (req->cmd_flags & REQ_OP_MASK))
+			op_str = entry[i].string;
+
+#ifdef CONFIG_NVME_VERBOSE_ERRORS
+	if ((nr->status & 0x7ff) <= NVME_ERRORS_SIZE)
+		err_str = nvme_errors[nr->status & 0x7ff];
+#endif
+	if (err_str == NULL)
+		err_str =  "NVME Error";
+
+	pr_err_ratelimited("%s: %s @ LBA %llu, %llu blocks, %s (sct 0x%x / sc 0x%x) %s%s\n",
+	       req->rq_disk ? req->rq_disk->disk_name : "?",
+	       op_str,
+	       (unsigned long long)nvme_sect_to_lba(ns, blk_rq_pos(req)),
+	       (unsigned long long)blk_rq_bytes(req) >> ns->lba_shift,
+	       err_str,
+	       nr->status >> 8 & 7, /* Status Code Type */
+	       nr->status & 0xff,    /* Status Code */
+	       nr->status & NVME_SC_MORE ? "MORE " : "",
+	       nr->status & NVME_SC_DNR  ? "DNR "  : "");
+}
+EXPORT_SYMBOL_GPL(nvme_error_log);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 9b095ee01364..7edd67b92a6b 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -922,4 +922,6 @@ static inline bool nvme_multi_css(struct nvme_ctrl *ctrl)
 	return (ctrl->ctrl_config & NVME_CC_CSS_MASK) == NVME_CC_CSS_CSI;
 }
 
+extern void nvme_error_log(struct request *req);
+
 #endif /* _NVME_H */
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 855dd9b3e84b..1f946e5bf7c1 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -1636,6 +1636,7 @@ enum {
 	NVME_SC_HOST_ABORTED_CMD	= 0x371,
 
 	NVME_SC_CRD			= 0x1800,
+	NVME_SC_MORE			= 0x2000,
 	NVME_SC_DNR			= 0x4000,
 };
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 1/1] nvme: Add verbose error logging
  2021-12-23 21:57 ` [PATCH V2 1/1] " Alan Adamson
@ 2021-12-27 16:07   ` Keith Busch
  2022-01-04 18:18     ` Alan Adamson
  2022-01-17 13:52   ` Hannes Reinecke
  1 sibling, 1 reply; 6+ messages in thread
From: Keith Busch @ 2021-12-27 16:07 UTC (permalink / raw)
  To: Alan Adamson; +Cc: linux-nvme, hch, sagi

On Thu, Dec 23, 2021 at 01:57:26PM -0800, Alan Adamson wrote:
> +
> +static const char * const nvme_errors[] = {
> +	"Success",
> +	"Invalid Command Opcode",
> +	"Invalid Field in Command",
> +	"Command ID Conflict",
> +	"Data Transfer Error",
> +	"Commands Aborted due to Power Loss Notification",
> +	"Internal Error",
> +	"Command Abort Requested",
> +	"Command Aborted due to SQ Deletion",
> +	"Command Aborted due to Failed Fused Command",
> +	"Command Aborted due to Missing Fused Command",
> +	"Invalid Namespace or Format",
> +	"Command Sequence Error",
> +	"Invalid SGL Segment Descriptor",
> +	"Invalid Number of SGL Descriptors",
> +	"Data SGL Length Invalid",
> +	"Metadata SGL Length Invalid",
> +	"SGL Descriptor Type Invalid",
> +	"Invalid Use of Controller Memory Buffer",
> +	"PRP Offset Invalid",
> +	"Atomic Write Unit Exceeded",
> +	"Operation Denied",
> +	"SGL Offset Invalid",
> +	"Reserved",
> +	"Host Identifier Inconsistent Format",
> +	"Keep Alive Timeout Expired",
> +	"Keep Alive Timeout Invalid",
> +	"Command Aborted due to Preempt and Abort",
> +	"Sanitize Failed",
> +	"Sanitize In Progress",
> +	"SGL Data Block Granularity Invalid",
> +	"Command Not Supported for Queue in CMB",
> +	"Namespace is Write Protected",
> +	"Command Interrupted",
> +	"Transient Transport Error",
> +	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

Tracking these NULL's is going to be problematic and error prone.

I recommend indexing the strings as you define them. For example:

static const char * const nvme_errors[] = {
	[NVME_SC_SUCCESS] = "Success",
	[NVME_SC_INVALID_OPCODE] = "Invalid Command Opcode",

etc...

Then you don't need to bother tracking the undefined indexes or making
sure everything is in order.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 1/1] nvme: Add verbose error logging
  2021-12-27 16:07   ` Keith Busch
@ 2022-01-04 18:18     ` Alan Adamson
  2022-01-04 18:48       ` Keith Busch
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Adamson @ 2022-01-04 18:18 UTC (permalink / raw)
  To: Keith Busch; +Cc: linux-nvme, Christoph Hellwig, Sagi Grimberg



> On Dec 27, 2021, at 8:07 AM, Keith Busch <kbusch@kernel.org> wrote:
> 
> On Thu, Dec 23, 2021 at 01:57:26PM -0800, Alan Adamson wrote:
>> +
>> +static const char * const nvme_errors[] = {
>> +	"Success",
>> +	"Invalid Command Opcode",
>> +	"Invalid Field in Command",
>> +	"Command ID Conflict",
>> +	"Data Transfer Error",
>> +	"Commands Aborted due to Power Loss Notification",
>> +	"Internal Error",
>> +	"Command Abort Requested",
>> +	"Command Aborted due to SQ Deletion",
>> +	"Command Aborted due to Failed Fused Command",
>> +	"Command Aborted due to Missing Fused Command",
>> +	"Invalid Namespace or Format",
>> +	"Command Sequence Error",
>> +	"Invalid SGL Segment Descriptor",
>> +	"Invalid Number of SGL Descriptors",
>> +	"Data SGL Length Invalid",
>> +	"Metadata SGL Length Invalid",
>> +	"SGL Descriptor Type Invalid",
>> +	"Invalid Use of Controller Memory Buffer",
>> +	"PRP Offset Invalid",
>> +	"Atomic Write Unit Exceeded",
>> +	"Operation Denied",
>> +	"SGL Offset Invalid",
>> +	"Reserved",
>> +	"Host Identifier Inconsistent Format",
>> +	"Keep Alive Timeout Expired",
>> +	"Keep Alive Timeout Invalid",
>> +	"Command Aborted due to Preempt and Abort",
>> +	"Sanitize Failed",
>> +	"Sanitize In Progress",
>> +	"SGL Data Block Granularity Invalid",
>> +	"Command Not Supported for Queue in CMB",
>> +	"Namespace is Write Protected",
>> +	"Command Interrupted",
>> +	"Transient Transport Error",
>> +	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> 
> Tracking these NULL's is going to be problematic and error prone.

I don’t disagree, definitely wasn’t fun putting them in there:)

If we don’t define the NULLs, what happens if the hardware responds with a undefined error status? 
We will attempt to log a undefined/non-string.

Alan

> 
> I recommend indexing the strings as you define them. For example:
> 
> static const char * const nvme_errors[] = {
> 	[NVME_SC_SUCCESS] = "Success",
> 	[NVME_SC_INVALID_OPCODE] = "Invalid Command Opcode",
> 
> etc...
> 
> Then you don't need to bother tracking the undefined indexes or making
> sure everything is in order.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 1/1] nvme: Add verbose error logging
  2022-01-04 18:18     ` Alan Adamson
@ 2022-01-04 18:48       ` Keith Busch
  0 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2022-01-04 18:48 UTC (permalink / raw)
  To: Alan Adamson; +Cc: linux-nvme, Christoph Hellwig, Sagi Grimberg

On Tue, Jan 04, 2022 at 06:18:27PM +0000, Alan Adamson wrote:
> > On Dec 27, 2021, at 8:07 AM, Keith Busch <kbusch@kernel.org> wrote:
> > 
> > On Thu, Dec 23, 2021 at 01:57:26PM -0800, Alan Adamson wrote:
> >> +
> >> +static const char * const nvme_errors[] = {
> >> +	"Success",
> >> +	"Invalid Command Opcode",
> >> +	"Invalid Field in Command",
> >> +	"Command ID Conflict",
> >> +	"Data Transfer Error",
> >> +	"Commands Aborted due to Power Loss Notification",
> >> +	"Internal Error",
> >> +	"Command Abort Requested",
> >> +	"Command Aborted due to SQ Deletion",
> >> +	"Command Aborted due to Failed Fused Command",
> >> +	"Command Aborted due to Missing Fused Command",
> >> +	"Invalid Namespace or Format",
> >> +	"Command Sequence Error",
> >> +	"Invalid SGL Segment Descriptor",
> >> +	"Invalid Number of SGL Descriptors",
> >> +	"Data SGL Length Invalid",
> >> +	"Metadata SGL Length Invalid",
> >> +	"SGL Descriptor Type Invalid",
> >> +	"Invalid Use of Controller Memory Buffer",
> >> +	"PRP Offset Invalid",
> >> +	"Atomic Write Unit Exceeded",
> >> +	"Operation Denied",
> >> +	"SGL Offset Invalid",
> >> +	"Reserved",
> >> +	"Host Identifier Inconsistent Format",
> >> +	"Keep Alive Timeout Expired",
> >> +	"Keep Alive Timeout Invalid",
> >> +	"Command Aborted due to Preempt and Abort",
> >> +	"Sanitize Failed",
> >> +	"Sanitize In Progress",
> >> +	"SGL Data Block Granularity Invalid",
> >> +	"Command Not Supported for Queue in CMB",
> >> +	"Namespace is Write Protected",
> >> +	"Command Interrupted",
> >> +	"Transient Transport Error",
> >> +	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> > 
> > Tracking these NULL's is going to be problematic and error prone.
> 
> I don’t disagree, definitely wasn’t fun putting them in there:)
> 
> If we don’t define the NULLs, what happens if the hardware responds with a undefined error status? 
> We will attempt to log a undefined/non-string.

Every index not defined below the maximum defined index is automatically
initialized to NULL.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 1/1] nvme: Add verbose error logging
  2021-12-23 21:57 ` [PATCH V2 1/1] " Alan Adamson
  2021-12-27 16:07   ` Keith Busch
@ 2022-01-17 13:52   ` Hannes Reinecke
  1 sibling, 0 replies; 6+ messages in thread
From: Hannes Reinecke @ 2022-01-17 13:52 UTC (permalink / raw)
  To: Alan Adamson, linux-nvme; +Cc: kbusch, hch, sagi

On 12/23/21 10:57 PM, Alan Adamson wrote:
> Improves logging of NVMe errors.  If NVME_VERBOSE_ERRORS is configured,
> a verbose description of the error is logged, otherwise only status codes/bits
> is logged.
> 
> Verbose logging example:
> nvme0n1: Read @ LBA 2304, 1 blocks, Unrecovered Read Error (sct 0x2 / sc 0x81) DNR
> 
> Non-verbose logging example:
> nvme0n1: Read @ LBA 2304, 1 blocks, NVME Error (sct 0x2 / sc 0x81) DNR
> 
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
> Signed-off-by: Alan Adamson <alan.adamson@oracle.com>
> Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
> ---
>  drivers/nvme/host/Kconfig  |   8 ++
>  drivers/nvme/host/Makefile |   2 +-
>  drivers/nvme/host/core.c   |   3 +
>  drivers/nvme/host/errors.c | 202 +++++++++++++++++++++++++++++++++++++
>  drivers/nvme/host/nvme.h   |   2 +
>  include/linux/nvme.h       |   1 +
>  6 files changed, 217 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/nvme/host/errors.c
> 
> diff --git a/drivers/nvme/host/Kconfig b/drivers/nvme/host/Kconfig
> index dc0450ca23a3..d6d056963c06 100644
> --- a/drivers/nvme/host/Kconfig
> +++ b/drivers/nvme/host/Kconfig
> @@ -24,6 +24,14 @@ config NVME_MULTIPATH
>  	   /dev/nvmeXnY device will show up for each NVMe namespace,
>  	   even if it is accessible through multiple controllers.
>  
> +config NVME_VERBOSE_ERRORS
> +	bool "NVMe verbose error reporting"
> +	depends on NVME_CORE
> +	help
> +	   This option enables verbose reporting for NVMe errors. The
> +	   error translation table will grow the kernel image size by
> +	   about 4 KB.
> +
>  config NVME_HWMON
>  	bool "NVMe hardware monitoring"
>  	depends on (NVME_CORE=y && HWMON=y) || (NVME_CORE=m && HWMON)
> diff --git a/drivers/nvme/host/Makefile b/drivers/nvme/host/Makefile
> index dfaacd472e5d..ea3d702feb51 100644
> --- a/drivers/nvme/host/Makefile
> +++ b/drivers/nvme/host/Makefile
> @@ -9,7 +9,7 @@ obj-$(CONFIG_NVME_RDMA)			+= nvme-rdma.o
>  obj-$(CONFIG_NVME_FC)			+= nvme-fc.o
>  obj-$(CONFIG_NVME_TCP)			+= nvme-tcp.o
>  
> -nvme-core-y				:= core.o ioctl.o
> +nvme-core-y				:= core.o ioctl.o errors.o
>  nvme-core-$(CONFIG_TRACING)		+= trace.o
>  nvme-core-$(CONFIG_NVME_MULTIPATH)	+= multipath.o
>  nvme-core-$(CONFIG_BLK_DEV_ZONED)	+= zns.o
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 1af8a4513708..fda029a55436 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -354,6 +354,9 @@ void nvme_complete_rq(struct request *req)
>  
>  	switch (nvme_decide_disposition(req)) {
>  	case COMPLETE:
> +		if (unlikely(nvme_req(req)->status != NVME_SC_SUCCESS))
> +			nvme_error_log(req);
> +
>  		nvme_end_req(req);
>  		return;
>  	case RETRY:
> diff --git a/drivers/nvme/host/errors.c b/drivers/nvme/host/errors.c
> new file mode 100644
> index 000000000000..3183b2e728d4
> --- /dev/null
> +++ b/drivers/nvme/host/errors.c
> @@ -0,0 +1,202 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * NVM Express device driver verbose errors
> + * Copyright (c) 2021, Oracle and/or its affiliates
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + */
> +
> +#include <linux/blkdev.h>
> +#include "nvme.h"
> +
> +struct nvme_string_table {
> +	unsigned int code;
> +	const unsigned char *string;
> +};
> +
> +static const struct nvme_string_table nvme_ops[] = {
> +	{ REQ_OP_READ,			"Read" },
> +	{ REQ_OP_WRITE,			"Write" },
> +	{ REQ_OP_FLUSH,			"Flush" },
> +	{ REQ_OP_DISCARD,		"Deallocate (DSM)" },
> +	{ REQ_OP_WRITE_ZEROES,		"Write Zeroes" },
> +	{ REQ_OP_ZONE_RESET_ALL,	"Zone Reset All" },
> +	{ REQ_OP_ZONE_RESET,		"Zone Reset" },
> +	{ REQ_OP_ZONE_OPEN,		"Zone Open" },
> +	{ REQ_OP_ZONE_CLOSE,		"Zone Close" },
> +	{ REQ_OP_ZONE_FINISH,		"Zone Finish" },
> +	{ REQ_OP_ZONE_APPEND,		"Zone Append" },
> +};
> +#define NVME_OPS_SIZE ARRAY_SIZE(nvme_ops)
> +
> +#ifdef CONFIG_NVME_VERBOSE_ERRORS
> +#define TEN_NULLS	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
> +
> +static const char * const nvme_errors[] = {
> +	"Success",
> +	"Invalid Command Opcode",
> +	"Invalid Field in Command",
> +	"Command ID Conflict",
> +	"Data Transfer Error",
> +	"Commands Aborted due to Power Loss Notification",
> +	"Internal Error",
> +	"Command Abort Requested",
> +	"Command Aborted due to SQ Deletion",
> +	"Command Aborted due to Failed Fused Command",
> +	"Command Aborted due to Missing Fused Command",
> +	"Invalid Namespace or Format",
> +	"Command Sequence Error",
> +	"Invalid SGL Segment Descriptor",
> +	"Invalid Number of SGL Descriptors",
> +	"Data SGL Length Invalid",
> +	"Metadata SGL Length Invalid",
> +	"SGL Descriptor Type Invalid",
> +	"Invalid Use of Controller Memory Buffer",
> +	"PRP Offset Invalid",
> +	"Atomic Write Unit Exceeded",
> +	"Operation Denied",
> +	"SGL Offset Invalid",
> +	"Reserved",
> +	"Host Identifier Inconsistent Format",
> +	"Keep Alive Timeout Expired",
> +	"Keep Alive Timeout Invalid",
> +	"Command Aborted due to Preempt and Abort",
> +	"Sanitize Failed",
> +	"Sanitize In Progress",
> +	"SGL Data Block Granularity Invalid",
> +	"Command Not Supported for Queue in CMB",
> +	"Namespace is Write Protected",
> +	"Command Interrupted",
> +	"Transient Transport Error",
> +	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +	"Invalid IO Command Set",
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS, TEN_NULLS, TEN_NULLS,
> +	NULL, NULL, NULL,
> +	"LBA Out of Range",
> +	"Capacity Exceeded",
> +	"Namespace Not Ready",
> +	"Reservation Conflict",
> +	"Format In Progress",
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS, TEN_NULLS, TEN_NULLS,
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, NULL, NULL, NULL,
> +	"Completion Queue Invalid",
> +	"Invalid Queue Identifier",
> +	"Invalid Queue Size",
> +	"Abort Command Limit Exceeded",
> +	"Reserved",
> +	"Asynchronous Event Request Limit Exceeded",
> +	"Invalid Firmware Slot",
> +	"Invalid Firmware Image",
> +	"Invalid Interrupt Vector",
> +	"Invalid Log Page",
> +	"Invalid Format",
> +	"Firmware Activation Requires Conventional Reset",
> +	"Invalid Queue Deletion",
> +	"Feature Identifier Not Saveable",
> +	"Feature Not Changeable",
> +	"Feature Not Namespace Specific",
> +	"Firmware Activation Requires NVM Subsystem Reset",
> +	"Firmware Activation Requires Reset",
> +	"Firmware Activation Requires Maximum Time Violation",
> +	"Firmware Activation Prohibited",
> +	"Overlapping Range",
> +	"Namespace Insufficient Capacity",
> +	"Namespace Identifier Unavailable",
> +	NULL,
> +	"Namespace Already Attached",
> +	"Namespace Is Private",
> +	"Namespace Not Attached",
> +	"Thin Provisioning Not Supported",
> +	"Controller List Invalid",
> +	"Device Self-test In Progress",
> +	"Boot Partition Write Prohibited",
> +	"Invalid Controller Identifier",
> +	"Invalid Secondary Controller State",
> +	"Invalid Number of Controller Resources",
> +	"Invalid Resource Identifier",
> +	"Sanitize Prohibited",
> +	"ANA Group Identifier Invalid",
> +	"ANA Attach Failed",
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS,
> +	"Conflicting Attributes",
> +	"Invalid Protection Information",
> +	"Attempted Write to Read Only Range",
> +	"ONCS Not Supported",
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, NULL, NULL,
> +	"Zoned Boundary Error",
> +	"Zone Is Full",
> +	"Zone Is Read Only",
> +	"Zone Is Offline",
> +	"Zone Invalid Write",
> +	"Too Many Active Zones",
> +	"Too Many Open Zones",
> +	"Invalid Zone State Transition",
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
> +	TEN_NULLS, NULL, NULL,
> +	"Write Fault",
> +	"Unrecovered Read Error",
> +	"End-to-end Guard Check Error",
> +	"End-to-end Application Tag Check Error",
> +	"End-to-end Reference Tag Check Error",
> +	"Compare Failure",
> +	"Access Denied",
> +	"Deallocated or Unwritten Logical Block",
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
> +	NULL,
> +	"Asymmetric Access Persistent Loss",
> +	"Asymmetric Access Inaccessible",
> +	"Asymmetric Access Transition",
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,  TEN_NULLS,
> +	TEN_NULLS, TEN_NULLS, TEN_NULLS, TEN_NULLS,
> +	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +	"Host Pathing Error",
> +};
> +#define NVME_ERRORS_SIZE ARRAY_SIZE(nvme_errors)
> +#endif /* CONFIG_NVME_VERBOSE_ERRORS */
> +

This 'ten NULLs' stuff is patently ugly.

I would suggest split off this array into several, taking a cue on how
the status codes are arranged in the NVMe spec.
IE have one array for generic status values
(ie figure 94 in NVMe-Base 2.0a; maybe even split that one into two for
the 0x8X values), another one for command specific values (ie figure 95)
and so on.
Within these sections the status codes are assigned consecutively, so
there shouldn't be any holes in them, and we do avoid the NULL padding.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		           Kernel Storage Architect
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-17 13:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-23 21:57 [PATCH V2 0/1] nvme: Add verbose error logging Alan Adamson
2021-12-23 21:57 ` [PATCH V2 1/1] " Alan Adamson
2021-12-27 16:07   ` Keith Busch
2022-01-04 18:18     ` Alan Adamson
2022-01-04 18:48       ` Keith Busch
2022-01-17 13:52   ` Hannes Reinecke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.