History

nvme: add verbose error logging

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.

Alan Adamson committed 4 years ago

Commit bd83fe61 parent 72e8b5c6 files · +247 −1Browse files

Unified · Split

6 files
  1. drivers/nvme/host/Kconfig +8 −0
  2. drivers/nvme/host/Makefile +1 −1
  3. drivers/nvme/host/constants.c +185 −0
  4. drivers/nvme/host/core.c +33 −0
  5. drivers/nvme/host/nvme.h +19 −0
  6. include/linux/nvme.h +1 −0
drivers/nvme/host/Kconfig+8−0
@@ -24,6 +24,14 @@ config NVME_MULTIPATH · 23 unmodified lines
2424 /dev/nvmeXnY device will show up for each NVMe namespace,
2525 even if it is accessible through multiple controllers.
2626
27+config NVME_VERBOSE_ERRORS
28+ bool "NVMe verbose error reporting"
29+ depends on NVME_CORE
30+ help
31+ This option enables verbose reporting for NVMe errors. The
32+ error translation table will grow the kernel image size by
33+ about 4 KB.
34+
2735 config NVME_HWMON
2836 bool "NVMe hardware monitoring"
2937 depends on (NVME_CORE=y && HWMON=y) || (NVME_CORE=m && HWMON)
drivers/nvme/host/Makefile+1−1
@@ -9,7 +9,7 @@ obj-$(CONFIG_NVME_RDMA) += nvme-rdma.o · 8 unmodified lines
99 obj-$(CONFIG_NVME_FC) += nvme-fc.o
1010 obj-$(CONFIG_NVME_TCP) += nvme-tcp.o
1111
12−nvme-core-y := core.o ioctl.o
12+nvme-core-y := core.o ioctl.o constants.o
1313 nvme-core-$(CONFIG_TRACING) += trace.o
1414 nvme-core-$(CONFIG_NVME_MULTIPATH) += multipath.o
1515 nvme-core-$(CONFIG_BLK_DEV_ZONED) += zns.o
drivers/nvme/host/constants.c+185−0
@@ -0,0 +1,185 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/*
3+ * NVM Express device driver verbose errors
4+ * Copyright (c) 2022, Oracle and/or its affiliates
5+ */
6+
7+#include <linux/blkdev.h>
8+#include "nvme.h"
9+
10+#ifdef CONFIG_NVME_VERBOSE_ERRORS
11+static const char * const nvme_ops[] = {
12+ [nvme_cmd_flush] = "Flush",
13+ [nvme_cmd_write] = "Write",
14+ [nvme_cmd_read] = "Read",
15+ [nvme_cmd_write_uncor] = "Write Uncorrectable",
16+ [nvme_cmd_compare] = "Compare",
17+ [nvme_cmd_write_zeroes] = "Write Zeros",
18+ [nvme_cmd_dsm] = "Dataset Management",
19+ [nvme_cmd_verify] = "Verify",
20+ [nvme_cmd_resv_register] = "Reservation Register",
21+ [nvme_cmd_resv_report] = "Reservation Report",
22+ [nvme_cmd_resv_acquire] = "Reservation Acquire",
23+ [nvme_cmd_resv_release] = "Reservation Release",
24+ [nvme_cmd_zone_mgmt_send] = "Zone Management Send",
25+ [nvme_cmd_zone_mgmt_recv] = "Zone Management Receive",
26+ [nvme_cmd_zone_append] = "Zone Management Append",
27+};
28+
29+static const char * const nvme_admin_ops[] = {
30+ [nvme_admin_delete_sq] = "Delete SQ",
31+ [nvme_admin_create_sq] = "Create SQ",
32+ [nvme_admin_get_log_page] = "Get Log Page",
33+ [nvme_admin_delete_cq] = "Delete CQ",
34+ [nvme_admin_create_cq] = "Create CQ",
35+ [nvme_admin_identify] = "Identify",
36+ [nvme_admin_abort_cmd] = "Abort Command",
37+ [nvme_admin_set_features] = "Set Features",
38+ [nvme_admin_get_features] = "Get Features",
39+ [nvme_admin_async_event] = "Async Event",
40+ [nvme_admin_ns_mgmt] = "Namespace Management",
41+ [nvme_admin_activate_fw] = "Activate Firmware",
42+ [nvme_admin_download_fw] = "Download Firmware",
43+ [nvme_admin_dev_self_test] = "Device Self Test",
44+ [nvme_admin_ns_attach] = "Namespace Attach",
45+ [nvme_admin_keep_alive] = "Keep Alive",
46+ [nvme_admin_directive_send] = "Directive Send",
47+ [nvme_admin_directive_recv] = "Directive Receive",
48+ [nvme_admin_virtual_mgmt] = "Virtual Management",
49+ [nvme_admin_nvme_mi_send] = "NVMe Send MI",
50+ [nvme_admin_nvme_mi_recv] = "NVMe Receive MI",
51+ [nvme_admin_dbbuf] = "Doorbell Buffer Config",
52+ [nvme_admin_format_nvm] = "Format NVM",
53+ [nvme_admin_security_send] = "Security Send",
54+ [nvme_admin_security_recv] = "Security Receive",
55+ [nvme_admin_sanitize_nvm] = "Sanitize NVM",
56+ [nvme_admin_get_lba_status] = "Get LBA Status",
57+};
58+
59+static const char * const nvme_statuses[] = {
60+ [NVME_SC_SUCCESS] = "Success",
61+ [NVME_SC_INVALID_OPCODE] = "Invalid Command Opcode",
62+ [NVME_SC_INVALID_FIELD] = "Invalid Field in Command",
63+ [NVME_SC_CMDID_CONFLICT] = "Command ID Conflict",
64+ [NVME_SC_DATA_XFER_ERROR] = "Data Transfer Error",
65+ [NVME_SC_POWER_LOSS] = "Commands Aborted due to Power Loss Notification",
66+ [NVME_SC_INTERNAL] = "Internal Error",
67+ [NVME_SC_ABORT_REQ] = "Command Abort Requested",
68+ [NVME_SC_ABORT_QUEUE] = "Command Aborted due to SQ Deletion",
69+ [NVME_SC_FUSED_FAIL] = "Command Aborted due to Failed Fused Command",
70+ [NVME_SC_FUSED_MISSING] = "Command Aborted due to Missing Fused Command",
71+ [NVME_SC_INVALID_NS] = "Invalid Namespace or Format",
72+ [NVME_SC_CMD_SEQ_ERROR] = "Command Sequence Error",
73+ [NVME_SC_SGL_INVALID_LAST] = "Invalid SGL Segment Descriptor",
74+ [NVME_SC_SGL_INVALID_COUNT] = "Invalid Number of SGL Descriptors",
75+ [NVME_SC_SGL_INVALID_DATA] = "Data SGL Length Invalid",
76+ [NVME_SC_SGL_INVALID_METADATA] = "Metadata SGL Length Invalid",
77+ [NVME_SC_SGL_INVALID_TYPE] = "SGL Descriptor Type Invalid",
78+ [NVME_SC_CMB_INVALID_USE] = "Invalid Use of Controller Memory Buffer",
79+ [NVME_SC_PRP_INVALID_OFFSET] = "PRP Offset Invalid",
80+ [NVME_SC_ATOMIC_WU_EXCEEDED] = "Atomic Write Unit Exceeded",
81+ [NVME_SC_OP_DENIED] = "Operation Denied",
82+ [NVME_SC_SGL_INVALID_OFFSET] = "SGL Offset Invalid",
83+ [NVME_SC_RESERVED] = "Reserved",
84+ [NVME_SC_HOST_ID_INCONSIST] = "Host Identifier Inconsistent Format",
85+ [NVME_SC_KA_TIMEOUT_EXPIRED] = "Keep Alive Timeout Expired",
86+ [NVME_SC_KA_TIMEOUT_INVALID] = "Keep Alive Timeout Invalid",
87+ [NVME_SC_ABORTED_PREEMPT_ABORT] = "Command Aborted due to Preempt and Abort",
88+ [NVME_SC_SANITIZE_FAILED] = "Sanitize Failed",
89+ [NVME_SC_SANITIZE_IN_PROGRESS] = "Sanitize In Progress",
90+ [NVME_SC_SGL_INVALID_GRANULARITY] = "SGL Data Block Granularity Invalid",
91+ [NVME_SC_CMD_NOT_SUP_CMB_QUEUE] = "Command Not Supported for Queue in CMB",
92+ [NVME_SC_NS_WRITE_PROTECTED] = "Namespace is Write Protected",
93+ [NVME_SC_CMD_INTERRUPTED] = "Command Interrupted",
94+ [NVME_SC_TRANSIENT_TR_ERR] = "Transient Transport Error",
95+ [NVME_SC_INVALID_IO_CMD_SET] = "Invalid IO Command Set",
96+ [NVME_SC_LBA_RANGE] = "LBA Out of Range",
97+ [NVME_SC_CAP_EXCEEDED] = "Capacity Exceeded",
98+ [NVME_SC_NS_NOT_READY] = "Namespace Not Ready",
99+ [NVME_SC_RESERVATION_CONFLICT] = "Reservation Conflict",
100+ [NVME_SC_FORMAT_IN_PROGRESS] = "Format In Progress",
101+ [NVME_SC_CQ_INVALID] = "Completion Queue Invalid",
102+ [NVME_SC_QID_INVALID] = "Invalid Queue Identifier",
103+ [NVME_SC_QUEUE_SIZE] = "Invalid Queue Size",
104+ [NVME_SC_ABORT_LIMIT] = "Abort Command Limit Exceeded",
105+ [NVME_SC_ABORT_MISSING] = "Reserved", /* XXX */
106+ [NVME_SC_ASYNC_LIMIT] = "Asynchronous Event Request Limit Exceeded",
107+ [NVME_SC_FIRMWARE_SLOT] = "Invalid Firmware Slot",
108+ [NVME_SC_FIRMWARE_IMAGE] = "Invalid Firmware Image",
109+ [NVME_SC_INVALID_VECTOR] = "Invalid Interrupt Vector",
110+ [NVME_SC_INVALID_LOG_PAGE] = "Invalid Log Page",
111+ [NVME_SC_INVALID_FORMAT] = "Invalid Format",
112+ [NVME_SC_FW_NEEDS_CONV_RESET] = "Firmware Activation Requires Conventional Reset",
113+ [NVME_SC_INVALID_QUEUE] = "Invalid Queue Deletion",
114+ [NVME_SC_FEATURE_NOT_SAVEABLE] = "Feature Identifier Not Saveable",
115+ [NVME_SC_FEATURE_NOT_CHANGEABLE] = "Feature Not Changeable",
116+ [NVME_SC_FEATURE_NOT_PER_NS] = "Feature Not Namespace Specific",
117+ [NVME_SC_FW_NEEDS_SUBSYS_RESET] = "Firmware Activation Requires NVM Subsystem Reset",
118+ [NVME_SC_FW_NEEDS_RESET] = "Firmware Activation Requires Reset",
119+ [NVME_SC_FW_NEEDS_MAX_TIME] = "Firmware Activation Requires Maximum Time Violation",
120+ [NVME_SC_FW_ACTIVATE_PROHIBITED] = "Firmware Activation Prohibited",
121+ [NVME_SC_OVERLAPPING_RANGE] = "Overlapping Range",
122+ [NVME_SC_NS_INSUFFICIENT_CAP] = "Namespace Insufficient Capacity",
123+ [NVME_SC_NS_ID_UNAVAILABLE] = "Namespace Identifier Unavailable",
124+ [NVME_SC_NS_ALREADY_ATTACHED] = "Namespace Already Attached",
125+ [NVME_SC_NS_IS_PRIVATE] = "Namespace Is Private",
126+ [NVME_SC_NS_NOT_ATTACHED] = "Namespace Not Attached",
127+ [NVME_SC_THIN_PROV_NOT_SUPP] = "Thin Provisioning Not Supported",
128+ [NVME_SC_CTRL_LIST_INVALID] = "Controller List Invalid",
129+ [NVME_SC_SELT_TEST_IN_PROGRESS] = "Device Self-test In Progress",
130+ [NVME_SC_BP_WRITE_PROHIBITED] = "Boot Partition Write Prohibited",
131+ [NVME_SC_CTRL_ID_INVALID] = "Invalid Controller Identifier",
132+ [NVME_SC_SEC_CTRL_STATE_INVALID] = "Invalid Secondary Controller State",
133+ [NVME_SC_CTRL_RES_NUM_INVALID] = "Invalid Number of Controller Resources",
134+ [NVME_SC_RES_ID_INVALID] = "Invalid Resource Identifier",
135+ [NVME_SC_PMR_SAN_PROHIBITED] = "Sanitize Prohibited",
136+ [NVME_SC_ANA_GROUP_ID_INVALID] = "ANA Group Identifier Invalid",
137+ [NVME_SC_ANA_ATTACH_FAILED] = "ANA Attach Failed",
138+ [NVME_SC_BAD_ATTRIBUTES] = "Conflicting Attributes",
139+ [NVME_SC_INVALID_PI] = "Invalid Protection Information",
140+ [NVME_SC_READ_ONLY] = "Attempted Write to Read Only Range",
141+ [NVME_SC_ONCS_NOT_SUPPORTED] = "ONCS Not Supported",
142+ [NVME_SC_ZONE_BOUNDARY_ERROR] = "Zoned Boundary Error",
143+ [NVME_SC_ZONE_FULL] = "Zone Is Full",
144+ [NVME_SC_ZONE_READ_ONLY] = "Zone Is Read Only",
145+ [NVME_SC_ZONE_OFFLINE] = "Zone Is Offline",
146+ [NVME_SC_ZONE_INVALID_WRITE] = "Zone Invalid Write",
147+ [NVME_SC_ZONE_TOO_MANY_ACTIVE] = "Too Many Active Zones",
148+ [NVME_SC_ZONE_TOO_MANY_OPEN] = "Too Many Open Zones",
149+ [NVME_SC_ZONE_INVALID_TRANSITION] = "Invalid Zone State Transition",
150+ [NVME_SC_WRITE_FAULT] = "Write Fault",
151+ [NVME_SC_READ_ERROR] = "Unrecovered Read Error",
152+ [NVME_SC_GUARD_CHECK] = "End-to-end Guard Check Error",
153+ [NVME_SC_APPTAG_CHECK] = "End-to-end Application Tag Check Error",
154+ [NVME_SC_REFTAG_CHECK] = "End-to-end Reference Tag Check Error",
155+ [NVME_SC_COMPARE_FAILED] = "Compare Failure",
156+ [NVME_SC_ACCESS_DENIED] = "Access Denied",
157+ [NVME_SC_UNWRITTEN_BLOCK] = "Deallocated or Unwritten Logical Block",
158+ [NVME_SC_ANA_PERSISTENT_LOSS] = "Asymmetric Access Persistent Loss",
159+ [NVME_SC_ANA_INACCESSIBLE] = "Asymmetric Access Inaccessible",
160+ [NVME_SC_ANA_TRANSITION] = "Asymmetric Access Transition",
161+ [NVME_SC_HOST_PATH_ERROR] = "Host Pathing Error",
162+};
163+
164+const unsigned char *nvme_get_error_status_str(u16 status)
165+{
166+ status &= 0x7ff;
167+ if (status < ARRAY_SIZE(nvme_statuses) && nvme_statuses[status])
168+ return nvme_statuses[status & 0x7ff];
169+ return "Unknown";
170+}
171+
172+const unsigned char *nvme_get_opcode_str(u8 opcode)
173+{
174+ if (opcode < ARRAY_SIZE(nvme_ops) && nvme_ops[opcode])
175+ return nvme_ops[opcode];
176+ return "Unknown";
177+}
178+
179+const unsigned char *nvme_get_admin_opcode_str(u8 opcode)
180+{
181+ if (opcode < ARRAY_SIZE(nvme_admin_ops) && nvme_admin_ops[opcode])
182+ return nvme_admin_ops[opcode];
183+ return "Unknown";
184+}
185+#endif /* CONFIG_NVME_VERBOSE_ERRORS */
drivers/nvme/host/core.c+33−0
@@ -299,6 +299,37 @@ static void nvme_retry_req(struct request *req) · 298 unmodified lines
299299 blk_mq_delay_kick_requeue_list(req->q, delay);
300300 }
301301
302+static void nvme_log_error(struct request *req)
303+{
304+ struct nvme_ns *ns = req->q->queuedata;
305+ struct nvme_request *nr = nvme_req(req);
306+
307+ if (ns) {
308+ pr_err_ratelimited("%s: %s(0x%x) @ LBA %llu, %llu blocks, %s (sct 0x%x / sc 0x%x) %s%s\n",
309+ ns->disk ? ns->disk->disk_name : "?",
310+ nvme_get_opcode_str(nr->cmd->common.opcode),
311+ nr->cmd->common.opcode,
312+ (unsigned long long)nvme_sect_to_lba(ns, blk_rq_pos(req)),
313+ (unsigned long long)blk_rq_bytes(req) >> ns->lba_shift,
314+ nvme_get_error_status_str(nr->status),
315+ nr->status >> 8 & 7, /* Status Code Type */
316+ nr->status & 0xff, /* Status Code */
317+ nr->status & NVME_SC_MORE ? "MORE " : "",
318+ nr->status & NVME_SC_DNR ? "DNR " : "");
319+ return;
320+ }
321+
322+ pr_err_ratelimited("%s: %s(0x%x), %s (sct 0x%x / sc 0x%x) %s%s\n",
323+ dev_name(nr->ctrl->device),
324+ nvme_get_admin_opcode_str(nr->cmd->common.opcode),
325+ nr->cmd->common.opcode,
326+ nvme_get_error_status_str(nr->status),
327+ nr->status >> 8 & 7, /* Status Code Type */
328+ nr->status & 0xff, /* Status Code */
329+ nr->status & NVME_SC_MORE ? "MORE " : "",
330+ nr->status & NVME_SC_DNR ? "DNR " : "");
331+}
332+
302333 enum nvme_disposition {
303334 COMPLETE,
304335 RETRY,
@@ -339,6 +370,8 @@ static inline void nvme_end_req(struct request *req) · 34 unmodified lines
339370 {
340371 blk_status_t status = nvme_error_status(nvme_req(req)->status);
341372
373+ if (unlikely(nvme_req(req)->status != NVME_SC_SUCCESS))
374+ nvme_log_error(req);
342375 nvme_end_req_zoned(req);
343376 nvme_trace_bio_complete(req);
344377 blk_mq_end_request(req, status);
drivers/nvme/host/nvme.h+19−0
@@ -938,4 +938,23 @@ static inline bool nvme_multi_css(struct nvme_ctrl *ctrl) · 937 unmodified lines
938938 return (ctrl->ctrl_config & NVME_CC_CSS_MASK) == NVME_CC_CSS_CSI;
939939 }
940940
941+#ifdef CONFIG_NVME_VERBOSE_ERRORS
942+const unsigned char *nvme_get_error_status_str(u16 status);
943+const unsigned char *nvme_get_opcode_str(u8 opcode);
944+const unsigned char *nvme_get_admin_opcode_str(u8 opcode);
945+#else /* CONFIG_NVME_VERBOSE_ERRORS */
946+static inline const unsigned char *nvme_get_error_status_str(u16 status)
947+{
948+ return "I/O Error";
949+}
950+static inline const unsigned char *nvme_get_opcode_str(u8 opcode)
951+{
952+ return "I/O Cmd";
953+}
954+static inline const unsigned char *nvme_get_admin_opcode_str(u8 opcode)
955+{
956+ return "Admin Cmd";
957+}
958+#endif /* CONFIG_NVME_VERBOSE_ERRORS */
959+
941960 #endif /* _NVME_H */
include/linux/nvme.h+1−0
@@ -1636,6 +1636,7 @@ enum { · 1635 unmodified lines
16361636 NVME_SC_HOST_ABORTED_CMD = 0x371,
16371637
16381638 NVME_SC_CRD = 0x1800,
1639+ NVME_SC_MORE = 0x2000,
16391640 NVME_SC_DNR = 0x4000,
16401641 };
16411642

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t