From patchwork Tue Sep 1 15:10:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 264588 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7C8DC433E2 for ; Tue, 1 Sep 2020 16:24:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B01D02078B for ; Tue, 1 Sep 2020 16:24:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598977455; bh=c7B7tLFeyCxXRTekFZ42saMcN9j228FuZVR/tA/OaYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=jIzS22+rQXSCSQQrclGmahwUNnRmJnXygjT98eTlYwPtTxLcIeEWBBVb2ChgAFgVh vFspytE8ESeCYC9BwufMpBkje+Q1Z4XJOp5HuIpQgr/Iek0rCFIzQxpswPICCDfgZs 2ht03wEWtauf1KtbRg1j3xDZ1Pyj4TINQvtseeSw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728041AbgIAQYM (ORCPT ); Tue, 1 Sep 2020 12:24:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:35752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730928AbgIAPcQ (ORCPT ); Tue, 1 Sep 2020 11:32:16 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 55CE920866; Tue, 1 Sep 2020 15:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974335; bh=c7B7tLFeyCxXRTekFZ42saMcN9j228FuZVR/tA/OaYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hs3FkdzIjvlwRWYJUP2SDCk0pMjG2H1adcj0hrRibaffHcGBgFiWY16r9Dr6ILG1o 3RPDdJ87VR+Pmwyh7+CpAfK875Pc95fsOn5HwXU8pjjssNNO6ens5MgJ2YD+FwICmH UOLvqXC8nNekINqGnJBqtJJNY0D6i3vtDlO6czVc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Avri Altman , Andy Teng , Stanley Chu , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.4 137/214] scsi: ufs: Fix possible infinite loop in ufshcd_hold Date: Tue, 1 Sep 2020 17:10:17 +0200 Message-Id: <20200901150959.544889977@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150952.963606936@linuxfoundation.org> References: <20200901150952.963606936@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Stanley Chu [ Upstream commit 93b6c5db06028a3b55122bbb74d0715dd8ca4ae0 ] In ufshcd_suspend(), after clk-gating is suspended and link is set as Hibern8 state, ufshcd_hold() is still possibly invoked before ufshcd_suspend() returns. For example, MediaTek's suspend vops may issue UIC commands which would call ufshcd_hold() during the command issuing flow. Now if UFSHCD_CAP_HIBERN8_WITH_CLK_GATING capability is enabled, then ufshcd_hold() may enter infinite loops because there is no clk-ungating work scheduled or pending. In this case, ufshcd_hold() shall just bypass, and keep the link as Hibern8 state. Link: https://lore.kernel.org/r/20200809050734.18740-1-stanley.chu@mediatek.com Reviewed-by: Avri Altman Co-developed-by: Andy Teng Signed-off-by: Andy Teng Signed-off-by: Stanley Chu Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index b41b88bcab3d9..336cf72397e50 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1516,6 +1516,7 @@ unblock_reqs: int ufshcd_hold(struct ufs_hba *hba, bool async) { int rc = 0; + bool flush_result; unsigned long flags; if (!ufshcd_is_clkgating_allowed(hba)) @@ -1547,7 +1548,9 @@ start: break; } spin_unlock_irqrestore(hba->host->host_lock, flags); - flush_work(&hba->clk_gating.ungate_work); + flush_result = flush_work(&hba->clk_gating.ungate_work); + if (hba->clk_gating.is_suspended && !flush_result) + goto out; spin_lock_irqsave(hba->host->host_lock, flags); goto start; }