nvme: add verbose error logging
v7 cover nvme: add verbose error logging
From: Chaitanya Kulkarni <[email protected]>
Hi,
I spent sometime on reviwing this patch, thought it will be helpeful if I fix things while reviwing it along with Christoph's comments.
Follwing is the original cover-letter:-
This patch improves logging for NVMe errors. Currently, we only get 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:
[ 183.333734] nvme0n1: Read(0x2) @ LBA 0, 1 blocks, Unrecovered Read Error (sct 0x2 / sc 0x81) DNR
[ 227.767945] nvme0: Activate Firmware(0x10), Invalid Field in Command (sct 0x0 / sc 0x2) DNR
-ck
V7:
- Remove local variables from helpers nvme_get_error_status_str() nvme_get_opcode_str(), nvme_get_admin_opcode_str().
- Fix commit message of patch and remove the example since cover-letter already has it.
- Un-export helper functions.
- Remove forward declaration of nvme_log_error().
- Move nvme_log_error() before its caller.
- Remove local variables initialization admin_op_str and op_str as they are getting overwritten by respective functions in nvme_log_error().
- Rename the error.c file to constants.c
- Fix the return type of the stubs nvme_get_error_status_str(u16 status), nvme_get_opcode_str(u8 opcode), and nvme_get_admin_opcode_str(u8 opcode) to const unsigned char * to match the what have in the constants.c.
- Add tabs before the comments for pr_err_ratelimited() functions arguments so that it will be consistent for nvme and admin commands.
V6:
- Create helpers that are stubbed out if
CONFIG_NVME_VERBOSE_ERRORS is not set.
- Couple more nits.
V5:
- Change nvme_ops[] and nvme_admin_ops[] to a sparse array where the opcode is used as an index into the array.
- Various other nits.
V4:
- Adding logging for admin commands.
- Display NVMe Command Opcode value rather than generic block opcode.
- Various other nits.
V3:
- Don't populate nvme_errors[] array with NULL strings.
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.
Chaitanya Kulkarni (1):
nvme-core: Add verbose error logging
drivers/nvme/host/Kconfig | 8 ++ drivers/nvme/host/Makefile | 2 +- drivers/nvme/host/constants.c | 185 ++++++++++++++++++++++++++++++++++ drivers/nvme/host/core.c | 34 +++++++ drivers/nvme/host/nvme.h | 19 ++++ include/linux/nvme.h | 1 + 6 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 drivers/nvme/host/constants.c
Signature · 1 line
2.29.0
PATCH v7 1/1 nvme-core: Add verbose error logging
From: Chaitanya Kulkarni <[email protected]>
From: Alan Adamson <[email protected]>
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.
[kch]: fix several nits, cosmetics, and trim down code.
--- drivers/nvme/host/Kconfig | 8 ++ drivers/nvme/host/Makefile | 2 +- drivers/nvme/host/constants.c | 185 ++++++++++++++++++++++++++++++++++ drivers/nvme/host/core.c | 34 +++++++ drivers/nvme/host/nvme.h | 19 ++++ include/linux/nvme.h | 1 + 6 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 drivers/nvme/host/constants.c
drivers/nvme/host/Kconfig +8 -0
@@ -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)
drivers/nvme/host/Makefile +1 -1
@@ -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 constants.o nvme-core-$(CONFIG_TRACING) += trace.o nvme-core-$(CONFIG_NVME_MULTIPATH) += multipath.o nvme-core-$(CONFIG_BLK_DEV_ZONED) += zns.o
drivers/nvme/host/constants.c new file +185 -0
185 lines not on this page · raw message
drivers/nvme/host/core.c +34 -0
@@ -299,6 +299,37 @@ static void nvme_retry_req(struct request *req)blk_mq_delay_kick_requeue_list (req->q, delay); } +static void nvme_log_error (struct request *req) +{ +struct nvme_ns *ns = req->q->queuedata; +struct nvme_request *nr =nvme_req (req); + +if (ns) { +pr_err_ratelimited ("%s: %s(0x%x) @ LBA %llu, %llu blocks, %s (sct 0x%x / sc 0x%x) %s%s\n" , + ns->disk ? ns->disk->disk_name :"?" , +nvme_get_opcode_str (nr->cmd->common.opcode), + nr->cmd->common.opcode, + (unsigned long long )nvme_sect_to_lba (ns,blk_rq_pos (req)), + (unsigned long long )blk_rq_bytes (req) >> ns->lba_shift, +nvme_get_error_status_str (nr->status), + nr->status >>8 &7 ,/* Status Code Type */ + nr->status &0xff ,/* Status Code */ + nr->status &NVME_SC_MORE ?"MORE " :"" , + nr->status &NVME_SC_DNR ?"DNR " :"" ); +return ; + } + +pr_err_ratelimited ("%s: %s(0x%x), %s (sct 0x%x / sc 0x%x) %s%s\n" , +dev_name (nr->ctrl->device), +nvme_get_admin_opcode_str (nr->cmd->common.opcode), + nr->cmd->common.opcode, +nvme_get_error_status_str (nr->status), + nr->status >>8 &7 ,/* Status Code Type */ + nr->status &0xff ,/* Status Code */ + nr->status &NVME_SC_MORE ?"MORE " :"" , + nr->status &NVME_SC_DNR ?"DNR " :"" ); +} +enum nvme_disposition {COMPLETE ,RETRY ,
@@ -354,6 +385,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_log_error (req); +nvme_end_req (req);return ;case RETRY :
drivers/nvme/host/nvme.h +19 -0
@@ -930,4 +930,23 @@ static inline bool nvme_multi_css(struct nvme_ctrl *ctrl) return (ctrl->ctrl_config & NVME_CC_CSS_MASK) == NVME_CC_CSS_CSI; } +#ifdef CONFIG_NVME_VERBOSE_ERRORS +const unsigned char *nvme_get_error_status_str (u16 status); +const unsigned char *nvme_get_opcode_str (u8 opcode); +const unsigned char *nvme_get_admin_opcode_str (u8 opcode); +#else /* CONFIG_NVME_VERBOSE_ERRORS */ +static inline const unsigned char *nvme_get_error_status_str (u16 status) +{ +return "I/O Error" ; +} +static inline const unsigned char *nvme_get_opcode_str (u8 opcode) +{ +return "I/O Cmd" ; +} +static inline const unsigned char *nvme_get_admin_opcode_str (u8 opcode) +{ +return "Admin Cmd" ; +} +#endif /* CONFIG_NVME_VERBOSE_ERRORS */ +#endif /* _NVME_H */
include/linux/nvme.h +1 -0
@@ -1636,6 +1636,7 @@ enum {NVME_SC_HOST_ABORTED_CMD =0x371 ,NVME_SC_CRD =0x1800 , +NVME_SC_MORE =0x2000 , NVME_SC_DNR = 0x4000, };
Signature · 1 line
2.29.0
Re: [PATCH V7 1/1] nvme-core: Add verbose error logging
Quoted 2 lines · Chaitanya Kulkarni
From: Chaitanya Kulkarni <[email protected]>
I've no idea how above line got added, see [1] this is how header of original patch looks like.
Quoted 6 lines
From: Alan Adamson <[email protected]>
Improves logging of NVMe errors. If
NVME_VERBOSE_ERRORSis configured, a verbose description of the error is logged, otherwise only status codes/bits is logged.
Quoted 7 lines
Signed-off-by Chaitanya Kulkarni <[email protected]>[kch]: fix several nits, cosmetics, and trim down code.
Signed-off-by Martin K. Petersen <[email protected]>Signed-off-by Alan Adamson <[email protected]>Reviewed-by Himanshu Madhani <[email protected]>Reviewed-by Keith Busch <[email protected]>---
[1] Header of original patch :-
From 96fab6f647458683011e01da550ee4820a44f7e2 Mon Sep 17 00:00:00 2001
From: Chaitanya Kulkarni <[email protected]>
Date: Wed, 2 Feb 2022 16:58:53 -0800
Subject: [PATCH V7 1/1] nvme-core: Add verbose error logging
From: Alan Adamson <[email protected]>
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.
[kch]: fix several nits, cosmetics, and trim down code.
---
Sagi Grimberg
maintainerRe: [PATCH V7 1/1] nvme-core: Add verbose error logging
Quoted 6 lines
Quoted 3 lines
From: Chaitanya Kulkarni <[email protected]>
I've no idea how above line got added, see [1] this is how header of original patch looks like.
You managed to confuse me...
You sent this v7 on behalf of Alan?
Re: [PATCH V7 1/1] nvme-core: Add verbose error logging
Quoted 9 lines · Sagi Grimberg
Quoted 6 lines
Quoted 3 lines
From: Chaitanya Kulkarni <[email protected]>
I've no idea how above line got added, see [1] this is how header of original patch looks like.
You managed to confuse me...
You sent this v7 on behalf of Alan?
Yes, sorry.
Christoph Hellwig
maintainerRe: [PATCH V7 1/1] nvme-core: Add verbose error logging
In reply to Chaitanya KulkarniAlan, does this good for your with the author line fixed up?
Re: [PATCH V7 1/1] nvme-core: Add verbose error logging
Yes it does.
Quoted 3 lines · Christoph Hellwig
Alan, does this good for your with the author line fixed up?
Thanks,
applied to nvme-5.18.
Alan,
Quoted 4 lines · Christoph Hellwig
Thanks,
applied to nvme-5.18.
Can you please write a block tests for this ?
-ck
Quoted 13 lines · Chaitanya Kulkarni
Alan,
Quoted 4 lines · Christoph Hellwig
Thanks,
applied to nvme-5.18.
Can you please write a block tests for this ?
Definitely.
Alan
Quoted 4 lines
-ck