* detect duplicate cntlids v2
@ 2019-05-13 6:25 Christoph Hellwig
2019-05-13 6:25 ` [PATCH 1/2] nvme: change locking for the per-subsystem controller list Christoph Hellwig
2019-05-13 6:25 ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Christoph Hellwig
0 siblings, 2 replies; 10+ messages in thread
From: Christoph Hellwig @ 2019-05-13 6:25 UTC (permalink / raw)
Hi all,
this series detects duplicate cntlids in a subsystems. It is
based on a patch from Hannes.
Changes since v1:
- add a lockdep check for a held lock
- improve printk format
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2] nvme: change locking for the per-subsystem controller list
2019-05-13 6:25 detect duplicate cntlids v2 Christoph Hellwig
@ 2019-05-13 6:25 ` Christoph Hellwig
2019-05-13 6:36 ` Hannes Reinecke
2019-05-13 15:15 ` Chaitanya Kulkarni
2019-05-13 6:25 ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Christoph Hellwig
1 sibling, 2 replies; 10+ messages in thread
From: Christoph Hellwig @ 2019-05-13 6:25 UTC (permalink / raw)
Life becomes a lot simpler if we just use the global
nvme_subsystems_lock to protect this list. Given that it is only
accessed during controller probing and removal that isn't a scalability
problem either.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
drivers/nvme/host/core.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index eebaeadaa800..70a2bc01e41e 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2346,13 +2346,13 @@ static int nvme_active_ctrls(struct nvme_subsystem *subsys)
int count = 0;
struct nvme_ctrl *ctrl;
- mutex_lock(&subsys->lock);
+ lockdep_assert_held(&nvme_subsystems_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;
}
@@ -2394,6 +2394,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
mutex_lock(&nvme_subsystems_lock);
found = __nvme_find_get_subsystem(subsys->subnqn);
if (found) {
+ __nvme_release_subsystem(subsys);
+ subsys = found;
+
/*
* Verify that the subsystem actually supports multiple
* controllers, else bail out.
@@ -2402,14 +2405,10 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
nvme_active_ctrls(found) && !(id->cmic & (1 << 1))) {
dev_err(ctrl->device,
"ignoring ctrl due to duplicate subnqn (%s).\n",
- found->subnqn);
- nvme_put_subsystem(found);
+ subsys->subnqn);
ret = -EINVAL;
- goto out_unlock;
+ goto out_put_subsystem;
}
-
- __nvme_release_subsystem(subsys);
- subsys = found;
} else {
ret = device_add(&subsys->dev);
if (ret) {
@@ -2421,23 +2420,20 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
list_add_tail(&subsys->entry, &nvme_subsystems);
}
- ctrl->subsys = subsys;
- mutex_unlock(&nvme_subsystems_lock);
-
if (sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj,
dev_name(ctrl->device))) {
dev_err(ctrl->device,
"failed to create sysfs link from subsystem.\n");
- /* the transport driver will eventually put the subsystem */
- return -EINVAL;
+ goto out_put_subsystem;
}
- mutex_lock(&subsys->lock);
+ ctrl->subsys = subsys;
list_add_tail(&ctrl->subsys_entry, &subsys->ctrls);
- mutex_unlock(&subsys->lock);
-
+ mutex_unlock(&nvme_subsystems_lock);
return 0;
+out_put_subsystem:
+ nvme_put_subsystem(subsys);
out_unlock:
mutex_unlock(&nvme_subsystems_lock);
put_device(&subsys->dev);
@@ -3695,10 +3691,10 @@ static void nvme_free_ctrl(struct device *dev)
__free_page(ctrl->discard_page);
if (subsys) {
- mutex_lock(&subsys->lock);
+ mutex_lock(&nvme_subsystems_lock);
list_del(&ctrl->subsys_entry);
- mutex_unlock(&subsys->lock);
sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device));
+ mutex_unlock(&nvme_subsystems_lock);
}
ctrl->ops->free_ctrl(ctrl);
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/2] nvme: validate cntlid during controller initialisation
2019-05-13 6:25 detect duplicate cntlids v2 Christoph Hellwig
2019-05-13 6:25 ` [PATCH 1/2] nvme: change locking for the per-subsystem controller list Christoph Hellwig
@ 2019-05-13 6:25 ` Christoph Hellwig
2019-05-13 6:36 ` Hannes Reinecke
` (3 more replies)
1 sibling, 4 replies; 10+ messages in thread
From: Christoph Hellwig @ 2019-05-13 6:25 UTC (permalink / raw)
The CNTLID value is required to be unique, and we do rely on this
for correct operation. So reject any controller for which a non-unique
CNTLID has been detected.
Based on a patch from Hannes Reinecke.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
drivers/nvme/host/core.c | 41 +++++++++++++++++++++++-----------------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 70a2bc01e41e..09a1d5ca872f 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2341,20 +2341,35 @@ static const struct attribute_group *nvme_subsys_attrs_groups[] = {
NULL,
};
-static int nvme_active_ctrls(struct nvme_subsystem *subsys)
+static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,
+ struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
{
- int count = 0;
- struct nvme_ctrl *ctrl;
+ struct nvme_ctrl *tmp;
lockdep_assert_held(&nvme_subsystems_lock);
- list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
- if (ctrl->state != NVME_CTRL_DELETING &&
- ctrl->state != NVME_CTRL_DEAD)
- count++;
+ list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) {
+ if (ctrl->state == NVME_CTRL_DELETING ||
+ ctrl->state == NVME_CTRL_DEAD)
+ continue;
+
+ if (tmp->cntlid == ctrl->cntlid) {
+ dev_err(ctrl->device,
+ "Duplicate cntlid %u with %s, rejecting\n",
+ ctrl->cntlid, dev_name(tmp->device));
+ return false;
+ }
+
+ if ((id->cmic & (1 << 1)) ||
+ (ctrl->opts && ctrl->opts->discovery_nqn))
+ continue;
+
+ dev_err(ctrl->device,
+ "Subsystem does not support multiple controllers\n");
+ return false;
}
- return count;
+ return true;
}
static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
@@ -2397,15 +2412,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
__nvme_release_subsystem(subsys);
subsys = found;
- /*
- * Verify that the subsystem actually supports multiple
- * controllers, else bail out.
- */
- if (!(ctrl->opts && ctrl->opts->discovery_nqn) &&
- nvme_active_ctrls(found) && !(id->cmic & (1 << 1))) {
- dev_err(ctrl->device,
- "ignoring ctrl due to duplicate subnqn (%s).\n",
- subsys->subnqn);
+ if (!nvme_validate_cntlid(subsys, ctrl, id)) {
ret = -EINVAL;
goto out_put_subsystem;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 1/2] nvme: change locking for the per-subsystem controller list
2019-05-13 6:25 ` [PATCH 1/2] nvme: change locking for the per-subsystem controller list Christoph Hellwig
@ 2019-05-13 6:36 ` Hannes Reinecke
2019-05-13 15:15 ` Chaitanya Kulkarni
1 sibling, 0 replies; 10+ messages in thread
From: Hannes Reinecke @ 2019-05-13 6:36 UTC (permalink / raw)
On 5/13/19 8:25 AM, Christoph Hellwig wrote:
> Life becomes a lot simpler if we just use the global
> nvme_subsystems_lock to protect this list. Given that it is only
> accessed during controller probing and removal that isn't a scalability
> problem either.
>
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
> drivers/nvme/host/core.c | 32 ++++++++++++++------------------
> 1 file changed, 14 insertions(+), 18 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare at suse.com>
Cheers,
Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
hare at suse.de +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] nvme: validate cntlid during controller initialisation
2019-05-13 6:25 ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Christoph Hellwig
@ 2019-05-13 6:36 ` Hannes Reinecke
2019-05-13 15:16 ` Chaitanya Kulkarni
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Hannes Reinecke @ 2019-05-13 6:36 UTC (permalink / raw)
On 5/13/19 8:25 AM, Christoph Hellwig wrote:
> The CNTLID value is required to be unique, and we do rely on this
> for correct operation. So reject any controller for which a non-unique
> CNTLID has been detected.
>
> Based on a patch from Hannes Reinecke.
>
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
> drivers/nvme/host/core.c | 41 +++++++++++++++++++++++-----------------
> 1 file changed, 24 insertions(+), 17 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare at suse.com>
Cheers,
Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
hare at suse.de +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2] nvme: change locking for the per-subsystem controller list
2019-05-13 6:25 ` [PATCH 1/2] nvme: change locking for the per-subsystem controller list Christoph Hellwig
2019-05-13 6:36 ` Hannes Reinecke
@ 2019-05-13 15:15 ` Chaitanya Kulkarni
1 sibling, 0 replies; 10+ messages in thread
From: Chaitanya Kulkarni @ 2019-05-13 15:15 UTC (permalink / raw)
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>.
On 05/12/2019 11:26 PM, Christoph Hellwig wrote:
> Life becomes a lot simpler if we just use the global
> nvme_subsystems_lock to protect this list. Given that it is only
> accessed during controller probing and removal that isn't a scalability
> problem either.
>
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
> drivers/nvme/host/core.c | 32 ++++++++++++++------------------
> 1 file changed, 14 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index eebaeadaa800..70a2bc01e41e 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2346,13 +2346,13 @@ static int nvme_active_ctrls(struct nvme_subsystem *subsys)
> int count = 0;
> struct nvme_ctrl *ctrl;
>
> - mutex_lock(&subsys->lock);
> + lockdep_assert_held(&nvme_subsystems_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;
> }
> @@ -2394,6 +2394,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
> mutex_lock(&nvme_subsystems_lock);
> found = __nvme_find_get_subsystem(subsys->subnqn);
> if (found) {
> + __nvme_release_subsystem(subsys);
> + subsys = found;
> +
> /*
> * Verify that the subsystem actually supports multiple
> * controllers, else bail out.
> @@ -2402,14 +2405,10 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
> nvme_active_ctrls(found) && !(id->cmic & (1 << 1))) {
> dev_err(ctrl->device,
> "ignoring ctrl due to duplicate subnqn (%s).\n",
> - found->subnqn);
> - nvme_put_subsystem(found);
> + subsys->subnqn);
> ret = -EINVAL;
> - goto out_unlock;
> + goto out_put_subsystem;
> }
> -
> - __nvme_release_subsystem(subsys);
> - subsys = found;
> } else {
> ret = device_add(&subsys->dev);
> if (ret) {
> @@ -2421,23 +2420,20 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
> list_add_tail(&subsys->entry, &nvme_subsystems);
> }
>
> - ctrl->subsys = subsys;
> - mutex_unlock(&nvme_subsystems_lock);
> -
> if (sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj,
> dev_name(ctrl->device))) {
> dev_err(ctrl->device,
> "failed to create sysfs link from subsystem.\n");
> - /* the transport driver will eventually put the subsystem */
> - return -EINVAL;
> + goto out_put_subsystem;
> }
>
> - mutex_lock(&subsys->lock);
> + ctrl->subsys = subsys;
> list_add_tail(&ctrl->subsys_entry, &subsys->ctrls);
> - mutex_unlock(&subsys->lock);
> -
> + mutex_unlock(&nvme_subsystems_lock);
> return 0;
>
> +out_put_subsystem:
> + nvme_put_subsystem(subsys);
> out_unlock:
> mutex_unlock(&nvme_subsystems_lock);
> put_device(&subsys->dev);
> @@ -3695,10 +3691,10 @@ static void nvme_free_ctrl(struct device *dev)
> __free_page(ctrl->discard_page);
>
> if (subsys) {
> - mutex_lock(&subsys->lock);
> + mutex_lock(&nvme_subsystems_lock);
> list_del(&ctrl->subsys_entry);
> - mutex_unlock(&subsys->lock);
> sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device));
> + mutex_unlock(&nvme_subsystems_lock);
> }
>
> ctrl->ops->free_ctrl(ctrl);
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] nvme: validate cntlid during controller initialisation
2019-05-13 6:25 ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Christoph Hellwig
2019-05-13 6:36 ` Hannes Reinecke
@ 2019-05-13 15:16 ` Chaitanya Kulkarni
2019-05-13 18:25 ` Heitke, Kenneth
2019-08-30 18:24 ` James Smart
3 siblings, 0 replies; 10+ messages in thread
From: Chaitanya Kulkarni @ 2019-05-13 15:16 UTC (permalink / raw)
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>.
On 05/12/2019 11:26 PM, Christoph Hellwig wrote:
> The CNTLID value is required to be unique, and we do rely on this
> for correct operation. So reject any controller for which a non-unique
> CNTLID has been detected.
>
> Based on a patch from Hannes Reinecke.
>
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
> drivers/nvme/host/core.c | 41 +++++++++++++++++++++++-----------------
> 1 file changed, 24 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 70a2bc01e41e..09a1d5ca872f 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2341,20 +2341,35 @@ static const struct attribute_group *nvme_subsys_attrs_groups[] = {
> NULL,
> };
>
> -static int nvme_active_ctrls(struct nvme_subsystem *subsys)
> +static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,
> + struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
> {
> - int count = 0;
> - struct nvme_ctrl *ctrl;
> + struct nvme_ctrl *tmp;
>
> lockdep_assert_held(&nvme_subsystems_lock);
>
> - list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
> - if (ctrl->state != NVME_CTRL_DELETING &&
> - ctrl->state != NVME_CTRL_DEAD)
> - count++;
> + list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) {
> + if (ctrl->state == NVME_CTRL_DELETING ||
> + ctrl->state == NVME_CTRL_DEAD)
> + continue;
> +
> + if (tmp->cntlid == ctrl->cntlid) {
> + dev_err(ctrl->device,
> + "Duplicate cntlid %u with %s, rejecting\n",
> + ctrl->cntlid, dev_name(tmp->device));
> + return false;
> + }
> +
> + if ((id->cmic & (1 << 1)) ||
> + (ctrl->opts && ctrl->opts->discovery_nqn))
> + continue;
> +
> + dev_err(ctrl->device,
> + "Subsystem does not support multiple controllers\n");
> + return false;
> }
>
> - return count;
> + return true;
> }
>
> static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
> @@ -2397,15 +2412,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
> __nvme_release_subsystem(subsys);
> subsys = found;
>
> - /*
> - * Verify that the subsystem actually supports multiple
> - * controllers, else bail out.
> - */
> - if (!(ctrl->opts && ctrl->opts->discovery_nqn) &&
> - nvme_active_ctrls(found) && !(id->cmic & (1 << 1))) {
> - dev_err(ctrl->device,
> - "ignoring ctrl due to duplicate subnqn (%s).\n",
> - subsys->subnqn);
> + if (!nvme_validate_cntlid(subsys, ctrl, id)) {
> ret = -EINVAL;
> goto out_put_subsystem;
> }
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] nvme: validate cntlid during controller initialisation
2019-05-13 6:25 ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Christoph Hellwig
2019-05-13 6:36 ` Hannes Reinecke
2019-05-13 15:16 ` Chaitanya Kulkarni
@ 2019-05-13 18:25 ` Heitke, Kenneth
2019-08-30 18:24 ` James Smart
3 siblings, 0 replies; 10+ messages in thread
From: Heitke, Kenneth @ 2019-05-13 18:25 UTC (permalink / raw)
On 5/13/2019 12:25 AM, Christoph Hellwig wrote:
> The CNTLID value is required to be unique, and we do rely on this
> for correct operation. So reject any controller for which a non-unique
> CNTLID has been detected.
>
> Based on a patch from Hannes Reinecke.
>
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
> drivers/nvme/host/core.c | 41 +++++++++++++++++++++++-----------------
> 1 file changed, 24 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 70a2bc01e41e..09a1d5ca872f 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2341,20 +2341,35 @@ static const struct attribute_group *nvme_subsys_attrs_groups[] = {
> NULL,
> };
>
> -static int nvme_active_ctrls(struct nvme_subsystem *subsys)
> +static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,
> + struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
> {
> - int count = 0;
> - struct nvme_ctrl *ctrl;
> + struct nvme_ctrl *tmp;
>
> lockdep_assert_held(&nvme_subsystems_lock);
>
> - list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
> - if (ctrl->state != NVME_CTRL_DELETING &&
> - ctrl->state != NVME_CTRL_DEAD)
> - count++;
> + list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) {
> + if (ctrl->state == NVME_CTRL_DELETING ||
> + ctrl->state == NVME_CTRL_DEAD)
> + continue;
> +
> + if (tmp->cntlid == ctrl->cntlid) {
> + dev_err(ctrl->device,
> + "Duplicate cntlid %u with %s, rejecting\n",
> + ctrl->cntlid, dev_name(tmp->device));
> + return false;
> + }
> +
> + if ((id->cmic & (1 << 1)) ||
> + (ctrl->opts && ctrl->opts->discovery_nqn))
> + continue;
Replace whitespace with tab
> +
> + dev_err(ctrl->device,
> + "Subsystem does not support multiple controllers\n");
> + return false;
> }
>
> - return count;
> + return true;
> }
>
> static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] nvme: validate cntlid during controller initialisation
2019-05-13 6:25 ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Christoph Hellwig
` (2 preceding siblings ...)
2019-05-13 18:25 ` Heitke, Kenneth
@ 2019-08-30 18:24 ` James Smart
2019-08-30 18:30 ` Sagi Grimberg
3 siblings, 1 reply; 10+ messages in thread
From: James Smart @ 2019-08-30 18:24 UTC (permalink / raw)
To: Christoph Hellwig, hare; +Cc: Sagi Grimberg, linux-nvme
On 5/12/2019 11:25 PM, Christoph Hellwig wrote:
> The CNTLID value is required to be unique, and we do rely on this
> for correct operation. So reject any controller for which a non-unique
> CNTLID has been detected.
>
> Based on a patch from Hannes Reinecke.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/nvme/host/core.c | 41 +++++++++++++++++++++++-----------------
> 1 file changed, 24 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 70a2bc01e41e..09a1d5ca872f 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2341,20 +2341,35 @@ static const struct attribute_group *nvme_subsys_attrs_groups[] = {
> NULL,
> };
>
> -static int nvme_active_ctrls(struct nvme_subsystem *subsys)
> +static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,
> + struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
> {
> - int count = 0;
> - struct nvme_ctrl *ctrl;
> + struct nvme_ctrl *tmp;
>
> lockdep_assert_held(&nvme_subsystems_lock);
>
> - list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
> - if (ctrl->state != NVME_CTRL_DELETING &&
> - ctrl->state != NVME_CTRL_DEAD)
> - count++;
> + list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) {
> + if (ctrl->state == NVME_CTRL_DELETING ||
> + ctrl->state == NVME_CTRL_DEAD)
> + continue;
> +
> + if (tmp->cntlid == ctrl->cntlid) {
> + dev_err(ctrl->device,
> + "Duplicate cntlid %u with %s, rejecting\n",
> + ctrl->cntlid, dev_name(tmp->device));
> + return false;
> + }
> + if ((id->cmic & (1 << 1)) ||
> + (ctrl->opts && ctrl->opts->discovery_nqn))
> + continue;
Do we have a problem here if the subsystem is a discovery controller nqn ?
Assume we have a connection to a discovery controller in place (it has
been created, is in the midst of reading the discovery log; or a
long-lived discovery controller) and a new one is being made. The new
one could be on completely different transport or different
host/subsystem ports:
It looks like __nvme_find_get_subsystem() when called with the discovery
nqn will match the subsystem for the existing discovery controller,
which then forces the call to nvme_validate_cntlid(), which will find a
live controller and it's very possible that controller id can be
different. The requirement for sameness does not apply to the discovery
controller - so it shouldn't be returning failure in this case. Agree ?
What's the best patch to avoid this ?
- change __nvme_find_get_subsystem() so that if discovery nqn, it treats
it as a separate subsystem ?
- change nvme_validate_cntlid() such that "(ctrl->opts &&
ctrl->opts->discovery_nqn)" is added to the ctrl state checks above this
test ?
-- james
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] nvme: validate cntlid during controller initialisation
2019-08-30 18:24 ` James Smart
@ 2019-08-30 18:30 ` Sagi Grimberg
0 siblings, 0 replies; 10+ messages in thread
From: Sagi Grimberg @ 2019-08-30 18:30 UTC (permalink / raw)
To: James Smart, Christoph Hellwig, hare; +Cc: linux-nvme
> On 5/12/2019 11:25 PM, Christoph Hellwig wrote:
>> The CNTLID value is required to be unique, and we do rely on this
>> for correct operation. So reject any controller for which a non-unique
>> CNTLID has been detected.
>>
>> Based on a patch from Hannes Reinecke.
>>
>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>> ---
>> drivers/nvme/host/core.c | 41 +++++++++++++++++++++++-----------------
>> 1 file changed, 24 insertions(+), 17 deletions(-)
>>
>> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
>> index 70a2bc01e41e..09a1d5ca872f 100644
>> --- a/drivers/nvme/host/core.c
>> +++ b/drivers/nvme/host/core.c
>> @@ -2341,20 +2341,35 @@ static const struct attribute_group
>> *nvme_subsys_attrs_groups[] = {
>> NULL,
>> };
>> -static int nvme_active_ctrls(struct nvme_subsystem *subsys)
>> +static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,
>> + struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
>> {
>> - int count = 0;
>> - struct nvme_ctrl *ctrl;
>> + struct nvme_ctrl *tmp;
>> lockdep_assert_held(&nvme_subsystems_lock);
>> - list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
>> - if (ctrl->state != NVME_CTRL_DELETING &&
>> - ctrl->state != NVME_CTRL_DEAD)
>> - count++;
>> + list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) {
>> + if (ctrl->state == NVME_CTRL_DELETING ||
>> + ctrl->state == NVME_CTRL_DEAD)
>> + continue;
>> +
>> + if (tmp->cntlid == ctrl->cntlid) {
>> + dev_err(ctrl->device,
>> + "Duplicate cntlid %u with %s, rejecting\n",
>> + ctrl->cntlid, dev_name(tmp->device));
>> + return false;
>> + }
>> + if ((id->cmic & (1 << 1)) ||
>> + (ctrl->opts && ctrl->opts->discovery_nqn))
>> + continue;
>
> Do we have a problem here if the subsystem is a discovery controller nqn ?
>
> Assume we have a connection to a discovery controller in place (it has
> been created, is in the midst of reading the discovery log; or a
> long-lived discovery controller) and a new one is being made. The new
> one could be on completely different transport or different
> host/subsystem ports:
>
> It looks like __nvme_find_get_subsystem() when called with the discovery
> nqn will match the subsystem for the existing discovery controller,
> which then forces the call to nvme_validate_cntlid(), which will find a
> live controller and it's very possible that controller id can be
> different. The requirement for sameness does not apply to the discovery
> controller - so it shouldn't be returning failure in this case. Agree ?
>
> What's the best patch to avoid this ?
> - change __nvme_find_get_subsystem() so that if discovery nqn, it treats
> it as a separate subsystem ?
> - change nvme_validate_cntlid() such that "(ctrl->opts &&
> ctrl->opts->discovery_nqn)" is added to the ctrl state checks above this
> test ?
Yes, you're right, we should allow this for the discovery subsystem.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2019-08-30 18:30 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-13 6:25 detect duplicate cntlids v2 Christoph Hellwig
2019-05-13 6:25 ` [PATCH 1/2] nvme: change locking for the per-subsystem controller list Christoph Hellwig
2019-05-13 6:36 ` Hannes Reinecke
2019-05-13 15:15 ` Chaitanya Kulkarni
2019-05-13 6:25 ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Christoph Hellwig
2019-05-13 6:36 ` Hannes Reinecke
2019-05-13 15:16 ` Chaitanya Kulkarni
2019-05-13 18:25 ` Heitke, Kenneth
2019-08-30 18:24 ` James Smart
2019-08-30 18:30 ` Sagi Grimberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox