Skip to contentSkip to conversation

bus: simple-pm-bus: fix forced runtime PM use

PATCH In review Johan Hovold 6 participants 8 messages Feb 14, 2025 – Feb 17, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus: simple-pm-bus: fix forced runtime PM use

The simple-pm-bus driver only enables runtime PM for some buses ('simple-pm-bus') yet has started calling pm_runtime_force_suspend() and pm_runtime_force_resume() during system suspend unconditionally.

This currently works, but that is not obvious and depends on implementation details which may change at some point.

Add dedicated system sleep ops and only call pm_runtime_force_suspend() and pm_runtime_force_resume() for buses that use runtime PM to avoid any future surprises.

Fixes c45839309c3d ("drivers: bus: simple-pm-bus: Use clocks")
Cc Liu Ying <[email protected]>
---
 drivers/bus/simple-pm-bus.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/bus/simple-pm-bus.c +21 -1
index 5dea31769f9a..d8e029e7e53f 100644
@@ -109,9 +109,29 @@ static int simple_pm_bus_runtime_resume(struct device *dev)
 	return 0;
 }
 
+static int simple_pm_bus_suspend(struct device *dev)
+{
+	struct simple_pm_bus *bus = dev_get_drvdata(dev);
+
+	if (!bus)
+		return 0;
+
+	return pm_runtime_force_suspend(dev);
+}
+
+static int simple_pm_bus_resume(struct device *dev)
+{
+	struct simple_pm_bus *bus = dev_get_drvdata(dev);
+
+	if (!bus)
+		return 0;
+
+	return pm_runtime_force_resume(dev);
+}
+
 static const struct dev_pm_ops simple_pm_bus_pm_ops = {
 	RUNTIME_PM_OPS(simple_pm_bus_runtime_suspend, simple_pm_bus_runtime_resume, NULL)
-	NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
+	NOIRQ_SYSTEM_SLEEP_PM_OPS(simple_pm_bus_suspend, simple_pm_bus_resume)
 };
 
 #define ONLY_BUS	((void *) 1) /* Match if the device is only a bus. */
Signature · 1 line
2.45.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Johan Hovold

The simple-pm-bus driver only enables runtime PM for some buses ('simple-pm-bus') yet has started calling pm_runtime_force_suspend() and pm_runtime_force_resume() during system suspend unconditionally.

Quoted 8 lines

This currently works, but that is not obvious and depends on implementation details which may change at some point.

Add dedicated system sleep ops and only call pm_runtime_force_suspend() and pm_runtime_force_resume() for buses that use runtime PM to avoid any future surprises.

Fixes c45839309c3d ("drivers: bus: simple-pm-bus: Use clocks")

This doesn't look like it is needed to me. It isn't broken, right?

Quoted 2 lines

Seems reasonable to me, but I think we need an ack from Geert here too.

Anyway, feel free to add:

Kind regards
Uffe

Quoted 42 lines
---
 drivers/bus/simple-pm-bus.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/bus/simple-pm-bus.c +21 -2
index 5dea31769f9a..d8e029e7e53f 100644
@@ -109,9 +109,29 @@ static int simple_pm_bus_runtime_resume(struct device *dev)
        return 0;
 }
 
+static int simple_pm_bus_suspend(struct device *dev)
+{
+       struct simple_pm_bus *bus = dev_get_drvdata(dev);
+
+       if (!bus)
+               return 0;
+
+       return pm_runtime_force_suspend(dev);
+}
+
+static int simple_pm_bus_resume(struct device *dev)
+{
+       struct simple_pm_bus *bus = dev_get_drvdata(dev);
+
+       if (!bus)
+               return 0;
+
+       return pm_runtime_force_resume(dev);
+}
+
 static const struct dev_pm_ops simple_pm_bus_pm_ops = {
        RUNTIME_PM_OPS(simple_pm_bus_runtime_suspend, simple_pm_bus_runtime_resume, NULL)
-       NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
+       NOIRQ_SYSTEM_SLEEP_PM_OPS(simple_pm_bus_suspend, simple_pm_bus_resume)
 };
 
 #define ONLY_BUS       ((void *) 1) /* Match if the device is only a bus. */
