Skip to content

Commit 03e0f3a

Browse files
Ming Leiaxboe
authored andcommitted
nvme-pci: avoid dereference of symbol from unloaded module
The 'remove_work' may be scheduled to run after nvme_remove() returns since we can't simply cancel it in nvme_remove() for avoiding deadlock. Once nvme_remove() returns, this module(nvme) can be unloaded. On the other hand, nvme_put_ctrl() calls ctr->ops->free_ctrl which may point to nvme_pci_free_ctrl() in unloaded module. This patch avoids this issue by queuing 'remove_work' via 'nvme_wq', and flush this worqueue in nvme_exit() as suggested by Sagi. Suggested-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Keith Busch <keith.busch@intel.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e3d7874 commit 03e0f3a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/nvme/host/pci.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,7 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, int status)
22802280

22812281
nvme_get_ctrl(&dev->ctrl);
22822282
nvme_dev_disable(dev, false);
2283-
if (!schedule_work(&dev->remove_work))
2283+
if (!queue_work(nvme_wq, &dev->remove_work))
22842284
nvme_put_ctrl(&dev->ctrl);
22852285
}
22862286

@@ -2703,6 +2703,7 @@ static int __init nvme_init(void)
27032703
static void __exit nvme_exit(void)
27042704
{
27052705
pci_unregister_driver(&nvme_driver);
2706+
flush_workqueue(nvme_wq);
27062707
_nvme_check_size();
27072708
}
27082709

0 commit comments

Comments
 (0)