From patchwork Thu Jul 26 23:34:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhani, Himanshu" X-Patchwork-Id: 10546521 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 57305112B for ; Thu, 26 Jul 2018 23:34:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 582AC2BB13 for ; Thu, 26 Jul 2018 23:34:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5687F2BD3F; Thu, 26 Jul 2018 23:34:58 +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 9E6412BC18 for ; Thu, 26 Jul 2018 23:34:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731773AbeG0AyA (ORCPT ); Thu, 26 Jul 2018 20:54:00 -0400 Received: from mail-dm3nam03on0043.outbound.protection.outlook.com ([104.47.41.43]:49120 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731286AbeG0AyA (ORCPT ); Thu, 26 Jul 2018 20:54:00 -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=nq1yfjMp+LuxPaTNylDg70FUIgqvOEVUpe+qB+r8uuI=; b=gxYunmYGEnp3CCs7s8ECyXJkWyDwdwXhdvVXl7DLHN4ri7xbF62QDtdGammOe7X7nAbDxMTus0e7rutse37bQdVRf0IOatJR6YIVu9O68P7Tm4Lj+0ZE03ggNMGncFnP6/IZVgDudvt8ZxDfvOacPXJJhhy5/c+9CNMFxslg558= Received: from SN1PR0701CA0055.namprd07.prod.outlook.com (2a01:111:e400:52fd::23) by SN1PR07MB1469.namprd07.prod.outlook.com (2a01:111:e400:5838::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.17; Thu, 26 Jul 2018 23:34:51 +0000 Received: from CO1NAM05FT004.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e50::206) by SN1PR0701CA0055.outlook.office365.com (2a01:111:e400:52fd::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.995.16 via Frontend Transport; Thu, 26 Jul 2018 23:34:51 +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 CO1NAM05FT004.mail.protection.outlook.com (10.152.96.109) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.20.1017.0 via Frontend Transport; Thu, 26 Jul 2018 23:34:50 +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; Thu, 26 Jul 2018 16:34:45 -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 w6QNYiEH013221; Thu, 26 Jul 2018 16:34:44 -0700 Received: (from root@localhost) by dut1171.mv.qlogic.com (8.14.7/8.14.7/Submit) id w6QNYiHh013220; Thu, 26 Jul 2018 16:34:44 -0700 From: Himanshu Madhani To: , CC: , Subject: [PATCH] qla2xxx: Fix memory leak for allocating abort IOCB Date: Thu, 26 Jul 2018 16:34:44 -0700 Message-ID: <20180726233444.13186-1-himanshu.madhani@cavium.com> X-Mailer: git-send-email 2.12.0 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)(39860400002)(346002)(396003)(136003)(376002)(2980300002)(438002)(189003)(199004)(186003)(14444005)(86362001)(110136005)(1857600001)(48376002)(2906002)(16586007)(316002)(106002)(486006)(44832011)(54906003)(2616005)(476003)(126002)(42186006)(8676002)(8936002)(81156014)(1076002)(26005)(50226002)(336012)(51416003)(81166006)(36756003)(50466002)(80596001)(478600001)(72206003)(87636003)(305945005)(69596002)(5660300001)(356003)(47776003)(4326008)(106466001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR07MB1469;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;CO1NAM05FT004;1:X4kenaL0RJJJEDrH6Mpelyr62DAA96JGTtJN2phfMMJAuGn8nRwzbAxcpBQSPDlxifqa/6PFPNCPO6l5PsTtIqKoFVZ1ZDeDLUBVeCnB517J+S0ovtAUtuqQeuZqyffO X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d8633df-fd21-44f1-0848-08d5f350621c X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4608076)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060);SRVR:SN1PR07MB1469; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB1469;3:4SOKLQhzTOJ9zOOouB77Ou+PGKGT8DP//90TXFAc3OM4jjARKtkAe4YHicrKMwM2l/VshjMC99FJbbOa1sfGPzlfDGm1f/i13UWiUedXA/vLoE4J/gFQ5eVFBY74lds3pFiTwR2UebtkYjifs0OcctO/F8K+4yF5lQ1ktiyNdt14cinsXYPArBXe1G+VojIOn8bG6VLZeVUk1uIxOmQfBCk3h6E05TCmcBpQv28O02uyE0iRDns9SETG+lIzNHBcb3yIYbmlmk7xjMRFE6xmUo0vfq3AZ4Gdv3PhAPImqhnLneMvvwsz2OM4d6+PkjVmJ1CxOQEQ54OIMJRfdeQD589SL76DtxA0I4D+p1zZAdU=;25:b0GoRPn3CgP4TtOHnajCrvnF/6c509Z8GPbVQbkQ6Qktn4MyIlioQjGrxvmodHC39RJGq0sxgHtV+JfdaSUn+SLm3AaeNAMB8dnCGLE1QgDsx6hG04rW2f1yERoEv6BjmJ3zrIb9mvxTQOlTdSIN3uC94oJAjZ9zVpb8zsU484UGls0oLpxvhQE7i79zy8/nRYAaLJ5PiAhGJeR30dwslp6Y2RvDL4LftWRtxx+A0yktX3m+kfrIoYf4zEE/vT7Un6nlgc7SmYnTw2pN8BnIxulA6Pmr+FVmTAbH3X8xaiOkf+8Eiba0kopwgYYqZ8orM5WvOLSkDg09SANeFGWfuI5aPHgPfXwfOr9wcuH8h94= X-MS-TrafficTypeDiagnostic: SN1PR07MB1469: X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB1469;31:SHrOW00dBhLf184BWu45B2pEn+e1Wzeg+JKJJrMufFRr8IsjtzM1pmJAnvmFkFwY9S7R8iwyKITr+Yb8O2QRPv6ZAHx6PitQ8OWyJcs2sL19l3HJDPnMbe7QsrhA+eh3r2XHVsRXhGWUwXLQMS1myku1ZPv1Soo/f0406czmgZOefBDcqlcXfAapKonNXvt8Yy/UWFbc+wBibfjVU5q4Tprusb2urI7yujE+mman5Ek=;20:uFyyObob5jOCOxSrHLvsRAp7rRCHtoWK5rrJAG5hbKlkC8ux5bVStGBanO51RimGRZNuzm6t2OQDlxt/4E97c4n8a5m9ZnZn/JwtCAzgCzWUu4twKW8UKqTGjsSpcOFYstJ8guYAho9EsJ1j3Yo+LIasmZHhgWonMae1Yg0xwhvqhppYjPqNRQeDxUXlyVLip+SRryG/8UC9RHLMlh5IasszWMfdvfk/TlFCF6Hg20uWxtoKc2Brhm8okfTYoZWaUyeZtrdyWrsgno2wG4QHMIuP4ldvB4rvG4u2j1llu8/BUFu7ti3osgNEnZAwT5kUxdKVaW7X+dV3OMv0yC3AGhu0uw3dvUm8Zv/HKcF2N0teQeQ7thqWuuSjosxDJSZmKNdqZVw8FBokwf6c+Vc645vWDK7LFU4vyc0d0zWHAyo++f4DTRj0LweVqqOvT2IJmQiORyn6I6+FFnZset1yFUV0JpVMepO7sMszxvkol78Em4QK8RpoJ4GZ7jZhOwhg X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(3231311)(944501410)(52105095)(10201501046)(93006095)(93004095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:SN1PR07MB1469;BCL:0;PCL:0;RULEID:;SRVR:SN1PR07MB1469; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB1469;4:pYhbslsAQ/52cOHr7nTXjqgybt0VkeVajaeNwJOf7Oe3s5eZNSGzkp9uCHdzATlQWggyP+99aAlX1vxmdoOp2bgDsDvf1eyncTXN5wPTwrqQ8Gp9C3oBbDMA4DGMj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Up2mSvn6jlrnM5QRsDodlkukQQuu76LgrT55XbWQ+FHqSslgfUu8BWMOpD9lFz36b8TQ==;5:HfrCrIMNJdhLtUw29PVQgp8/KbRpzMKrf8s/fzz2l+Ncn7gN+FtlU9iHL8WRwnfHCbkGEyWyr/4xORvCV+KEMUKzbzODwe7+xn8bCmPuf9T7hrG52L3pYT5gqcb0WRcs19bHdIQcq+mvkOoMsrKj8tEyomQ7BshHYl6wzT3Z6mk=;7:R2HR3Jhyt7tbixzZdLDZqKNV/XJ3Ie1rnxIuu0Zm57E83I0NjSOl+THM45AFUZz9AVwsAz+/HcjDLuCmVAzJwyymx581BcGUusICsrItjBYpjH7pTwL9hKOYW34zCn6BYWnrqkJEW04zcDq6GyFz8nVyBcv1EQ3jApizSfIznrmF6hXxt+pDZs77vhCtivDquEb4ygcWMUDwhv4eoLOO0cVZ7ntyZrCQUKOxsMUV0KvIqzuJxt6nxgBX8mHUC//d SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2018 23:34:50.0480 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d8633df-fd21-44f1-0848-08d5f350621c 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: SN1PR07MB1469 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 In the case of IOCB QFull, Initiator code can leave behind a stale pointer to an SRB structure on the outstanding command array. Fixes: 82de802ad46e ("scsi: qla2xxx: Preparation for Target MQ.") Cc: stable@vger.kernel.org #4.16 Signed-off-by: Quinn Tran Signed-off-by: Himanshu Madhani --- Hi Martin, This patch fixes memory leak detected in the automation framework which triggers lots of error condition. Please apply this patch to 4.18/scsi-fixes at your earliest convenience. Thanks, Himanshu --- drivers/scsi/qla2xxx/qla_iocb.c | 53 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c index a91cca52b5d5..dd93a22fe843 100644 --- a/drivers/scsi/qla2xxx/qla_iocb.c +++ b/drivers/scsi/qla2xxx/qla_iocb.c @@ -2130,34 +2130,11 @@ __qla2x00_alloc_iocbs(struct qla_qpair *qpair, srb_t *sp) req_cnt = 1; handle = 0; - if (!sp) - goto skip_cmd_array; - - /* Check for room in outstanding command list. */ - handle = req->current_outstanding_cmd; - for (index = 1; index < req->num_outstanding_cmds; index++) { - handle++; - if (handle == req->num_outstanding_cmds) - handle = 1; - if (!req->outstanding_cmds[handle]) - break; - } - if (index == req->num_outstanding_cmds) { - ql_log(ql_log_warn, vha, 0x700b, - "No room on outstanding cmd array.\n"); - goto queuing_error; - } - - /* Prep command array. */ - req->current_outstanding_cmd = handle; - req->outstanding_cmds[handle] = sp; - sp->handle = handle; - - /* Adjust entry-counts as needed. */ - if (sp->type != SRB_SCSI_CMD) + if (sp && (sp->type != SRB_SCSI_CMD)) { + /* Adjust entry-counts as needed. */ req_cnt = sp->iocbs; + } -skip_cmd_array: /* Check for room on request queue. */ if (req->cnt < req_cnt + 2) { if (qpair->use_shadow_reg) @@ -2183,6 +2160,28 @@ __qla2x00_alloc_iocbs(struct qla_qpair *qpair, srb_t *sp) if (req->cnt < req_cnt + 2) goto queuing_error; + if (sp) { + /* Check for room in outstanding command list. */ + handle = req->current_outstanding_cmd; + for (index = 1; index < req->num_outstanding_cmds; index++) { + handle++; + if (handle == req->num_outstanding_cmds) + handle = 1; + if (!req->outstanding_cmds[handle]) + break; + } + if (index == req->num_outstanding_cmds) { + ql_log(ql_log_warn, vha, 0x700b, + "No room on outstanding cmd array.\n"); + goto queuing_error; + } + + /* Prep command array. */ + req->current_outstanding_cmd = handle; + req->outstanding_cmds[handle] = sp; + sp->handle = handle; + } + /* Prep packet */ req->cnt -= req_cnt; pkt = req->ring_ptr; @@ -2195,6 +2194,8 @@ __qla2x00_alloc_iocbs(struct qla_qpair *qpair, srb_t *sp) pkt->handle = handle; } + return pkt; + queuing_error: qpair->tgt_counters.num_alloc_iocb_failed++; return pkt;