From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Tudor Ambarus <tudor.ambarus@linaro.org>
Cc: "Linux PM" <linux-pm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"Alan Stern" <stern@rowland.harvard.edu>,
"Ulf Hansson" <ulf.hansson@linaro.org>,
"Johan Hovold" <johan@kernel.org>,
"Jon Hunter" <jonathanh@nvidia.com>,
"Saravana Kannan" <saravanak@google.com>,
"William McVicker" <willmcvicker@google.com>,
"Peter Griffin" <peter.griffin@linaro.org>,
"André Draszik" <andre.draszik@linaro.org>
Subject: Re: [PATCH v3 1/5] PM: sleep: Resume children after resuming the parent
Date: Sat, 12 Jul 2025 09:54:58 +0200 [thread overview]
Message-ID: <4677865.LvFx2qVVIh@rjwysocki.net> (raw)
In-Reply-To: <CAJZ5v0jFP2njw3ic47yyh_7u7evKQKQuqGp27Vj7X-FfDLH7uQ@mail.gmail.com>
On Friday, July 11, 2025 3:54:00 PM CEST Rafael J. Wysocki wrote:
> On Fri, Jul 11, 2025 at 3:38 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Fri, Jul 11, 2025 at 3:08 PM Tudor Ambarus <tudor.ambarus@linaro.org> wrote:
> > >
> > >
> > > Hi, Rafael,
> > >
> > > On 3/14/25 12:50 PM, Rafael J. Wysocki wrote:
> > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > >
> > > > According to [1], the handling of device suspend and resume, and
> > > > particularly the latter, involves unnecessary overhead related to
> > > > starting new async work items for devices that cannot make progress
> > > > right away because they have to wait for other devices.
> > > >
> > > > To reduce this problem in the resume path, use the observation that
> > > > starting the async resume of the children of a device after resuming
> > > > the parent is likely to produce less scheduling and memory management
> > > > noise than starting it upfront while at the same time it should not
> > > > increase the resume duration substantially.
> > > >
> > > > Accordingly, modify the code to start the async resume of the device's
> > > > children when the processing of the parent has been completed in each
> > > > stage of device resume and only start async resume upfront for devices
> > > > without parents.
> > > >
> > > > Also make it check if a given device can be resumed asynchronously
> > > > before starting the synchronous resume of it in case it will have to
> > > > wait for another that is already resuming asynchronously.
> > > >
> > > > In addition to making the async resume of devices more friendly to
> > > > systems with relatively less computing resources, this change is also
> > > > preliminary for analogous changes in the suspend path.
> > > >
> > > > On the systems where it has been tested, this change by itself does
> > > > not affect the overall system resume duration in a measurable way.
> > > >
> > > > Link: https://lore.kernel.org/linux-pm/20241114220921.2529905-1-saravanak@google.com/ [1]
> > > > Suggested-by: Saravana Kannan <saravanak@google.com>
> > > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > >
> > > I'd like to let you know of a suspend crash that I'm dealing with
> > > when using the OOT pixel6 drivers on top of v6.16-rc4.
> >
> > Well, thanks, but there's not much I can do about it.
> >
> > It is also better to start a new thread in such cases than to reply to
> > a patch submission.
> >
> > > Similar to what Jon reported, everything gets back to normal if
> > > I disable pm_async or if I revert the following patches:
> > > 443046d1ad66 PM: sleep: Make suspend of devices more asynchronous
> > > aa7a9275ab81 PM: sleep: Suspend async parents after suspending children
> > > 0cbef962ce1f PM: sleep: Resume children after resuming the parent
> > >
> > > I also reverted their fixes when testing:
> > > 8887abccf8aa PM: sleep: Add locking to dpm_async_resume_children()
> > > d46c4c839c20 PM: sleep: Fix power.is_suspended cleanup for direct-complete devices
> > > 079e8889ad13 PM: sleep: Fix list splicing in device suspend error paths
> > >
> > > It seems that the hang happens in dpm_suspend() at
> > > async_synchronize_full() time after a driver fails to suspend.
> > > The phone then naturally resets with an APC watchdog.
> > >
> > > [ 519.142279][ T7917] lwis lwis-eeprom-m24c64x: Can't suspend because eeprom-m24c64x is in use!
> > > [ 519.143556][ T7917] lwis-i2c eeprom@2: PM: dpm_run_callback(): platform_pm_suspend returns -16
> > > [ 519.143872][ T7917] lwis-i2c eeprom@2: PM: platform_pm_suspend returned -16 after 1596 usecs
> > > [ 519.144197][ T7917] lwis-i2c eeprom@2: PM: failed to suspend: error -16
> > > [ 519.144448][ T7917] PM: tudor: dpm_suspend: after while loop, list_empty(&dpm_prepared_list)? 1
> > > [ 519.144779][ T7917] PM: tudor: dpm_suspend: before async_synchronize_full
> > >
> > > The extra prints are because of:
> > > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> > > index d9d4fc58bc5a..3efe538c2ec2 100644
> > > --- a/drivers/base/power/main.c
> > > +++ b/drivers/base/power/main.c
> > > @@ -1967,10 +1967,15 @@ int dpm_suspend(pm_message_t state)
> > > break;
> > > }
> > > }
> > > + pr_err("tudor: %s: after while loop, list_empty(&dpm_prepared_list)? %d\n",
> > > + __func__, list_empty(&dpm_prepared_list));
> > >
> > > mutex_unlock(&dpm_list_mtx);
> > >
> > > + pr_err("tudor: %s: before async_synchronize_full\n", __func__);
> > > async_synchronize_full();
> > > + pr_err("tudor: %s: after async_synchronize_full();\n", __func__);
> > > +
> > > if (!error)
> > > error = async_error;
> > >
> > > The synchronous suspend works because its strict, one-by-one ordering
> > > ensures that device dependencies are met and that no device is suspended
> > > while another is still using it. The asynchronous suspend fails because
> > > it creates a race condition where the lwis-eeprom-m24c64x is called for
> > > suspension before the process using it has been suspended, leading to a
> > > fatal "device busy" error. Should the failure of a device suspend be
> > > fatal?
> >
> > It shouldn't in principle, but it depends on what exactly is involved and how.
> >
> > It looks like something is blocking on power.completion somewhere.
> > I'll check the code, maybe a complete() is missing in an error path or
> > similar.
>
> It doesn't look like anything is missing in the core, so the suspend
> failure seems to be triggering a deadlock of some sort.
Well, I'm taking this back.
The following scenario definitely can happen:
1. Device A is async and it depends on device B that is sync.
2. Async suspend is scheduled for A before the processing of B is started.
3. A is waiting for B.
4. In the meantime, an unrelated device fails to suspend and returns an error.
5. The processing of B doesn't start at all and its power.completion is not
updated.
6. A is still waiting for B when async_synchronize_full() is called.
7. Deadlock ensues.
If this is what happens in your case, the (untested) patch below should help
(unless I messed it up, that is).
---
drivers/base/power/main.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1323,6 +1323,22 @@
device_links_read_unlock(idx);
}
+static void dpm_async_suspend_complete_all(struct list_head *device_list)
+{
+ struct device *dev;
+
+ guard(mutex)(&async_wip_mtx);
+
+ list_for_each_entry_reverse(dev, device_list, power.entry) {
+ /*
+ * In case the device is being waited for and async processing
+ * has not started for it yet, let the waiters make progress.
+ */
+ if (!dev->power.work_in_progress)
+ complete_all(&dev->power.completion);
+ }
+}
+
/**
* resume_event - Return a "resume" message for given "suspend" sleep state.
* @sleep_state: PM message representing a sleep state.
@@ -1499,6 +1515,7 @@
mutex_lock(&dpm_list_mtx);
if (error || async_error) {
+ dpm_async_suspend_complete_all(&dpm_late_early_list);
/*
* Move all devices to the target list to resume them
* properly.
@@ -1701,6 +1718,7 @@
mutex_lock(&dpm_list_mtx);
if (error || async_error) {
+ dpm_async_suspend_complete_all(&dpm_suspended_list);
/*
* Move all devices to the target list to resume them
* properly.
@@ -1994,6 +2012,7 @@
mutex_lock(&dpm_list_mtx);
if (error || async_error) {
+ dpm_async_suspend_complete_all(&dpm_prepared_list);
/*
* Move all devices to the target list to resume them
* properly.
next prev parent reply other threads:[~2025-07-12 7:55 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 12:46 [PATCH v3 0/5] PM: sleep: Improvements of async suspend and resume of devices Rafael J. Wysocki
2025-03-14 12:50 ` [PATCH v3 1/5] PM: sleep: Resume children after resuming the parent Rafael J. Wysocki
2025-05-01 9:51 ` Jon Hunter
2025-05-02 20:33 ` Rafael J. Wysocki
2025-05-07 13:21 ` Jon Hunter
2025-05-07 13:39 ` Rafael J. Wysocki
2025-05-07 14:25 ` Rafael J. Wysocki
2025-05-07 14:39 ` Jon Hunter
2025-05-07 14:56 ` Rafael J. Wysocki
2025-05-07 15:39 ` Jon Hunter
2025-05-07 16:43 ` Rafael J. Wysocki
2025-05-08 13:38 ` Jon Hunter
2025-05-08 18:06 ` Rafael J. Wysocki
2025-05-10 11:39 ` Rafael J. Wysocki
2025-05-10 11:50 ` Jon Hunter
2025-07-11 13:08 ` Tudor Ambarus
2025-07-11 13:38 ` Rafael J. Wysocki
2025-07-11 13:54 ` Rafael J. Wysocki
2025-07-11 18:30 ` Saravana Kannan
2025-07-12 7:57 ` Rafael J. Wysocki
2025-07-12 7:54 ` Rafael J. Wysocki [this message]
2025-07-14 7:09 ` Tudor Ambarus
2025-07-14 7:29 ` Rafael J. Wysocki
2025-07-14 10:35 ` Tudor Ambarus
2025-07-14 12:14 ` Tudor Ambarus
2025-03-14 13:13 ` [PATCH v3 2/5] PM: sleep: Suspend async parents after suspending children Rafael J. Wysocki
2025-06-02 12:11 ` Chris Bainbridge
2025-06-02 14:29 ` Rafael J. Wysocki
2025-06-02 15:21 ` Mario Limonciello
2025-06-02 19:58 ` Rafael J. Wysocki
2025-06-03 9:38 ` Rafael J. Wysocki
2025-06-03 10:17 ` Chris Bainbridge
2025-06-03 10:29 ` Rafael J. Wysocki
2025-06-03 10:30 ` Rafael J. Wysocki
2025-06-03 11:37 ` Rafael J. Wysocki
2025-06-03 11:39 ` Rafael J. Wysocki
2025-06-03 12:14 ` Chris Bainbridge
2025-06-03 12:23 ` Rafael J. Wysocki
2025-06-03 12:26 ` Chris Bainbridge
2025-06-03 13:04 ` Rafael J. Wysocki
2025-06-03 13:36 ` Chris Bainbridge
2025-06-03 13:59 ` Rafael J. Wysocki
2025-03-14 13:14 ` [PATCH v3 3/5] PM: sleep: Make suspend of devices more asynchronous Rafael J. Wysocki
2025-03-14 13:16 ` [PATCH v3 4/5] PM: sleep: Make async suspend handle suppliers like parents Rafael J. Wysocki
2025-03-14 13:17 ` [PATCH v3 5/5] PM: sleep: Make async resume handle consumers like children Rafael J. Wysocki
2025-03-14 21:06 ` [PATCH v3 0/5] PM: sleep: Improvements of async suspend and resume of devices Saravana Kannan
2025-03-15 14:57 ` Rafael J. Wysocki
2025-04-08 13:39 ` 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=4677865.LvFx2qVVIh@rjwysocki.net \
--to=rafael@kernel.org \
--cc=andre.draszik@linaro.org \
--cc=johan@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=peter.griffin@linaro.org \
--cc=saravanak@google.com \
--cc=stern@rowland.harvard.edu \
--cc=tudor.ambarus@linaro.org \
--cc=ulf.hansson@linaro.org \
--cc=willmcvicker@google.com \
/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
all inboxes | Powered by JetHome®