From patchwork Fri Jun 2 03:19:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 9761481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4E22760363 for ; Fri, 2 Jun 2017 03:19:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4176E28456 for ; Fri, 2 Jun 2017 03:19:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34AFE28521; Fri, 2 Jun 2017 03:19:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9406928456 for ; Fri, 2 Jun 2017 03:19:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751141AbdFBDTT (ORCPT ); Thu, 1 Jun 2017 23:19:19 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:39287 "EHLO linux-iscsi.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751136AbdFBDTT (ORCPT ); Thu, 1 Jun 2017 23:19:19 -0400 Received: from [192.168.1.66] (75-37-194-224.lightspeed.lsatca.sbcglobal.net [75.37.194.224]) (using SSLv3 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: nab) by linux-iscsi.org (Postfix) with ESMTPSA id B2DC440959; Fri, 2 Jun 2017 03:22:16 +0000 (UTC) Message-ID: <1496373556.27407.210.camel@haakon3.risingtidesystems.com> Subject: Re: Kernel crash with target-pending/for-next From: "Nicholas A. Bellinger" To: Bart Van Assche Cc: "target-devel@vger.kernel.org" Date: Thu, 01 Jun 2017 20:19:16 -0700 In-Reply-To: <1496341047.3075.8.camel@sandisk.com> References: <1496341047.3075.8.camel@sandisk.com> X-Mailer: Evolution 3.4.4-1 Mime-Version: 1.0 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, 2017-06-01 at 18:17 +0000, Bart Van Assche wrote: > Hello Nic, > > This morning I started testing your for-next branch (commit b968ec8ff101 > with no changes). After a few seconds a kernel crash was triggered (see below). > In the many tests I ran during the past two years of the ib_srpt driver I had > not encountered any crash triggered by ib_srpt so this must be a recently > introduced regression in the target core. This regression most likely has been > introduced by one of these patches: > > b968ec8ff101 target/configfs: Kill se_lun->lun_link_magic > baacb554a73b target/configfs: Kill se_device->dev_link_magic > ba438d7c8d39 target: Avoid target_shutdown_sessions loop during queue_depth change Alas, the local list and unprotected list_del_init() ba438d7c8d won't work for all fabric cases. Here's the updated version to restore original behavior for se_node_acl delete, but still avoid the endless loop with the iscsi-target specific case where se_node_acl->queue_depth changes. Care to verify on ib_srpt, or just a report and never confirm..? From 9fdc33be4ef60ba87c8bf8a4dab6e756ec3b06e6 Mon Sep 17 00:00:00 2001 From: Nicholas Bellinger Date: Thu, 1 Jun 2017 08:57:15 +0200 Subject: [PATCH-v2] target: Avoid target_shutdown_sessions loop during queue_depth change When target_shutdown_sessions() is invoked to shutdown all active sessions associated with a se_node_acl when se_node_acl->queue_depth is changed via core_tpg_set_initiator_node_queue_depth(), it's possible that new connections reconnect immediately after explicit shutdown occurs via target_shutdown_sessions(). Which means it's possible for the newly reconnected session with the proper queue_depth can be shutdown multiple times when target_shutdown_sessions() loops to drain all active sessions for all cases. This was regression was introduced by: commit bc6e6bb470eda42f44bcac96c261cff1216577b3 Author: Christoph Hellwig Date: Mon May 2 15:45:19 2016 +0200 target: consolidate and fix session shutdown To avoid this case, instead change target_shutdown_sessions() to pass 'do_restart' and avoid the looping drain of sessions when invoked via core_tpg_set_initiator_node_queue_depth(), but still loop during normal se_node_acl delete until all associated sessions have been shutdown. (v2 - go back to the original version instead of a local list, in order to protect list_del_init(&sess->sess_acl_list) from transport_deregister_session_configfs. Also use safe list walking in target_shutdown_sessions - nab) Cc: Christoph Hellwig Cc: Mike Christie Cc: Hannes Reinecke Signed-off-by: Nicholas Bellinger --- drivers/target/target_core_tpg.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index 3691373..1b2b60e 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c @@ -336,14 +336,14 @@ struct se_node_acl *core_tpg_add_initiator_node_acl( return acl; } -static void target_shutdown_sessions(struct se_node_acl *acl) +static void target_shutdown_sessions(struct se_node_acl *acl, bool do_restart) { - struct se_session *sess; + struct se_session *sess, *sess_tmp; unsigned long flags; restart: spin_lock_irqsave(&acl->nacl_sess_lock, flags); - list_for_each_entry(sess, &acl->acl_sess_list, sess_acl_list) { + list_for_each_entry_safe(sess, sess_tmp, &acl->acl_sess_list, sess_acl_list) { if (sess->sess_tearing_down) continue; @@ -352,7 +352,11 @@ static void target_shutdown_sessions(struct se_node_acl *acl) if (acl->se_tpg->se_tpg_tfo->close_session) acl->se_tpg->se_tpg_tfo->close_session(sess); - goto restart; + + if (do_restart) + goto restart; + + spin_lock_irqsave(&acl->nacl_sess_lock, flags); } spin_unlock_irqrestore(&acl->nacl_sess_lock, flags); } @@ -367,7 +371,7 @@ void core_tpg_del_initiator_node_acl(struct se_node_acl *acl) list_del(&acl->acl_list); mutex_unlock(&tpg->acl_node_mutex); - target_shutdown_sessions(acl); + target_shutdown_sessions(acl, true); target_put_nacl(acl); /* @@ -414,7 +418,7 @@ int core_tpg_set_initiator_node_queue_depth( /* * Shutdown all pending sessions to force session reinstatement. */ - target_shutdown_sessions(acl); + target_shutdown_sessions(acl, false); pr_debug("Successfully changed queue depth to: %d for Initiator" " Node: %s on %s Target Portal Group: %u\n", acl->queue_depth,