From patchwork Tue Apr 2 21:24:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Madhani X-Patchwork-Id: 10882363 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 98152922 for ; Tue, 2 Apr 2019 21:26:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83D7E288BA for ; Tue, 2 Apr 2019 21:26:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 785FA288D2; Tue, 2 Apr 2019 21:26:18 +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 D5634288BA for ; Tue, 2 Apr 2019 21:26:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbfDBV0R (ORCPT ); Tue, 2 Apr 2019 17:26:17 -0400 Received: from mail-eopbgr720067.outbound.protection.outlook.com ([40.107.72.67]:61520 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726078AbfDBV0Q (ORCPT ); Tue, 2 Apr 2019 17:26:16 -0400 Received: from DM5PR07CA0048.namprd07.prod.outlook.com (2603:10b6:3:16::34) by DM5PR07MB4024.namprd07.prod.outlook.com (2603:10b6:4:b2::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.15; Tue, 2 Apr 2019 21:26:13 +0000 Received: from CO1NAM05FT022.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e50::203) by DM5PR07CA0048.outlook.office365.com (2603:10b6:3:16::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.15 via Frontend Transport; Tue, 2 Apr 2019 21:26:13 +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 CO1NAM05FT022.mail.protection.outlook.com (10.152.96.130) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.20.1771.6 via Frontend Transport; Tue, 2 Apr 2019 21:26:12 +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; Tue, 2 Apr 2019 14:25:03 -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 x32LP3hx028540; Tue, 2 Apr 2019 14:25:03 -0700 Received: (from root@localhost) by dut1171.mv.qlogic.com (8.14.7/8.14.7/Submit) id x32LP3Dn028539; Tue, 2 Apr 2019 14:25:03 -0700 From: Himanshu Madhani To: , CC: , Subject: [PATCH v2 09/15] qla2xxx: Use mutex protection during qla2x00_sysfs_read_fw_dump() Date: Tue, 2 Apr 2019 14:24:28 -0700 Message-ID: <20190402212434.28469-10-hmadhani@marvell.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20190402212434.28469-1-hmadhani@marvell.com> References: <20190402212434.28469-1-hmadhani@marvell.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131987139730472418;(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)(396003)(376002)(136003)(346002)(39860400002)(2980300002)(1110001)(1109001)(339900001)(189003)(199004)(1076003)(336012)(85426001)(126002)(14444005)(76176011)(2616005)(476003)(50466002)(11346002)(486006)(5660300002)(26826003)(48376002)(356004)(81156014)(305945005)(81166006)(47776003)(97736004)(6666004)(16586007)(2906002)(36756003)(36906005)(69596002)(68736007)(86362001)(51416003)(4326008)(80596001)(53936002)(498600001)(26005)(8676002)(87636003)(110136005)(54906003)(446003)(50226002)(105606002)(106466001)(316002)(8936002)(42186006);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR07MB4024;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: dbdf211c-9b6b-4f89-88c7-08d6b7b1d504 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(5600139)(711020)(4605104)(2017052603328);SRVR:DM5PR07MB4024; X-MS-TrafficTypeDiagnostic: DM5PR07MB4024: X-Microsoft-Antispam-PRVS: X-Forefront-PRVS: 0995196AA2 X-Microsoft-Antispam-Message-Info: V8WNRr1fQvtjJcUReVNvRGBtzou34uSIuifjUJL4AiTXTmnbBPBOC0gQ4IEf2NE9fZCXrTIDRqYIq3AFKdU5jm7bWwS6GRREFd3HdrniZtnIliDTnCbFBPyJZkckdVrMdb6b40oX5x4RN49FnCK8F8TbnWQYL12fjDsxOGmnhTQz/G1Gi1pIzpyUHEWJth++JjnpE6YU/FCBeWelgxOKWwaSEPAEUxheULUjXGcGJUrNea1Lcr/mnz+RKJt3J0BUkwsHvNL050DBkFWTf4S/7h0JOsSepFFn3WL60KjS5X6SbM0FUZ3rlqNsliUvYNJ5Dz897r8LKJaE8sivPiwa3p48PGaglS89THWbVhph+mDlf5sTedu4mgSJlCdtY//Sgbb3np10LEvtiqwkuOvyWnUxJbm5GcnYbDZTiEXpPSM= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2019 21:26:12.7520 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dbdf211c-9b6b-4f89-88c7-08d6b7b1d504 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: DM5PR07MB4024 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 57ee2d979efe..ab212b4853a1 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); } } }