[PATCH v4] PM: sleep: Don't wait for SYNC_STATE_ONLY device links

Pin-yen Lin posted 1 patch 5 days, 11 hours ago
drivers/base/base.h       | 1 +
drivers/base/core.c       | 2 +-
drivers/base/power/main.c | 6 ++++--
3 files changed, 6 insertions(+), 3 deletions(-)
[PATCH v4] PM: sleep: Don't wait for SYNC_STATE_ONLY device links
Posted by Pin-yen Lin 5 days, 11 hours ago
Device links with DL_FLAG_SYNC_STATE_ONLY should not affect suspend
and resume, and functions like device_reorder_to_tail() and
device_link_add() doesn't try to reorder the consumers with such flag.

However, dpm_wait_for_consumers() and dpm_wait_for_suppliers() doesn't
check this flag before triggering dpm_wait, leading to potential hang
during suspend/resume.

This can be reproduced on MT8186 Corsola Chromebook with devicetree like:

usb-a-connector {
        compatible = "usb-a-connector";
        port {
                usb_a_con: endpoint {
                        remote-endpoint = <&usb_hs>;
                };
        };
};

usb_host {
        compatible = "mediatek,mt8186-xhci", "mediatek,mtk-xhci";
        port {
                usb_hs: endpoint {
                        remote-endpoint = <&usb_a_con>;
                };
        };
};

In this case, the two nodes form a cycle and a SYNC_STATE_ONLY devlink
between usb_host (supplier) and usb-a-connector (consumer) is created.

Export device_link_flag_is_sync_state_only() and use it to check this in
dpm_wait_for_consumers() and dpm_wait_for_suppliers() to fix this.

Fixes: 05ef983e0d65a ("driver core: Add device link support for SYNC_STATE_ONLY flag")
Signed-off-by: Pin-yen Lin <treapking@chromium.org>
---

Changes in v4:
- Remove inline for device_link_flag_is_sync_state_only()

Changes in v3:
- Squash to one patch and fix the export approach

Changes in v2:
- Update commit message
- Use device_link_flag_is_sync_state_only()

 drivers/base/base.h       | 1 +
 drivers/base/core.c       | 2 +-
 drivers/base/power/main.c | 6 ++++--
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 123031a757d9..80415b140ce7 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -248,6 +248,7 @@ void device_links_driver_cleanup(struct device *dev);
 void device_links_no_driver(struct device *dev);
 bool device_links_busy(struct device *dev);
 void device_links_unbind_consumers(struct device *dev);
+bool device_link_flag_is_sync_state_only(u32 flags);
 void fw_devlink_drivers_done(void);
 void fw_devlink_probing_done(void);
 
diff --git a/drivers/base/core.c b/drivers/base/core.c
index d22d6b23e758..a54ec6df1058 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -287,7 +287,7 @@ static bool device_is_ancestor(struct device *dev, struct device *target)
 #define DL_MARKER_FLAGS		(DL_FLAG_INFERRED | \
 				 DL_FLAG_CYCLE | \
 				 DL_FLAG_MANAGED)
-static inline bool device_link_flag_is_sync_state_only(u32 flags)
+bool device_link_flag_is_sync_state_only(u32 flags)
 {
 	return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;
 }
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 2ea6e05e6ec9..73a1916170ae 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -282,7 +282,8 @@ static void dpm_wait_for_suppliers(struct device *dev, bool async)
 	 * walking.
 	 */
 	list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node)
-		if (READ_ONCE(link->status) != DL_STATE_DORMANT)
+		if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
+		    !device_link_flag_is_sync_state_only(link->flags))
 			dpm_wait(link->supplier, async);
 
 	device_links_read_unlock(idx);
@@ -339,7 +340,8 @@ static void dpm_wait_for_consumers(struct device *dev, bool async)
 	 * unregistration).
 	 */
 	list_for_each_entry_rcu_locked(link, &dev->links.consumers, s_node)
-		if (READ_ONCE(link->status) != DL_STATE_DORMANT)
+		if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
+		    !device_link_flag_is_sync_state_only(link->flags))
 			dpm_wait(link->consumer, async);
 
 	device_links_read_unlock(idx);
