Skip to content

Commit 70fbfc4

Browse files
igawkeithbusch
authored andcommitted
nvme-fc: do not wait in vain when unloading module
The module exit path has race between deleting all controllers and freeing 'left over IDs'. To prevent double free a synchronization between nvme_delete_ctrl and ida_destroy has been added by the initial commit. There is some logic around trying to prevent from hanging forever in wait_for_completion, though it does not handling all cases. E.g. blktests is able to reproduce the situation where the module unload hangs forever. If we completely rely on the cleanup code executed from the nvme_delete_ctrl path, all IDs will be freed eventually. This makes calling ida_destroy unnecessary. We only have to ensure that all nvme_delete_ctrl code has been executed before we leave nvme_fc_exit_module. This is done by flushing the nvme_delete_wq workqueue. While at it, remove the unused nvme_fc_wq workqueue too. Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Daniel Wagner <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 0d150be commit 70fbfc4

File tree

1 file changed

+6
-41
lines changed
  • drivers/nvme/host

1 file changed

+6
-41
lines changed

drivers/nvme/host/fc.c

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,6 @@ static LIST_HEAD(nvme_fc_lport_list);
221221
static DEFINE_IDA(nvme_fc_local_port_cnt);
222222
static DEFINE_IDA(nvme_fc_ctrl_cnt);
223223

224-
static struct workqueue_struct *nvme_fc_wq;
225-
226-
static bool nvme_fc_waiting_to_unload;
227-
static DECLARE_COMPLETION(nvme_fc_unload_proceed);
228-
229224
/*
230225
* These items are short-term. They will eventually be moved into
231226
* a generic FC class. See comments in module init.
@@ -255,8 +250,6 @@ nvme_fc_free_lport(struct kref *ref)
255250
/* remove from transport list */
256251
spin_lock_irqsave(&nvme_fc_lock, flags);
257252
list_del(&lport->port_list);
258-
if (nvme_fc_waiting_to_unload && list_empty(&nvme_fc_lport_list))
259-
complete(&nvme_fc_unload_proceed);
260253
spin_unlock_irqrestore(&nvme_fc_lock, flags);
261254

262255
ida_free(&nvme_fc_local_port_cnt, lport->localport.port_num);
@@ -3896,10 +3889,6 @@ static int __init nvme_fc_init_module(void)
38963889
{
38973890
int ret;
38983891

3899-
nvme_fc_wq = alloc_workqueue("nvme_fc_wq", WQ_MEM_RECLAIM, 0);
3900-
if (!nvme_fc_wq)
3901-
return -ENOMEM;
3902-
39033892
/*
39043893
* NOTE:
39053894
* It is expected that in the future the kernel will combine
@@ -3917,7 +3906,7 @@ static int __init nvme_fc_init_module(void)
39173906
ret = class_register(&fc_class);
39183907
if (ret) {
39193908
pr_err("couldn't register class fc\n");
3920-
goto out_destroy_wq;
3909+
return ret;
39213910
}
39223911

39233912
/*
@@ -3941,8 +3930,6 @@ static int __init nvme_fc_init_module(void)
39413930
device_destroy(&fc_class, MKDEV(0, 0));
39423931
out_destroy_class:
39433932
class_unregister(&fc_class);
3944-
out_destroy_wq:
3945-
destroy_workqueue(nvme_fc_wq);
39463933

39473934
return ret;
39483935
}
@@ -3962,45 +3949,23 @@ nvme_fc_delete_controllers(struct nvme_fc_rport *rport)
39623949
spin_unlock(&rport->lock);
39633950
}
39643951

3965-
static void
3966-
nvme_fc_cleanup_for_unload(void)
3952+
static void __exit nvme_fc_exit_module(void)
39673953
{
39683954
struct nvme_fc_lport *lport;
39693955
struct nvme_fc_rport *rport;
3970-
3971-
list_for_each_entry(lport, &nvme_fc_lport_list, port_list) {
3972-
list_for_each_entry(rport, &lport->endp_list, endp_list) {
3973-
nvme_fc_delete_controllers(rport);
3974-
}
3975-
}
3976-
}
3977-
3978-
static void __exit nvme_fc_exit_module(void)
3979-
{
39803956
unsigned long flags;
3981-
bool need_cleanup = false;
39823957

39833958
spin_lock_irqsave(&nvme_fc_lock, flags);
3984-
nvme_fc_waiting_to_unload = true;
3985-
if (!list_empty(&nvme_fc_lport_list)) {
3986-
need_cleanup = true;
3987-
nvme_fc_cleanup_for_unload();
3988-
}
3959+
list_for_each_entry(lport, &nvme_fc_lport_list, port_list)
3960+
list_for_each_entry(rport, &lport->endp_list, endp_list)
3961+
nvme_fc_delete_controllers(rport);
39893962
spin_unlock_irqrestore(&nvme_fc_lock, flags);
3990-
if (need_cleanup) {
3991-
pr_info("%s: waiting for ctlr deletes\n", __func__);
3992-
wait_for_completion(&nvme_fc_unload_proceed);
3993-
pr_info("%s: ctrl deletes complete\n", __func__);
3994-
}
3963+
flush_workqueue(nvme_delete_wq);
39953964

39963965
nvmf_unregister_transport(&nvme_fc_transport);
39973966

3998-
ida_destroy(&nvme_fc_local_port_cnt);
3999-
ida_destroy(&nvme_fc_ctrl_cnt);
4000-
40013967
device_destroy(&fc_class, MKDEV(0, 0));
40023968
class_unregister(&fc_class);
4003-
destroy_workqueue(nvme_fc_wq);
40043969
}
40053970

40063971
module_init(nvme_fc_init_module);

0 commit comments

Comments
 (0)