From patchwork Thu Mar 28 17:10:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Madhani X-Patchwork-Id: 10875473 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 C141313B5 for ; Thu, 28 Mar 2019 17:12:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EA8328CD0 for ; Thu, 28 Mar 2019 17:12:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D1DE28ECE; Thu, 28 Mar 2019 17:12:26 +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,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 01D6B28EDB for ; Thu, 28 Mar 2019 17:12:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726681AbfC1RMZ (ORCPT ); Thu, 28 Mar 2019 13:12:25 -0400 Received: from mail-eopbgr720058.outbound.protection.outlook.com ([40.107.72.58]:16203 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725849AbfC1RMZ (ORCPT ); Thu, 28 Mar 2019 13:12:25 -0400 Received: from BYAPR07CA0042.namprd07.prod.outlook.com (2603:10b6:a03:60::19) by CY1PR07MB2538.namprd07.prod.outlook.com (2a01:111:e400:c636::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.16; Thu, 28 Mar 2019 17:11:52 +0000 Received: from BY2NAM05FT033.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e52::204) by BYAPR07CA0042.outlook.office365.com (2603:10b6:a03:60::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1750.15 via Frontend Transport; Thu, 28 Mar 2019 17:11:52 +0000 Authentication-Results: spf=fail (sender IP is 199.233.58.38) smtp.mailfrom=marvell.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=fail action=none header.from=marvell.com; Received-SPF: Fail (protection.outlook.com: domain of marvell.com does not designate 199.233.58.38 as permitted sender) receiver=protection.outlook.com; client-ip=199.233.58.38; helo=CAEXCH02.caveonetworks.com; Received: from CAEXCH02.caveonetworks.com (199.233.58.38) by BY2NAM05FT033.mail.protection.outlook.com (10.152.100.170) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.20.1771.6 via Frontend Transport; Thu, 28 Mar 2019 17:11:51 +0000 Received: from dut1171.mv.qlogic.com (10.112.88.18) by CAEXCH02.caveonetworks.com (10.67.98.110) with Microsoft SMTP Server (TLS) id 14.2.347.0; Thu, 28 Mar 2019 10:10: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 x2SHAjr5026496; Thu, 28 Mar 2019 10:10:45 -0700 Received: (from root@localhost) by dut1171.mv.qlogic.com (8.14.7/8.14.7/Submit) id x2SHAjtq026495; Thu, 28 Mar 2019 10:10:45 -0700 From: Himanshu Madhani To: , CC: , Subject: [PATCH 09/15] qla2xxx: Use mutex protection during qla2x00_sysfs_read_fw_dump() Date: Thu, 28 Mar 2019 10:10:06 -0700 Message-ID: <20190328171012.26425-10-hmadhani@marvell.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20190328171012.26425-1-hmadhani@marvell.com> References: <20190328171012.26425-1-hmadhani@marvell.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131982667120078542;(abac79dc-c90b-41ba-8033-08d666125e47);(abac79dc-c90b-41ba-8033-08d666125e47) X-Forefront-Antispam-Report: CIP:199.233.58.38;IPV:CAL;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(376002)(396003)(39860400002)(346002)(136003)(2980300002)(1110001)(1109001)(339900001)(189003)(199004)(76176011)(53936002)(126002)(36756003)(2616005)(486006)(476003)(498600001)(26826003)(6666004)(87636003)(446003)(85426001)(356004)(11346002)(305945005)(5660300002)(26005)(47776003)(80596001)(69596002)(2906002)(48376002)(50466002)(8676002)(81166006)(81156014)(51416003)(14444005)(106466001)(8936002)(50226002)(336012)(42186006)(316002)(86362001)(110136005)(68736007)(97736004)(54906003)(16586007)(4326008)(1076003)(105606002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR07MB2538;H:CAEXCH02.caveonetworks.com;FPR:;SPF:Fail;LANG:en;PTR:InfoDomainNonexistent;MX:1;A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 587caa67-c5f8-4ff6-f9ae-08d6b3a078a9 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(5600127)(711020)(4605104)(2017052603328);SRVR:CY1PR07MB2538; X-MS-TrafficTypeDiagnostic: CY1PR07MB2538: X-Microsoft-Antispam-PRVS: X-Forefront-PRVS: 0990C54589 X-Microsoft-Antispam-Message-Info: WTg9joyLzNhMV+eVXExPCn8En8730iMLL4XAchz09jTySvXe7wiZDSmFHz5G7djTMffVcU54LWVo4mhuaggDiavKCFrOlcF4/Qxt/6t0AGacexEHngxiVUQlXMe09b+11sRB30skzHeuakYxoK/4bWUmgndVB1p4251QJLDoQfXL6gqet1KLW0w0WlU1uvz9Ox+kil4o487qNf0wRxiL0zHy1BN5Pf58S1JIbZPOZBrs18XXEt9cphcLVzGkDRh0ZhNbqXnwGrgLWBbEePB+rGk0ba5Oa/02bl9/ZsL2SHNyzDYTW2iIweKo6qBoIPgUGD9jJAlf97AF1XPubiHKWX/jslTl55CgI855v3SP8ieQvZStR6YZ1hvOk2SjTnycnclK3qRVHAsMcTsWjp/bPhvMMzt4uTyfqqq5HRwfwwo= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2019 17:11:51.3903 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 587caa67-c5f8-4ff6-f9ae-08d6b3a078a9 X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[199.233.58.38];Helo=[CAEXCH02.caveonetworks.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2538 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 user extract FW dump from driver, add mutex protection to prevent driver from freeing the FW dump buffer from freeing while the extraction is in progress. Signed-off-by: Quinn Tran Signed-off-by: Himanshu Madhani --- drivers/scsi/qla2xxx/qla_attr.c | 25 ++++++++++++++----------- drivers/scsi/qla2xxx/qla_init.c | 6 +++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c index b2520e49971d..da64fe54f59e 100644 --- a/drivers/scsi/qla2xxx/qla_attr.c +++ b/drivers/scsi/qla2xxx/qla_attr.c @@ -29,24 +29,27 @@ qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj, if (!(ha->fw_dump_reading || ha->mctp_dump_reading)) return 0; + mutex_lock(&ha->optrom_mutex); if (IS_P3P_TYPE(ha)) { if (off < ha->md_template_size) { rval = memory_read_from_buffer(buf, count, &off, ha->md_tmplt_hdr, ha->md_template_size); - return rval; + } else { + off -= ha->md_template_size; + rval = memory_read_from_buffer(buf, count, + &off, ha->md_dump, ha->md_dump_size); } - off -= ha->md_template_size; - rval = memory_read_from_buffer(buf, count, - &off, ha->md_dump, ha->md_dump_size); - return rval; - } else if (ha->mctp_dumped && ha->mctp_dump_reading) - return memory_read_from_buffer(buf, count, &off, ha->mctp_dump, + } else if (ha->mctp_dumped && ha->mctp_dump_reading) { + rval = memory_read_from_buffer(buf, count, &off, ha->mctp_dump, MCTP_DUMP_SIZE); - else if (ha->fw_dump_reading) - return memory_read_from_buffer(buf, count, &off, ha->fw_dump, + } else if (ha->fw_dump_reading) { + rval = memory_read_from_buffer(buf, count, &off, ha->fw_dump, ha->fw_dump_len); - else - return 0; + } else { + rval = 0; + } + mutex_unlock(&ha->optrom_mutex); + return rval; } static ssize_t diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c index d244479f2332..8187791b5bd0 100644 --- a/drivers/scsi/qla2xxx/qla_init.c +++ b/drivers/scsi/qla2xxx/qla_init.c @@ -3234,6 +3234,7 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) "Unable to allocate (%d KB) for firmware dump.\n", dump_size / 1024); } else { + mutex_lock(&ha->optrom_mutex); if (ha->fw_dumped) { memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len); vfree(ha->fw_dump); @@ -3253,8 +3254,10 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); - if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) + if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) { + mutex_unlock(&ha->optrom_mutex); return; + } ha->fw_dump->signature[0] = 'Q'; ha->fw_dump->signature[1] = 'L'; @@ -3277,6 +3280,7 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) htonl(offsetof (struct qla2xxx_fw_dump, isp)); } + mutex_unlock(&ha->optrom_mutex); } } }