From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stanley Chu Subject: RE: [PATCH v1] scsi: ufs: Avoid runtime suspend possibly being blocked forever Date: Wed, 12 Jun 2019 22:03:24 +0800 Message-ID: <1560348204.19782.6.camel@mtkswgap22> References: <1560325326-1598-1-git-send-email-stanley.chu@mediatek.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: stable-owner@vger.kernel.org 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" List-Id: linux-scsi@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