[PATCH V2 1/1] nvme: Add verbose error logging

Hannes Reinecke hare at suse.de
Mon Jan 17 05:52:41 PST 2022


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 at oracle.com>
> Signed-off-by: Alan Adamson <alan.adamson at oracle.com>
> Reviewed-by: Himanshu Madhani <himanshu.madhani at 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 at 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



More information about the Linux-nvme mailing list