Skip to content

Commit

Permalink
nvme: fix the deadlock in nvme_update_formats
Browse files Browse the repository at this point in the history
nvme_update_formats will invoke nvme_ns_remove under namespaces_mutext.
The will cause deadlock because nvme_ns_remove will also require
the namespaces_mutext. Fix it by getting the ns entries which should
be removed under namespaces_mutext and invoke nvme_ns_remove out of
namespaces_mutext.

Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
  • Loading branch information
Jianchao Wang authored and Keith Busch committed Feb 14, 2018
1 parent 0a34e46 commit 3fd176b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/nvme/host/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,14 +1117,19 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

static void nvme_update_formats(struct nvme_ctrl *ctrl)
{
struct nvme_ns *ns;
struct nvme_ns *ns, *next;
LIST_HEAD(rm_list);

mutex_lock(&ctrl->namespaces_mutex);
list_for_each_entry(ns, &ctrl->namespaces, list) {
if (ns->disk && nvme_revalidate_disk(ns->disk))
nvme_ns_remove(ns);
if (ns->disk && nvme_revalidate_disk(ns->disk)) {
list_move_tail(&ns->list, &rm_list);
}
}
mutex_unlock(&ctrl->namespaces_mutex);

list_for_each_entry_safe(ns, next, &rm_list, list)
nvme_ns_remove(ns);
}

static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
Expand Down

0 comments on commit 3fd176b

Please sign in to comment.