From: Ziyu Zhang <ziyuzhang201@gmail.com>
To: rafael@kernel.org
Cc: pavel@ucw.cz, lenb@kernel.org, gregkh@linuxfoundation.org,
dakr@kernel.org, johan@kernel.org, linux-pm@vger.kernel.org,
driver-core@lists.linux.dev, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] PM: core: Do not wait for a device's own completion
Date: Tue, 1 Dec 2026 15:29:44 +0800 [thread overview]
Message-ID: <20261201072944.73205-1-ziyuzhang201@gmail.com> (raw)
device_pm_wait_for_dev() waits on the completion of @dev when the
subordinate has async suspend enabled. That completion is signaled only
after the PM callback of @dev returns, and dpm_resume() reinitializes it
when the phase starts, so passing the same device twice waits for a
callback that is still running:
resume of D device_pm_wait_for_dev(D, D)
---------- -----------------------------
device_resume(D)
device_lock(D)
resume callback
dpm_wait(D, async = true)
wait_for_completion(
&D->power.completion)
/* returns only here */
device_unlock(D)
complete_all(&D->power.completion)
The wait has no timeout and device_resume() holds D->mutex across the
callback, so the resume never finishes and D stays locked for the rest
of the transition.
ehci_platform is the only caller in the tree that can build this pair.
ehci_platform_resume() takes the companion of its controller from the
device tree and passes it to device_pm_wait_for_dev() together with the
controller. A "companion" phandle that points back at its own node
makes both arguments the same device: of_parse_phandle() returns the
node and of_find_device_by_node() returns the platform device that is
being resumed.
Return without waiting when both arguments are the same device. A
device cannot depend on a completion that is signaled only after the
callback it is running returns, so there is nothing to wait for. The
other two callers, in usb/core, always pass two different devices.
If two EHCI controllers name each other as companions, their resume
callbacks can still wait for each other's completion because the device
pointers differ. One option for ehci-platform would be to skip the
wait when the companion is another EHCI controller that points back to
the first. This would preserve the existing resume ordering between
EHCI and OHCI companions.
Signed-off-by: Ziyu Zhang <ziyuzhang201@gmail.com>
---
drivers/base/power/main.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 88a31e09e4f3..16506c1fac8b 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -2401,9 +2401,15 @@ EXPORT_SYMBOL_GPL(__suspend_report_result);
* device_pm_wait_for_dev - Wait for suspend/resume of a device to complete.
* @subordinate: Device that needs to wait for @dev.
* @dev: Device to wait for.
+ *
+ * A device that resolves to itself is not waited for: its completion is
+ * only signaled after the PM callback that is running right now returns.
*/
int device_pm_wait_for_dev(struct device *subordinate, struct device *dev)
{
+ if (subordinate == dev)
+ return async_error;
+
dpm_wait(dev, subordinate->power.async_suspend);
return async_error;
}
--
2.34.1
reply other threads:[~2026-12-01 7:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261201072944.73205-1-ziyuzhang201@gmail.com \
--to=ziyuzhang201@gmail.com \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=pavel@ucw.cz \
--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
all inboxes | Powered by JetHome®