* [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 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