Skip to contentSkip to conversation

NVMe: eliminate potential deadlock bynvme_get_ns_from_disk invoking nvme_free_ns

PATCH New Wang Sheng-Hui 2 participants 2 messages May 5, 2016 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 NVMe: eliminate potential deadlock bynvme_get_ns_from_disk invoking nvme_free_ns

Release dev_list_lock before enter nvme_free_ns from nvme_get_ns_from_disk to avoid potential deadlock.

The change is finally made by Keith Busch, which improve v1/v2 version:
* Smaller change
* Fix the module reference drop issue in v2 version
* Remove gotos

Signed-off-by Wang Sheng-Hui <shhuiw at foxmail.com>
---
 drivers/nvme/host/core.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/nvme/host/core.c +5 -9
index 643f457..8788ef3 100644
@@ -87,20 +87,16 @@ static struct nvme_ns *nvme_get_ns_from_disk(struct gendisk *disk)
 	spin_lock(&dev_list_lock);
 	ns = disk->private_data;
 	if (ns) {
-		if (!kref_get_unless_zero(&ns->kref))
-			goto fail;
 		if (!try_module_get(ns->ctrl->ops->module))
-			goto fail_put_ns;
+			ns = NULL;
+		else if (!kref_get_unless_zero(&ns->kref)) {
+			module_put(ns->ctrl->ops->module);
+			ns = NULL;
+		}
 	}
 	spin_unlock(&dev_list_lock);
 
 	return ns;
-
-fail_put_ns:
-	kref_put(&ns->kref, nvme_free_ns);
-fail:
-	spin_unlock(&dev_list_lock);
-	return NULL;
 }
 
 void nvme_requeue_req(struct request *req)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/1 NVMe: eliminate potential deadlock bynvme_get_ns_from_disk invoking nvme_free_ns

Quoted 10 lines · Wang Sheng-Hui

Release dev_list_lock before enter nvme_free_ns from nvme_get_ns_from_disk to avoid potential deadlock.

The change is finally made by Keith Busch, which improve v1/v2 version:
* Smaller change
* Fix the module reference drop issue in v2 version
* Remove gotos

Signed-off-by Wang Sheng-Hui <shhuiw at foxmail.com>

Looks fine,

Reviewed-by Christoph Hellwig <hch at lst.de>