diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index c9837263898a..982749efa6e1 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -490,8 +490,9 @@ static void nvmet_ns_dev_disable(struct nvmet_ns *ns) nvmet_file_ns_disable(ns); } -static int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns) - __must_hold(&ns->subsys->lock) +static int nvmet_p2pmem_ns_enable(struct nvmet_subsys *subsys, + struct nvmet_ns *ns) + __must_hold(&subsys->lock) { int ret; struct pci_dev *p2p_dev; @@ -511,7 +512,8 @@ static int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns) } if (ns->p2p_dev) { - ret = pci_p2pdma_distance(ns->p2p_dev, nvmet_ns_dev(ns), true); + ret = pci_p2pdma_distance(ns->p2p_dev, nvmet_ns_dev(subsys, ns), + true); if (ret < 0) return -EINVAL; } else { @@ -522,7 +524,7 @@ static int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns) * setup the controller when the port's device is available. */ - p2p_dev = pci_p2pmem_find(nvmet_ns_dev(ns)); + p2p_dev = pci_p2pmem_find(nvmet_ns_dev(subsys, ns)); if (!p2p_dev) { pr_err("no peer-to-peer memory is available for %s\n", ns->device_path); @@ -535,21 +537,16 @@ static int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns) return 0; } -static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl, +static void nvmet_p2pmem_ns_add_p2p(struct nvmet_subsys *subsys, + struct nvmet_ctrl *ctrl, struct nvmet_ns *ns) - __must_hold(&ctrl->subsys->lock) + __must_hold(&subsys->lock) { struct device *clients[2]; struct pci_dev *p2p_dev; int ret; - lockdep_assert_held(&ctrl->subsys->lock); - /* - * Both ctrl->subsys->lock and ns->subsys->lock refers to the same lock. - * However there's no way for us to annotate such locking semantics - * using clang context annotation. So explicitly assert the capability. - */ - __assume_ctx_lock(&ns->subsys->lock); + lockdep_assert_held(&subsys->lock); if (!ctrl->p2p_client || !ns->use_p2pmem) return; @@ -562,7 +559,7 @@ static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl, p2p_dev = pci_dev_get(ns->p2p_dev); } else { clients[0] = ctrl->p2p_client; - clients[1] = nvmet_ns_dev(ns); + clients[1] = nvmet_ns_dev(subsys, ns); p2p_dev = pci_p2pmem_find_many(clients, ARRAY_SIZE(clients)); if (!p2p_dev) { @@ -620,20 +617,12 @@ int nvmet_ns_enable(struct nvmet_ns *ns) if (ret) goto out_unlock; - ret = nvmet_p2pmem_ns_enable(ns); + ret = nvmet_p2pmem_ns_enable(subsys, ns); if (ret) goto out_dev_disable; - list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { - /* - * Both subsys->lock and ctrl->subsys->lock refers to the same - * lock. However there's no way for us to annotate such locking - * semantics using clang context annotation. So explicitly - * assert the capability. - */ - __assume_ctx_lock(&ctrl->subsys->lock); - nvmet_p2pmem_ns_add_p2p(ctrl, ns); - } + list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) + nvmet_p2pmem_ns_add_p2p(subsys, ctrl, ns); if (ns->pr.enable) { ret = nvmet_pr_init_ns(ns); @@ -1591,14 +1580,15 @@ bool nvmet_host_allowed(struct nvmet_subsys *subsys, const char *hostnqn) return false; } -static void nvmet_setup_p2p_ns_map(struct nvmet_ctrl *ctrl, - struct device *p2p_client) - __must_hold(&ctrl->subsys->lock) +static void nvmet_setup_p2p_ns_map(struct nvmet_subsys *subsys, + struct nvmet_ctrl *ctrl, + struct device *p2p_client) + __must_hold(&subsys->lock) { struct nvmet_ns *ns; unsigned long idx; - lockdep_assert_held(&ctrl->subsys->lock); + lockdep_assert_held(&subsys->lock); if (!p2p_client) return; @@ -1606,7 +1596,7 @@ static void nvmet_setup_p2p_ns_map(struct nvmet_ctrl *ctrl, ctrl->p2p_client = get_device(p2p_client); nvmet_for_each_enabled_ns(&ctrl->subsys->namespaces, idx, ns) - nvmet_p2pmem_ns_add_p2p(ctrl, ns); + nvmet_p2pmem_ns_add_p2p(subsys, ctrl, ns); } static void nvmet_release_p2p_ns_map(struct nvmet_ctrl *ctrl) @@ -1752,13 +1742,7 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args) goto init_pr_fail; list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); - /* - * Both subsys->lock and ctrl->subsys->lock refers to the same lock. - * However there's no way for us to annotate such locking semantics - * using clang context annotation. So explicitly assert the capability. - */ - __assume_ctx_lock(&ctrl->subsys->lock); - nvmet_setup_p2p_ns_map(ctrl, args->p2p_client); + nvmet_setup_p2p_ns_map(subsys, ctrl, args->p2p_client); nvmet_debugfs_ctrl_setup(ctrl); mutex_unlock(&subsys->lock); up_read(&nvmet_config_sem); diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 41912877ade3..270cb112e702 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -207,8 +207,9 @@ static inline struct nvmet_ns *to_nvmet_ns(struct config_item *item) return container_of(to_config_group(item), struct nvmet_ns, group); } -static inline struct device *nvmet_ns_dev(struct nvmet_ns *ns) - __must_hold(&ns->subsys->lock) +static inline struct device *nvmet_ns_dev(struct nvmet_subsys *subsys, + struct nvmet_ns *ns) + __must_hold(&subsys->lock) { return ns->bdev ? disk_to_dev(ns->bdev->bd_disk) : NULL; }