From patchwork Wed Feb 8 22:24:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9563619 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 28C106020F for ; Wed, 8 Feb 2017 22:27:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F16772840B for ; Wed, 8 Feb 2017 22:27:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E64E12852B; Wed, 8 Feb 2017 22:27:29 +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 8B2E62840B for ; Wed, 8 Feb 2017 22:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751799AbdBHW12 (ORCPT ); Wed, 8 Feb 2017 17:27:28 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:63845 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751443AbdBHW1Z (ORCPT ); Wed, 8 Feb 2017 17:27:25 -0500 X-IronPort-AV: E=Sophos;i="5.35,348,1483977600"; d="scan'208";a="76618141" Received: from unknown (HELO milsmgep15.sandisk.com) ([63.163.107.21]) by ob1.hgst.iphmx.com with ESMTP; 09 Feb 2017 06:28:18 +0800 Received: from MILHUBIP03.sdcorp.global.sandisk.com (Unknown_Domain [10.201.67.162]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by (Symantec Messaging Gateway) with SMTP id D3.54.57638.9CA9B985; Wed, 8 Feb 2017 14:25:13 -0800 (PST) Received: from milsmgip12.sandisk.com (10.177.9.6) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Wed, 8 Feb 2017 14:25:11 -0800 X-AuditID: 0ac94369-26dee9800001e126-f3-589b9ac96b25 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id F1.42.18148.7CA9B985; Wed, 8 Feb 2017 14:25:11 -0800 (PST) From: Bart Van Assche To: Bart Van Assche CC: , Hannes Reinecke , Christoph Hellwig , Andy Grover , David Disseldorp Subject: [PATCH v4 14/37] target: Use the command reference counting mechanism consistently Date: Wed, 8 Feb 2017 14:24:44 -0800 Message-ID: <20170208222507.25715-15-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170208222507.25715-1-bart.vanassche@sandisk.com> References: <20170208222507.25715-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrPLMWRmVeSWpSXmKPExsXCddJ5ke7JWbMjDK4uM7TYP+sZk8XX/9NZ LBa82ctmsXL1USaL1qVvmRxYPXbfbGDzeL/vKpvH+i1XWTw2n672+LxJLoA1issmJTUnsyy1 SN8ugStj87Ze1oJpghVz1jUxNjAe4eti5OSQEDCR+HtpHmMXIxeHkMBSJok9hxqZQRJCAlsZ JU7t9oQp2tN8kB2iaCOjxO/+B4wgCTYBI4lv72eygNgiAgYSv3svgMWZBVYzSlx/KAliCwtE S+w/v5IVxGYRUJGYse0NWA2vgIPE5TtLmCEWyEvsarsIVsMJFJ/w8hkjxBH2Eq8OfAG7TkJg EqvEv97/rBDNghInZz5hgVgmIXHwxQuoq9UlTi6ZzzSBUWgWkrJZSMoWMDKtYhTLzcwpzk1P LTA01StOzEvJLM7WS87P3cQICfbMHYx3n3gfYhTgYFTi4a2wnB0hxJpYVlyZe4hRgoNZSYQ3 ZRpQiDclsbIqtSg/vqg0J7X4EKM0B4uSOO85makRQgLpiSWp2ampBalFMFkmDk6pBkaWY4Hv BP9MnS4oF3n/qua7l88iFA04p5Z5Z95f294usrb6TTNzwaz5XCU7Ln61YpP65LJnVvNnvdoH 3Q6CJ0M8EkIa9aV0H97asDt/Pgv7savBYr+u/9H4qcMvf+tBMNdvb3kT/aMaicK/2rquzTkn VSnJGFoyc677jS0MQk97/dUjWJ5KMSmxFGckGmoxFxUnAgBSQqpocgIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAJMWRmVeSWpSXmKPExsXCtZGTTff4rNkRBivOqlnsn/WMyeLgzzZG i6//p7NYLHizl81i5eqjTBatS98yObB57L7ZwObxft9VNo9pa84zeazfcpXFY/Ppao/Pm+QC 2KK4bFJSczLLUov07RK4MjZv62UtmCZYMWddE2MD4xG+LkZODgkBE4k9zQfZuxi5OIQE1jNK TOv5zAKSYBMwkvj2fiaYLSJgIPG79wIjSBGzwFpGiT0zZrGCJIQFoiX2n18JZrMIqEo8vNzA CGLzCjhITPmwkglig7zErraLYDWcQPEJL5+B1QgJ2Eu8OvCFcQIj9wJGhlWMYrmZOcW56ZkF hkZ6xYl5KZnF2XrJ+bmbGCFhErWD8fpE80OMTBycUg2MPRKWKv2bWK/EJK1XqxFSeRVplvZY Imvi5yU2HJ4FQVsPiRzYtqf2bu2Fv7pPC27kFnRzeZceKY+bNvdsW8fWUu+13YyXmf0aGBdL N646dWefkfKGu31WP76+j3xRdSjv0o15glZn7Z7edyx2WHHzQwLPN26WHpmuxH0Wv+edqNnw fMITudd3lViKMxINtZiLihMBX5UolcMBAAA= 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 Use the se_cmd reference counting mechanism instead of calling the .release_cmd() method directly. Fix a reference leak triggered by transport_cmd_check_stop_to_fabric() that did not matter until now because of the direct .release_cmd() calls. If CMD_T_STOP is set for a command, transport_cmd_finish_abort() namely calls transport_cmd_check_stop_to_fabric() and the latter function returns 1 although the command refcount is not yet zero. Signed-off-by: Bart Van Assche Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Andy Grover Cc: David Disseldorp Reviewed-by: Hannes Reinecke --- drivers/target/target_core_transport.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 1e1f1ed2ef17..7b5ae36e3c58 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -622,13 +622,11 @@ static int transport_cmd_check_stop(struct se_cmd *cmd, bool remove_from_lists, pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08llx\n", __func__, __LINE__, cmd->tag); - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - complete_all(&cmd->t_transport_stop_comp); - return 1; + } else { + cmd->transport_state &= ~CMD_T_ACTIVE; } - cmd->transport_state &= ~CMD_T_ACTIVE; if (remove_from_lists) { /* * Some fabric modules like tcm_loop can release @@ -2532,7 +2530,7 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) if (aborted) { pr_debug("Detected CMD_T_ABORTED for ITT: %llu\n", cmd->tag); wait_for_completion(&cmd->cmd_wait_comp); - cmd->se_tfo->release_cmd(cmd); + transport_put_cmd(cmd); ret = 1; } return ret; @@ -2695,7 +2693,8 @@ void target_wait_for_sess_cmds(struct se_session *se_sess) " fabric state: %d\n", se_cmd, se_cmd->t_state, se_cmd->se_tfo->get_cmd_state(se_cmd)); - se_cmd->se_tfo->release_cmd(se_cmd); + WARN_ON_ONCE(!se_cmd->se_sess); + target_put_sess_cmd(se_cmd); } spin_lock_irqsave(&se_sess->sess_cmd_lock, flags);