From: sashiko-bot@kernel.org
To: "Ziyu Zhang" <ziyuzhang201@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] PM: core: Do not wait for a device's own completion
Date: Tue, 01 Dec 2026 07:37:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-242778@kernel.org> (raw)
In-Reply-To: <20261201072944.73205-1-ziyuzhang201@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] PM: core: device_pm_wait_for_dev() papers over self-companion
DT bug
- [Low] PM: core: missing Fixes trailer for device_pm_wait_for_dev()
deadlock fix
--
commit 5ff73b0e5039a3b4e0f21b35ef7f4e433f37c17b
Author: Ziyu Zhang <ziyuzhang201@gmail.com>
> PM: core: Do not wait for a device's own completion
>
> 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>
[Severity: Low]
Since this fixes a deadlock in device_pm_wait_for_dev(), should it carry a
Fixes tag such as:
Fixes: f8824cee405c ("PM: Allow device drivers to use dpm_wait()")
or:
Fixes: d4d75128b8fd ("usb: host: ehci-platform: fix usb 1.1 device is not connected in system resume")
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index 88a31e09e4f3f..16506c1fac8bc 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;
> }
[Severity: Medium]
Should a self-referential "companion" phandle be rejected in
usb_of_get_companion_dev() instead of being silently ignored in
device_pm_wait_for_dev()?
A device cannot be its own companion, and leaving usb_of_get_companion_dev()
to return the caller's own device when node == dev->of_node leaves other
consumers broken for the same malformed device tree. For example, in
ehci-platform.c, quirk_poll_rebind_companion() unbinds companion_dev from
inside quirk_poll_work():
drivers/usb/host/ehci-platform.c:quirk_poll_rebind_companion() {
...
companion_dev = usb_of_get_companion_dev(hcd->self.controller);
if (!companion_dev)
return;
device_release_driver(companion_dev);
if (device_attach(companion_dev) < 0)
ehci_err(ehci, "%s: failed\n", __func__);
...
}
When companion_dev is hcd->self.controller, device_release_driver() runs
ehci_platform_remove() (which only does a non-synchronous
cancel_delayed_work(&priv->poll_work)) and frees hcd and ehci while
quirk_poll_rebind_companion() is still running, leading to a use-after-free.
Similarly, renesas_usb3_role_work() calls device_release_driver() on the
companion stored in usb3->host_dev, which calls renesas_usb3_remove() on
itself and deadlocks in cancel_work_sync(&usb3->role_work).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201072944.73205-1-ziyuzhang201@gmail.com?part=1
next prev parent reply other threads:[~2026-12-01 7:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 7:29 [PATCH] PM: core: Do not wait for a device's own completion Ziyu Zhang
2026-12-01 7:37 ` sashiko-bot [this message]
2026-12-01 8:28 ` ziyu zhang
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=sashiko-outbox-242778@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=ziyuzhang201@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.