-- 
2.51.0.536.g15c5d4f767-goog
Re: [PATCH v4] PM: sleep: Don't wait for SYNC_STATE_ONLY device links
Posted by Rafael J. Wysocki 4 days, 9 hours ago
On Fri, Sep 26, 2025 at 12:23 PM Pin-yen Lin <treapking@chromium.org> wrote:
>
> Device links with DL_FLAG_SYNC_STATE_ONLY should not affect suspend
> and resume, and functions like device_reorder_to_tail() and
> device_link_add() doesn't try to reorder the consumers with such flag.
>
> However, dpm_wait_for_consumers() and dpm_wait_for_suppliers() doesn't
> check this flag before triggering dpm_wait, leading to potential hang
> during suspend/resume.
>
> This can be reproduced on MT8186 Corsola Chromebook with devicetree like:
>
> usb-a-connector {
>         compatible = "usb-a-connector";
>         port {
>                 usb_a_con: endpoint {
>                         remote-endpoint = <&usb_hs>;
>                 };
>         };
> };
>
> usb_host {
>         compatible = "mediatek,mt8186-xhci", "mediatek,mtk-xhci";
>         port {
>                 usb_hs: endpoint {
>                         remote-endpoint = <&usb_a_con>;
>                 };
>         };
> };
>
> In this case, the two nodes form a cycle and a SYNC_STATE_ONLY devlink
> between usb_host (supplier) and usb-a-connector (consumer) is created.
>
> Export device_link_flag_is_sync_state_only() and use it to check this in
> dpm_wait_for_consumers() and dpm_wait_for_suppliers() to fix this.
>
> Fixes: 05ef983e0d65a ("driver core: Add device link support for SYNC_STATE_ONLY flag")
> Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> ---
>
> Changes in v4:
> - Remove inline for device_link_flag_is_sync_state_only()
>
> Changes in v3:
> - Squash to one patch and fix the export approach
>
> Changes in v2:
> - Update commit message
> - Use device_link_flag_is_sync_state_only()
>
>  drivers/base/base.h       | 1 +
>  drivers/base/core.c       | 2 +-
>  drivers/base/power/main.c | 6 ++++--
>  3 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/base.h b/drivers/base/base.h
> index 123031a757d9..80415b140ce7 100644
> --- a/drivers/base/base.h
> +++ b/drivers/base/base.h
> @@ -248,6 +248,7 @@ void device_links_driver_cleanup(struct device *dev);
>  void device_links_no_driver(struct device *dev);
>  bool device_links_busy(struct device *dev);
>  void device_links_unbind_consumers(struct device *dev);
> +bool device_link_flag_is_sync_state_only(u32 flags);
>  void fw_devlink_drivers_done(void);
>  void fw_devlink_probing_done(void);
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index d22d6b23e758..a54ec6df1058 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -287,7 +287,7 @@ static bool device_is_ancestor(struct device *dev, struct device *target)
>  #define DL_MARKER_FLAGS                (DL_FLAG_INFERRED | \
>                                  DL_FLAG_CYCLE | \
>                                  DL_FLAG_MANAGED)
> -static inline bool device_link_flag_is_sync_state_only(u32 flags)
> +bool device_link_flag_is_sync_state_only(u32 flags)
>  {
>         return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;
>  }
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index 2ea6e05e6ec9..73a1916170ae 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -282,7 +282,8 @@ static void dpm_wait_for_suppliers(struct device *dev, bool async)
>          * walking.
>          */
>         list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node)
> -               if (READ_ONCE(link->status) != DL_STATE_DORMANT)
> +               if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
> +                   !device_link_flag_is_sync_state_only(link->flags))
>                         dpm_wait(link->supplier, async);
>
>         device_links_read_unlock(idx);
> @@ -339,7 +340,8 @@ static void dpm_wait_for_consumers(struct device *dev, bool async)
>          * unregistration).
>          */
>         list_for_each_entry_rcu_locked(link, &dev->links.consumers, s_node)
> -               if (READ_ONCE(link->status) != DL_STATE_DORMANT)
> +               if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
> +                   !device_link_flag_is_sync_state_only(link->flags))
>                         dpm_wait(link->consumer, async);
>
>         device_links_read_unlock(idx);
> --

Rebased on top of linux-pm.git/linux-next and applied as 6.18 material
with some minor edits in the subject and changelog.

Thanks!
Re: [PATCH v4] PM: sleep: Don't wait for SYNC_STATE_ONLY device links
Posted by Pin-yen Lin 22 hours ago
Hi Rafael,

On Sat, Sep 27, 2025 at 8:13 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Fri, Sep 26, 2025 at 12:23 PM Pin-yen Lin <treapking@chromium.org> wrote:
> >
> > Device links with DL_FLAG_SYNC_STATE_ONLY should not affect suspend
> > and resume, and functions like device_reorder_to_tail() and
> > device_link_add() doesn't try to reorder the consumers with such flag.
> >
> > However, dpm_wait_for_consumers() and dpm_wait_for_suppliers() doesn't
> > check this flag before triggering dpm_wait, leading to potential hang
> > during suspend/resume.
> >
> > This can be reproduced on MT8186 Corsola Chromebook with devicetree like:
> >
> > usb-a-connector {
> >         compatible = "usb-a-connector";
> >         port {
> >                 usb_a_con: endpoint {
> >                         remote-endpoint = <&usb_hs>;
> >                 };
> >         };
> > };
> >
> > usb_host {
> >         compatible = "mediatek,mt8186-xhci", "mediatek,mtk-xhci";
> >         port {
> >                 usb_hs: endpoint {
> >                         remote-endpoint = <&usb_a_con>;
> >                 };
> >         };
> > };
> >
> > In this case, the two nodes form a cycle and a SYNC_STATE_ONLY devlink
> > between usb_host (supplier) and usb-a-connector (consumer) is created.
> >
> > Export device_link_flag_is_sync_state_only() and use it to check this in
> > dpm_wait_for_consumers() and dpm_wait_for_suppliers() to fix this.
> >
> > Fixes: 05ef983e0d65a ("driver core: Add device link support for SYNC_STATE_ONLY flag")
> > Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> > ---
> >
> > Changes in v4:
> > - Remove inline for device_link_flag_is_sync_state_only()
> >
> > Changes in v3:
> > - Squash to one patch and fix the export approach
> >
> > Changes in v2:
> > - Update commit message
> > - Use device_link_flag_is_sync_state_only()
> >
> >  drivers/base/base.h       | 1 +
> >  drivers/base/core.c       | 2 +-
> >  drivers/base/power/main.c | 6 ++++--
> >  3 files changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/base/base.h b/drivers/base/base.h
> > index 123031a757d9..80415b140ce7 100644
> > --- a/drivers/base/base.h
> > +++ b/drivers/base/base.h
> > @@ -248,6 +248,7 @@ void device_links_driver_cleanup(struct device *dev);
> >  void device_links_no_driver(struct device *dev);
> >  bool device_links_busy(struct device *dev);
> >  void device_links_unbind_consumers(struct device *dev);
> > +bool device_link_flag_is_sync_state_only(u32 flags);
> >  void fw_devlink_drivers_done(void);
> >  void fw_devlink_probing_done(void);
> >
> > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > index d22d6b23e758..a54ec6df1058 100644
> > --- a/drivers/base/core.c
> > +++ b/drivers/base/core.c
> > @@ -287,7 +287,7 @@ static bool device_is_ancestor(struct device *dev, struct device *target)
> >  #define DL_MARKER_FLAGS                (DL_FLAG_INFERRED | \
> >                                  DL_FLAG_CYCLE | \
> >                                  DL_FLAG_MANAGED)
> > -static inline bool device_link_flag_is_sync_state_only(u32 flags)
> > +bool device_link_flag_is_sync_state_only(u32 flags)
> >  {
> >         return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;
> >  }
> > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> > index 2ea6e05e6ec9..73a1916170ae 100644
> > --- a/drivers/base/power/main.c
> > +++ b/drivers/base/power/main.c
> > @@ -282,7 +282,8 @@ static void dpm_wait_for_suppliers(struct device *dev, bool async)
> >          * walking.
> >          */
> >         list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node)
> > -               if (READ_ONCE(link->status) != DL_STATE_DORMANT)
> > +               if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
> > +                   !device_link_flag_is_sync_state_only(link->flags))
> >                         dpm_wait(link->supplier, async);
> >
> >         device_links_read_unlock(idx);
> > @@ -339,7 +340,8 @@ static void dpm_wait_for_consumers(struct device *dev, bool async)
> >          * unregistration).
> >          */
> >         list_for_each_entry_rcu_locked(link, &dev->links.consumers, s_node)
> > -               if (READ_ONCE(link->status) != DL_STATE_DORMANT)
> > +               if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
> > +                   !device_link_flag_is_sync_state_only(link->flags))
> >                         dpm_wait(link->consumer, async);
> >
> >         device_links_read_unlock(idx);
> > --
>
> Rebased on top of linux-pm.git/linux-next and applied as 6.18 material
> with some minor edits in the subject and changelog.
>
> Thanks!

Thanks for updating the commit message and applying the patch.

However, I can't find this patch at
https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/log/?h=linux-next

Did I check the wrong place for this?

Regards,
Pin-yen
Re: [PATCH v4] PM: sleep: Don't wait for SYNC_STATE_ONLY device links
Posted by Rafael J. Wysocki 11 hours ago
Hi,

