Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751173AbdFBBOa (ORCPT ); Thu, 1 Jun 2017 21:14:30 -0400 Received: from m12-16.163.com ([220.181.12.16]:32914 "EHLO m12-16.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750892AbdFBBO3 (ORCPT ); Thu, 1 Jun 2017 21:14:29 -0400 Message-ID: <5930BBC1.9070608@163.com> Date: Fri, 02 Jun 2017 09:13:37 +0800 From: Jia-Ju Bai User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1 MIME-Version: 1.0 To: "Nicholas A. Bellinger" CC: bart.vanassche@sandisk.com, davem@davemloft.net, hare@suse.com, elfring@users.sourceforge.net, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iscsi: Fix a sleep-in-atomic bug References: <1496201199-3661-1-git-send-email-baijiaju1990@163.com> <1496298093.27407.203.camel@haakon3.risingtidesystems.com> In-Reply-To: <1496298093.27407.203.camel@haakon3.risingtidesystems.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: EMCowAAn4S02uzBZSbjxHQ--.32866S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZF48ZFyxJry7Xry3Ar1DKFg_yoW5JFWfpF WDWw1akrWDX3y8uwnFqa1IqFsYgw4rGryUJFW7G34rCFsrJrZ5XF17t343uFW3tFyDCFnY ga12vas0grWIvFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j9vtAUUUUU= X-Originating-IP: [166.111.70.19] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbipRbqelUMFDjwCgAAss Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2719 Lines: 71 On 06/01/2017 02:21 PM, Nicholas A. Bellinger wrote: > Hi Jia-Ju, > > On Wed, 2017-05-31 at 11:26 +0800, Jia-Ju Bai wrote: >> The driver may sleep under a spin lock, and the function call path is: >> iscsit_tpg_enable_portal_group (acquire the lock by spin_lock) >> iscsi_update_param_value >> kstrdup(GFP_KERNEL) --> may sleep >> >> To fix it, the "GFP_KERNEL" is replaced with "GFP_ATOMIC". >> >> Signed-off-by: Jia-Ju Bai >> --- >> drivers/target/iscsi/iscsi_target_parameters.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) > Btw, the use of tpg->tpg_state_lock in iscsit_tpg_enable_portal_group() > while checking existing state and calling iscsi_update_param_value() is > not necessary, since lio_target_tpg_enable_store() is already holding > iscsit_get_tpg() -> tpg->tpg_access_lock. > > How about the following instead to only take tpg->tpg_state_lock when > updating tpg->tpg_state instead..? > > diff --git a/drivers/target/iscsi/iscsi_target_tpg.c b/drivers/target/iscsi/iscsi_target_tpg.c > index 2e7e08d..abaabba 100644 > --- a/drivers/target/iscsi/iscsi_target_tpg.c > +++ b/drivers/target/iscsi/iscsi_target_tpg.c > @@ -311,11 +311,9 @@ int iscsit_tpg_enable_portal_group(struct iscsi_portal_group *tpg) > struct iscsi_tiqn *tiqn = tpg->tpg_tiqn; > int ret; > > - spin_lock(&tpg->tpg_state_lock); > if (tpg->tpg_state == TPG_STATE_ACTIVE) { > pr_err("iSCSI target portal group: %hu is already" > " active, ignoring request.\n", tpg->tpgt); > - spin_unlock(&tpg->tpg_state_lock); > return -EINVAL; > } > /* > @@ -324,10 +322,8 @@ int iscsit_tpg_enable_portal_group(struct iscsi_portal_group *tpg) > * is enforced (as per default), and remove the NONE option. > */ > param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list); > - if (!param) { > - spin_unlock(&tpg->tpg_state_lock); > + if (!param) > return -EINVAL; > - } > > if (tpg->tpg_attrib.authentication) { > if (!strcmp(param->value, NONE)) { > @@ -341,6 +337,7 @@ int iscsit_tpg_enable_portal_group(struct iscsi_portal_group *tpg) > goto err; > } > > + spin_lock(&tpg->tpg_state_lock); > tpg->tpg_state = TPG_STATE_ACTIVE; > spin_unlock(&tpg->tpg_state_lock); > > @@ -353,7 +350,6 @@ int iscsit_tpg_enable_portal_group(struct iscsi_portal_group *tpg) > return 0; > > err: > - spin_unlock(&tpg->tpg_state_lock); > return ret; > } > I think it is fine to me. Thanks, Jia-Ju Bai