mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code
@ 2025-12-02 19:30 Brian Norris
  2025-12-02 19:30 ` [PATCH 2/3] PM: runtime: Make pm_runtime_barrier() return void Brian Norris
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Brian Norris @ 2025-12-02 19:30 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Guenter Roeck, Len Brown, Pavel Machek, Nicolas Palix, linux-pm,
	Julia Lawall, linux-kernel, cocci, Brian Norris

Apparently this test is the only code that checks the return code from
pm_runtime_barrier(), and it turns out that's for good reason -- it's
inherently racy, and a bad idea. We're going to make
pm_runtime_barrier() return void, so prepare for that by dropping any
return code checks.

This resolves some test failures seen like the following:

[   34.559694]     # pm_runtime_error_test: EXPECTATION FAILED at drivers/base/power/runtime-test.c:177
[   34.559694]     Expected 1 == pm_runtime_barrier(dev), but
[   34.559694]         pm_runtime_barrier(dev) == 0 (0x0)
[   34.563604]     # pm_runtime_error_test: pass:0 fail:1 skip:0 total:1

Reported-by: Guenter Roeck <linux@roeck-us.net>
Closes: https://lore.kernel.org/lkml/93259f2b-7017-4096-a31b-cabbf6152e9b@roeck-us.net/
Signed-off-by: Brian Norris <briannorris@chromium.org>
---

 drivers/base/power/runtime-test.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/base/power/runtime-test.c b/drivers/base/power/runtime-test.c
index 477feca804c7..1535ad2b0264 100644
--- a/drivers/base/power/runtime-test.c
+++ b/drivers/base/power/runtime-test.c
@@ -37,10 +37,6 @@ static void pm_runtime_already_suspended_test(struct kunit *test)
 	pm_runtime_enable(dev);
 	KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
 
-	pm_runtime_get_noresume(dev);
-	KUNIT_EXPECT_EQ(test, 0, pm_runtime_barrier(dev)); /* no wakeup needed */
-	pm_runtime_put(dev);
-
 	pm_runtime_get_noresume(dev);
 	KUNIT_EXPECT_EQ(test, 1, pm_runtime_put_sync(dev));
 
@@ -174,7 +170,7 @@ static void pm_runtime_error_test(struct kunit *test)
 	KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
 
 	KUNIT_EXPECT_EQ(test, 0, pm_runtime_get(dev));
-	KUNIT_EXPECT_EQ(test, 1, pm_runtime_barrier(dev)); /* resume was pending */
+	pm_runtime_barrier(dev);
 	pm_runtime_put(dev);
 	pm_runtime_suspend(dev); /* flush the put(), to suspend */
 	KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
@@ -225,7 +221,7 @@ static void pm_runtime_probe_active_test(struct kunit *test)
 	KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
 
 	/* Nothing to flush. We stay active. */
-	KUNIT_EXPECT_EQ(test, 0, pm_runtime_barrier(dev));
+	pm_runtime_barrier(dev);
 	KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
 
 	/* Ask for idle? Now we suspend. */
-- 
2.52.0.158.g65b55ccf14-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] PM: runtime: Make pm_runtime_barrier() return void
  2025-12-02 19:30 [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code Brian Norris
@ 2025-12-02 19:30 ` Brian Norris
  2025-12-03  3:34   ` Guenter Roeck
  2025-12-02 19:30 ` [PATCH 3/3] coccinelle: Drop pm_runtime_barrier() error code checks Brian Norris
  2025-12-03  3:34 ` [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code Guenter Roeck
  2 siblings, 1 reply; 7+ messages in thread
From: Brian Norris @ 2025-12-02 19:30 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Guenter Roeck, Len Brown, Pavel Machek, Nicolas Palix, linux-pm,
	Julia Lawall, linux-kernel, cocci, Brian Norris

No callers check the return code, and that's a good thing. Doing so
would be racy and unhelpful.

Drop the return code entirely, so we don't make anyone think about its
complexities.

Signed-off-by: Brian Norris <briannorris@chromium.org>
---

 Documentation/power/runtime_pm.rst |  6 ++----
 drivers/base/power/runtime.c       | 14 ++------------
 include/linux/pm_runtime.h         |  4 ++--
 3 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
index 8246df3cecd7..455b9d135d85 100644
--- a/Documentation/power/runtime_pm.rst
+++ b/Documentation/power/runtime_pm.rst
@@ -443,13 +443,11 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
       necessary to execute the subsystem-level resume callback for the device
       to satisfy that request, otherwise 0 is returned
 
-  `int pm_runtime_barrier(struct device *dev);`
+  `void pm_runtime_barrier(struct device *dev);`
     - check if there's a resume request pending for the device and resume it
       (synchronously) in that case, cancel any other pending runtime PM requests
       regarding it and wait for all runtime PM operations on it in progress to
-      complete; returns 1 if there was a resume request pending and it was
-      necessary to execute the subsystem-level resume callback for the device to
-      satisfy that request, otherwise 0 is returned
+      complete
 
   `void pm_suspend_ignore_children(struct device *dev, bool enable);`
     - set/unset the power.ignore_children flag of the device
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 62707738caa4..84676cc24221 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1467,30 +1467,20 @@ static void __pm_runtime_barrier(struct device *dev)
  * Next, make sure that all pending requests for the device have been flushed
  * from pm_wq and wait for all runtime PM operations involving the device in
  * progress to complete.
- *
- * Return value:
- * 1, if there was a resume request pending and the device had to be woken up,
- * 0, otherwise
  */
-int pm_runtime_barrier(struct device *dev)
+void pm_runtime_barrier(struct device *dev)
 {
-	int retval = 0;
-
 	pm_runtime_get_noresume(dev);
 	spin_lock_irq(&dev->power.lock);
 
 	if (dev->power.request_pending
-	    && dev->power.request == RPM_REQ_RESUME) {
+	    && dev->power.request == RPM_REQ_RESUME)
 		rpm_resume(dev, 0);
-		retval = 1;
-	}
 
 	__pm_runtime_barrier(dev);
 
 	spin_unlock_irq(&dev->power.lock);
 	pm_runtime_put_noidle(dev);
-
-	return retval;
 }
 EXPORT_SYMBOL_GPL(pm_runtime_barrier);
 
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 911d7a4d32c1..41037c513f06 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -76,7 +76,7 @@ extern int pm_runtime_get_if_active(struct device *dev);
 extern int pm_runtime_get_if_in_use(struct device *dev);
 extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
 extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
-extern int pm_runtime_barrier(struct device *dev);
+extern void pm_runtime_barrier(struct device *dev);
 extern bool pm_runtime_block_if_disabled(struct device *dev);
 extern void pm_runtime_unblock(struct device *dev);
 extern void pm_runtime_enable(struct device *dev);
@@ -284,7 +284,7 @@ static inline int pm_runtime_get_if_active(struct device *dev)
 }
 static inline int __pm_runtime_set_status(struct device *dev,
 					    unsigned int status) { return 0; }
-static inline int pm_runtime_barrier(struct device *dev) { return 0; }
+static inline void pm_runtime_barrier(struct device *dev) {}
 static inline bool pm_runtime_block_if_disabled(struct device *dev) { return true; }
 static inline void pm_runtime_unblock(struct device *dev) {}
 static inline void pm_runtime_enable(struct device *dev) {}
-- 
2.52.0.158.g65b55ccf14-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] coccinelle: Drop pm_runtime_barrier() error code checks
  2025-12-02 19:30 [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code Brian Norris
  2025-12-02 19:30 ` [PATCH 2/3] PM: runtime: Make pm_runtime_barrier() return void Brian Norris
