From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1945984AbbKTXjq (ORCPT ); Fri, 20 Nov 2015 18:39:46 -0500 Received: from smtp2.ccs.ornl.gov ([160.91.199.39]:57245 "EHLO smtp2.ccs.ornl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422755AbbKTXg6 (ORCPT ); Fri, 20 Nov 2015 18:36:58 -0500 From: James Simmons To: Greg Kroah-Hartman , devel@driverdev.osuosl.org, Oleg Drokin , Andreas Dilger Cc: Linux Kernel Mailing List , lustre-devel@lists.lustre.org, Amir Shehata Subject: [PATCH 32/40] staging: lustre: prevent assert on LNet module unload Date: Fri, 20 Nov 2015 18:36:08 -0500 Message-Id: <1448062576-23757-33-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1448062576-23757-1-git-send-email-jsimmons@infradead.org> References: <1448062576-23757-1-git-send-email-jsimmons@infradead.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Amir Shehata There is a use case where lnet can be unloaded while there are no NIs configured. Removing lnet in this case will cause LNetFini() to be called without a prior call to LNetNIFini(). This will cause the LASSERT(the_lnet.ln_refcount == 0) to be triggered. To deal with this use case when LNet is configured a reference count on the module is taken using try_module_get(). This way LNet must be unconfigured before it could be removed; therefore avoiding the above case. When LNet is unconfigured module_put() is called to return the reference count. Signed-off-by: Amir Shehata Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6010 Reviewed-on: http://review.whamcloud.com/13110 Reviewed-by: James Simmons Reviewed-by: Doug Oucharek Reviewed-by: Oleg Drokin --- drivers/staging/lustre/lnet/lnet/module.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/drivers/staging/lustre/lnet/lnet/module.c b/drivers/staging/lustre/lnet/lnet/module.c index 48eb085..b1f32a6 100644 --- a/drivers/staging/lustre/lnet/lnet/module.c +++ b/drivers/staging/lustre/lnet/lnet/module.c @@ -53,13 +53,21 @@ lnet_configure(void *arg) mutex_lock(&lnet_config_mutex); if (!the_lnet.ln_niinit_self) { + rc = try_module_get(THIS_MODULE); + + if (rc != 1) + goto out; + rc = LNetNIInit(LNET_PID_LUSTRE); if (rc >= 0) { the_lnet.ln_niinit_self = 1; rc = 0; + } else { + module_put(THIS_MODULE); } } +out: mutex_unlock(&lnet_config_mutex); return rc; } @@ -74,6 +82,7 @@ lnet_unconfigure(void) if (the_lnet.ln_niinit_self) { the_lnet.ln_niinit_self = 0; LNetNIFini(); + module_put(THIS_MODULE); } mutex_lock(&the_lnet.ln_api_mutex); -- 1.7.1