From patchwork Fri Feb 24 21:37:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhani, Himanshu" X-Patchwork-Id: 9591243 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A87AC601AE for ; Fri, 24 Feb 2017 21:38:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 974EE28947 for ; Fri, 24 Feb 2017 21:38:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C0EA2895A; Fri, 24 Feb 2017 21:38:32 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 2148D28947 for ; Fri, 24 Feb 2017 21:38:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751314AbdBXVi3 (ORCPT ); Fri, 24 Feb 2017 16:38:29 -0500 Received: from mail-bn3nam01on0060.outbound.protection.outlook.com ([104.47.33.60]:50293 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751332AbdBXViR (ORCPT ); Fri, 24 Feb 2017 16:38:17 -0500 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; bh=c94Z7h7lbVy2GUTXfpFZWvfvaofA9RYbfK0Xpt3s0fI=; b=egNjwq6U45a0Cteit3x0TwdLGsYlNbWTKxphue02iL51YFK8Y+IG3l20NcHRErDkPmwVTC8lcPjHrn/uuUnAedDJsXeVzhW2OLjv0WaZwDBo6ZUIm5wE4wWawt2N9xBbP3kfSeHQcz5+Habcv1B4ys/6ciNRh0vDSU3X92YO+uM= Received: from BY2PR07CA0090.namprd07.prod.outlook.com (10.166.107.43) by BLUPR07MB626.namprd07.prod.outlook.com (10.141.207.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.919.13; Fri, 24 Feb 2017 21:38:07 +0000 Received: from BY2FFO11OLC016.protection.gbl (2a01:111:f400:7c0c::172) by BY2PR07CA0090.outlook.office365.com (2a01:111:e400:7bff::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16 via Frontend Transport; Fri, 24 Feb 2017 21:38:06 +0000 Authentication-Results: spf=none (sender IP is 50.232.66.26) smtp.mailfrom=cavium.com; linux-iscsi.org; dkim=none (message not signed) header.d=none; linux-iscsi.org; dmarc=none action=none header.from=cavium.com; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) Received: from CAEXCH02.caveonetworks.com (50.232.66.26) by BY2FFO11OLC016.mail.protection.outlook.com (10.1.15.61) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.919.10 via Frontend Transport; Fri, 24 Feb 2017 21:38:06 +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.309.2; Fri, 24 Feb 2017 13:37:46 -0800 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 v1OLbkRb003876; Fri, 24 Feb 2017 13:37:46 -0800 Received: (from root@localhost) by dut1171.mv.qlogic.com (8.14.7/8.14.7/Submit) id v1OLbkO9003875; Fri, 24 Feb 2017 13:37:46 -0800 From: Himanshu Madhani To: , , CC: , , Subject: [PATCH v3 13/14] qla2xxx: Fix sess_lock & hardware_lock lock order problem. Date: Fri, 24 Feb 2017 13:37:42 -0800 Message-ID: <1487972263-3795-14-git-send-email-himanshu.madhani@cavium.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487972263-3795-1-git-send-email-himanshu.madhani@cavium.com> References: <1487972263-3795-1-git-send-email-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)(6009001)(7916002)(39450400003)(2980300002)(428002)(189002)(199003)(2201001)(50466002)(2906002)(33646002)(80596001)(305945005)(54906002)(92566002)(8936002)(69596002)(106466001)(47776003)(48376002)(5003940100001)(356003)(107886003)(105586002)(626004)(6666003)(4720700003)(189998001)(81166006)(101416001)(50986999)(36756003)(2950100002)(8656002)(5660300001)(38730400002)(1691005)(81156014)(42186005)(50226002)(4326007)(8676002)(76176999)(86362001)(87636001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR07MB626; H:CAEXCH02.caveonetworks.com; FPR:; SPF:None; PTR:50-232-66-26-static.hfc.comcastbusiness.net; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11OLC016; 1:kVegkOqnIXvDjoBmhgt5Lk/EDHxzHN3/23qHA8iyRPX5JCVpN8g3JMWvzUs28Y6p6eiROi4Ggy9pmpeoPYma3sZytoUgAXdAh81z/C4HM4DWL1il2yGwPfvdYgXbKVgOe7by9F8h6abyk6dyoZxuDc/cce3m0InYZT9PCoPHu0z3N8dYzCjP+auqXC1v/KxQcD/Vd09WN6YHw047YE5aSRgZzjrl0IO8oNsImP+E1hBbUra3opITaP/1QQ4A8hVYThZB9ZMo65aWPR5/wQFv/D0eB1YlJnCWPzEg6aKDrHdS4zT9SwaEBhuJTkP29LefWYKbgjq4Ya3oO1EAfqvGQlSyImMj5bX/VJMlEDF6qaGvVt4QhH8v2avd5eH8nIzNWgyznLuBTPA/sgGnr8Ego2DBVDymW17meWIkWZgmqZxs6SKqBmNYvCsfVzz932Ip7+OFy/p4rSkPlOZEGxRadZxIfHdE6HTK1GPSgTY6NicIwNKHBykS2QtpmtqjMJBT84d7c3PsrK2o/bw7tinE8JNHEKe3Fzm3y/fWqR6mZLI= X-MS-Office365-Filtering-Correlation-Id: 72dd27e0-a5e1-48b8-7091-08d45cfd6b89 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BLUPR07MB626; X-Microsoft-Exchange-Diagnostics: 1; BLUPR07MB626; 3:3jtusy0aHJ11WjVydwX7NfJ8r3tKsxhj9VAzdfKxOalwdqumTS8t5UFrxgltjbberIyptLj5h8jD/EkSMvCcGtfJKckDi1eprWTXYB6FmlZ5azZPzIrqf4ZBHkHheZqM6U97iFwHZJKDhOwA8Va8QJ8QED9d9f0+QKmKxBiaojR+Zk8pzrmL46g9Jn82MT9qxSy+WC3K0G8dbcv+1tHNbq6SlZ/Lxji0qd/itqGb0v31bwdasHbY+vC6o4mlhhb0Bv12cLDohMh/gYkCwQUyCtKWwA7sB6bIcQ5oBfvFUU2ovv1EqNtbl93yMvBPLODpSItkiE04y4Ot2aOfg/PU+/81L7xe4e/YhU5psFuUKqDG5/9zgDNTYFJrtKDub3vt; 25:Fh7ugXCwN1llakpJEwvNLs7KdMXlZtlsI7U/0E5Kb1w/KnaZZaQhROjS91cah4ftRYh/fE9B8p/4GI++LgthSLlcoIRwqNeKwwnsinxvYIWNqUEwvdca9fifO2iNK22Bw38UK7iLDE+/1gawssDSEE3GJNwPm0djXb4v77lGpS+1DmvqecS8Saznk3bLY65/5Tl6MkieNr8mLXYA+Sxmp/DxEoE9exi12sLX+CdPwboYtJIu9KMfv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oft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(13015025)(13017025)(13023025)(13024025)(8121501046)(5005006)(13018025)(10201501046)(3002001)(6041248)(20161123560025)(20161123562025)(20161123564025)(20161123555025)(20161123558025)(6072148); SRVR:BLUPR07MB626; BCL:0; PCL:0; RULEID:; SRVR:BLUPR07MB626; X-Microsoft-Exchange-Diagnostics: 1; BLUPR07MB626; 4:nQ+LG89AKLLIhnZTUni7ysJ+oifUOmxT22vuW0WlC5csZv5SlWUeWwyQ2NoRDMuuvK0aF728kZxK0aaDslpCOa7yyjgBoA75uAnGsTE5C9YIp/TAV94G3+nOSZsYUCn/KM8tln9/UjdEp9AfJvVFZGk0DBdvxX4Kn5AygOHeh7/4EZyUAVSr/qslsywtMKsG5yVlvuDk21BPqUnLisOrNe85KgvCx3iMlKm/Dxfm4AGfKzvdYwp7izSYLYDG05cbbmBh+CMZjIzl8bRMoRCHK+dfuPRnkH8a8X1IJdxUx2yuaSuwQJvVP/djWi1mSb3JSbfs+fF/tjz4mejS8odb2rSFtzoiD110V1A4h0RqtjszB0NBGPxikuN14Gt4NvGvtM9PIT8R7wUGQzsPIWHxEoG1rU91D39Mpwg4P4T0FQWfAov97KDftVZRWrjj7xS9tSZwgJwvZURid7L1IsAbw3Ejf1Ep6ZbhgQz+9Pt2LqOOC200oWVA1Feoyuk2ncOSo8QZtgt4RBSmDvr7gtWKJhd2j4x0/r9LByox4Etl2z3OCYMhMQZag2chEdBBpo48plIroRi8DWQVS0uATCmWLP+9zuTk2dnDSrwOjvzrURyCBeL+n2l5bcitl/SLgWMZXdVIE1K9Sof7l2S5jYKtGqfIr+Y+EeBJq2B0udi7DkDjeJWjNwG/SG+s1FHPmiq3sQzso5DXiN1fC/pglOvfdDHQwjyEDqZJbIkTGQfPKiJy4XeNwGlFQrG6CUY47Ml7TvDcU3HK/jtLPgbcCx0vLg== X-Forefront-PRVS: 0228DDDDD7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR07MB626; 23:dDj3RjweL4JzteH5ciqtzCLTC0SoJRqtwaPVjCj70C?= =?us-ascii?Q?wFcVOgtukQtRdC9iPcZdDvVYHD4/jw4p/ELPhmDknAx02n73FkqtirAPM+bs?= =?us-ascii?Q?MWidYcFhde+FjDffp2qS/c8fMqQiwtlbfcrBLEta3FIJNh1rEi76rOS75Sq+?= =?us-ascii?Q?62MxNhyt0LGrcpCz1bmZN876Gy6VCnsnWLP2K0YMhyD7NAB8apeQpYvhhuxS?= =?us-ascii?Q?ieWKKqjkZbA85zwPtkp6uewPd2RsELXbYd1rl15YaLcs41FEtwq+fxO1m//Y?= =?us-ascii?Q?PLLxFC+6eZODdqjdBdqVXy5d+mq6o0tIkNxhWt0TbVipRy9QGgqXOUATqEkj?= =?us-ascii?Q?wnHhDQHIbk4ejnJL9K6Orp2agRSTbA9LBp3v+ibrmXnHRzXTxiTVt6zoqpZS?= =?us-ascii?Q?N9ZTCh2064OoKYrfEkHus5bzXZtXpFeEQ/VWgV9diyFFoqhGPbXtSaYGSMe1?= =?us-ascii?Q?q/IdHt/NBP+IKjfdZfE0lw4kZkbUWsXw4jaqj7Eji6F1Mu8vpUecSHqX5B8B?= =?us-ascii?Q?VP7ITwahL3WwbS9aP8QQZfBCouHpn7lQee/Xw9Yua1CXrzsoIsqD8MrpKHIr?= =?us-ascii?Q?4jb+vNqO/qRfCxJ21B+nnUE7TR/sNZIxyX1+calQpLSO7xn2V0ScPgahrNbp?= =?us-ascii?Q?1u9Y0kuqhnMftjde3dIZdC/OvispXDMt8bGfBu54qmos1O46WrK3VNWGqiZR?= =?us-ascii?Q?2z5Nk4GZVejJZLvQEJBOPC0btCP+pgERjelrDRi2TwvIp8UYmGI7TSIcZFAS?= =?us-ascii?Q?i2kFnP4DoxjqumGrRbDTzF6ZS6n/k4WWzBDrVhu4ciBLURK31tkAiAwGY//u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ycbNGfQHOIvq0+80xfY878= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR07MB626; 7:szk/jQAReevGzowG+esgW0mUECHgyg3++OqAkWtM8P71AMqc8qv8HnwYA5Zuezn1EMcdCSY9TWx83zvm8Eo3gGro7CQjF3sVhhQxZV//SuilhUCKhSSKoVGsrj6kqxspJCHf7VEqwHyNstAX/4riDtt0l8iM3klQdA0YBattcRDJkvupZXoESwv9hPrUbVZ+PZ9maamtkp5p3y39KJkjKJzu4lCiYuemnBWxamZF6+Jvq8m7GdrYhWz+HIY1HJotfoK9YbitMKmsIKnEE1NelBT24DxBeyceDlHCsARh78LYfqn2CI2CED5OtYk/LCNxk7SXrcWueO3dSz9S3UMvRQ== X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2017 21:38:06.4549 (UTC) 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: BLUPR07MB626 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Quinn Tran The main lock that needs to be held for CMD or TMR submission to upper layer is the sess_lock. The sess_lock is used to serialize cmd submission and session deletion. The addition of hardware_lock being held is not necessary. This patch removes hardware_lock dependency from CMD/TMR submission. Use hardware_lock only for error response in this case. Path1 CPU0 CPU1 ---- ---- lock(&(&ha->tgt.sess_lock)->rlock); lock(&(&ha->hardware_lock)->rlock); lock(&(&ha->tgt.sess_lock)->rlock); lock(&(&ha->hardware_lock)->rlock); Path2/deadlock *** DEADLOCK *** Call Trace: dump_stack+0x85/0xc2 print_circular_bug+0x1e3/0x250 __lock_acquire+0x1425/0x1620 lock_acquire+0xbf/0x210 _raw_spin_lock_irqsave+0x53/0x70 qlt_sess_work_fn+0x21d/0x480 [qla2xxx] process_one_work+0x1f4/0x6e0 Cc: Cc: Bart Van Assche Reported-by: Bart Van Assche Signed-off-by: Quinn Tran Signed-off-by: Himanshu Madhani --- drivers/scsi/qla2xxx/qla_target.c | 41 +++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c index e523c49..46a409e 100644 --- a/drivers/scsi/qla2xxx/qla_target.c +++ b/drivers/scsi/qla2xxx/qla_target.c @@ -5831,30 +5831,23 @@ static void qlt_abort_work(struct qla_tgt *tgt, } } - spin_lock_irqsave(&ha->hardware_lock, flags); - - if (tgt->tgt_stop) - goto out_term; - rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); + ha->tgt.tgt_ops->put_sess(sess); + spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); + if (rc != 0) goto out_term; - spin_unlock_irqrestore(&ha->hardware_lock, flags); - if (sess) - ha->tgt.tgt_ops->put_sess(sess); - spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); return; out_term2: - spin_lock_irqsave(&ha->hardware_lock, flags); + if (sess) + ha->tgt.tgt_ops->put_sess(sess); + spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); out_term: + spin_lock_irqsave(&ha->hardware_lock, flags); qlt_24xx_send_abts_resp(vha, &prm->abts, FCP_TMF_REJECTED, false); spin_unlock_irqrestore(&ha->hardware_lock, flags); - - if (sess) - ha->tgt.tgt_ops->put_sess(sess); - spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); } static void qlt_tmr_work(struct qla_tgt *tgt, @@ -5874,7 +5867,7 @@ static void qlt_tmr_work(struct qla_tgt *tgt, spin_lock_irqsave(&ha->tgt.sess_lock, flags); if (tgt->tgt_stop) - goto out_term; + goto out_term2; s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); @@ -5886,11 +5879,11 @@ static void qlt_tmr_work(struct qla_tgt *tgt, spin_lock_irqsave(&ha->tgt.sess_lock, flags); if (!sess) - goto out_term; + goto out_term2; } else { if (sess->deleted) { sess = NULL; - goto out_term; + goto out_term2; } if (!kref_get_unless_zero(&sess->sess_kref)) { @@ -5898,7 +5891,7 @@ static void qlt_tmr_work(struct qla_tgt *tgt, "%s: kref_get fail %8phC\n", __func__, sess->port_name); sess = NULL; - goto out_term; + goto out_term2; } } @@ -5908,17 +5901,19 @@ static void qlt_tmr_work(struct qla_tgt *tgt, unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun); rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); - if (rc != 0) - goto out_term; - ha->tgt.tgt_ops->put_sess(sess); spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); + + if (rc != 0) + goto out_term; return; +out_term2: + if (sess) + ha->tgt.tgt_ops->put_sess(sess); + spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); out_term: qlt_send_term_exchange(vha, NULL, &prm->tm_iocb2, 1, 0); - ha->tgt.tgt_ops->put_sess(sess); - spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); } static void qlt_sess_work_fn(struct work_struct *work)