From: Xu Yang <xu.yang_2@nxp.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: len.brown@intel.com, pavel@kernel.org,
gregkh@linuxfoundation.org, dakr@kernel.org,
stern@rowland.harvard.edu, linux-pm@vger.kernel.org,
imx@lists.linux.dev, jun.li@nxp.com
Subject: Re: [PATCH v2] PM: sleep: core: Clear is_prepared if no_pm_callbacks is true before checking power.syscore
Date: Mon, 24 Feb 2025 14:19:59 +0800 [thread overview]
Message-ID: <20250224061959.xzsk5eddj4xjlenq@hippo> (raw)
In-Reply-To: <CAJZ5v0g40qBahsytn9AUn_dPLG-1E+UCQSucA=8kCGdi3bzq8A@mail.gmail.com>
Hi Rafael,
On Fri, Feb 21, 2025 at 09:49:11PM +0100, Rafael J. Wysocki wrote:
> On Thu, Feb 13, 2025 at 10:33 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Thu, Feb 13, 2025 at 11:58 AM Xu Yang <xu.yang_2@nxp.com> wrote:
> > >
> > > Currently, if power.no_callbacks is true for a device, device_prepare()
> > > will also set power.direct_complete to true. When device_resume() check
> > > power.direct_complete, setting power.is_prepared will be skipped if it
> > > can directly complete. This will cause a warning when add new devices
> > > during resume() stage.
> > >
> > > Although power.is_prepared should be cleared in complete() state, commit
> > > (f76b168b6f11 PM: Rename dev_pm_info.in_suspend to is_prepared) allow
> > > clear it in earlier resume() stage. However, we need also set is_prepared
> > > to false before checking syscore if the device has no pm callbacks.
> > >
> > > Take USB as example:
> > > The usb_interface is such a device which setting power.no_callbacks to
> > > true. Then if the user call usb_set_interface() during resume() stage,
> > > the kernel will print below warning since the system will create and
> > > add ep devices.
> > >
> > > [ 186.461414] usb 1-1: reset high-speed USB device number 3 using ci_hdrc
> > > [ 187.102681] ep_81: PM: parent 1-1:1.1 should not be sleeping
> > > [ 187.105010] PM: resume devices took 0.936 seconds
> > >
> > > Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> > >
> > > ---
> > > v2: clear is_prepared before check syscore as suggested by Rafael
> > > ---
> > > drivers/base/power/main.c | 3 +++
> > > 1 file changed, 3 insertions(+)
> > >
> > > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> > > index 40e1d8d8a589..5e69cfaec661 100644
> > > --- a/drivers/base/power/main.c
> > > +++ b/drivers/base/power/main.c
> > > @@ -926,6 +926,9 @@ static void device_resume(struct device *dev, pm_message_t state, bool async)
> > > TRACE_DEVICE(dev);
> > > TRACE_RESUME(0);
> > >
> > > + if (dev->power.no_pm_callbacks)
> > > + dev->power.is_prepared = false;
> > > +
> > > if (dev->power.syscore)
> > > goto Complete;
> > >
> > > --
> >
> > As I've already said in the other thread, my initial feedback was
> > based on an oversimplified view of this code, and the problem will
> > need to be addressed differently.
> >
> > Sorry about that.
>
> Unfortunately, I don't think that this can cover all of the corner
> cases. Something is going to escape, this way or another.
Agree. Although I don't know how the corner case looks, it seems like
a risk in the future.
>
> To minimize the number of things that may escape, I would first treat
> direct_complete as a special case, so only clear power.is_prepared
> early if direct_complete is set.
>
> Then, clear it only for devices with power.no_pm_callbacks set, that is
>
> if (dev->power.direct_complete) {
> /* Add explanatory comment here */
> if (dev->power.no_pm_callbacks)
> dev->power.is_prepared = false;
>
> /* Match the pm_runtime_disable() in device_suspend(). */
> pm_runtime_enable(dev);
> goto Complete;
> }
Thank you for the analysis and suggestions! Combined checking direct_complete
and no_pm_callbacks seems like a better solution and this will precisely cover
the issue I reported. I will adjust the patch and send v3 later.
>
> This is not perfect because ideally the device with no callbacks
> should wait for its parent and suppliers (if any) to resume before new
> children can be added under it safely (in case the children depend on
> the devices that it depends on) and is_prepared may be cleared before
> that happens, but those new children may be added by the parent's
> resume callback and they won't appear if the parent is not ready
> anyway.
Understand.
Thanks,
Xu Yang
prev parent reply other threads:[~2025-02-24 6:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 10:58 [PATCH v2] PM: sleep: core: Clear is_prepared if no_pm_callbacks is true before checking power.syscore Xu Yang
2025-02-13 21:33 ` Rafael J. Wysocki
2025-02-21 20:49 ` Rafael J. Wysocki
2025-02-24 6:19 ` Xu Yang [this message]
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=20250224061959.xzsk5eddj4xjlenq@hippo \
--to=xu.yang_2@nxp.com \
--cc=dakr@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=imx@lists.linux.dev \
--cc=jun.li@nxp.com \
--cc=len.brown@intel.com \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=stern@rowland.harvard.edu \
/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