Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3962851pxb; Mon, 21 Feb 2022 09:09:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8HiWnrTxIYpYZh6UKdu2yPK0fllh6ZRPmcuR5ttnHMeT9MMCqz0+BIoAbM9yPYoNGQBs+ X-Received: by 2002:a63:64a:0:b0:36c:6d40:5688 with SMTP id 71-20020a63064a000000b0036c6d405688mr16736223pgg.554.1645463399022; Mon, 21 Feb 2022 09:09:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645463399; cv=none; d=google.com; s=arc-20160816; b=UQ9cAkny10TWgcZAOYnpRmMDl2vlhaxE9tHSG/D4PVJG8mOqMuLwKjbs9jPk5vy1ME KGKCj1ET4zcgCzyiWXWEp06C69R87TgLXjeUotBBBTdI4+YwM6l2613hcDjQlFzs9ADe 06RNqtu0qCDDrjZUs5BRmgCYXm7hy/BoPYcuKiXGEFYwzmlT5OIwewIszVDiMqkkKT/1 PNNOep+SFN1T+B5AQwVzAUGEfqwNM5EdrdIKxnQKODBRrt2+t0Gakk6+uds9SUVBikwb v3YhuFDIoEeV5Ewx0xhkwzfdSn10QLVqUVeUXXpJXCw64YesT1jpCcJStT67OPyYYDIx wfVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GOwT1Fn3EluUE0zIe+VCcJpTa2whJHNctk9eSS6pjfg=; b=eY8H/IMbh0BeTfVB/1rq6YAq59FRieQ+ylpXFfll3xvcXRCFMXhrXw4YyQeuri1frB AzlL9WccfNADQ8nYmVnHAKMmbkbPYPNPTkrWMwWkl9Uey/BJLievYOZj/ZPEP1jVxiCN Rx5bH9MxP27Jbzfeo8JLYdLe2nE3TVnwZW//9Pf+Z0KS/O29JJ+NmeF2wl26am8M0Xhk jIQxyd2iUblGPEDrzMKTiPmbiPKk3lmF/Oe5Jfx4niuG/CAioAgd037Riw3jCrn2nA+h vW7zq6HOjCX3wcicOnWT9EGMjnzfl8cE6uegOewIl0JrBrNW6AJNgAQyNqwY5EHdW2S6 ohYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F0Q8o8uC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 204si9803601pfu.82.2022.02.21.09.09.43; Mon, 21 Feb 2022 09:09:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F0Q8o8uC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239635AbiBUKEw (ORCPT + 99 others); Mon, 21 Feb 2022 05:04:52 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:36722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353519AbiBUJ5b (ORCPT ); Mon, 21 Feb 2022 04:57:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1228FDF89; Mon, 21 Feb 2022 01:26:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A177C61016; Mon, 21 Feb 2022 09:26:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86E15C340E9; Mon, 21 Feb 2022 09:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435597; bh=gTQ04QDOxJ+4r8PsB+BEiOsQwripN+5lfxt370p67Sg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F0Q8o8uCGoK4yancxqRc3jeOLuOf+FRTf6Q1N9xIRHtZX11tJF9nz0hCYNjN033PO dYSrnccdk4SXwBNeZ1vvHz3glRjlx0E+8Zh94u4KW4YuyOQH0xw5RPJKamLbXj1RkA UYV33TuKt6zUtq6TRuYfFiSeSBdmIyV+vBtehCJ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Manish Rangankar , Nilesh Javali , TOTE Robot , Jia-Ju Bai , Mike Christie , "Martin K. Petersen" Subject: [PATCH 5.16 187/227] scsi: qedi: Fix ABBA deadlock in qedi_process_tmf_resp() and qedi_process_cmd_cleanup_resp() Date: Mon, 21 Feb 2022 09:50:06 +0100 Message-Id: <20220221084941.030096409@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Christie commit f10f582d28220f50099d3f561116256267821429 upstream. This fixes a deadlock added with commit b40f3894e39e ("scsi: qedi: Complete TMF works before disconnect") Bug description from Jia-Ju Bai: qedi_process_tmf_resp() spin_lock(&session->back_lock); --> Line 201 (Lock A) spin_lock(&qedi_conn->tmf_work_lock); --> Line 230 (Lock B) qedi_process_cmd_cleanup_resp() spin_lock_bh(&qedi_conn->tmf_work_lock); --> Line 752 (Lock B) spin_lock_bh(&conn->session->back_lock); --> Line 784 (Lock A) When qedi_process_tmf_resp() and qedi_process_cmd_cleanup_resp() are concurrently executed, the deadlock can occur. This patch fixes the deadlock by not holding the tmf_work_lock in qedi_process_cmd_cleanup_resp while holding the back_lock. The tmf_work_lock is only needed while we remove the tmf_work from the work_list. Link: https://lore.kernel.org/r/20220208185448.6206-1-michael.christie@oracle.com Fixes: b40f3894e39e ("scsi: qedi: Complete TMF works before disconnect") Cc: Manish Rangankar Cc: Nilesh Javali Reported-by: TOTE Robot Reported-by: Jia-Ju Bai Signed-off-by: Mike Christie Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/qedi/qedi_fw.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/drivers/scsi/qedi/qedi_fw.c +++ b/drivers/scsi/qedi/qedi_fw.c @@ -771,11 +771,10 @@ static void qedi_process_cmd_cleanup_res qedi_cmd->list_tmf_work = NULL; } } + spin_unlock_bh(&qedi_conn->tmf_work_lock); - if (!found) { - spin_unlock_bh(&qedi_conn->tmf_work_lock); + if (!found) goto check_cleanup_reqs; - } QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_SCSI_TM, "TMF work, cqe->tid=0x%x, tmf flags=0x%x, cid=0x%x\n", @@ -806,7 +805,6 @@ static void qedi_process_cmd_cleanup_res qedi_cmd->state = CLEANUP_RECV; unlock: spin_unlock_bh(&conn->session->back_lock); - spin_unlock_bh(&qedi_conn->tmf_work_lock); wake_up_interruptible(&qedi_conn->wait_queue); return;