From: kenneth.heitke@intel.com (Heitke, Kenneth)
Subject: [PATCH 2/2] nvme: validate cntlid during controller initialisation
Date: Mon, 13 May 2019 12:25:19 -0600 [thread overview]
Message-ID: <e90ee6c7-8742-6f21-26c7-e0f578b419be@intel.com> (raw)
In-Reply-To: <20190513062510.756-3-hch@lst.de>
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)
next prev parent reply other threads:[~2019-05-13 18:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2019-08-30 18:24 ` James Smart
2019-08-30 18:30 ` Sagi Grimberg
-- strict thread matches above, loose matches on Subject: below --
2019-04-03 22:41 [PATCH 0/2] nvme: validate CNTLID Hannes Reinecke
2019-04-03 22:41 ` [PATCH 2/2] nvme: validate cntlid during controller initialisation Hannes Reinecke
2019-04-04 5:26 ` 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=e90ee6c7-8742-6f21-26c7-e0f578b419be@intel.com \
--to=kenneth.heitke@intel.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