--

2.45.3

#2 lore raw
Quoted 9 lines · Ulf Hansson
Quoted 8 lines · Johan Hovold

The simple-pm-bus driver only enables runtime PM for some buses ('simple-pm-bus') yet has started calling pm_runtime_force_suspend() and pm_runtime_force_resume() during system suspend unconditionally.

This currently works, but that is not obvious and depends on implementation details which may change at some point.

Quoted 7 lines
Quoted 5 lines

Add dedicated system sleep ops and only call pm_runtime_force_suspend() and pm_runtime_force_resume() for buses that use runtime PM to avoid any future surprises.

Fixes c45839309c3d ("drivers: bus: simple-pm-bus: Use clocks")

This doesn't look like it is needed to me. It isn't broken, right?

I didn't add a CC stable tag since this currently works, but I still consider it a bug to call these helpers unconditionally when not using runtime PM.

[ And during rc1 these callbacks were suddenly called and triggered a NULL-pointer dereference as you know. [1] ]

Johan

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

Reviewed-by
#3 lore raw

Hi Johan,

Quoted 7 lines · Johan Hovold
Quoted 6 lines · Ulf Hansson
Quoted 5 lines · Johan Hovold

The simple-pm-bus driver only enables runtime PM for some buses ('simple-pm-bus') yet has started calling pm_runtime_force_suspend() and pm_runtime_force_resume() during system suspend unconditionally.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

This currently works, but that is not obvious and depends on implementation details which may change at some point.

Add dedicated system sleep ops and only call pm_runtime_force_suspend() and pm_runtime_force_resume() for buses that use runtime PM to avoid any future surprises.

Thanks for your patch!

Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Fixes c45839309c3d ("drivers: bus: simple-pm-bus: Use clocks")

This doesn't look like it is needed to me. It isn't broken, right?

I didn't add a CC stable tag since this currently works, but I still consider it a bug to call these helpers unconditionally when not using runtime PM.

Quoted 6 lines

[ And during rc1 these callbacks were suddenly called and triggered a NULL-pointer dereference as you know. [1] ]

Johan

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

Thanks, that was the context I needed to raise review priority ;)

Perhaps Reported-by: and Closes:?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#4 lore raw
Quoted 8 lines · Geert Uytterhoeven
Quoted 3 lines · Johan Hovold

I didn't add a CC stable tag since this currently works, but I still consider it a bug to call these helpers unconditionally when not using runtime PM.

Quoted 8 lines
Quoted 4 lines

[ And during rc1 these callbacks were suddenly called and triggered a NULL-pointer dereference as you know. [1] ]

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

Thanks, that was the context I needed to raise review priority ;)

Perhaps Reported-by: and Closes:?

The glitch was only temporary this time and the immediate issue was addressed by Rafael's partial revert in rc2:

	https://lore.kernel.org/lkml/[email protected]/

(and which has these tags).

Johan

#5 lore raw

Hi Johan,

Quoted 16 lines · Johan Hovold
Quoted 15 lines · Geert Uytterhoeven
Quoted 3 lines · Johan Hovold

I didn't add a CC stable tag since this currently works, but I still consider it a bug to call these helpers unconditionally when not using runtime PM.

Quoted 4 lines

[ And during rc1 these callbacks were suddenly called and triggered a NULL-pointer dereference as you know. [1] ]

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

Thanks, that was the context I needed to raise review priority ;)

Quoted 8 lines
Quoted 1 line

Perhaps Reported-by: and Closes:?

The glitch was only temporary this time and the immediate issue was addressed by Rafael's partial revert in rc2:

        https://lore.kernel.org/lkml/[email protected]/

(and which has these tags).

OK.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Acked-by on v1 1/1
#6 lore raw
In reply to Johan Hovold
Quoted 8 lines · Johan Hovold

