public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanyak@nvidia.com>
To: <kbusch@kernel.org>, <hch@lst.de>, <sagi@grimberg.me>
Cc: <linux-nvme@lists.infradead.org>, Chaitanya Kulkarni <kch@nvidia.com>
Subject: [PATCH 1/3] nvme-core: make cid gencounter configurable
Date: Fri, 10 Dec 2021 03:21:14 -0800	[thread overview]
Message-ID: <20211210112116.9299-2-chaitanyak@nvidia.com> (raw)
In-Reply-To: <20211210112116.9299-1-chaitanyak@nvidia.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="y", Size: 2807 bytes --]

From: Chaitanya Kulkarni <kch@nvidia.com>

The recent commit uses a combination of command id and a gencounter
to calculate the command id so that we can call out buggy controllers
for spurious completions and that also avoids use after free.
This commit adds various if statements and bitwise operations
such as &, <<, >>, & along with comparison operations to validate the  
gencounter and print out the errors.
 
This feature is required to catch the buggy controller, but in the  
production environment where controller is validated and known to be
stable this achieves nothing but adds additional code and runtime CPU  
instructions for the PCIe controller.
Worst case scenario when NVMeOF setup is using passthru backend then
these instructions get duplicated on the host and on the target side
for each controller.
 
This patch makes the gencounter feature configurable by   
using new macro CONFIG_NVME_DEBUG_USE_CID_GENCTR. We move the current
tag + gencounter code when CONFIG_NVME_DEBUG_USE_CID_GENCTR is defined
and keep the original code where we use tag-based command id where
NVME_DEBUG_USE_CID_GENCTR is not defined.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/nvme/host/nvme.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index b334af8aa264..98d7627cfdce 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -153,7 +153,9 @@ enum nvme_quirks {
 struct nvme_request {
 	struct nvme_command	*cmd;
 	union nvme_result	result;
+#ifdef CONFIG_NVME_DEBUG_USE_CID_GENCTR
 	u8			genctr;
+#endif
 	u8			retries;
 	u8			flags;
 	u16			status;
@@ -496,6 +498,7 @@ struct nvme_ctrl_ops {
 	int (*get_address)(struct nvme_ctrl *ctrl, char *buf, int size);
 };
 
+#ifdef CONFIG_NVME_DEBUG_USE_CID_GENCTR
 /*
  * nvme command_id is constructed as such:
  * | xxxx | xxxxxxxxxxxx |
@@ -538,6 +541,32 @@ static inline struct request *nvme_cid_to_rq(struct blk_mq_tags *tags,
 {
 	return blk_mq_tag_to_rq(tags, nvme_tag_from_cid(command_id));
 }
+#else
+#define nvme_tag_from_cid(cid)			(cid)
+static inline u16 nvme_cid(struct request *rq)
+{
+	return rq->tag;
+}
+
+static inline struct request *nvme_cid_to_rq(struct blk_mq_tags *tags,
+		u16 command_id)
+{
+	return blk_mq_tag_to_rq(tags, command_id);
+}
+
+static inline struct request *nvme_find_rq(struct blk_mq_tags *tags,
+		u16 command_id)
+{
+	u16 tag = nvme_tag_from_cid(command_id);
+	struct request *rq;
+
+	rq = blk_mq_tag_to_rq(tags, tag);
+	if (unlikely(!rq))
+		pr_err("could not locate request for tag %#x\n", tag);
+
+	return rq;
+}
+#endif /* CONFIG_NVME_DEBUG_USE_CID_GENCTR */
 
 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
 void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
-- 
2.29.0



  reply	other threads:[~2021-12-10 11:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-10 11:21 [PATCH 0/3] nvme-core: make gencounter feature tunable Chaitanya Kulkarni
2021-12-10 11:21 ` Chaitanya Kulkarni [this message]
2021-12-10 11:21 ` [PATCH 2/3] nvme-core: move gencounter check into nvme_cid() Chaitanya Kulkarni
2021-12-10 15:43   ` Keith Busch
2021-12-10 17:46     ` Chaitanya Kulkarni
2021-12-12  9:19       ` Sagi Grimberg
2021-12-13  7:07         ` Chaitanya Kulkarni
2021-12-10 11:21 ` [PATCH 3/3] nvme: add KConfig options for debug features Chaitanya Kulkarni
2021-12-12  9:22   ` Sagi Grimberg
2021-12-13  7:39     ` Chaitanya Kulkarni
2021-12-13  9:27       ` Sagi Grimberg
2021-12-14  7:54         ` Chaitanya Kulkarni
2021-12-14 11:03           ` Sagi Grimberg
2021-12-17  6:52             ` Chaitanya Kulkarni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211210112116.9299-2-chaitanyak@nvidia.com \
    --to=chaitanyak@nvidia.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox