Skip to contentSkip to conversation

PM: sleep: Don't wait for SYNC_STATE_ONLY device links

PATCH Superseded Pin-yen Lin 3 participants 4 messages Sep 12, 2025 – Sep 16, 2025

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 PM: sleep: Don't wait for SYNC_STATE_ONLY device links

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")

---

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(-)
drivers/base/base.h +1 -0
index 123031a757d9..80415b140ce7 100644
@@ -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);
 
drivers/base/core.c +1 -1
index d22d6b23e758..741aa0571fc7 100644
@@ -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)
+inline bool device_link_flag_is_sync_state_only(u32 flags)
 {
 	return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;
 }
drivers/base/power/main.c +4 -2
index 2ea6e05e6ec9..73a1916170ae 100644
@@ -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);
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
#1 lore raw
Quoted 68 lines · Pin-yen Lin

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")

---

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(-)
drivers/base/base.h +1 -0
index 123031a757d9..80415b140ce7 100644
@@ -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);
 
drivers/base/core.c +0 -0
index d22d6b23e758..741aa0571fc7 100644

drivers/base/core.c static bool device_is_ancestor(struct device *dev, struct device *target) · line 290

Quoted 5 lines
drivers/base/core.c +1 -1
@@ -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)
+inline bool device_link_flag_is_sync_state_only(u32 flags)

We generally don't use inline without static. Let the compiler decide what to do with it.

Quoted 28 lines
drivers/base/core.c +0 -0
 {
        return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;
 }
drivers/base/power/main.c +4 -3
index 2ea6e05e6ec9..73a1916170ae 100644
@@ -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 lore raw
In reply to Pin-yen Lin
Quoted 20 lines · Pin-yen Lin

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>;
                };
        };
};
Quoted 8 lines
usb_host {
        compatible = "mediatek,mt8186-xhci", "mediatek,mtk-xhci";
        port {
                usb_hs: endpoint {
                        remote-endpoint = <&usb_a_con>;
                };
        };
};

We've had SYNC_STATE_ONLY devlink for years in the kernel. Also, SYNC_STATE_ONLY device links get deleted once the consumer device probes. You also can't suspend a device before it probes.

Why are you hitting this issue only now? Something doesn't sound right. I'm asking this because I'm wondering if some other recent change broke any of my statements/design decisions above.

Not to fix this, but to also ensure better suspend/resume ordering in the future, you might want to add a "post-init-suppliers" to the real supplier node here and point it to the real consumer here. This will also help break the cycle here. Because even with this fix, all it does is avoid enforcing any ordering between these two devices. It is just working based on the order in DT, which you shouldn't count on for correctness.

Thanks,
Saravana

Quoted 75 lines

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")

---

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(-)
drivers/base/base.h +1 -0
index 123031a757d9..80415b140ce7 100644
@@ -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);
 
drivers/base/core.c +1 -1
index d22d6b23e758..741aa0571fc7 100644
@@ -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)
+inline bool device_link_flag_is_sync_state_only(u32 flags)
 {
        return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;
 }
drivers/base/power/main.c +4 -3
index 2ea6e05e6ec9..73a1916170ae 100644
@@ -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.384.g4c02a37b29-goog

#3 lore raw

Hi Saravana,

Thanks for the review.

Quoted 31 lines · Saravana Kannan
Quoted 20 lines · Pin-yen Lin

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>;
                };
        };
};
Quoted 8 lines
usb_host {
        compatible = "mediatek,mt8186-xhci", "mediatek,mtk-xhci";
        port {
                usb_hs: endpoint {
                        remote-endpoint = <&usb_a_con>;
                };
        };
};
Quoted 3 lines

We've had SYNC_STATE_ONLY devlink for years in the kernel. Also, SYNC_STATE_ONLY device links get deleted once the consumer device probes. You also can't suspend a device before it probes.

In this case, "usb-a-connector" is a descriptive-only node that has no driver binding into it, and this is why the SYNC_STATE_ONLY link never gets deleted.

Also, out of curiosity, does that mean a system might not suspend if I add a device node but doesn't include its driver in the kernel?

Quoted 4 lines

Why are you hitting this issue only now? Something doesn't sound right. I'm asking this because I'm wondering if some other recent change broke any of my statements/design decisions above.

For our team, we didn't describe the on-board USB topology until Stephen's series for the on-board USB hub support[1]. So, on previous platforms we worked on, we don't have a graph connection from the USB hosts and the USB connectors.

One explanation is that there aren't many use cases where you want to add a graph connection to a node without a driver binding into that. However, the code has been here for so many years, so I'm not sure if this explanation really makes sense either.

[1]: https://lore.kernel.org/all/[email protected]/

Quoted 8 lines

Not to fix this, but to also ensure better suspend/resume ordering in the future, you might want to add a "post-init-suppliers" to the real supplier node here and point it to the real consumer here. This will also help break the cycle here. Because even with this fix, all it does is avoid enforcing any ordering between these two devices. It is just working based on the order in DT, which you shouldn't count on for correctness.

In this case, there is no driver for "usb-a-connector", so we don't need any dependency between them.

Quoted 3 lines

Thanks,
Saravana

Regards,
Pin-yen

Quoted 76 lines
Quoted 76 lines

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")

---

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(-)
drivers/base/base.h +1 -0
index 123031a757d9..80415b140ce7 100644
@@ -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);
 
drivers/base/core.c +1 -1
index d22d6b23e758..741aa0571fc7 100644
@@ -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)
+inline bool device_link_flag_is_sync_state_only(u32 flags)
 {
        return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;
 }
drivers/base/power/main.c +4 -3
index 2ea6e05e6ec9..73a1916170ae 100644
@@ -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.384.g4c02a37b29-goog