The simple-pm-bus driver only enables runtime PM for some buses ('simple-pm-bus') yet has started calling pm_runtime_force_suspend() and pm_runtime_force_resume() during system suspend unconditionally.

This currently works, but that is not obvious and depends on implementation details which may change at some point.

Quoted 7 lines

Add dedicated system sleep ops and only call pm_runtime_force_suspend() and pm_runtime_force_resume() for buses that use runtime PM to avoid any future surprises.

Fixes c45839309c3d ("drivers: bus: simple-pm-bus: Use clocks")
Cc Liu Ying <[email protected]>
Quoted 40 lines
---
 drivers/bus/simple-pm-bus.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/bus/simple-pm-bus.c +21 -2
index 5dea31769f9a..d8e029e7e53f 100644
@@ -109,9 +109,29 @@ static int simple_pm_bus_runtime_resume(struct device *dev)
        return 0;
 }
 
+static int simple_pm_bus_suspend(struct device *dev)
+{
+       struct simple_pm_bus *bus = dev_get_drvdata(dev);
+
+       if (!bus)
+               return 0;
+
+       return pm_runtime_force_suspend(dev);
+}
+
+static int simple_pm_bus_resume(struct device *dev)
+{
+       struct simple_pm_bus *bus = dev_get_drvdata(dev);
+
+       if (!bus)
+               return 0;
+
+       return pm_runtime_force_resume(dev);
+}
+
 static const struct dev_pm_ops simple_pm_bus_pm_ops = {
        RUNTIME_PM_OPS(simple_pm_bus_runtime_suspend, simple_pm_bus_runtime_resume, NULL)
-       NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
+       NOIRQ_SYSTEM_SLEEP_PM_OPS(simple_pm_bus_suspend, simple_pm_bus_resume)
 };
 
 #define ONLY_BUS       ((void *) 1) /* Match if the device is only a bus. */
--
Acked-by on v1 1/1
#7 lore raw
In reply to Johan Hovold
Quoted 6 lines · Johan Hovold

The simple-pm-bus driver only enables runtime PM for some buses ('simple-pm-bus') yet has started calling pm_runtime_force_suspend() and pm_runtime_force_resume() during system suspend unconditionally.

This currently works, but that is not obvious and depends on implementation details which may change at some point.

Fair enough. It's not a good practice to depend on the PM core behaviour.

Quoted 47 lines

Add dedicated system sleep ops and only call pm_runtime_force_suspend() and pm_runtime_force_resume() for buses that use runtime PM to avoid any future surprises.

Fixes c45839309c3d ("drivers: bus: simple-pm-bus: Use clocks")
Cc Liu Ying <[email protected]>
---
 drivers/bus/simple-pm-bus.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/bus/simple-pm-bus.c +21 -1
index 5dea31769f9a..d8e029e7e53f 100644
@@ -109,9 +109,29 @@ static int simple_pm_bus_runtime_resume(struct device *dev)
 	return 0;
 }
 
+static int simple_pm_bus_suspend(struct device *dev)
+{
+	struct simple_pm_bus *bus = dev_get_drvdata(dev);
+
+	if (!bus)
+		return 0;
+
+	return pm_runtime_force_suspend(dev);
+}
+
+static int simple_pm_bus_resume(struct device *dev)
+{
+	struct simple_pm_bus *bus = dev_get_drvdata(dev);
+
+	if (!bus)
+		return 0;
+
+	return pm_runtime_force_resume(dev);
+}
+
 static const struct dev_pm_ops simple_pm_bus_pm_ops = {
 	RUNTIME_PM_OPS(simple_pm_bus_runtime_suspend, simple_pm_bus_runtime_resume, NULL)
-	NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
+	NOIRQ_SYSTEM_SLEEP_PM_OPS(simple_pm_bus_suspend, simple_pm_bus_resume)
 };
 
 #define ONLY_BUS	((void *) 1) /* Match if the device is only a bus. */
Signature · 2 lines
Regards,
Liu Ying