Skip to contentSkip to conversation

PM: sleep: core: Clear device async state upfront during suspend

PATCH In review Rafael J. Wysocki 3 participants 7 messages Feb 3 – Feb 5

Subsystems (4)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 PM: sleep: core: Clear device async state upfront during suspend

From: Rafael J. Wysocki <[email protected]>

In all of the system suspend transition phases, async state of all devices needs to be cleared before starting async processing for any of them because the latter may race with power.work_in_progress updates for the device's parent or suppliers and if it touches bit fields from the same group (for example, power.must_resume or power.wakeup_path), bit field corruption is possible.

Rearrange the code accordingly.

Fixes aa7a9275ab81 ("PM: sleep: Suspend async parents after suspending children")
Fixes 443046d1ad66 ("PM: sleep: Make suspend of devices more asynchronous")
Cc All applicable <[email protected]>
---
 drivers/base/power/main.c |   33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
drivers/base/power/main.c +30 -3
@@ -1527,11 +1527,20 @@ static int dpm_noirq_suspend_devices(pm_
 	mutex_lock(&dpm_list_mtx);
 
 	/*
+	 * Clear the async state for all devices upfront to prevent the
+	 * power.work_in_progress updates from racing with power.must_resume
+	 * updates carried out by dpm_superior_set_must_resume(), since these
+	 * flags belong to the same group of bit fields and they should not be
+	 * updated at the same time without synchronization.
+	 */
+	list_for_each_entry_reverse(dev, &dpm_late_early_list, power.entry)
+		dpm_clear_async_state(dev);
+
+	/*
 	 * Start processing "async" leaf devices upfront so they don't need to
 	 * wait for the "sync" devices they don't depend on.
 	 */
 	list_for_each_entry_reverse(dev, &dpm_late_early_list, power.entry) {
-		dpm_clear_async_state(dev);
 		if (dpm_leaf_device(dev))
 			dpm_async_with_cleanup(dev, async_suspend_noirq);
 	}
@@ -1732,11 +1741,20 @@ int dpm_suspend_late(pm_message_t state)
 	mutex_lock(&dpm_list_mtx);
 
 	/*
+	 * Clear the async state for all devices upfront to prevent the
+	 * power.work_in_progress updates from racing with power.wakeup_path
+	 * updates carried out by dpm_propagate_wakeup_to_parent(), since these
+	 * flags belong to the same group of bit fields and they should not be
+	 * updated at the same time without synchronization.
+	 */
+	list_for_each_entry_reverse(dev, &dpm_suspended_list, power.entry)
+		dpm_clear_async_state(dev);
+
+	/*
 	 * Start processing "async" leaf devices upfront so they don't need to
 	 * wait for the "sync" devices they don't depend on.
 	 */
 	list_for_each_entry_reverse(dev, &dpm_suspended_list, power.entry) {
-		dpm_clear_async_state(dev);
 		if (dpm_leaf_device(dev))
 			dpm_async_with_cleanup(dev, async_suspend_late);
 	}
@@ -2023,11 +2041,20 @@ int dpm_suspend(pm_message_t state)
 	mutex_lock(&dpm_list_mtx);
 
 	/*
+	 * Clear the async state for all devices upfront to prevent the
+	 * power.work_in_progress updates from racing with power.wakeup_path
+	 * updates carried out by dpm_propagate_wakeup_to_parent(), since these
+	 * flags belong to the same group of bit fields and they should not be
+	 * updated at the same time without synchronization.
+	 */
+	list_for_each_entry_reverse(dev, &dpm_prepared_list, power.entry)
+		dpm_clear_async_state(dev);
+
+	/*
 	 * Start processing "async" leaf devices upfront so they don't need to
 	 * wait for the "sync" devices they don't depend on.
 	 */
 	list_for_each_entry_reverse(dev, &dpm_prepared_list, power.entry) {
-		dpm_clear_async_state(dev);
 		if (dpm_leaf_device(dev))
 			dpm_async_with_cleanup(dev, async_suspend);
 	}
#1 lore raw

Hi Rafael,

Quoted 11 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In all of the system suspend transition phases, async state of all devices needs to be cleared before starting async processing for any of them because the latter may race with power.work_in_progress updates for the device's parent or suppliers and if it touches bit fields from the same group (for example, power.must_resume or power.wakeup_path), bit field corruption is possible.

Rearrange the code accordingly.

Could we use the following patch:

include/linux/pm.h +1 -0
index 98a899858ece..afcaaa37a812 100644
@@ -681,10 +681,10 @@ struct dev_pm_info {
        struct list_head        entry;
        struct completion       completion;
        struct wakeup_source    *wakeup;
+       bool                    work_in_progress;       /* Owned by

the PM core */

        bool                    wakeup_path:1;
        bool                    syscore:1;
        bool                    no_pm_callbacks:1;      /* Owned by

the PM core */
- bool work_in_progress:1; /* Owned by
the PM core */
bool smart_suspend:1; /* Owned by
the PM core */
bool must_resume:1; /* Owned by
the PM core */
bool may_skip_resume:1; /* Set by subsystems */

Due to byte alignment, the size of struct dev_pm_info remains unchanged, while also preventing concurrency issues between work_in_progress and other variables.
Additionally, with this modification, there’s no need to traverse the device list twice.

BR
---
xuewen

Quoted 83 lines
Fixes aa7a9275ab81 ("PM: sleep: Suspend async parents after suspending children")
Fixes 443046d1ad66 ("PM: sleep: Make suspend of devices more asynchronous")
Cc All applicable <[email protected]>
---
 drivers/base/power/main.c |   33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
drivers/base/power/main.c +30 -3
@@ -1527,11 +1527,20 @@ static int dpm_noirq_suspend_devices(pm_
        mutex_lock(&dpm_list_mtx);
 
        /*
+        * Clear the async state for all devices upfront to prevent the
+        * power.work_in_progress updates from racing with power.must_resume
+        * updates carried out by dpm_superior_set_must_resume(), since these
+        * flags belong to the same group of bit fields and they should not be
+        * updated at the same time without synchronization.
+        */
+       list_for_each_entry_reverse(dev, &dpm_late_early_list, power.entry)
+               dpm_clear_async_state(dev);
+
+       /*
         * Start processing "async" leaf devices upfront so they don't need to
         * wait for the "sync" devices they don't depend on.
         */
        list_for_each_entry_reverse(dev, &dpm_late_early_list, power.entry) {
-               dpm_clear_async_state(dev);
                if (dpm_leaf_device(dev))
                        dpm_async_with_cleanup(dev, async_suspend_noirq);
        }
@@ -1732,11 +1741,20 @@ int dpm_suspend_late(pm_message_t state)
        mutex_lock(&dpm_list_mtx);
 
        /*
+        * Clear the async state for all devices upfront to prevent the
+        * power.work_in_progress updates from racing with power.wakeup_path
+        * updates carried out by dpm_propagate_wakeup_to_parent(), since these
+        * flags belong to the same group of bit fields and they should not be
+        * updated at the same time without synchronization.
+        */
+       list_for_each_entry_reverse(dev, &dpm_suspended_list, power.entry)
+               dpm_clear_async_state(dev);
+
+       /*
         * Start processing "async" leaf devices upfront so they don't need to
         * wait for the "sync" devices they don't depend on.
         */
        list_for_each_entry_reverse(dev, &dpm_suspended_list, power.entry) {
-               dpm_clear_async_state(dev);
                if (dpm_leaf_device(dev))
                        dpm_async_with_cleanup(dev, async_suspend_late);
        }
@@ -2023,11 +2041,20 @@ int dpm_suspend(pm_message_t state)
        mutex_lock(&dpm_list_mtx);
 
        /*
+        * Clear the async state for all devices upfront to prevent the
+        * power.work_in_progress updates from racing with power.wakeup_path
+        * updates carried out by dpm_propagate_wakeup_to_parent(), since these
+        * flags belong to the same group of bit fields and they should not be
+        * updated at the same time without synchronization.
+        */
+       list_for_each_entry_reverse(dev, &dpm_prepared_list, power.entry)
+               dpm_clear_async_state(dev);
+
+       /*
         * Start processing "async" leaf devices upfront so they don't need to
         * wait for the "sync" devices they don't depend on.
         */
        list_for_each_entry_reverse(dev, &dpm_prepared_list, power.entry) {
-               dpm_clear_async_state(dev);
                if (dpm_leaf_device(dev))
                        dpm_async_with_cleanup(dev, async_suspend);
        }
author maintainer
#2 lore raw
Quoted 14 lines · Xuewen Yan

Hi Rafael,

Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In all of the system suspend transition phases, async state of all devices needs to be cleared before starting async processing for any of them because the latter may race with power.work_in_progress updates for the device's parent or suppliers and if it touches bit fields from the same group (for example, power.must_resume or power.wakeup_path), bit field corruption is possible.

Quoted 3 lines
Quoted 1 line

Rearrange the code accordingly.

Could we use the following patch:

Yes, we can make this change.

Quoted 22 lines
include/linux/pm.h +1 -0
index 98a899858ece..afcaaa37a812 100644
@@ -681,10 +681,10 @@ struct dev_pm_info {
        struct list_head        entry;
        struct completion       completion;
        struct wakeup_source    *wakeup;
+       bool                    work_in_progress;       /* Owned by

the PM core */

        bool                    wakeup_path:1;
        bool                    syscore:1;
        bool                    no_pm_callbacks:1;      /* Owned by

the PM core */
- bool work_in_progress:1; /* Owned by
the PM core */
bool smart_suspend:1; /* Owned by
the PM core */
bool must_resume:1; /* Owned by
the PM core */
bool may_skip_resume:1; /* Set by subsystems */

Quoted 1 line

Due to byte alignment, the size of struct dev_pm_info remains unchanged,

I had considered making it, but I thought it would cause struct dev_pm_info to grow.

Quoted 3 lines

while also preventing concurrency issues between work_in_progress and other variables. Additionally, with this modification, there’s no need to traverse the device list twice.

Sure.

I'll just commit the above change with your sign-off, please let me know if there are any issues with that.

Thanks!

#3 lore raw
Quoted 49 lines · Rafael J. Wysocki
Quoted 14 lines · Xuewen Yan

Hi Rafael,

Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In all of the system suspend transition phases, async state of all devices needs to be cleared before starting async processing for any of them because the latter may race with power.work_in_progress updates for the device's parent or suppliers and if it touches bit fields from the same group (for example, power.must_resume or power.wakeup_path), bit field corruption is possible.

Quoted 3 lines
Quoted 1 line

Rearrange the code accordingly.

Could we use the following patch:

Yes, we can make this change.

Quoted 22 lines
include/linux/pm.h +1 -0
index 98a899858ece..afcaaa37a812 100644
@@ -681,10 +681,10 @@ struct dev_pm_info {
        struct list_head        entry;
        struct completion       completion;
        struct wakeup_source    *wakeup;
+       bool                    work_in_progress;       /* Owned by

the PM core */

        bool                    wakeup_path:1;
        bool                    syscore:1;
        bool                    no_pm_callbacks:1;      /* Owned by

the PM core */
- bool work_in_progress:1; /* Owned by
the PM core */
bool smart_suspend:1; /* Owned by
the PM core */
bool must_resume:1; /* Owned by
the PM core */
bool may_skip_resume:1; /* Set by subsystems */

Quoted 1 line

Due to byte alignment, the size of struct dev_pm_info remains unchanged,

I had considered making it, but I thought it would cause struct dev_pm_info to grow.

Quoted 8 lines
Quoted 3 lines

while also preventing concurrency issues between work_in_progress and other variables. Additionally, with this modification, there’s no need to traverse the device list twice.

Sure.

I'll just commit the above change with your sign-off, please let me know if there are any issues with that.

I have no other questions.

Thanks!

BR
--
xuewen

Reviewed-by on v1 1/1
#4 lore raw
In reply to Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In all of the system suspend transition phases, async state of all devices needs to be cleared before starting async processing for any of them because the latter may race with power.work_in_progress updates for the device's parent or suppliers and if it touches bit fields from the same group (for example, power.must_resume or power.wakeup_path), bit field corruption is possible.

Quoted 8 lines

Rearrange the code accordingly.

Fixes aa7a9275ab81 ("PM: sleep: Suspend async parents after suspending children")
Fixes 443046d1ad66 ("PM: sleep: Make suspend of devices more asynchronous")
Cc All applicable <[email protected]>

Looks good to me!

Kind regards
Uffe

Quoted 75 lines
---
 drivers/base/power/main.c |   33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
drivers/base/power/main.c +30 -3
@@ -1527,11 +1527,20 @@ static int dpm_noirq_suspend_devices(pm_
        mutex_lock(&dpm_list_mtx);
 
        /*
+        * Clear the async state for all devices upfront to prevent the
+        * power.work_in_progress updates from racing with power.must_resume
+        * updates carried out by dpm_superior_set_must_resume(), since these
+        * flags belong to the same group of bit fields and they should not be
+        * updated at the same time without synchronization.
+        */
+       list_for_each_entry_reverse(dev, &dpm_late_early_list, power.entry)
+               dpm_clear_async_state(dev);
+
+       /*
         * Start processing "async" leaf devices upfront so they don't need to
         * wait for the "sync" devices they don't depend on.
         */
        list_for_each_entry_reverse(dev, &dpm_late_early_list, power.entry) {
-               dpm_clear_async_state(dev);
                if (dpm_leaf_device(dev))
                        dpm_async_with_cleanup(dev, async_suspend_noirq);
        }
@@ -1732,11 +1741,20 @@ int dpm_suspend_late(pm_message_t state)
        mutex_lock(&dpm_list_mtx);
 
        /*
+        * Clear the async state for all devices upfront to prevent the
+        * power.work_in_progress updates from racing with power.wakeup_path
+        * updates carried out by dpm_propagate_wakeup_to_parent(), since these
+        * flags belong to the same group of bit fields and they should not be
+        * updated at the same time without synchronization.
+        */
+       list_for_each_entry_reverse(dev, &dpm_suspended_list, power.entry)
+               dpm_clear_async_state(dev);
+
+       /*
         * Start processing "async" leaf devices upfront so they don't need to
         * wait for the "sync" devices they don't depend on.
         */
        list_for_each_entry_reverse(dev, &dpm_suspended_list, power.entry) {
-               dpm_clear_async_state(dev);
                if (dpm_leaf_device(dev))
                        dpm_async_with_cleanup(dev, async_suspend_late);
        }
@@ -2023,11 +2041,20 @@ int dpm_suspend(pm_message_t state)
        mutex_lock(&dpm_list_mtx);
 
        /*
+        * Clear the async state for all devices upfront to prevent the
+        * power.work_in_progress updates from racing with power.wakeup_path
+        * updates carried out by dpm_propagate_wakeup_to_parent(), since these
+        * flags belong to the same group of bit fields and they should not be
+        * updated at the same time without synchronization.
+        */
+       list_for_each_entry_reverse(dev, &dpm_prepared_list, power.entry)
+               dpm_clear_async_state(dev);
+
+       /*
         * Start processing "async" leaf devices upfront so they don't need to
         * wait for the "sync" devices they don't depend on.
         */
        list_for_each_entry_reverse(dev, &dpm_prepared_list, power.entry) {
-               dpm_clear_async_state(dev);
                if (dpm_leaf_device(dev))
                        dpm_async_with_cleanup(dev, async_suspend);
        }
author maintainer
#5 lore raw
Quoted 20 lines · CET Ulf Hansson
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In all of the system suspend transition phases, async state of all devices needs to be cleared before starting async processing for any of them because the latter may race with power.work_in_progress updates for the device's parent or suppliers and if it touches bit fields from the same group (for example, power.must_resume or power.wakeup_path), bit field corruption is possible.

Quoted 8 lines

Rearrange the code accordingly.

Fixes aa7a9275ab81 ("PM: sleep: Suspend async parents after suspending children")
Fixes 443046d1ad66 ("PM: sleep: Make suspend of devices more asynchronous")
Cc All applicable <[email protected]>
Quoted 3 lines

Looks good to me!

Thanks!

In the meantime though I have decided to commit the patch below instead because it is simpler and basically no overhead.

Please let me know if you have any concerns regarding it.

---
From 0491f3f9f664e7e0131eb4d2a8b19c49562e5c64 Mon Sep 17 00:00:00 2001
From: Xuewen Yan <[email protected]>
Date: Wed, 4 Feb 2026 13:25:09 +0100
Subject: [PATCH] PM: sleep: core: Avoid bit field races related to work_in_progress

In all of the system suspend transition phases, the async processing of a device may be carried out in parallel with power.work_in_progress updates for the device's parent or suppliers and if it touches bit fields from the same group (for example, power.must_resume or power.wakeup_path), bit field corruption is possible.

To avoid that, turn work_in_progress in struct dev_pm_info into a proper bool field and relocate it to save space.

Fixes aa7a9275ab81 ("PM: sleep: Suspend async parents after suspending children")
Fixes 443046d1ad66 ("PM: sleep: Make suspend of devices more asynchronous")
Cc All applicable <[email protected]>
[ rjw: Added subject and changelog ]
---
 include/linux/pm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pm.h +1 -1
index 98a899858ece..afcaaa37a812 100644
@@ -681,10 +681,10 @@ struct dev_pm_info {
 	struct list_head	entry;
 	struct completion	completion;
 	struct wakeup_source	*wakeup;
+	bool			work_in_progress;	/* Owned by the PM core */
 	bool			wakeup_path:1;
 	bool			syscore:1;
 	bool			no_pm_callbacks:1;	/* Owned by the PM core */
-	bool			work_in_progress:1;	/* Owned by the PM core */
 	bool			smart_suspend:1;	/* Owned by the PM core */
 	bool			must_resume:1;		/* Owned by the PM core */
 	bool			may_skip_resume:1;	/* Set by subsystems */
Signature · 1 line
2.51.0
#6 lore raw
Quoted 39 lines · Rafael J. Wysocki
Quoted 20 lines · CET Ulf Hansson
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In all of the system suspend transition phases, async state of all devices needs to be cleared before starting async processing for any of them because the latter may race with power.work_in_progress updates for the device's parent or suppliers and if it touches bit fields from the same group (for example, power.must_resume or power.wakeup_path), bit field corruption is possible.

Quoted 8 lines

Rearrange the code accordingly.

Fixes aa7a9275ab81 ("PM: sleep: Suspend async parents after suspending children")
Fixes 443046d1ad66 ("PM: sleep: Make suspend of devices more asynchronous")
Cc All applicable <[email protected]>
Quoted 3 lines

Looks good to me!

Thanks!

In the meantime though I have decided to commit the patch below instead because it is simpler and basically no overhead.

Please let me know if you have any concerns regarding it.

---
From 0491f3f9f664e7e0131eb4d2a8b19c49562e5c64 Mon Sep 17 00:00:00 2001
From: Xuewen Yan <[email protected]>
Date: Wed, 4 Feb 2026 13:25:09 +0100
Subject: [PATCH] PM: sleep: core: Avoid bit field races related to work_in_progress

Quoted 8 lines

In all of the system suspend transition phases, the async processing of a device may be carried out in parallel with power.work_in_progress updates for the device's parent or suppliers and if it touches bit fields from the same group (for example, power.must_resume or power.wakeup_path), bit field corruption is possible.

To avoid that, turn work_in_progress in struct dev_pm_info into a proper bool field and relocate it to save space.

I compiled using the config file attached on the ARM64 platform, and the size of dev_pm_info remains 320 both before and after applying this patch.

Thanks!

Quoted 36 lines
Fixes aa7a9275ab81 ("PM: sleep: Suspend async parents after suspending children")
Fixes 443046d1ad66 ("PM: sleep: Make suspend of devices more asynchronous")
Cc All applicable <[email protected]>
[ rjw: Added subject and changelog ]
---
 include/linux/pm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pm.h +1 -2
index 98a899858ece..afcaaa37a812 100644
@@ -681,10 +681,10 @@ struct dev_pm_info {
        struct list_head        entry;
        struct completion       completion;
        struct wakeup_source    *wakeup;
+       bool                    work_in_progress;       /* Owned by the PM core */
        bool                    wakeup_path:1;
        bool                    syscore:1;
        bool                    no_pm_callbacks:1;      /* Owned by the PM core */
-       bool                    work_in_progress:1;     /* Owned by the PM core */
        bool                    smart_suspend:1;        /* Owned by the PM core */
        bool                    must_resume:1;          /* Owned by the PM core */
        bool                    may_skip_resume:1;      /* Set by subsystems */
--

2.51.0