@ 2025-12-02 19:30 ` Brian Norris
  2025-12-03  3:34   ` Guenter Roeck
  2025-12-03  3:34 ` [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code Guenter Roeck
  2 siblings, 1 reply; 7+ messages in thread
From: Brian Norris @ 2025-12-02 19:30 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Guenter Roeck, Len Brown, Pavel Machek, Nicolas Palix, linux-pm,
	Julia Lawall, linux-kernel, cocci, Brian Norris

This function doesn't return anything any more, so the compiler would
notice any bad error handling before any cocci script would.

Signed-off-by: Brian Norris <briannorris@chromium.org>
---

 scripts/coccinelle/api/pm_runtime.cocci | 1 -
 1 file changed, 1 deletion(-)

diff --git a/scripts/coccinelle/api/pm_runtime.cocci b/scripts/coccinelle/api/pm_runtime.cocci
index 2c931e748dda..bf128ccae921 100644
--- a/scripts/coccinelle/api/pm_runtime.cocci
+++ b/scripts/coccinelle/api/pm_runtime.cocci
@@ -37,7 +37,6 @@ ret@p = \(pm_runtime_idle\|
 	pm_runtime_put_sync_autosuspend\|
 	pm_runtime_set_active\|
 	pm_schedule_suspend\|
-	pm_runtime_barrier\|
 	pm_generic_runtime_suspend\|
 	pm_generic_runtime_resume\)(...);
 ...
-- 
2.52.0.158.g65b55ccf14-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code
  2025-12-02 19:30 [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code Brian Norris
  2025-12-02 19:30 ` [PATCH 2/3] PM: runtime: Make pm_runtime_barrier() return void Brian Norris
  2025-12-02 19:30 ` [PATCH 3/3] coccinelle: Drop pm_runtime_barrier() error code checks Brian Norris
@ 2025-12-03  3:34 ` Guenter Roeck
  2025-12-04 19:41   ` Rafael J. Wysocki
  2 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2025-12-03  3:34 UTC (permalink / raw)
  To: Brian Norris
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Nicolas Palix,
	linux-pm, Julia Lawall, linux-kernel, cocci

On Tue, Dec 02, 2025 at 11:30:24AM -0800, Brian Norris wrote:
> Apparently this test is the only code that checks the return code from
> pm_runtime_barrier(), and it turns out that's for good reason -- it's
> inherently racy, and a bad idea. We're going to make
> pm_runtime_barrier() return void, so prepare for that by dropping any
> return code checks.
> 
> This resolves some test failures seen like the following:
> 
> [   34.559694]     # pm_runtime_error_test: EXPECTATION FAILED at drivers/base/power/runtime-test.c:177
> [   34.559694]     Expected 1 == pm_runtime_barrier(dev), but
> [   34.559694]         pm_runtime_barrier(dev) == 0 (0x0)
> [   34.563604]     # pm_runtime_error_test: pass:0 fail:1 skip:0 total:1
> 
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Closes: https://lore.kernel.org/lkml/93259f2b-7017-4096-a31b-cabbf6152e9b@roeck-us.net/
> Signed-off-by: Brian Norris <briannorris@chromium.org>

With this series on top of v6.18:

Qemu test results:
	total: 610 pass: 610 fail: 0
Unit test results:
	pass: 666898 fail: 0

Tested-by: Guenter Roeck <linux@roeck-us.net>

Guenter

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] PM: runtime: Make pm_runtime_barrier() return void
  2025-12-02 19:30 ` [PATCH 2/3] PM: runtime: Make pm_runtime_barrier() return void Brian Norris
