From patchwork Tue Sep 11 17:18:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhani, Himanshu" X-Patchwork-Id: 10596005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38CCE920 for ; Tue, 11 Sep 2018 17:18:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BD7C29B1F for ; Tue, 11 Sep 2018 17:18:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FE3829B23; Tue, 11 Sep 2018 17:18:50 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,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 7AF8F29B1F for ; Tue, 11 Sep 2018 17:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728127AbeIKWTG (ORCPT ); Tue, 11 Sep 2018 18:19:06 -0400 Received: from mail-bl2nam02on0051.outbound.protection.outlook.com ([104.47.38.51]:34336 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728010AbeIKWTF (ORCPT ); Tue, 11 Sep 2018 18:19:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pyA6XakyqvfMV9DpRqFABpQKjSypQgJd01c+GralKEI=; b=EZK/B1YoEV8sQpwwwiAD9tPkYiW2vfI3myGDRPF2vlbDEaSuE7S2N1k0Ll3K8IJijW9XYjNAhSw4vB9yCMsEVCSLqFVGT2f5JALC/LJAF3DSXaD4CsBfbmkT7atOAimBB0R+1X3aJGo9vfkmKebtpSzkOu8d47j+5m63Ma4z0fE= Received: from DM6PR07CA0011.namprd07.prod.outlook.com (2603:10b6:5:94::24) by DM6PR07MB5498.namprd07.prod.outlook.com (2603:10b6:5:30::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1101.16; Tue, 11 Sep 2018 17:18:46 +0000 Received: from CO1NAM05FT061.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e50::202) by DM6PR07CA0011.outlook.office365.com (2603:10b6:5:94::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1122.15 via Frontend Transport; Tue, 11 Sep 2018 17:18:46 +0000 Authentication-Results: spf=pass (sender IP is 50.232.66.26) smtp.mailfrom=cavium.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=cavium.com; Received-SPF: Pass (protection.outlook.com: domain of cavium.com designates 50.232.66.26 as permitted sender) receiver=protection.outlook.com; client-ip=50.232.66.26; helo=CAEXCH02.caveonetworks.com; Received: from CAEXCH02.caveonetworks.com (50.232.66.26) by CO1NAM05FT061.mail.protection.outlook.com (10.152.96.179) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.20.1164.5 via Frontend Transport; Tue, 11 Sep 2018 17:18:45 +0000 Received: from dut1171.mv.qlogic.com (172.29.51.171) by CAEXCH02.caveonetworks.com (10.17.4.29) with Microsoft SMTP Server id 14.2.347.0; Tue, 11 Sep 2018 10:18:31 -0700 Received: from dut1171.mv.qlogic.com (localhost [127.0.0.1]) by dut1171.mv.qlogic.com (8.14.7/8.14.7) with ESMTP id w8BHITT8029099; Tue, 11 Sep 2018 10:18:29 -0700 Received: (from root@localhost) by dut1171.mv.qlogic.com (8.14.7/8.14.7/Submit) id w8BHITao029098; Tue, 11 Sep 2018 10:18:29 -0700 From: Himanshu Madhani To: , CC: , Subject: [PATCH 12/16] qla2xxx: Fix premature command free Date: Tue, 11 Sep 2018 10:18:23 -0700 Message-ID: <20180911171827.29016-13-himanshu.madhani@cavium.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20180911171827.29016-1-himanshu.madhani@cavium.com> References: <20180911171827.29016-1-himanshu.madhani@cavium.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:50.232.66.26;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(136003)(396003)(346002)(39860400002)(376002)(2980300002)(438002)(189003)(199004)(51416003)(76176011)(81156014)(8676002)(4326008)(81166006)(47776003)(6666003)(2906002)(69596002)(50226002)(316002)(110136005)(54906003)(305945005)(14444005)(8936002)(356003)(50466002)(106466001)(36756003)(48376002)(476003)(44832011)(446003)(486006)(86362001)(11346002)(80596001)(87636003)(2616005)(126002)(106002)(16586007)(5660300001)(42186006)(26005)(1076002)(336012)(478600001)(186003)(72206003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR07MB5498;H:CAEXCH02.caveonetworks.com;FPR:;SPF:Pass;LANG:en;PTR:50-232-66-26-static.hfc.comcastbusiness.net;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;CO1NAM05FT061;1:cSmatDChGBxfaPeegAWaAY3t78m6ecKbkGWC9NMlPjNKrYn4kOglGHDR+OPS/IlwKpbVeRQawPul96RqbM28LtqGKwywMOFgFEe8zxsh66ZR3rL+mTWRicGB30Khjf+I X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7fbb3a7d-d49a-414e-33c9-08d6180aa1ab X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4608076)(2017052603328)(7153060);SRVR:DM6PR07MB5498; X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5498;3:Q9HId7VUhEZiaxZlM+Twamm0L0jZIg0JuLokIjYqzvqML4Q6zoAO47IJxi77gtvi6dlBSoQLgIQsbR5cJz5mKHPovQtA0700Ir1Vtx4qBRx+AvYnUzRa6MgMLbUU4GTVwz0Jqj6XNECVkGuHm/GeSTTXBD+K5eKE+gos6G+zRO+OYTKuaceQnUk66NTCqM8PKgXOZoTcC+1i5oS1+T7dwgon96R/j5Wbnr+KBLGZpuQedk/o3LvuM+cQad5j7Z/XnjmnwOhcpdzmMTmTC8R7LlayiQUMj47OUUQuXgtY1yK7M77CFHdOE0kFkSHtZtIb5aM39YjMUv5+sNXObQ6S26r2K5cIjHvQMHxtXWwjKvg=;25:2HuohjGeMclE8x+fVoMCEQXSCVWpjCV8DDRpDk7Sk/5g0/0pnZHW83y8mWPAMQxHIf1bEVIPXYLvVDRBQO/JXla7QwSqPuArPtQx38A2avZ58Rv8FjkBrNKmM9SN+IPWi7w+IsTPA+Lbt0N+5YshjGFLpZr44HCZGjV1zmLbdNKLstvPsmhu50SqL+J2sCbMNiST4LGgvXX71cUdyGB20bO2tug3H6RVqFllUVvEntzHUJ3nU9X1kku4VFhlD1Q4sNIXvLYKKs7tJqHAjuybSvEw3B62QFntxXY9odFE0olgv8DrQqeSIb6w1wObycuDdg5krNuschFqfk/oevXEtA== X-MS-TrafficTypeDiagnostic: DM6PR07MB5498: X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5498;31:9TdB8TbJRhlUyTAGlnaUJ07XytQskJaeadm10Pvh3qWtkE7oygYOXtjrRhT1fgJloExA22bvsl+O7GYTw6TgnmrFmnTUlKQ2JafSsyKnx4Q4/TnF8evB64F1p+wv8AIqHlof/UGPcHDdWeTD1tsDQSsSxMNJIbzYc2yesPrVmyAt8/9OxvIioppuX47DPG0RwXC/hCcYDjd284qwLC/6oyKsAMvATdA6gMVI2e+vmZQ=;20:xdDnAbRCEedqyKGFCwckPV5mcYydN2ast8DyTe+sfGicVv4ci5R1NyKHdcPSGBgIlrTC6qVJZK3F/m9xyv2mzYSdauygjRZsbGoHHg3X3gm9o1nkmj+Hun8o0xAarypKqjqOFS7MNp4T1xdHUeWhtMT+6obauq1l5NObTE5Cdr7wjK5eHkbrc+t7E9M5ItVycjZVc+GMZ88zDL+0tR/HxmNIJSx/eSRgQfU8dkB1BhAC5IB+NMugzXKKcR+mQ+xK5WrCVJWfHRd1PIu+Oh17sFtzlk37aRDdNxbfa4kSP7mAsc3AeqmEMR9LXHILLvGhCrdYeZkF3Qf/XbkDfS7k6oI3HGHGMSVV0GvExHu7vzpQ2S5NNZuarf6Yj+GBTJSDKn+17G7uFZFQJBZfCkBN2PzuJVZSSeMlOSox9QV3jYSholXVvobcln1pPZKUswXYM4ETA4wJvIlOkAcCyeKSiamO2UtY9CmCUp7icWTZRPcwuLEFIY6T+nPCxWP4WGcC X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231311)(944501410)(52105095)(3002001)(93006095)(93004095)(10201501046)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699050);SRVR:DM6PR07MB5498;BCL:0;PCL:0;RULEID:;SRVR:DM6PR07MB5498; X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5498;4:ZOyAu5O1EfBkvUIxIMnS+uF8/Ga7lhd0W/5HkmtiXlpdT1f56OOMr2KXX5fGYns2KkymKcRMwIIz/2sCymI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Wj0DRhouek2TmoWrHIexw8zwDyIjyR+m4vfXZ18N500kEEG4ZsJei2MIv3esETikHrQL4xlSeIS4GmymbtAb0DZ9ZcGJWc0rvS8CiCfIMl7E7fY3dPRz6DRQPS9VbdKAgg6JVYHXLpA==;5:eY64A/3dpigbHeDbyVzashVpO9DUXE1HM3xF9PYJOGti2UGNpbKz+wfXzzX7Fh8omFx9bh9kjFcqyG1NReJgASoMG4aPN0t/ddlKR7m/F4ezo7XuDE+XhjvLudliSdVbnZ8mADcxz0dI6B7ua92nwp26qE3r0du7senzwV4I1XI=;7:9kUVrTKFHxo6OjtGL85zn3KQ21i0gmf7fnHTIu3pZ03erIGh34vbAXko2YWllUPDg+n8Y5HCRPEs6JWdbSu+diuYYIoR04nlk/Eu+NXJI80xq0637codniCQ4o3CV8UpaZC34FGrZOVSSVrnpHwzE15CD6D/1luhBfBt7ofA39igDI70idZNwS+zPnOMsQP+M90vioYZNoEu/I4Y4LdqKEx+hUt1o7DeD/9x27ZdnjXFR6dRDgipfuoSsC2+5Kv0 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2018 17:18:45.2470 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7fbb3a7d-d49a-414e-33c9-08d6180aa1ab X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=711e4ccf-2e9b-4bcf-a551-4094005b6194;Ip=[50.232.66.26];Helo=[CAEXCH02.caveonetworks.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB5498 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Quinn Tran When qla2xxx and Target Core gets out of sync, during command cleanup, qla2xxx will not free command until it is out of firmware's hand and Target Core has called the release on the command. This patch adds synchronization using cmd_lock and release flag. if the release flag is set then qla2xxx will free up the command using qlt_free_cmd() otherwise transport_generic_free_cmd() will be responsible for relase of the command. Signed-off-by: Quinn Tran Signed-off-by: Himanshu Madhani --- drivers/scsi/qla2xxx/qla_target.c | 4 ++++ drivers/scsi/qla2xxx/qla_target.h | 1 + drivers/scsi/qla2xxx/tcm_qla2xxx.c | 45 +++++++++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c index 666146a86d10..a69ec4519d81 100644 --- a/drivers/scsi/qla2xxx/qla_target.c +++ b/drivers/scsi/qla2xxx/qla_target.c @@ -3383,7 +3383,9 @@ int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ + spin_lock(&cmd->cmd_lock); cmd->cmd_sent_to_fw = 1; + spin_unlock(&cmd->cmd_lock); cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); /* Memory Barrier */ @@ -3462,7 +3464,9 @@ int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) qlt_load_data_segments(&prm); cmd->state = QLA_TGT_STATE_NEED_DATA; + spin_lock(&cmd->cmd_lock); cmd->cmd_sent_to_fw = 1; + spin_unlock(&cmd->cmd_lock); cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); /* Memory Barrier */ diff --git a/drivers/scsi/qla2xxx/qla_target.h b/drivers/scsi/qla2xxx/qla_target.h index 6a59c99a63da..91403269b204 100644 --- a/drivers/scsi/qla2xxx/qla_target.h +++ b/drivers/scsi/qla2xxx/qla_target.h @@ -900,6 +900,7 @@ struct qla_tgt_cmd { unsigned int aborted:1; unsigned int data_work:1; unsigned int data_work_free:1; + unsigned int released:1; struct scatterlist *sg; /* cmd data buffer SG vector */ int sg_cnt; /* SG segments count */ diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c index e03d12a5f986..7d3d4a82fe96 100644 --- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c +++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c @@ -277,14 +277,25 @@ static void tcm_qla2xxx_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) static void tcm_qla2xxx_complete_free(struct work_struct *work) { struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work); + bool released = false; + unsigned long flags; cmd->cmd_in_wq = 0; WARN_ON(cmd->trc_flags & TRC_CMD_FREE); + spin_lock_irqsave(&cmd->cmd_lock, flags); cmd->qpair->tgt_counters.qla_core_ret_sta_ctio++; cmd->trc_flags |= TRC_CMD_FREE; - transport_generic_free_cmd(&cmd->se_cmd, 0); + cmd->cmd_sent_to_fw = 0; + if (cmd->released) + released = true; + spin_unlock_irqrestore(&cmd->cmd_lock, flags); + + if (released) + qlt_free_cmd(cmd); + else + transport_generic_free_cmd(&cmd->se_cmd, 0); } /* @@ -325,6 +336,7 @@ static int tcm_qla2xxx_check_stop_free(struct se_cmd *se_cmd) static void tcm_qla2xxx_release_cmd(struct se_cmd *se_cmd) { struct qla_tgt_cmd *cmd; + unsigned long flags; if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) { struct qla_tgt_mgmt_cmd *mcmd = container_of(se_cmd, @@ -332,9 +344,16 @@ static void tcm_qla2xxx_release_cmd(struct se_cmd *se_cmd) qlt_free_mcmd(mcmd); return; } - cmd = container_of(se_cmd, struct qla_tgt_cmd, se_cmd); - qlt_free_cmd(cmd); + + spin_lock_irqsave(&cmd->cmd_lock, flags); + if (cmd->cmd_sent_to_fw) { + cmd->released = 1; + spin_unlock_irqrestore(&cmd->cmd_lock, flags); + } else { + spin_unlock_irqrestore(&cmd->cmd_lock, flags); + qlt_free_cmd(cmd); + } } static void tcm_qla2xxx_release_session(struct kref *kref) @@ -499,6 +518,7 @@ static int tcm_qla2xxx_handle_cmd(scsi_qla_host_t *vha, struct qla_tgt_cmd *cmd, static void tcm_qla2xxx_handle_data_work(struct work_struct *work) { struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work); + unsigned long flags; /* * Ensure that the complete FCP WRITE payload has been received. @@ -506,6 +526,25 @@ static void tcm_qla2xxx_handle_data_work(struct work_struct *work) */ cmd->cmd_in_wq = 0; + spin_lock_irqsave(&cmd->cmd_lock, flags); + cmd->cmd_sent_to_fw = 0; + + if (cmd->released) { + spin_unlock_irqrestore(&cmd->cmd_lock, flags); + qlt_free_cmd(cmd); + return; + } + + cmd->data_work = 1; + if (cmd->aborted) { + cmd->data_work_free = 1; + spin_unlock_irqrestore(&cmd->cmd_lock, flags); + + tcm_qla2xxx_free_cmd(cmd); + return; + } + spin_unlock_irqrestore(&cmd->cmd_lock, flags); + cmd->qpair->tgt_counters.qla_core_ret_ctio++; if (!cmd->write_data_transferred) { /*