nvme: add passthrough error logging opt-in
v2 cover nvme: add passthrough error logging opt-in
v2:
- Included Pankaj Raghav's patch 'nvme: ignore starting sector while error logging for passthrough requests' with a couple changes.
- Moved error_logging flag to nvme_ctrl structure
- The entire nvme-debugfs.c does not need to be guarded by #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS.
- Use IS_ENABLED((CONFIG_NVME_ERROR_LOGGING_DEBUG_FS)) to determine if error logging should be initialized.
- Various other nits.
Commit d7ac8dca938c ("nvme: quiet user passthrough command errors") disabled error logging for user passthrough commands. This commit adds the ability to opt in to passthrough error logging via debugfs.
Currently nvme uses debugfs for nvme fault injection. A change is needed to extend the nvme debugfs implementation to go beyond error injection.
Move Fault Injection to nvme-debugfs.c. Add new config parameter (CONFIG_NVME_FAULT_INJECTION_DEBUG_FS) which enables the compilation of Fault Injection functionality. Other consumers
of nvme-debugfs can be added without requiring Fault Injection.
Add new consumer of nvme-debugfs (CONFIG_NVME_ERROR_LOGGING_DEBUG_FS) that provides the ability of passthrough error logging.
To enable passthrough error logging:
echo 1 > /sys/kernel/debug/nvme0/error-logging
To disable passthrough error logging:
echo 0 > /sys/kernel/debug/nvme0/error-logging
By default, passthrough error logging will remain disabled.
RFC v2 1/3 nvme: move fault injector to nvme-debugfs.c
Move the nvme fault injector code associated with debugfs into nvme-debugfs.c (new file) so all nvme debugfs associated can reside in a common place.
CONFIG_NVME_FAULT_INJECTION_DEBUG_FS needs to be enabled to be able to use fault injection.
---
drivers/nvme/host/Kconfig | 6 ++
drivers/nvme/host/Makefile | 2 +-
drivers/nvme/host/core.c | 11 ++--
.../host/{fault_inject.c => nvme-debugfs.c} | 56 +++++++++----------
drivers/nvme/host/nvme.h | 31 +++++-----
5 files changed, 59 insertions(+), 47 deletions(-)
rename drivers/nvme/host/{fault_inject.c => nvme-debugfs.c} (60%)drivers/nvme/host/Kconfig +6 -0
@@ -32,6 +32,12 @@ config NVME_VERBOSE_ERRORS error translation table will grow the kernel image size by about 4 KB. +config NVME_FAULT_INJECTION_DEBUG_FS + bool "NVMe Fault Injection" + depends on FAULT_INJECTION_DEBUG_FS + help + This enables NVMe Fault Injection through debugfs. + config NVME_HWMON bool "NVMe hardware monitoring" depends on (NVME_CORE=y && HWMON=y) || (NVME_CORE=m && HWMON)
drivers/nvme/host/Makefile +1 -1
@@ -15,7 +15,7 @@ nvme-core-$(CONFIG_NVME_VERBOSE_ERRORS) += constants.o nvme-core-$(CONFIG_TRACING) += trace.o nvme-core-$(CONFIG_NVME_MULTIPATH) += multipath.o nvme-core-$(CONFIG_BLK_DEV_ZONED) += zns.o -nvme-core-$(CONFIG_FAULT_INJECTION_DEBUG_FS) += fault_inject.o +nvme-core-$(CONFIG_FAULT_INJECTION_DEBUG_FS) += nvme-debugfs.o nvme-core-$(CONFIG_NVME_HWMON) += hwmon.o nvme-core-$(CONFIG_NVME_AUTH) += auth.o
drivers/nvme/host/core.c +7 -4
@@ -4336,7 +4336,9 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)nvme_add_ns_cdev (ns);nvme_mpath_add_disk (ns, info->anagrpid); -nvme_fault_inject_init (&ns->fault_inject, ns->disk->disk_name); + +nvme_debugfs_init (&ns->debugfs, ns->disk->disk_name); +nvme_fault_inject_init (&ns->debugfs);return ;
@@ -4367,7 +4369,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)clear_bit (NVME_NS_READY , &ns->flags);set_capacity (ns->disk,0 ); -nvme_fault_inject_fini (&ns->fault_inject); +nvme_debugfs_remove (&ns->debugfs);/* * Ensure that !NVME_NS_READY is seen by other threads to prevent
@@ -5064,7 +5066,7 @@ EXPORT_SYMBOL_GPL(nvme_start_ctrl);void nvme_uninit_ctrl (struct nvme_ctrl *ctrl) {nvme_hwmon_exit (ctrl); -nvme_fault_inject_fini (&ctrl->fault_inject); +nvme_debugfs_remove (&ctrl->debugfs);dev_pm_qos_hide_latency_tolerance (ctrl->device);cdev_device_del (&ctrl->cdev, ctrl->device);nvme_put_ctrl (ctrl);
@@ -5189,7 +5191,8 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,dev_pm_qos_update_user_latency_tolerance (ctrl->device,min (default_ps_max_latency_us, (unsigned long )S32_MAX )); -nvme_fault_inject_init (&ctrl->fault_inject,dev_name (ctrl->device)); +nvme_debugfs_init (&ctrl->debugfs,dev_name (ctrl->device)); +nvme_fault_inject_init (&ctrl->debugfs);nvme_mpath_init_ctrl (ctrl); ret =nvme_auth_init_ctrl (ctrl);if (ret)
drivers/nvme/host/nvme-debugfs.c renamed from drivers/nvme/host/fault_inject.c +27 -29
98 lines not on this page · raw message
drivers/nvme/host/nvme.h +18 -13
@@ -231,12 +231,16 @@ enum nvme_ctrl_state {struct nvme_fault_inject {#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS struct fault_attr attr; -struct dentry *parent;bool dont_retry;/* DNR, do not retry */ u16 status;/* status code */ #endif }; +struct nvme_debugfs { +struct dentry *parent; +struct nvme_fault_inject fault_inject; +}; +enum nvme_ctrl_flags {NVME_CTRL_FAILFAST_EXPIRED =0 ,NVME_CTRL_ADMIN_Q_STOPPED =1 ,
@@ -370,7 +374,7 @@ struct nvme_ctrl {struct page *discard_page;unsigned long discard_page_busy; -struct nvme_fault_inject fault_inject; +struct nvme_debugfs debugfs;enum nvme_ctrl_type cntrltype;enum nvme_dctype dctype;
@@ -496,8 +500,7 @@ struct nvme_ns {struct cdev cdev;struct device cdev_device; -struct nvme_fault_inject fault_inject; - +struct nvme_debugfs debugfs; };/* NVMe ns supports metadata actions by the controller (generate/strip) */
@@ -598,21 +601,23 @@ static inline void nvme_print_device_info(struct nvme_ctrl *ctrl) }#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS -void nvme_fault_inject_init (struct nvme_fault_inject *fault_inj, -const char *dev_name); -void nvme_fault_inject_fini (struct nvme_fault_inject *fault_inject); +void nvme_debugfs_init (struct nvme_debugfs *debugfs, +const char *dev_name); +void nvme_debugfs_remove (struct nvme_debugfs *debugfs); +#else +static inline void nvme_debugfs_init (struct nvme_debugfs *debugfs, +const char *dev_name) {} +static inline void nvme_debugfs_remove (struct nvme_debugfs *debugfs) {} +#endif +#ifdef CONFIG_NVME_FAULT_INJECTION_DEBUG_FS +void nvme_fault_inject_init (struct nvme_debugfs *debugfs);void nvme_should_fail (struct request *req);#else -static inline void nvme_fault_inject_init (struct nvme_fault_inject *fault_inj, -const char *dev_name) -{ -} -static inline void nvme_fault_inject_fini (struct nvme_fault_inject *fault_inj) +static inline void nvme_fault_inject_init (struct nvme_debugfs *debugfs) { }static inline void nvme_should_fail (struct request *req) {}#endif -bool nvme_wait_reset (struct nvme_ctrl *ctrl);int nvme_try_sched_reset (struct nvme_ctrl *ctrl);
Signature · 1 line
2.31.1
Re: [RFC v2 1/3] nvme: move fault injector to nvme-debugfs.c
Could we still retain the fault_inject.c code to avoid #ifdef for the fault_inject code in debugfs.c?
We have two options:
- We could have both fault_inject.c and nvme-debugfs.c. Move the fault inject code from nvme-debugfs.c to fault_inject.c so that we get rid of #ifdefs from nvme-debugfs.c.
- As the code for nvme-debugfs.c itself is not a lot (just 3 small functions including the next patch) apart from the fault_inject code, we could move them to the header with the appropriate #ifdefs and conditionally link the fault_inject.c code as before.
Let me know what you think.
--
Pankaj
Quoted 17 lines · Alan Adamson
Move the nvme fault injector code associated with debugfs into
nvme-debugfs.c(new file) so all nvme debugfs associated can reside in a common place.
CONFIG_NVME_FAULT_INJECTION_DEBUG_FSneeds to be enabled to be able to use fault injection.Signed-off-by Alan Adamson <[email protected]>--- drivers/nvme/host/Kconfig | 6 ++ drivers/nvme/host/Makefile | 2 +- drivers/nvme/host/core.c | 11 ++-- .../host/{fault_inject.c => nvme-debugfs.c} | 56 +++++++++---------- drivers/nvme/host/nvme.h | 31 +++++----- 5 files changed, 59 insertions(+), 47 deletions(-) rename drivers/nvme/host/{fault_inject.c => nvme-debugfs.c} (60%)
Christoph Hellwig
maintainerRe: [RFC v2 1/3] nvme: move fault injector to nvme-debugfs.c
In reply to Alan AdamsonQuoted 6 lines · Alan Adamson
Move the nvme fault injector code associated with debugfs into
nvme-debugfs.c(new file) so all nvme debugfs associated can reside in a common place.
CONFIG_NVME_FAULT_INJECTION_DEBUG_FSneeds to be enabled to be able to use fault injection.
It feels a bit pointless to me to have a separate file for what even with the next patch is way under 100 lines of code.
Keith, Sagi, any opinion?
Sagi Grimberg
maintainerRe: [RFC v2 1/3] nvme: move fault injector to nvme-debugfs.c
Quoted 5 lines
Quoted 5 lines
Move the nvme fault injector code associated with debugfs into
nvme-debugfs.c(new file) so all nvme debugfs associated can reside in a common place.
Quoted 7 lines
Quoted 2 lines
CONFIG_NVME_FAULT_INJECTION_DEBUG_FSneeds to be enabled to be able to use fault injection.It feels a bit pointless to me to have a separate file for what even with the next patch is way under 100 lines of code.
Keith, Sagi, any opinion?
If we add stuff to debugfs other than fault injection, maybe the file is better off called debugfs.c instead of fault_inject.c
In that case we can have nvme_debugfs_init(ns)/nvme_debugfs_fini that would do what it needs based on config opts (fault_inject and error_logging).
I don't see why we need a separate CONFIG_NVME_FAULT_INJECTION_DEBUG_FS though...
RFC v2 2/3 nvme: add error logging opt-in
In reply to Alan AdamsonCommit d7ac8dca938c ("nvme: quiet user passthrough command errors") disabled error logging for user passthrough commands. This commit adds the ability to opt-in to passthrough error logging.
To enable passthrough error logging:
echo 1 > /sys/kernel/debug/nvme0/error-logging
To disable passthrough error logging:
echo 0 > /sys/kernel/debug/nvme0/error-logging
By default, passthrough error logging will remain disabled.
CONFIG_NVME_ERROR_LOGGING_DEBUG_FS needs to be enabled to to enable passthrough error logging.
--- drivers/nvme/host/Kconfig | 6 ++++++ drivers/nvme/host/core.c | 14 ++++++++++++-- drivers/nvme/host/nvme-debugfs.c | 7 +++++-- drivers/nvme/host/nvme.h | 2 ++ 4 files changed, 25 insertions(+), 4 deletions(-)
drivers/nvme/host/Kconfig +6 -0
@@ -38,6 +38,12 @@ config NVME_FAULT_INJECTION_DEBUG_FS help This enables NVMe Fault Injection through debugfs. +config NVME_ERROR_LOGGING_DEBUG_FS + bool "NVMe Passthrough Error Logging" + depends on FAULT_INJECTION_DEBUG_FS + help + This enables NVMe Passthrough command error logging. + config NVME_HWMON bool "NVMe hardware monitoring" depends on (NVME_CORE=y && HWMON=y) || (NVME_CORE=m && HWMON)
drivers/nvme/host/core.c +12 -2
@@ -666,6 +666,8 @@ static inline void nvme_clear_nvme_request(struct request *req)/* initialize a passthrough request */ void nvme_init_request (struct request *req,struct nvme_command *cmd) { +struct nvme_request *nr =nvme_req (req); +if (req->q->queuedata) req->timeout =NVME_IO_TIMEOUT ;else /* no queuedata implies admin queue */
@@ -678,8 +680,11 @@ void nvme_init_request(struct request *req, struct nvme_command *cmd)if (req->mq_hctx->type ==HCTX_TYPE_POLL ) req->cmd_flags |=REQ_POLLED ;nvme_clear_nvme_request (req); - req->rq_flags |=RQF_QUIET ; -memcpy (nvme_req (req)->cmd, cmd,sizeof (*cmd)); + +if (!nr->ctrl->error_logging) + req->rq_flags |=RQF_QUIET ; + +memcpy (nr->cmd, cmd,sizeof (*cmd)); }EXPORT_SYMBOL_GPL (nvme_init_request);
@@ -5193,6 +5198,11 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,nvme_debugfs_init (&ctrl->debugfs,dev_name (ctrl->device));nvme_fault_inject_init (&ctrl->debugfs); + + ctrl->error_logging = false; +if (IS_ENABLED (CONFIG_NVME_ERROR_LOGGING_DEBUG_FS )) +nvme_error_logging_init (ctrl); +nvme_mpath_init_ctrl (ctrl); ret =nvme_auth_init_ctrl (ctrl);if (ret)
drivers/nvme/host/nvme-debugfs.c +5 -2
@@ -8,7 +8,6 @@#include <linux/moduleparam.h> #include "nvme.h" -#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS void nvme_debugfs_init (struct nvme_debugfs *debugfs,const char *dev_name) {
@@ -77,4 +76,8 @@ void nvme_should_fail(struct request *req) }EXPORT_SYMBOL_GPL (nvme_should_fail);#endif /* CONFIG_NVME_FAULT_INJECTION_DEBUG_FS */ -#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ +void nvme_error_logging_init (struct nvme_ctrl *ctrl) +{ +debugfs_create_bool ("error-logging" ,0600 , ctrl->debugfs.parent, + &ctrl->error_logging); +}
drivers/nvme/host/nvme.h +2 -0
@@ -252,6 +252,7 @@ struct nvme_ctrl {bool comp_seen;enum nvme_ctrl_state state;bool identified; +bool error_logging;spinlock_t lock;struct mutex scan_lock;const struct nvme_ctrl_ops *ops;
@@ -618,6 +619,7 @@ static inline void nvme_fault_inject_init(struct nvme_debugfs *debugfs) }static inline void nvme_should_fail (struct request *req) {}#endif +void nvme_error_logging_init (struct nvme_ctrl *ctrl);bool nvme_wait_reset (struct nvme_ctrl *ctrl);int nvme_try_sched_reset (struct nvme_ctrl *ctrl);
Signature · 1 line
2.31.1
Christoph Hellwig
maintainerRe: [RFC v2 2/3] nvme: add error logging opt-in
Quoted 7 lines · Alan Adamson
Commit
d7ac8dca938c("nvme: quiet user passthrough command errors") disabled error logging for user passthrough commands. This commit adds the ability to opt-in to passthrough error logging.To enable passthrough error logging:
echo 1 >/sys/kernel/debug/nvme0/error-logging
Quoted 7 lines
To disable passthrough error logging:
echo 0 >/sys/kernel/debug/nvme0/error-loggingBy default, passthrough error logging will remain disabled.
CONFIG_NVME_ERROR_LOGGING_DEBUG_FSneeds to be enabled to to enable passthrough error logging.
Any reason to do this in debugfs vs sysfs which is someting that we can a handle too much more easily?
Also why do we need a config option for a trivial mount of code?
Sagi Grimberg
maintainerRe: [RFC v2 2/3] nvme: add error logging opt-in
Quoted 13 lines
Quoted 13 lines
Commit
d7ac8dca938c("nvme: quiet user passthrough command errors") disabled error logging for user passthrough commands. This commit adds the ability to opt-in to passthrough error logging.To enable passthrough error logging:
echo 1 >/sys/kernel/debug/nvme0/error-loggingTo disable passthrough error logging:
echo 0 >/sys/kernel/debug/nvme0/error-loggingBy default, passthrough error logging will remain disabled.
Quoted 7 lines
Quoted 2 lines
CONFIG_NVME_ERROR_LOGGING_DEBUG_FSneeds to be enabled to to enable passthrough error logging.Any reason to do this in debugfs vs sysfs which is someting that we can a handle too much more easily?
Also why do we need a config option for a trivial mount of code?
I think it is because the fault_inject thing is dependent on a config. But if we move fault injection to a debugfs init/fini we can hide this stuff without a config option
Re: [RFC v2 2/3] nvme: add error logging opt-in
In reply to Christoph HellwigQuoted 11 lines · Christoph Hellwig
Quoted 10 lines · Alan Adamson
Commit
d7ac8dca938c("nvme: quiet user passthrough command errors") disabled error logging for user passthrough commands. This commit adds the ability to opt-in to passthrough error logging.To enable passthrough error logging:
echo 1 >/sys/kernel/debug/nvme0/error-loggingTo disable passthrough error logging:
echo 0 >/sys/kernel/debug/nvme0/error-logging
Quoted 9 lines
Quoted 4 lines
By default, passthrough error logging will remain disabled.
CONFIG_NVME_ERROR_LOGGING_DEBUG_FSneeds to be enabled to to enable passthrough error logging.Any reason to do this in debugfs vs sysfs which is someting that we can a handle too much more easily?
Also why do we need a config option for a trivial mount of code?
Putting it in sysfs may make more sense and not require debugfs to be configured. See below.
Alan
drivers/nvme/host/core.c +0 -0
@@ -337,6 +337,49 @@ static void nvme_log_error(struct request *req)
nr->status & NVME_SC_DNR ? "DNR " : ""); }
+static void nvme_log_error_passthrough(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), %s (sct 0x%x / sc 0x%x) %s%s: " + "cdw10=0x%x cdw11=0x%x cdw12=0x%x cdw13=0x%x cdw14=0x%x cdw15=0x%x\n", + ns->disk ? ns->disk->disk_name : "?",
+ nvme_get_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 " : "",
+ nr->cmd->common.cdw10,
+ nr->cmd->common.cdw11,
+ nr->cmd->common.cdw12,
+ nr->cmd->common.cdw13,
+ nr->cmd->common.cdw14,
+ nr->cmd->common.cdw15);
+ return;
+ }
+
+ pr_err_ratelimited("%s: %s(0x%x), %s (sct 0x%x / sc 0x%x) %s%s: "
+ "cdw10=0x%x cdw11=0x%x cdw12=0x%x cdw13=0x%x cdw14=0x%x cdw15=0x%x\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 " : "",
+ nr->cmd->common.cdw10,
+ nr->cmd->common.cdw11,
+ nr->cmd->common.cdw12,
+ nr->cmd->common.cdw13,
+ nr->cmd->common.cdw14,
+ nr->cmd->common.cdw15);
+}
+
enum nvme_disposition {
COMPLETE,
RETRY,
@@ -381,8 +424,12 @@ static inline void nvme_end_req(struct request *req) {
blk_status_t status = nvme_error_status(nvme_req(req)->status);
- if (unlikely(nvme_req(req)->status && !(req->rq_flags & RQF_QUIET)))
- nvme_log_error(req);
+ if (unlikely(nvme_req(req)->status && !(req->rq_flags & RQF_QUIET))) { + if (blk_rq_is_passthrough(req))
+ nvme_log_error_passthrough(req);
+ else
+ nvme_log_error(req);
+ }
nvme_end_req_zoned(req);
nvme_trace_bio_complete(req);
if (req->cmd_flags & REQ_NVME_MPATH)
@@ -666,6 +713,8 @@ static inline void nvme_clear_nvme_request(struct request *req) /* initialize a passthrough request */
void nvme_init_request(struct request *req, struct nvme_command *cmd)
{
+ struct nvme_request *nr = nvme_req(req);
+
if (req->q->queuedata)
req->timeout = NVME_IO_TIMEOUT;
else /* no queuedata implies admin queue */
@@ -678,8 +727,10 @@ void nvme_init_request(struct request *req, struct nvme_command *cmd) if (req->mq_hctx->type == HCTX_TYPE_POLL)
req->cmd_flags |= REQ_POLLED;
nvme_clear_nvme_request(req);
- req->rq_flags |= RQF_QUIET;
- memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd));
+ if (!nr->ctrl->error_logging)
+ req->rq_flags |= RQF_QUIET;
+
+ memcpy(nr->cmd, cmd, sizeof(*cmd));
}
EXPORT_SYMBOL_GPL(nvme_init_request);
@@ -3418,6 +3469,37 @@ static ssize_t nvme_sysfs_rescan(struct device *dev, }
static DEVICE_ATTR(rescan_controller, S_IWUSR, NULL, nvme_sysfs_rescan);
+static ssize_t nvme_passthrough_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+ if (ctrl->error_logging)
+ return sysfs_emit(buf, "on\n");
+ else
+ return sysfs_emit(buf, "off\n");
+}
+
+static ssize_t nvme_passthrough_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+ int passthrough_enable, err;
+
+ err = kstrtoint(buf, 10, &passthrough_enable);
+ if (err)
+ return -EINVAL;
+
+ if (passthrough_enable)
+ ctrl->error_logging = true;
+ else
+ ctrl->error_logging = false;
+
+ return count;
+}
+
+static DEVICE_ATTR(passthrough_logging, S_IRUGO | S_IWUSR, nvme_passthrough_show, nvme_passthrough_store); +
static inline struct nvme_ns_head *dev_to_ns_head(struct device *dev)
{
struct gendisk *disk = dev_to_disk(dev);
@@ -3926,6 +4008,7 @@ static struct attribute *nvme_dev_attrs[] = { &dev_attr_dhchap_secret.attr,
&dev_attr_dhchap_ctrl_secret.attr,
#endif
+ &dev_attr_passthrough_logging.attr,
NULL
};
@@ -5125,6 +5208,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, int ret;
ctrl->state = NVME_CTRL_NEW;
+ ctrl->error_logging = false; clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); spin_lock_init(&ctrl->lock); mutex_init(&ctrl->scan_lock);
drivers/nvme/host/nvme.h +0 -0
@@ -248,6 +248,7 @@ struct nvme_ctrl {
bool comp_seen;
enum nvme_ctrl_state state;
bool identified;
+ bool error_logging;
spinlock_t lock;
struct mutex scan_lock;
const struct nvme_ctrl_ops *ops;
Signature · 1 line
2.31.1
Sagi Grimberg
maintainerRe: [RFC v2 2/3] nvme: add error logging opt-in
Quoted 145 lines
Quoted 11 lines
Quoted 11 lines
Commit
d7ac8dca938c("nvme: quiet user passthrough command errors") disabled error logging for user passthrough commands. This commit adds the ability to opt-in to passthrough error logging.To enable passthrough error logging:
echo 1 >/sys/kernel/debug/nvme0/error-loggingTo disable passthrough error logging:
echo 0 >/sys/kernel/debug/nvme0/error-loggingQuoted 9 lines
Quoted 4 lines
By default, passthrough error logging will remain disabled.
CONFIG_NVME_ERROR_LOGGING_DEBUG_FSneeds to be enabled to to enable passthrough error logging.Any reason to do this in debugfs vs sysfs which is someting that we can a handle too much more easily?
Also why do we need a config option for a trivial mount of code?
Putting it in sysfs may make more sense and not require debugfs to be configured. See below.
Alan
drivers/nvme/host/core.c +43
-0@@ -337,6 +337,49 @@ static void nvme_log_error(struct request *req) nr->status & NVME_SC_DNR ? "DNR " : ""); } +static void nvme_log_error_passthrough (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), %s (sct 0x%x / sc 0x%x) %s%s: " + "cdw10=0x%x cdw11=0x%x cdw12=0x%x cdw13=0x%x cdw14=0x%x cdw15=0x%x\n", + ns->disk ? ns->disk->disk_name : "?", + nvme_get_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 " : "", + nr->cmd->common.cdw10, + nr->cmd->common.cdw11, + nr->cmd->common.cdw12, + nr->cmd->common.cdw13, + nr->cmd->common.cdw14, + nr->cmd->common.cdw15); + return; + } + + pr_err_ratelimited("%s: %s(0x%x), %s (sct 0x%x / sc 0x%x) %s%s: " + "cdw10=0x%x cdw11=0x%x cdw12=0x%x cdw13=0x%x cdw14=0x%x cdw15=0x%x\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 " : "", + nr->cmd->common.cdw10, + nr->cmd->common.cdw11, + nr->cmd->common.cdw12, + nr->cmd->common.cdw13, + nr->cmd->common.cdw14, + nr->cmd->common.cdw15); +} + enum nvme_disposition {COMPLETE,
RETRY,drivers/nvme/host/core.c +8
-2@@ -381,8 +424,12 @@ static inline void nvme_end_req(struct request *req) { blk_status_t status = nvme_error_status(nvme_req(req)->status); - if (unlikely(nvme_req(req)->status && !(req->rq_flags & RQF_QUIET))) - nvme_log_error(req); + if (unlikely(nvme_req(req)->status && !(req->rq_flags & RQF_QUIET))) { + if (blk_rq_is_passthrough(req)) + nvme_log_error_passthrough(req); + else + nvme_log_error(req); + } nvme_end_req_zoned(req); nvme_trace_bio_complete(req); if (req->cmd_flags & REQ_NVME_MPATH)@@ -666,6 +713,8 @@ static inline void nvme_clear_nvme_request(struct request *req) /* initialize a passthrough request */ void nvme_init_request(struct request *req, struct nvme_command *cmd) { + struct nvme_request *nr = nvme_req(req); + if (req->q->queuedata) req->timeout = NVME_IO_TIMEOUT;else /* no queuedata implies admin queue */
drivers/nvme/host/core.c +25
-2@@ -678,8 +727,10 @@ void nvme_init_request(struct request *req, struct nvme_command *cmd) if (req->mq_hctx->type == HCTX_TYPE_POLL) req->cmd_flags |= REQ_POLLED; nvme_clear_nvme_request(req); - req->rq_flags |= RQF_QUIET; - memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd)); + if (!nr->ctrl->error_logging) + req->rq_flags |= RQF_QUIET; + + memcpy(nr->cmd, cmd, sizeof(*cmd)); } EXPORT_SYMBOL_GPL(nvme_init_request);@@ -3418,6 +3469,37 @@ static ssize_t nvme_sysfs_rescan(struct device *dev, } static DEVICE_ATTR(rescan_controller, S_IWUSR, NULL, nvme_sysfs_rescan); +static ssize_t nvme_passthrough_show (struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + + if (ctrl->error_logging) + return sysfs_emit(buf, "on\n"); + else + return sysfs_emit(buf, "off\n"); +} + +static ssize_t nvme_passthrough_store (struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + int passthrough_enable, err; + + err = kstrtoint(buf, 10, &passthrough_enable); + if (err) + return -EINVAL; +
drivers/nvme/host/core.c static ssize_t nvme_sysfs_rescan(struct device *dev, · line 3502
Quoted 10 lines
drivers/nvme/host/core.c +9
-0+ if (passthrough_enable) + ctrl->error_logging = true; + else + ctrl->error_logging = false; + + return count; +} + +static DEVICE_ATTR(passthrough_logging, S_IRUGO | S_IWUSR, nvme_passthrough_show, nvme_passthrough_store);
Is this something that we need per ctrl? My assumption is that if someone wants this, one would enable it for all controllers. Maybe this should be a modparam instead?
Re: [RFC v2 2/3] nvme: add error logging opt-in
Quoted 156 lines · Sagi Grimberg
Quoted 156 lines
Quoted 11 lines
Quoted 11 lines
Commit
d7ac8dca938c("nvme: quiet user passthrough command errors") disabled error logging for user passthrough commands. This commit adds the ability to opt-in to passthrough error logging.To enable passthrough error logging:
echo 1 >/sys/kernel/debug/nvme0/error-loggingTo disable passthrough error logging:
echo 0 >/sys/kernel/debug/nvme0/error-loggingQuoted 9 lines
Quoted 4 lines
By default, passthrough error logging will remain disabled.
CONFIG_NVME_ERROR_LOGGING_DEBUG_FSneeds to be enabled to to enable passthrough error logging.Any reason to do this in debugfs vs sysfs which is someting that we can a handle too much more easily?
Also why do we need a config option for a trivial mount of code?
Putting it in sysfs may make more sense and not require debugfs to be configured. See below.
Alan
drivers/nvme/host/core.c +7
-0@@ -337,6 +337,49 @@ static void nvme_log_error(struct request *req) nr->status & NVME_SC_DNR ? "DNR " : ""); } +static void nvme_log_error_passthrough (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), %s (sct 0x%x / sc 0x%x)%s%s: "
+ "cdw10=0x%x cdw11=0x%x cdw12=0x%x cdw13=0x%x cdw14=0x%x cdw15=0x%x\n",
+ns->disk?ns->disk->disk_name: "?",
+nvme_get_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 " : "",
+nr->cmd->common.cdw10,
+nr->cmd->common.cdw11,
+nr->cmd->common.cdw12,
+nr->cmd->common.cdw13,
+nr->cmd->common.cdw14,
+nr->cmd->common.cdw15);
+ return;
+ }
+
+ pr_err_ratelimited("%s: %s(0x%x), %s (sct 0x%x / sc 0x%x) %s%s: " + "cdw10=0x%x cdw11=0x%x cdw12=0x%x cdw13=0x%x cdw14=0x%x cdw15=0x%x\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 " : "",
+nr->cmd->common.cdw10,
+nr->cmd->common.cdw11,
+nr->cmd->common.cdw12,
+nr->cmd->common.cdw13,
+nr->cmd->common.cdw14,
+nr->cmd->common.cdw15);drivers/nvme/host/core.c +2
-0+} +enum
nvme_disposition{
COMPLETE,
RETRY,drivers/nvme/host/core.c +6
-2@@ -381,8 +424,12 @@ static inline void nvme_end_req(struct request *req) { blk_status_t status = nvme_error_status(nvme_req(req)->status); - if (unlikely(nvme_req(req)->status && !(req->rq_flags & RQF_QUIET))) - nvme_log_error(req); + if (unlikely(nvme_req(req)->status && !(req->rq_flags &RQF_QUIET ))) { + if (blk_rq_is_passthrough(req)) + nvme_log_error_passthrough(req); + else + nvme_log_error(req); + }
nvme_end_req_zoned(req);
nvme_trace_bio_complete(req);
if (req->cmd_flags&REQ_NVME_MPATH)drivers/nvme/host/core.c +2
-0@@ -666,6 +713,8 @@ static inline void nvme_clear_nvme_request(struct request *req) /* initialize a passthrough request */ void nvme_init_request(struct request *req, struct nvme_command *cmd) { + struct nvme_request *nr = nvme_req(req); + if (req->q->queuedata) req->timeout = NVME_IO_TIMEOUT;else /* no queuedata implies admin queue */
drivers/nvme/host/core.c +31
-2@@ -678,8 +727,10 @@ void nvme_init_request(struct request *req, struct nvme_command *cmd) if (req->mq_hctx->type == HCTX_TYPE_POLL) req->cmd_flags |= REQ_POLLED; nvme_clear_nvme_request(req); - req->rq_flags |= RQF_QUIET; - memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd)); + if (!nr->ctrl->error_logging) + req->rq_flags |= RQF_QUIET; + + memcpy(nr->cmd, cmd, sizeof(*cmd)); } EXPORT_SYMBOL_GPL(nvme_init_request);@@ -3418,6 +3469,37 @@ static ssize_t nvme_sysfs_rescan(struct device *dev, } static DEVICE_ATTR(rescan_controller, S_IWUSR, NULL, nvme_sysfs_rescan); +static ssize_t nvme_passthrough_show (struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + + if (ctrl->error_logging) + return sysfs_emit(buf, "on\n"); + else + return sysfs_emit(buf, "off\n"); +} + +static ssize_t nvme_passthrough_store (struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + int passthrough_enable, err; + + err = kstrtoint(buf, 10, &passthrough_enable); + if (err) + return -EINVAL; + + if (passthrough_enable) + ctrl->error_logging = true; + else + ctrl->error_logging = false; + + return count;
Quoted 8 lines
drivers/nvme/host/core.c static ssize_t nvme_sysfs_rescan(struct device · line 3503
Quoted 4 lines
drivers/nvme/host/core.c +3
-0+} + +static DEVICE_ATTR(passthrough_logging, S_IRUGO | S_IWUSR, nvme_passthrough_show, nvme_passthrough_store);Is this something that we need per ctrl? My assumption is that if someone wants this, one would enable it for all controllers. Maybe this should be a modparam instead?
Maybe both? Have the ability to set the system-wide default value via modparam and sysfs to change it per ctrl?
Alan
Sagi Grimberg
maintainerRe: [RFC v2 2/3] nvme: add error logging opt-in
Quoted 165 lines
Quoted 156 lines
Quoted 156 lines
Quoted 11 lines
Quoted 11 lines
Commit
d7ac8dca938c("nvme: quiet user passthrough command errors") disabled error logging for user passthrough commands. This commit adds the ability to opt-in to passthrough error logging.To enable passthrough error logging:
echo 1 >/sys/kernel/debug/nvme0/error-loggingTo disable passthrough error logging:
echo 0 >/sys/kernel/debug/nvme0/error-loggingQuoted 9 lines
Quoted 4 lines
By default, passthrough error logging will remain disabled.
CONFIG_NVME_ERROR_LOGGING_DEBUG_FSneeds to be enabled to to enable passthrough error logging.Any reason to do this in debugfs vs sysfs which is someting that we can a handle too much more easily?
Also why do we need a config option for a trivial mount of code?
Putting it in sysfs may make more sense and not require debugfs to be configured. See below.
Alan
drivers/nvme/host/core.c +7
-0@@ -337,6 +337,49 @@ static void nvme_log_error(struct request *req) nr->status & NVME_SC_DNR ? "DNR " : ""); } +static void nvme_log_error_passthrough (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), %s (sct 0x%x / sc 0x%x)%s%s: "
+ "cdw10=0x%x cdw11=0x%x cdw12=0x%x cdw13=0x%x cdw14=0x%x cdw15=0x%x\n",
+ns->disk?ns->disk->disk_name: "?",
+nvme_get_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 " : "",
+nr->cmd->common.cdw10,
+nr->cmd->common.cdw11,
+nr->cmd->common.cdw12,
+nr->cmd->common.cdw13,
+nr->cmd->common.cdw14,
+nr->cmd->common.cdw15);
+ return;
+ }
+
+ pr_err_ratelimited("%s: %s(0x%x), %s (sct 0x%x / sc 0x%x) %s%s: " + "cdw10=0x%x cdw11=0x%x cdw12=0x%x cdw13=0x%x cdw14=0x%x cdw15=0x%x\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 " : "",
+nr->cmd->common.cdw10,
+nr->cmd->common.cdw11,
+nr->cmd->common.cdw12,
+nr->cmd->common.cdw13,
+nr->cmd->common.cdw14,
+nr->cmd->common.cdw15);drivers/nvme/host/core.c +2
-0+} +enum
nvme_disposition{
COMPLETE,
RETRY,drivers/nvme/host/core.c +6
-2@@ -381,8 +424,12 @@ static inline void nvme_end_req(struct request *req) { blk_status_t status = nvme_error_status(nvme_req(req)->status); - if (unlikely(nvme_req(req)->status && !(req->rq_flags & RQF_QUIET))) - nvme_log_error(req); + if (unlikely(nvme_req(req)->status && !(req->rq_flags &RQF_QUIET ))) { + if (blk_rq_is_passthrough(req)) + nvme_log_error_passthrough(req); + else + nvme_log_error(req); + }
nvme_end_req_zoned(req);
nvme_trace_bio_complete(req);
if (req->cmd_flags&REQ_NVME_MPATH)drivers/nvme/host/core.c +2
-0@@ -666,6 +713,8 @@ static inline void nvme_clear_nvme_request(struct request *req) /* initialize a passthrough request */ void nvme_init_request(struct request *req, struct nvme_command *cmd) { + struct nvme_request *nr = nvme_req(req); + if (req->q->queuedata) req->timeout = NVME_IO_TIMEOUT;else /* no queuedata implies admin queue */
drivers/nvme/host/core.c +31
-2@@ -678,8 +727,10 @@ void nvme_init_request(struct request *req, struct nvme_command *cmd) if (req->mq_hctx->type == HCTX_TYPE_POLL) req->cmd_flags |= REQ_POLLED; nvme_clear_nvme_request(req); - req->rq_flags |= RQF_QUIET; - memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd)); + if (!nr->ctrl->error_logging) + req->rq_flags |= RQF_QUIET; + + memcpy(nr->cmd, cmd, sizeof(*cmd)); } EXPORT_SYMBOL_GPL(nvme_init_request);@@ -3418,6 +3469,37 @@ static ssize_t nvme_sysfs_rescan(struct device *dev, } static DEVICE_ATTR(rescan_controller, S_IWUSR, NULL, nvme_sysfs_rescan); +static ssize_t nvme_passthrough_show (struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + + if (ctrl->error_logging) + return sysfs_emit(buf, "on\n"); + else + return sysfs_emit(buf, "off\n"); +} + +static ssize_t nvme_passthrough_store (struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); + int passthrough_enable, err; + + err = kstrtoint(buf, 10, &passthrough_enable); + if (err) + return -EINVAL; + + if (passthrough_enable) + ctrl->error_logging = true; + else + ctrl->error_logging = false; + + return count;Quoted 8 lines
drivers/nvme/host/core.c static ssize_t nvme_sysfs_rescan(struct device · line 3503
Quoted 4 lines
drivers/nvme/host/core.c +3
-0+} + +static DEVICE_ATTR(passthrough_logging, S_IRUGO | S_IWUSR, nvme_passthrough_show, nvme_passthrough_store);Is this something that we need per ctrl? My assumption is that if someone wants this, one would enable it for all controllers. Maybe this should be a modparam instead?
Quoted 1 line
Maybe both? Have the ability to set the system-wide default value via modparam and sysfs to change it per ctrl?
Definitely not both. If per controller setting is needed then lets do that, and if not, lets do a global modparam.
Re: [RFC v2 2/3] nvme: add error logging opt-in
Quoted 8 lines · Sagi Grimberg
Quoted 5 lines
Quoted 3 lines
Is this something that we need per ctrl? My assumption is that if someone wants this, one would enable it for all controllers. Maybe this should be a modparam instead?
Maybe both? Have the ability to set the system-wide default value via modparam and sysfs to change it per ctrl?
Definitely not both. If per controller setting is needed then lets do that, and if not, lets do a global modparam.
I think the use-case for it would be:
- debugging a problematic controller. So you would only need logging enabled for a short time while debugging that controller.
- Some application that is sending passthrough commands to a specific controller.
Its probably best to enable it per controller.
Alan
RFC v2 3/3 nvme: ignore starting sector while error logging for passthrough requests
In reply to Alan AdamsonError log will print a garbage value as the starting LBA for passthrough requests and requests with uninitialized starting sector that return an error.
--- drivers/nvme/host/core.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +28 -1
@@ -306,6 +306,33 @@ static void nvme_retry_req(struct request *req)blk_mq_delay_kick_requeue_list (req->q, delay); } +static inline u64 nvme_log_error_rq_lba (struct nvme_ns *ns,struct request *rq) +{ +struct nvme_request *nr =nvme_req (rq); + +if (blk_rq_is_passthrough (rq)) { +switch (nr->cmd->common.opcode) { +u64 cdw11; + +case nvme_cmd_flush: +case nvme_cmd_write: +case nvme_cmd_read: +case nvme_cmd_write_uncor: +case nvme_cmd_compare: +case nvme_cmd_write_zeroes: +case nvme_cmd_verify: + cdw11 = nr->cmd->common.cdw11; + +return nr->cmd->common.cdw10 | (cdw11 <<32 ); +default : +return 0 ; + } + } +if (blk_rq_pos (rq) == (sector_t)-1 ) +return 0 ; +return nvme_sect_to_lba (ns,blk_rq_pos (rq)); +} +static void nvme_log_error (struct request *req) {struct nvme_ns *ns = req->q->queuedata;
@@ -316,7 +343,7 @@ static void nvme_log_error(struct request *req) 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 )nvme_log_error_rq_lba (ns, 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 */
Signature · 1 line
2.31.1
Christoph Hellwig
maintainerRe: [RFC v2 3/3] nvme: ignore starting sector while error logging for passthrough requests
Yikes, no. Anything that needs to poke into details of passthrough commands is fundamentally wrong. Maybe we need a separate log message for passthrough that is just based on the cdw values instead of trying to decode it.
Sagi Grimberg
maintainerRe: [RFC v2 3/3] nvme: ignore starting sector while error logging for passthrough requests
Quoted 5 lines
Yikes, no. Anything that needs to poke into details of passthrough commands is fundamentally wrong. Maybe we need a separate log message for passthrough that is just based on the cdw values instead of trying to decode it.
Agree
Re: [RFC v2 3/3] nvme: ignore starting sector while error logging for passthrough requests
Quoted 7 lines · Sagi Grimberg
Quoted 5 lines
Yikes, no. Anything that needs to poke into details of passthrough commands is fundamentally wrong. Maybe we need a separate log message for passthrough that is just based on the cdw values instead of trying to decode it.
Agree
We can do something like this:
nvme0: Unknown(0x96), Invalid Command Opcode (sct 0x0 / sc 0x1) DNR : cdw10=0x1 cdw11=0x0 cdw12=0x0 cdw13=0x0 cdw14=0x0 cdw15=0x0
nvme0n1: Read(0x2), LBA Out of Range (sct 0x0 / sc 0x80) DNR : cdw10=0x0 cdw11=0x1 cdw12=0x70000 cdw13=0x0 cdw14=0x0 cdw15=0x0
Alan