From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3E4EC4828F for ; Wed, 7 Feb 2024 22:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ffNikIgs/eKPSxTexWU4tDv3TD1bTgOima2Gal8vvMs=; b=1RmOrvN7FxKd7j1vQftbiNleNO 4UM00EuZzYkGqDmgAMFCqfPnuegKiMx+iRueLenKQ3FzGpEg1UjO6p3Mlw2yAczb3Ius/tf3cl9N5 u6QMfo4m49aVsEOzgWzThuGSCoUkVDKdR+3x9AZS92lQG1tYFaMTgoKyS5wVdgpNdkiJAgeg3qttk JrZRVtIBvMpq/mV0hU/KO8m+rHyoRoJoWsENSpJfb0smmwEerT0tXLAZ+PjiJAXSaYFB97FnU+ROV XIHvtKvW4Mw7tyu173M+E5Mf6uduqrjPMcTi427wvXkhCO6QsbSR7fplPx6lSW67vrvJCx4POXcZ4 ZMX1DPEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXqSJ-0000000C77j-43XY; Wed, 07 Feb 2024 22:31:48 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXpS6-0000000Btec-0Q5m for linux-nvme@bombadil.infradead.org; Wed, 07 Feb 2024 21:27:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ffNikIgs/eKPSxTexWU4tDv3TD1bTgOima2Gal8vvMs=; b=a6EsJ2ht+JYpRzYygzaii05/JR jj6Q6MaYYXHkdYnqKeWOoQZyR2lIOunI67qlS0HUbeHlVN9nuno8A8Q2xVJLCwNkqWpPa4isvl+FW jFXPhtw8TnocG28hC88FBfLEW287jbPZq+MLPZ22JcFTX3qOu/ARaPXLfhr35qke2leHfJAtDlkZX dneBSz7OmCAjuJ1PHYjygjgt1qfIlYEogOeutaNV+Aqvhh6dNkT1sEbQNmMNhh90j6SCgvE8CbwKV vO6vf57b6LKAadaSEnXPX1xOmN6AvOl7yVBGZL6VZ+U9hBvgwv9vfs0y8CFzvBytJHI7R4mc9xdEW PzQz/OtA==; Received: from dfw.source.kernel.org ([139.178.84.217]) by casper.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXpRz-0000000G8gr-2k6S for linux-nvme@lists.infradead.org; Wed, 07 Feb 2024 21:27:28 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 685F961AC4; Wed, 7 Feb 2024 21:27:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E109C433A6; Wed, 7 Feb 2024 21:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707341239; bh=MsV25K9BNlrdfm4UPrwCA5Vjn7UlNplH337sPHqe4II=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZQCBwHMqE8jyqKCASWxLepEB1/O/ICJKknM1K44tJpmV2F27xAq++Cd1Xu5qLlzV7 rzTL5Yi6PjyyFBEo+JHVu05UTE/U8i4qKgUCMp8jzQna3O22Y67cTP80bPnf84KEOu Hc32ZevRvTmAuA3UBNjTOAIcAEP1f+WR0L9zuLT9V1vo1IVMGMXM2hnl6lauTCR4iu lDj3trzQR1F16V7c+mybqJx/pg9p990uUFdg91tNHevhiCd1xarojMZkFyUvC2lZQL ZbhLSNvwqnATwuhpiVwDwUD7a+I9HDhz6mzk+hdhl16P6gr8SupslGruxpZb2XX4Q3 jDj96d6wVJ3Eg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Daniel Wagner , Christoph Hellwig , Hannes Reinecke , Keith Busch , Sasha Levin , james.smart@broadcom.com, sagi@grimberg.me, linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 5.10 10/16] nvme-fc: do not wait in vain when unloading module Date: Wed, 7 Feb 2024 16:26:50 -0500 Message-ID: <20240207212700.4287-10-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207212700.4287-1-sashal@kernel.org> References: <20240207212700.4287-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.209 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240207_212725_378887_6BE50924 X-CRM114-Status: GOOD ( 15.40 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org From: Daniel Wagner [ Upstream commit 70fbfc47a392b98e5f8dba70c6efc6839205c982 ] 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 Reviewed-by: Hannes Reinecke Signed-off-by: Daniel Wagner Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/fc.c | 47 ++++++------------------------------------ 1 file changed, 6 insertions(+), 41 deletions(-) diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index 906cab35afe7..8e05239073ef 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -220,11 +220,6 @@ static LIST_HEAD(nvme_fc_lport_list); static DEFINE_IDA(nvme_fc_local_port_cnt); static DEFINE_IDA(nvme_fc_ctrl_cnt); -static struct workqueue_struct *nvme_fc_wq; - -static bool nvme_fc_waiting_to_unload; -static DECLARE_COMPLETION(nvme_fc_unload_proceed); - /* * These items are short-term. They will eventually be moved into * a generic FC class. See comments in module init. @@ -254,8 +249,6 @@ nvme_fc_free_lport(struct kref *ref) /* remove from transport list */ spin_lock_irqsave(&nvme_fc_lock, flags); list_del(&lport->port_list); - if (nvme_fc_waiting_to_unload && list_empty(&nvme_fc_lport_list)) - complete(&nvme_fc_unload_proceed); spin_unlock_irqrestore(&nvme_fc_lock, flags); ida_simple_remove(&nvme_fc_local_port_cnt, lport->localport.port_num); @@ -3823,10 +3816,6 @@ static int __init nvme_fc_init_module(void) { int ret; - nvme_fc_wq = alloc_workqueue("nvme_fc_wq", WQ_MEM_RECLAIM, 0); - if (!nvme_fc_wq) - return -ENOMEM; - /* * NOTE: * It is expected that in the future the kernel will combine @@ -3844,7 +3833,7 @@ static int __init nvme_fc_init_module(void) ret = class_register(&fc_class); if (ret) { pr_err("couldn't register class fc\n"); - goto out_destroy_wq; + return ret; } /* @@ -3868,8 +3857,6 @@ static int __init nvme_fc_init_module(void) device_destroy(&fc_class, MKDEV(0, 0)); out_destroy_class: class_unregister(&fc_class); -out_destroy_wq: - destroy_workqueue(nvme_fc_wq); return ret; } @@ -3889,45 +3876,23 @@ nvme_fc_delete_controllers(struct nvme_fc_rport *rport) spin_unlock(&rport->lock); } -static void -nvme_fc_cleanup_for_unload(void) +static void __exit nvme_fc_exit_module(void) { struct nvme_fc_lport *lport; struct nvme_fc_rport *rport; - - list_for_each_entry(lport, &nvme_fc_lport_list, port_list) { - list_for_each_entry(rport, &lport->endp_list, endp_list) { - nvme_fc_delete_controllers(rport); - } - } -} - -static void __exit nvme_fc_exit_module(void) -{ unsigned long flags; - bool need_cleanup = false; spin_lock_irqsave(&nvme_fc_lock, flags); - nvme_fc_waiting_to_unload = true; - if (!list_empty(&nvme_fc_lport_list)) { - need_cleanup = true; - nvme_fc_cleanup_for_unload(); - } + list_for_each_entry(lport, &nvme_fc_lport_list, port_list) + list_for_each_entry(rport, &lport->endp_list, endp_list) + nvme_fc_delete_controllers(rport); spin_unlock_irqrestore(&nvme_fc_lock, flags); - if (need_cleanup) { - pr_info("%s: waiting for ctlr deletes\n", __func__); - wait_for_completion(&nvme_fc_unload_proceed); - pr_info("%s: ctrl deletes complete\n", __func__); - } + flush_workqueue(nvme_delete_wq); nvmf_unregister_transport(&nvme_fc_transport); - ida_destroy(&nvme_fc_local_port_cnt); - ida_destroy(&nvme_fc_ctrl_cnt); - device_destroy(&fc_class, MKDEV(0, 0)); class_unregister(&fc_class); - destroy_workqueue(nvme_fc_wq); } module_init(nvme_fc_init_module); -- 2.43.0