@ 2025-12-03  3:34   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2025-12-03  3:34 UTC (permalink / raw)
  To: Brian Norris
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Nicolas Palix,
	linux-pm, Julia Lawall, linux-kernel, cocci

On Tue, Dec 02, 2025 at 11:30:25AM -0800, Brian Norris wrote:
> No callers check the return code, and that's a good thing. Doing so
> would be racy and unhelpful.
> 
> Drop the return code entirely, so we don't make anyone think about its
> complexities.
> 
> Signed-off-by: Brian Norris <briannorris@chromium.org>

Tested-by: Guenter Roeck <linux@roeck-us.net>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] coccinelle: Drop pm_runtime_barrier() error code checks
  2025-12-02 19:30 ` [PATCH 3/3] coccinelle: Drop pm_runtime_barrier() error code checks Brian Norris
@ 2025-12-03  3:34   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2025-12-03  3:34 UTC (permalink / raw)
  To: Brian Norris
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Nicolas Palix,
	linux-pm, Julia Lawall, linux-kernel, cocci

On Tue, Dec 02, 2025 at 11:30:26AM -0800, Brian Norris wrote:
> This function doesn't return anything any more, so the compiler would
> notice any bad error handling before any cocci script would.
> 
> Signed-off-by: Brian Norris <briannorris@chromium.org>

Tested-by: Guenter Roeck <linux@roeck-us.net>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code
  2025-12-03  3:34 ` [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code Guenter Roeck
@ 2025-12-04 19:41   ` Rafael J. Wysocki
  0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2025-12-04 19:41 UTC (permalink / raw)
  To: Guenter Roeck, Brian Norris
  Cc: Len Brown, Pavel Machek, Nicolas Palix, linux-pm, Julia Lawall,
	linux-kernel, cocci

On Wed, Dec 3, 2025 at 4:34 AM Guenter Roeck <linux@roeck-us.net> wrote:
>
> On Tue, Dec 02, 2025 at 11:30:24AM -0800, Brian Norris wrote:
> > Apparently this test is the only code that checks the return code from
> > pm_runtime_barrier(), and it turns out that's for good reason -- it's
> > inherently racy, and a bad idea. We're going to make
> > pm_runtime_barrier() return void, so prepare for that by dropping any
> > return code checks.
> >
> > This resolves some test failures seen like the following:
> >
> > [   34.559694]     # pm_runtime_error_test: EXPECTATION FAILED at drivers/base/power/runtime-test.c:177
> > [   34.559694]     Expected 1 == pm_runtime_barrier(dev), but
> > [   34.559694]         pm_runtime_barrier(dev) == 0 (0x0)
> > [   34.563604]     # pm_runtime_error_test: pass:0 fail:1 skip:0 total:1
> >
> > Reported-by: Guenter Roeck <linux@roeck-us.net>
> > Closes: https://lore.kernel.org/lkml/93259f2b-7017-4096-a31b-cabbf6152e9b@roeck-us.net/
> > Signed-off-by: Brian Norris <briannorris@chromium.org>
>
> With this series on top of v6.18:
>
> Qemu test results:
>         total: 610 pass: 610 fail: 0
> Unit test results:
>         pass: 666898 fail: 0
>
> Tested-by: Guenter Roeck <linux@roeck-us.net>

Applied along with the [2-3/3] as 6.19-rc material, thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-12-04 19:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-02 19:30 [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code Brian Norris
2025-12-02 19:30 ` [PATCH 2/3] PM: runtime: Make pm_runtime_barrier() return void Brian Norris
2025-12-03  3:34   ` Guenter Roeck
2025-12-02 19:30 ` [PATCH 3/3] coccinelle: Drop pm_runtime_barrier() error code checks Brian Norris
2025-12-03  3:34   ` Guenter Roeck
2025-12-03  3:34 ` [PATCH 1/3] PM: runtime: Stop checking pm_runtime_barrier() return code Guenter Roeck
2025-12-04 19:41   ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®