On Wed, Oct 1, 2025 at 1:08 AM Pin-yen Lin <treapking@chromium.org> wrote:
>
> Hi Rafael,
>
> On Sat, Sep 27, 2025 at 8:13 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Fri, Sep 26, 2025 at 12:23 PM Pin-yen Lin <treapking@chromium.org> wrote:
> > >
> > > Device links with DL_FLAG_SYNC_STATE_ONLY should not affect suspend
> > > and resume, and functions like device_reorder_to_tail() and
> > > device_link_add() doesn't try to reorder the consumers with such flag.
> > >
> > > However, dpm_wait_for_consumers() and dpm_wait_for_suppliers() doesn't
> > > check this flag before triggering dpm_wait, leading to potential hang
> > > during suspend/resume.
> > >
> > > This can be reproduced on MT8186 Corsola Chromebook with devicetree like:
> > >
> > > usb-a-connector {
> > >         compatible = "usb-a-connector";
> > >         port {
> > >                 usb_a_con: endpoint {
> > >                         remote-endpoint = <&usb_hs>;
> > >                 };
> > >         };
> > > };
> > >
> > > usb_host {
> > >         compatible = "mediatek,mt8186-xhci", "mediatek,mtk-xhci";
> > >         port {
> > >                 usb_hs: endpoint {
> > >                         remote-endpoint = <&usb_a_con>;
> > >                 };
> > >         };
> > > };
> > >
> > > In this case, the two nodes form a cycle and a SYNC_STATE_ONLY devlink
> > > between usb_host (supplier) and usb-a-connector (consumer) is created.
> > >
> > > Export device_link_flag_is_sync_state_only() and use it to check this in
> > > dpm_wait_for_consumers() and dpm_wait_for_suppliers() to fix this.
> > >
> > > Fixes: 05ef983e0d65a ("driver core: Add device link support for SYNC_STATE_ONLY flag")
> > > Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> > > ---
> > >
> > > Changes in v4:
> > > - Remove inline for device_link_flag_is_sync_state_only()
> > >
> > > Changes in v3:
> > > - Squash to one patch and fix the export approach
> > >
> > > Changes in v2:
> > > - Update commit message
> > > - Use device_link_flag_is_sync_state_only()
> > >
> > >  drivers/base/base.h       | 1 +
> > >  drivers/base/core.c       | 2 +-
> > >  drivers/base/power/main.c | 6 ++++--
> > >  3 files changed, 6 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/base/base.h b/drivers/base/base.h
> > > index 123031a757d9..80415b140ce7 100644
> > > --- a/drivers/base/base.h
> > > +++ b/drivers/base/base.h
> > > @@ -248,6 +248,7 @@ void device_links_driver_cleanup(struct device *dev);
> > >  void device_links_no_driver(struct device *dev);
> > >  bool device_links_busy(struct device *dev);
> > >  void device_links_unbind_consumers(struct device *dev);
> > > +bool device_link_flag_is_sync_state_only(u32 flags);
> > >  void fw_devlink_drivers_done(void);
> > >  void fw_devlink_probing_done(void);
> > >
> > > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > > index d22d6b23e758..a54ec6df1058 100644
> > > --- a/drivers/base/core.c
> > > +++ b/drivers/base/core.c
> > > @@ -287,7 +287,7 @@ static bool device_is_ancestor(struct device *dev, struct device *target)
> > >  #define DL_MARKER_FLAGS                (DL_FLAG_INFERRED | \
> > >                                  DL_FLAG_CYCLE | \
> > >                                  DL_FLAG_MANAGED)
> > > -static inline bool device_link_flag_is_sync_state_only(u32 flags)
> > > +bool device_link_flag_is_sync_state_only(u32 flags)
> > >  {
> > >         return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;
> > >  }
> > > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> > > index 2ea6e05e6ec9..73a1916170ae 100644
> > > --- a/drivers/base/power/main.c
> > > +++ b/drivers/base/power/main.c
> > > @@ -282,7 +282,8 @@ static void dpm_wait_for_suppliers(struct device *dev, bool async)
> > >          * walking.
> > >          */
> > >         list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node)
> > > -               if (READ_ONCE(link->status) != DL_STATE_DORMANT)
> > > +               if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
> > > +                   !device_link_flag_is_sync_state_only(link->flags))
> > >                         dpm_wait(link->supplier, async);
> > >
> > >         device_links_read_unlock(idx);
> > > @@ -339,7 +340,8 @@ static void dpm_wait_for_consumers(struct device *dev, bool async)
> > >          * unregistration).
> > >          */
> > >         list_for_each_entry_rcu_locked(link, &dev->links.consumers, s_node)
> > > -               if (READ_ONCE(link->status) != DL_STATE_DORMANT)
> > > +               if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
> > > +                   !device_link_flag_is_sync_state_only(link->flags))
> > >                         dpm_wait(link->consumer, async);
> > >
> > >         device_links_read_unlock(idx);
> > > --
> >
> > Rebased on top of linux-pm.git/linux-next and applied as 6.18 material
> > with some minor edits in the subject and changelog.
> >
> > Thanks!
>
> Thanks for updating the commit message and applying the patch.
>
> However, I can't find this patch at
> https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/log/?h=linux-next
>
> Did I check the wrong place for this?

Yes, it was on the bleeding-edge branch for CI build testing coverage.

It has been added to the linux-next branch now.

Thanks!