From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Adrian Hunter <adrian.hunter@intel.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Nitin Rawat <quic_nitirawa@quicinc.com>,
Tushar Nimkar <quic_tnimkar@quicinc.com>,
linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-arm-msm@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
bjorn.andersson@kernel.org, quic_mkshah@quicinc.com,
quic_lsrao@quicinc.com, bvanassche@acm.org,
Peter Wang <peter.wang@mediatek.com>
Subject: Re: PM-runtime: supplier looses track of consumer during probe
Date: Thu, 01 Dec 2022 20:44:03 +0100 [thread overview]
Message-ID: <12104185.O9o76ZdvQC@kreacher> (raw)
In-Reply-To: <CAJZ5v0gdg=PUz-j0yd_QJRPmjhZ7pCuRrHt30U60H4QyTHCmdA@mail.gmail.com>
On Thursday, December 1, 2022 8:28:25 PM CET Rafael J. Wysocki wrote:
> On Thu, Dec 1, 2022 at 2:10 PM Adrian Hunter <adrian.hunter@intel.com> wrote:
> >
> > On 29/11/22 18:56, Nitin Rawat wrote:
> > > Hi Adrian,
> > >
> > > On 11/21/2022 11:38 AM, Tushar Nimkar wrote:
> > >> Hi Adrian,
> > >>
> > >> On 11/18/2022 8:25 PM, Adrian Hunter wrote:
> > >>> On 4/11/22 11:19, Tushar Nimkar wrote:
> > >>>> Hi linux-pm/linux-scsi,
> > >>
> > >>>>> Process -1
> > >>>>> ufshcd_async_scan context (process 1)
> > >>>>> scsi_autopm_put_device() //0:0:0:0
> > >>>
> > >>> I am having trouble following your description. What function is calling
> > >>> scsi_autopm_put_device() here?
> > >>>
> > >> Below is flow which calls scsi_autopm_put_device()
> > >> Process -1
> > >> ufshcd_async_scan()
> > >> scsi_probe_and_add_lun()
> > >> scsi_add_lun()
> > >> slave_configure()
> > >> scsi_sysfs_add_sdev()
> > >> scsi_autopm_get_device()
> > >> device_add() <- invoked [Process 2] sd_probe()
> > >> scsi_autopm_put_device()
> > >>
> > >>>>> pm_runtime_put_sync()
> > >>>>> __pm_runtime_idle()
> > >>>>> rpm_idle() -- RPM_GET_PUT(4)
> > >>>>> __rpm_callback
> > >>>>> scsi_runtime_idle()
> > >>>>> pm_runtime_mark_last_busy()
> > >>>>> pm_runtime_autosuspend() --[A]
> > >>>>> rpm_suspend() -- RPM_AUTO(8)
> > >>>>> pm_runtime_autosuspend_expiration() use_autosuspend is false return 0 --- [B]
> > >>>>> __update_runtime_status to RPM_SUSPENDING
> > >>>>> __rpm_callback()
> > >>>>> __rpm_put_suppliers(dev, false)
> > >>>>> __update_runtime_status to RPM_SUSPENDED
> > >>>>> rpm_suspend_suppliers()
> > >>>>> rpm_idle() for supplier -- RPM_ASYNC(1) return (-EAGAIN) [ Other consumer active for supplier]
> > >>>>> rpm_suspend() – END with return=0
> > >>>>> scsi_runtime_idle() END return (-EBUSY) always.
> > >>>
> > >>> Not following here either. Which device is EBUSY and why?
> > >>
> > >> scsi_runtime_idle() return -EBUSY always [3]
> > >> Storage/scsi team can better explain -EBUSY implementation.
> > >
> > > EBUSY is returned from below code for consumer dev 0:0:0:0.
> > > scsi_runtime_idle is called from scsi_autopm_put_device which inturn is called from ufshcd_async_scan (Process 1 as per above call stack)
> > > static int scsi_runtime_idle(struct device *dev)
> > > {
> > > :
> > >
> > > if (scsi_is_sdev_device(dev)) {
> > > pm_runtime_mark_last_busy(dev);
> > > pm_runtime_autosuspend(dev);
> > > return -EBUSY; ---> EBUSY returned from here.
> > > }
> > >
> > >
> > > }
> > >
> > >>
> > >> [3] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/scsi/scsi_pm.c?h=next-20221118#n210
> > >>
> > >>
> > >>>>>
> > >>>>> [1]: https://lore.kernel.org/lkml/4748074.GXAFRqVoOG@kreacher/T/
> > >>>>> [2]: https://lkml.org/lkml/2022/10/12/259
> >
> > It looks to me like __rpm_callback() makes assumptions about
> > dev->power.runtime_status that are not necessarily true because
> > dev->power.lock is dropped.
>
> Well, this happens because rpm_idle() calls __rpm_callback() and
> allows it to run concurrently with rpm_suspend() and rpm_resume(), so
> one of them may change runtime_status to RPM_SUSPENDING or
> RPM_RESUMING while __rpm_callback() is running.
>
> It is somewhat questionable whether or not this should be allowed to
> happen, but since it is generally allowed to suspend the device from
> its .runtime_idle callback, there is not too much that can be done
> about it.
But this means that the patch below should help too.
I actually think that we can do both, because rpm_idle() doesn't have to do
the whole device links dance and the fact that it still calls __rpm_callback()
is a clear oversight.
---
drivers/base/power/runtime.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
Index: linux-pm/drivers/base/power/runtime.c
===================================================================
--- linux-pm.orig/drivers/base/power/runtime.c
+++ linux-pm/drivers/base/power/runtime.c
@@ -484,7 +484,17 @@ static int rpm_idle(struct device *dev,
dev->power.idle_notification = true;
- retval = __rpm_callback(callback, dev);
+ if (dev->power.irq_safe)
+ spin_unlock(&dev->power.lock);
+ else
+ spin_unlock_irq(&dev->power.lock);
+
+ retval = callback(dev);
+
+ if (dev->power.irq_safe)
+ spin_lock(&dev->power.lock);
+ else
+ spin_lock_irq(&dev->power.lock);
dev->power.idle_notification = false;
wake_up_all(&dev->power.wait_queue);
next prev parent reply other threads:[~2022-12-01 19:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-14 10:50 PM-runtime: supplier looses track of consumer during probe Tushar Nimkar
2022-11-04 9:19 ` Tushar Nimkar
2022-11-18 14:55 ` Adrian Hunter
2022-11-21 6:08 ` Tushar Nimkar
2022-11-29 16:56 ` Nitin Rawat
2022-12-01 13:09 ` Adrian Hunter
2022-12-01 14:54 ` Nitin Rawat
2022-12-01 19:28 ` Rafael J. Wysocki
2022-12-01 19:44 ` Rafael J. Wysocki [this message]
2022-12-02 12:22 ` Tushar Nimkar
2022-12-02 13:22 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=12104185.O9o76ZdvQC@kreacher \
--to=rjw@rjwysocki.net \
--cc=adrian.hunter@intel.com \
--cc=bjorn.andersson@kernel.org \
--cc=bvanassche@acm.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=peter.wang@mediatek.com \
--cc=quic_lsrao@quicinc.com \
--cc=quic_mkshah@quicinc.com \
--cc=quic_nitirawa@quicinc.com \
--cc=quic_tnimkar@quicinc.com \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox