From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY 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 ED285C31E46 for ; Wed, 12 Jun 2019 14:03:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF14C21019 for ; Wed, 12 Jun 2019 14:03:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407758AbfFLODh (ORCPT ); Wed, 12 Jun 2019 10:03:37 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:8991 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2407368AbfFLODh (ORCPT ); Wed, 12 Jun 2019 10:03:37 -0400 X-UUID: 0ec276bfe8ac41e39318012d65bb6cff-20190612 X-UUID: 0ec276bfe8ac41e39318012d65bb6cff-20190612 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1598698959; Wed, 12 Jun 2019 22:03:32 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs02n2.mediatek.inc (172.21.101.101) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 12 Jun 2019 22:03:24 +0800 Received: from [172.21.77.33] (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 12 Jun 2019 22:03:23 +0800 Message-ID: <1560348204.19782.6.camel@mtkswgap22> Subject: RE: [PATCH v1] scsi: ufs: Avoid runtime suspend possibly being blocked forever From: Stanley Chu To: Avri Altman CC: "linux-scsi@vger.kernel.org" , "martin.petersen@oracle.com" , "alim.akhtar@samsung.com" , "pedrom.sousa@synopsys.com" , "linux-mediatek@lists.infradead.org" , "linux-arm-kernel@lists.infradead.org" , "matthias.bgg@gmail.com" , "evgreen@chromium.org" , "beanhuo@micron.com" , "marc.w.gonzalez@free.fr" , "ygardi@codeaurora.org" , "subhashj@codeaurora.org" , "kuohong.wang@mediatek.com" , "peter.wang@mediatek.com" , "chun-hung.wu@mediatek.com" , "andy.teng@mediatek.com" , "stable@vger.kernel.org" , Date: Wed, 12 Jun 2019 22:03:24 +0800 In-Reply-To: References: <1560325326-1598-1-git-send-email-stanley.chu@mediatek.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-TM-SNTS-SMTP: 4018B39517CC99ADF846BD09B0727C651F76F30778E15F902E6C0D2819EA72F62000:8 X-MTK: N Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Hi Avri, On Wed, 2019-06-12 at 11:10 +0000, Avri Altman wrote: > Hi, > > > > > UFS runtime suspend can be triggered after pm_runtime_enable() > > is invoked in ufshcd_pltfrm_init(). However if the first runtime > > suspend is triggered before binding ufs_hba structure to ufs > > device structure via platform_set_drvdata(), then UFS runtime > > suspend will be no longer triggered in the future because its > > dev->power.runtime_error was set in the first triggering and does > > not have any chance to be cleared. > > > > To be more clear, dev->power.runtime_error is set if hba is NULL > > in ufshcd_runtime_suspend() which returns -EINVAL to rpm_callback() > > where dev->power.runtime_error is set as -EINVAL. In this case, any > > future rpm_suspend() for UFS device fails because > > rpm_check_suspend_allowed() fails due to non-zero > > dev->power.runtime_error. > > > > To resolve this issue, make sure the first UFS runtime suspend > > get valid "hba" in ufshcd_runtime_suspend(): Enable UFS runtime PM > > only after hba is successfully bound to UFS device structure. > > > > Fixes: e3ce73d (scsi: ufs: fix bugs related to null pointer access and array size) > This code was inserted before platform_set_drvdata in > 6269473 [SCSI] ufs: Add runtime PM support for UFS host controller driver. > Why do you point to e3ce73d? e3ce73d (scsi: ufs: fix bugs related to null pointer access and array size) changed the returned value from 0 to -EINVAL in case of NULL "hba" in ufshcd_runtime_suspend(). But you are right, above patch may do the right thing, and the real root cause is the incorrect timing of pm_runtime_enable(). I will fix commit message in next version. > > Thanks, > Avri Thanks. Stanley