From patchwork Tue Sep 1 15:10:00 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: 264650 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 1A3E9C433E2 for ; Tue, 1 Sep 2020 16:04:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE7462078B for ; Tue, 1 Sep 2020 16:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598976269; bh=PGfxuD/0CedvscxTZBFLO4uNZzYGlM5Fygon8FtRPoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Ei/UShq3QzB/+7BR9ENfFcBK/6KmT9CEaoxf9pGFTkGXPjG85j6Zj1jGhBg42gNnl CxBH0uwd6l2XT26HCTmksgMnn+LBpH4lHoLURrqjuYcNF2vT1sUF6+MEE6YSg60jVH vL66ntK2dNj1UB6Hy0fOkGqtBm0eldyU9OnxtM6I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729715AbgIAQE2 (ORCPT ); Tue, 1 Sep 2020 12:04:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:54826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728084AbgIAPmK (ORCPT ); Tue, 1 Sep 2020 11:42:10 -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 9DFDE206EB; Tue, 1 Sep 2020 15:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974930; bh=PGfxuD/0CedvscxTZBFLO4uNZzYGlM5Fygon8FtRPoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YHO2C1EPlUTDawFTVp7IOnNkIOivNfBgJeHTdICFsiWYmsYVVZwB62lsZ79P0p+El s+kN7D2RDvTPqercINZQ/DlyA/juHpypY0xmuMKQwcROH9FLmF8e88wuuqtAsbJAfQ glfnZobgwk/Iqyfg+aRety3dScdEgUwx2HqQKZRo= 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.8 144/255] scsi: ufs: Fix possible infinite loop in ufshcd_hold Date: Tue, 1 Sep 2020 17:10:00 +0200 Message-Id: <20200901151007.602712332@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901151000.800754757@linuxfoundation.org> References: <20200901151000.800754757@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 136b863bc1d45..2b5acdfb17820 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1566,6 +1566,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)) @@ -1597,7 +1598,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; }