From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796110633; b=FRySNNgNr1ITxkzr41SiG5jVLAUafyiSLa8Nz1v0nvhGSzTwGtec9REVez9cLDOYsmBv 3Pau6t27V9zSbDBuKDTMaL9fXr7S5twNj5HoDEmCN5Km5X29mDmvTWoJDOqpRdMFDeStV R5fRQHi4nj/Ww9dqp/18TT/1Ze7CcdLhVKsV8ZVLvdg25Bkc4lXq9KYuU3gGr6nf/mhdn sDsok5vrnEqt2csaH5zOl8XCA4ajGIcYXPYq+IYAhydGBFjDQnF3DfEYu6+ZnYyXLhYWk 2uYM0yy3VByV9Pyh76R2IgJu9482vW1iqJKdDFdfiJZIBcMy3TeD0V8eXqCXikShyXQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796110633; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=0KByrnGfpetsa+OMf4xj4ktI37ZKlu5+es1PLXBQUoc=; b=vcv/gK5khu7P2iWz158c6mqkJ9ZMursKbyfOUsuj4e8ZXbFHEEJioWZ+uZ7iJX1HxeQL ZqzzxI0zownjMPXcMIbYduYpLJ8SD6wThLFj5ga2HkolNJGxfbwDQx9t9OuE0nDf8xn8L xXLLy5Bk6LjfZDdj84eCbQlAKK+hXpkmhfVJ0DiQvvyiwTsmRpsN3/WgkcQkABaZ7JYMJ nn1gikJCEujNUolxL3gTZJ50CKsdarSaqyPRgytCQ1YyfZZWrr3js+aH8OmUfleUWdjsS Edzch30YpNYcJRAfqbfBWGyjc57uPom9dNwv6ATWXiw46PbMsPKNRLGLr2rb3QELqdA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GEzZvghS; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C0F9606A31A for ; Tue, 1 Dec 2026 07:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GEzZvghS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F3791F00893; Tue, 1 Dec 2026 07:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796110633; bh=0KByrnGfpetsa+OMf4xj4ktI37ZKlu5+es1PLXBQUoc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=GEzZvghSRjvTLhQ9LSL2YnifSBFYVmemGKv9/RQUmbTSxmBPfqZcrZG3ed293ht1f Slo9wMBTS6/JnbSjFPforclOewhrfTVXUo6iOL5cQ+GkofWo3tvPUwVBDRpRgkcKd5 Gx5CXkn3B8uTm7yXpVB3pd4fxRxgjjMlXq+78/ZlzCbsoD/DahJxGUExrkBcQUV9C3 Li5j3T9VoQymLZlp/eE4FC1J17v4pREHCSKa6wMM3pe8Sj2pqMzdEod29Law70P3P3 aXRYIRdm8PG4sliJLxK+XvJu99xUMIGjPYa7wuHG66ld1dy7YF81kmCr/BEFn01nuU IDW7wPGlu7P1A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] PM: core: Do not wait for a device's own completion Reply-To: sashiko-reviews@lists.linux.dev To: "Ziyu Zhang" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261201072944.73205-1-ziyuzhang201@gmail.com> References: <20261201072944.73205-1-ziyuzhang201@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 07:37:12 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > 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 =3D 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 [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 compl= ete. > * @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 *de= v) > { > + if (subordinate =3D=3D 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 =3D=3D 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 =3D 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). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201072944.7320= 5-1-ziyuzhang201@gmail.com?part=3D1