From patchwork Thu Mar 28 17:10:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Madhani X-Patchwork-Id: 10875467 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 3B4D9186E for ; Thu, 28 Mar 2019 17:12:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17B5F28EC6 for ; Thu, 28 Mar 2019 17:12:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12EB728EBB; Thu, 28 Mar 2019 17:12:11 +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 703DA28EC6 for ; Thu, 28 Mar 2019 17:12:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727532AbfC1RMK (ORCPT ); Thu, 28 Mar 2019 13:12:10 -0400 Received: from mail-eopbgr740077.outbound.protection.outlook.com ([40.107.74.77]:21632 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726248AbfC1RMJ (ORCPT ); Thu, 28 Mar 2019 13:12:09 -0400 Received: from BYAPR07CA0042.namprd07.prod.outlook.com (2603:10b6:a03:60::19) by BN3PR07MB2530.namprd07.prod.outlook.com (2a01:111:e400:c5f0::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.17; Thu, 28 Mar 2019 17:12:05 +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:12:05 +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:12:05 +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:11:01 -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 x2SHB0k7026524; Thu, 28 Mar 2019 10:11:00 -0700 Received: (from root@localhost) by dut1171.mv.qlogic.com (8.14.7/8.14.7/Submit) id x2SHB0xO026523; Thu, 28 Mar 2019 10:11:00 -0700 From: Himanshu Madhani To: , CC: , Subject: [PATCH 14/15] qla2xxx: Change abort wait_loop from msleep to wait_event_timeout Date: Thu, 28 Mar 2019 10:10:11 -0700 Message-ID: <20190328171012.26425-15-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: 131982667256466833;(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)(39860400002)(346002)(136003)(396003)(376002)(2980300002)(1110001)(1109001)(339900001)(199004)(189003)(6666004)(47776003)(48376002)(498600001)(87636003)(106466001)(356004)(1076003)(2906002)(14444005)(105606002)(86362001)(26826003)(5660300002)(53936002)(4326008)(2616005)(80596001)(76176011)(336012)(305945005)(69596002)(54906003)(316002)(42186006)(446003)(11346002)(36906005)(16586007)(51416003)(110136005)(97736004)(85426001)(81156014)(81166006)(8936002)(36756003)(68736007)(50226002)(486006)(126002)(8676002)(476003)(26005)(50466002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN3PR07MB2530;H:CAEXCH02.caveonetworks.com;FPR:;SPF:Fail;LANG:en;PTR:InfoDomainNonexistent;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0745326c-fd7a-4eb1-3f61-08d6b3a080cb X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(5600127)(711020)(4605104)(2017052603328);SRVR:BN3PR07MB2530; X-MS-TrafficTypeDiagnostic: BN3PR07MB2530: X-Microsoft-Antispam-PRVS: X-Forefront-PRVS: 0990C54589 X-Microsoft-Antispam-Message-Info: x3dWwHGmvM8lQ5Od7q14Ydu5K05trpo5cycMf8tpjKqksXpSoQMLnq0Eda4SBPLJa95q3idl3OAuGdD5AAekzqCC+ljP3pSvYqb6I/cv3bdA+R9CnWQQL8to0K1sjo9LbBl+FyXuxeht4iaTLZ/R70ha4ScSbqXqqg3M3zZZ6vfSk4Nf9KbmHOULFS+FKrRLFC23HD9NNYAbEgSY3Rv6iNSuM/kmyT7YdiuetIaPHQt3Thc3Mi6qS1/AGlBX7p8MH8vkg43XEVoNJXbG6VNWBAuL7N5LJyT5aSDc0LFj4s9nAPKZXZ1ihPM2vXnLnf2eyRIlUMbtO/FNBbQWuNPcubCLqoA7U07hdrb2bWIcihZ7/Rub9v90AQsW4aQoela9gkb9u12H8adxmYiHVZ244CSrsgN+EL+GV/WTfWLdCv0= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2019 17:12:05.3714 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0745326c-fd7a-4eb1-3f61-08d6b3a080cb 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: BN3PR07MB2530 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: Giridhar Malavali This patch converts driver wait time from using msleep to wair_event_timeout to prevent race condition. Signed-off-by: Giridhar Malavali Signed-off-by: Himanshu Madhani --- drivers/scsi/qla2xxx/qla_def.h | 2 +- drivers/scsi/qla2xxx/qla_os.c | 83 +++++++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h index 8d28ea9b0b73..b7b0a3e0ecbc 100644 --- a/drivers/scsi/qla2xxx/qla_def.h +++ b/drivers/scsi/qla2xxx/qla_def.h @@ -546,6 +546,7 @@ typedef struct srb { int rc; int retry_count; struct completion comp; + wait_queue_head_t *cwaitq; union { struct srb_iocb iocb_cmd; struct bsg_job *bsg_job; @@ -4794,5 +4795,4 @@ struct sff_8247_a0 { #include "qla_gbl.h" #include "qla_dbg.h" #include "qla_inline.h" - #endif diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c index 837860e1827b..7fd1b6d5da9b 100644 --- a/drivers/scsi/qla2xxx/qla_os.c +++ b/drivers/scsi/qla2xxx/qla_os.c @@ -726,7 +726,7 @@ qla2x00_sp_free_dma(void *ptr) } if (!ctx) - goto end; + return; if (sp->flags & SRB_CRC_CTX_DSD_VALID) { /* List assured to be having elements */ @@ -751,12 +751,6 @@ qla2x00_sp_free_dma(void *ptr) ha->gbl_dsd_avail += ctx1->dsd_use_cnt; mempool_free(ctx1, ha->ctx_mempool); } - -end: - if (sp->type != SRB_NVME_CMD && sp->type != SRB_NVME_LS) { - CMD_SP(cmd) = NULL; - qla2x00_rel_sp(sp); - } } void @@ -764,6 +758,7 @@ qla2x00_sp_compl(void *ptr, int res) { srb_t *sp = ptr; struct scsi_cmnd *cmd = GET_CMD_SP(sp); + wait_queue_head_t *cwaitq = sp->cwaitq; if (atomic_read(&sp->ref_count) == 0) { ql_dbg(ql_dbg_io, sp->vha, 0x3015, @@ -778,7 +773,11 @@ qla2x00_sp_compl(void *ptr, int res) sp->free(sp); cmd->result = res; + CMD_SP(cmd) = NULL; cmd->scsi_done(cmd); + if (cwaitq) + wake_up(cwaitq); + qla2x00_rel_sp(sp); } void @@ -801,7 +800,7 @@ qla2xxx_qpair_sp_free_dma(void *ptr) } if (!ctx) - goto end; + return; if (sp->flags & SRB_CRC_CTX_DSD_VALID) { /* List assured to be having elements */ @@ -861,10 +860,6 @@ qla2xxx_qpair_sp_free_dma(void *ptr) } sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID; } - -end: - CMD_SP(cmd) = NULL; - qla2xxx_rel_qpair_sp(sp->qpair, sp); } void @@ -872,8 +867,7 @@ qla2xxx_qpair_sp_compl(void *ptr, int res) { srb_t *sp = ptr; struct scsi_cmnd *cmd = GET_CMD_SP(sp); - - cmd->result = res; + wait_queue_head_t *cwaitq = sp->cwaitq; if (atomic_read(&sp->ref_count) == 0) { ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079, @@ -887,7 +881,12 @@ qla2xxx_qpair_sp_compl(void *ptr, int res) return; sp->free(sp); + cmd->result = res; + CMD_SP(cmd) = NULL; cmd->scsi_done(cmd); + if (cwaitq) + wake_up(cwaitq); + qla2xxx_rel_qpair_sp(sp->qpair, sp); } /* If we are SP1 here, we need to still take and release the host_lock as SP1 @@ -1377,7 +1376,6 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd) vha->host_no, id, lun, sp, cmd, sp->handle); /* Get a reference to the sp and drop the lock.*/ - rval = ha->isp_ops->abort_command(sp); if (rval) { if (rval == QLA_FUNCTION_PARAMETER_ERROR) @@ -1394,37 +1392,46 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd) } spin_lock_irqsave(qpair->qp_lock_ptr, flags); - /* - * Clear the slot in the oustanding_cmds array if we can't find the - * command to reclaim the resources. - */ - if (rval == QLA_FUNCTION_PARAMETER_ERROR) - vha->req->outstanding_cmds[sp->handle] = NULL; /* - * sp->done will do ref_count-- - * sp_get() took an extra count above + * Releasing of the SRB and associated command resources + * is managed through ref_count. + * Whether we need to wait for the abort completion or complete + * the abort handler should be based on the ref_count. */ - sp->done(sp, DID_RESET << 16); - - /* Did the command return during mailbox execution? */ - if (ret == FAILED && !CMD_SP(cmd)) - ret = SUCCESS; + if (atomic_read(&sp->ref_count) > 1) { + /* + * The command is not yet completed. We need to wait for either + * command completion or abort completion. + */ + DECLARE_WAIT_QUEUE_HEAD_ONSTACK(eh_waitq); + uint32_t ratov = ha->r_a_tov/10; - if (!CMD_SP(cmd)) - wait = 0; + /* Go ahead and release the extra ref_count obtained earlier */ + sp->done(sp, DID_RESET << 16); + sp->cwaitq = &eh_waitq; - spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); - - /* Wait for the command to be returned. */ - if (wait) { - if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) { - ql_log(ql_log_warn, vha, 0x8006, - "Abort handler timed out cmd=%p.\n", cmd); + if (!wait_event_lock_irq_timeout(eh_waitq, + CMD_SP(cmd) == NULL, *qpair->qp_lock_ptr, + msecs_to_jiffies(4 * ratov * 1000))) { + /* + * The abort got dropped, LOGO will be sent and the + * original command will be completed with CS_TIMEOUT + * completion + */ + ql_dbg(ql_dbg_taskm, vha, 0xffff, + "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n", + __func__, ha->r_a_tov); + sp->cwaitq = NULL; ret = FAILED; + goto end; } + } else { + /* Command completed while processing the abort */ + sp->done(sp, DID_RESET << 16); } - +end: + spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); ql_log(ql_log_info, vha, 0x801c, "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n", vha->host_no, id, lun, wait, ret);