diff options
| author | Christoph Hellwig <hch@lst.de> | 2019-05-09 03:01:26 -0400 |
|---|---|---|
| committer | Christoph Hellwig <hch@lst.de> | 2019-05-14 11:19:50 -0400 |
| commit | 1b1031ca63b2ce1d3b664b35b77ec94e458693e9 (patch) | |
| tree | 1b9d9e846749128f79474e6f1637e7551e798997 | |
| parent | 32fd90c407680935f84fb3ffc60fb3e020257d38 (diff) | |
nvme: validate cntlid during controller initialisation
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>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
| -rw-r--r-- | drivers/nvme/host/core.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d2d8e6088c46..d7de0642c832 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[] = { | |||
| 2341 | NULL, | 2341 | NULL, |
| 2342 | }; | 2342 | }; |
| 2343 | 2343 | ||
| 2344 | static int nvme_active_ctrls(struct nvme_subsystem *subsys) | 2344 | static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, |
| 2345 | struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) | ||
| 2345 | { | 2346 | { |
| 2346 | int count = 0; | 2347 | struct nvme_ctrl *tmp; |
| 2347 | struct nvme_ctrl *ctrl; | ||
| 2348 | 2348 | ||
| 2349 | lockdep_assert_held(&nvme_subsystems_lock); | 2349 | lockdep_assert_held(&nvme_subsystems_lock); |
| 2350 | 2350 | ||
| 2351 | list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { | 2351 | list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) { |
| 2352 | if (ctrl->state != NVME_CTRL_DELETING && | 2352 | if (ctrl->state == NVME_CTRL_DELETING || |
| 2353 | ctrl->state != NVME_CTRL_DEAD) | 2353 | ctrl->state == NVME_CTRL_DEAD) |
| 2354 | count++; | 2354 | continue; |
| 2355 | |||
| 2356 | if (tmp->cntlid == ctrl->cntlid) { | ||
| 2357 | dev_err(ctrl->device, | ||
| 2358 | "Duplicate cntlid %u with %s, rejecting\n", | ||
| 2359 | ctrl->cntlid, dev_name(tmp->device)); | ||
| 2360 | return false; | ||
| 2361 | } | ||
| 2362 | |||
| 2363 | if ((id->cmic & (1 << 1)) || | ||
| 2364 | (ctrl->opts && ctrl->opts->discovery_nqn)) | ||
| 2365 | continue; | ||
| 2366 | |||
| 2367 | dev_err(ctrl->device, | ||
| 2368 | "Subsystem does not support multiple controllers\n"); | ||
| 2369 | return false; | ||
| 2355 | } | 2370 | } |
| 2356 | 2371 | ||
| 2357 | return count; | 2372 | return true; |
| 2358 | } | 2373 | } |
| 2359 | 2374 | ||
| 2360 | static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) | 2375 | 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) | |||
| 2397 | __nvme_release_subsystem(subsys); | 2412 | __nvme_release_subsystem(subsys); |
| 2398 | subsys = found; | 2413 | subsys = found; |
| 2399 | 2414 | ||
| 2400 | /* | 2415 | if (!nvme_validate_cntlid(subsys, ctrl, id)) { |
| 2401 | * Verify that the subsystem actually supports multiple | ||
| 2402 | * controllers, else bail out. | ||
| 2403 | */ | ||
| 2404 | if (!(ctrl->opts && ctrl->opts->discovery_nqn) && | ||
| 2405 | nvme_active_ctrls(found) && !(id->cmic & (1 << 1))) { | ||
| 2406 | dev_err(ctrl->device, | ||
| 2407 | "ignoring ctrl due to duplicate subnqn (%s).\n", | ||
| 2408 | subsys->subnqn); | ||
| 2409 | ret = -EINVAL; | 2416 | ret = -EINVAL; |
| 2410 | goto out_put_subsystem; | 2417 | goto out_put_subsystem; |
| 2411 | } | 2418 | } |
