From: maxg@mellanox.com (Max Gurtovoy)
Subject: [PATCH 2/2] nvme: Fix subsystem multiple controllers support check
Date: Thu, 4 Jan 2018 17:56:14 +0200 [thread overview]
Message-ID: <1515081374-22328-2-git-send-email-maxg@mellanox.com> (raw)
In-Reply-To: <1515081374-22328-1-git-send-email-maxg@mellanox.com>
From: Israel Rukshin <israelr@mellanox.com>
There is a problem when another module (e.g. nvmet) takes
a refcount on the nvme block device and the physical nvme drive is removed.
In that case nvme_free_ctrl() will not be called and the controller state
will be "deleting" or "dead" unless nvmet module releases the block device.
Later on, the same nvme drive probes back and nvme_init_subsystem() will be
called and fail due to duplicate subnqn (if the nvme device doesn't support
subsystem with multiple controllers). This will cause a probe failure.
This commit changes the check of multiple controllers support at
nvme_init_subsystem() by not counting all the controllers at "dead" or
"deleting" state (this is safe because controllers at this state will never
be active again).
Fixes: ab9e00cc72fa ("nvme: track subsystems")
Reviewed-by: Max Gurtovoy <maxg at mellanox.com>
Signed-off-by: Israel Rukshin <israelr at mellanox.com>
---
drivers/nvme/host/core.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index cb6b08e..f6dfdd3 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2063,6 +2063,22 @@ static ssize_t nvme_subsys_show_nqn(struct device *dev,
NULL,
};
+static int nvme_active_ctrls(struct nvme_subsystem *subsys)
+{
+ int count = 0;
+ struct nvme_ctrl *ctrl;
+
+ mutex_lock(&subsys->lock);
+ list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
+ if (ctrl->state != NVME_CTRL_DELETING &&
+ ctrl->state != NVME_CTRL_DEAD)
+ count++;
+ }
+ mutex_unlock(&subsys->lock);
+
+ return count;
+}
+
static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
{
struct nvme_subsystem *subsys, *found;
@@ -2101,7 +2117,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
* Verify that the subsystem actually supports multiple
* controllers, else bail out.
*/
- if (!(id->cmic & (1 << 1))) {
+ if (nvme_active_ctrls(found) && !(id->cmic & (1 << 1))) {
dev_err(ctrl->device,
"ignoring ctrl due to duplicate subnqn (%s).\n",
found->subnqn);
--
1.8.3.1
next prev parent reply other threads:[~2018-01-04 15:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-04 15:56 [PATCH 1/2] nvme: Take refcount on transport module when using block device operations Max Gurtovoy
2018-01-04 15:56 ` Max Gurtovoy [this message]
2018-01-08 10:14 ` [PATCH 2/2] nvme: Fix subsystem multiple controllers support check Christoph Hellwig
2018-01-08 10:16 ` Christoph Hellwig
2018-01-08 14:43 ` Israel Rukshin
2018-01-18 13:43 ` Israel Rukshin
2018-01-08 10:12 ` [PATCH 1/2] nvme: Take refcount on transport module when using block device operations Christoph Hellwig
2018-01-08 15:51 ` Minwoo Im
2018-01-08 15:56 ` Christoph Hellwig
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=1515081374-22328-2-git-send-email-maxg@mellanox.com \
--to=maxg@mellanox.com \
/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