Skip to contentSkip to conversation

PM / runtime: Drop children check from __pm_runtime_set_status()

PATCH In review Rafael J. Wysocki 7 participants 30 messages Nov 12, 2017 – Dec 5, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / runtime: Drop children check from __pm_runtime_set_status()

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable().

---
 drivers/base/power/runtime.c |   30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
drivers/base/power/runtime.c +10 -20
Index: linux-pm/drivers/base/power/runtime.c
===================================================================
@@ -1101,29 +1101,13 @@ int __pm_runtime_set_status(struct devic
 		goto out;
 	}
 
-	if (dev->power.runtime_status == status)
+	if (dev->power.runtime_status == status || !parent)
 		goto out_set;
 
 	if (status == RPM_SUSPENDED) {
-		/*
-		 * It is invalid to suspend a device with an active child,
-		 * unless it has been set to ignore its children.
-		 */
-		if (!dev->power.ignore_children &&
-			atomic_read(&dev->power.child_count)) {
-			dev_err(dev, "runtime PM trying to suspend device but active child\n");
-			error = -EBUSY;
-			goto out;
-		}
-
-		if (parent) {
-			atomic_add_unless(&parent->power.child_count, -1, 0);
-			notify_parent = !parent->power.ignore_children;
-		}
-		goto out_set;
-	}
-
-	if (parent) {
+		atomic_add_unless(&parent->power.child_count, -1, 0);
+		notify_parent = !parent->power.ignore_children;
+	} else {
 		spin_lock_nested(&parent->power.lock, SINGLE_DEPTH_NESTING);
 
 		/*
@@ -1307,6 +1291,12 @@ void pm_runtime_enable(struct device *de
 	else
 		dev_warn(dev, "Unbalanced %s!\n", __func__);
 
+	WARN(dev->power.runtime_status == RPM_SUSPENDED &&
+	     !dev->power.ignore_children &&
+	     atomic_read(&dev->power.child_count) > 0,
+	     "Enabling runtime PM for inactive device (%s) with active children\n",
+	     dev_name(dev));
+
 	spin_unlock_irqrestore(&dev->power.lock, flags);
 }
 EXPORT_SYMBOL_GPL(pm_runtime_enable);
#1 lore raw
Quoted 10 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

The reason to why I changed this in commit a8636c89648a ("PM /
Runtime: Don't allow to suspend a device with an active child") was because to get a consistent behavior.

Because, setting the device's status to active (RPM_ACTIVE) via __pm_runtime_set_status(), requires its parent to also be active (in case the parent has runtime PM enabled).

I would prefer to try maintain this consistency, but I also I realize that commit a8636c89648a, should also have been checking if the parent has runtime PM enabled (again for consistency), which it doesn't.

What about fixing that instead?

Kind regards
Uffe

Quoted 62 lines

For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable().

---
 drivers/base/power/runtime.c |   30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c +10 -20
@@ -1101,29 +1101,13 @@ int __pm_runtime_set_status(struct devic
                goto out;
        }
 
-       if (dev->power.runtime_status == status)
+       if (dev->power.runtime_status == status || !parent)
                goto out_set;
 
        if (status == RPM_SUSPENDED) {
-               /*
-                * It is invalid to suspend a device with an active child,
-                * unless it has been set to ignore its children.
-                */
-               if (!dev->power.ignore_children &&
-                       atomic_read(&dev->power.child_count)) {
-                       dev_err(dev, "runtime PM trying to suspend device but active child\n");
-                       error = -EBUSY;
-                       goto out;
-               }
-
-               if (parent) {
-                       atomic_add_unless(&parent->power.child_count, -1, 0);
-                       notify_parent = !parent->power.ignore_children;
-               }
-               goto out_set;
-       }
-
-       if (parent) {
+               atomic_add_unless(&parent->power.child_count, -1, 0);
+               notify_parent = !parent->power.ignore_children;
+       } else {
                spin_lock_nested(&parent->power.lock, SINGLE_DEPTH_NESTING);
 
                /*
@@ -1307,6 +1291,12 @@ void pm_runtime_enable(struct device *de
        else
                dev_warn(dev, "Unbalanced %s!\n", __func__);
 
+       WARN(dev->power.runtime_status == RPM_SUSPENDED &&
+            !dev->power.ignore_children &&
+            atomic_read(&dev->power.child_count) > 0,
+            "Enabling runtime PM for inactive device (%s) with active children\n",
+            dev_name(dev));
+
        spin_unlock_irqrestore(&dev->power.lock, flags);
 }
 EXPORT_SYMBOL_GPL(pm_runtime_enable);
#2 lore raw
Quoted 12 lines · CET Ulf Hansson
Quoted 10 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

Quoted 3 lines

The reason to why I changed this in commit a8636c89648a ("PM /
Runtime: Don't allow to suspend a device with an active child") was because to get a consistent behavior.

Well, it causes the function to return an error in a non-error situation, which IMnsHO is a bug.

Quoted 3 lines

Because, setting the device's status to active (RPM_ACTIVE) via __pm_runtime_set_status(), requires its parent to also be active (in case the parent has runtime PM enabled).

No!!!

The check is in there, because the parent's usage_count is affected by that code and incrementing it in case the parent has runtime PM enabled and is RPM_SUSPENDED leads to an inconsistent runtime PM state of the parent. IOW, it would confuse the framework.

There's no such issue if the runtime PM status of a child is set to RPM_SUSPENDED.

It is all consistent without the check I'm removing and is made inconsistent by that very check.

Quoted 5 lines

I would prefer to try maintain this consistency, but I also I realize that commit a8636c89648a, should also have been checking if the parent has runtime PM enabled (again for consistency), which it doesn't.

What about fixing that instead?

Runtime PM is *disabled* for the parent at this point, guaranteed, so there's nothing to check, I'm afraid ...

OTOH, the runtime PM status of the children doesn't matter here, because their reference counters are not updated.

Thanks,
Rafael

#3 lore raw
Quoted 20 lines · Rafael J. Wysocki
Quoted 12 lines · CET Ulf Hansson
Quoted 10 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

Quoted 3 lines

The reason to why I changed this in commit a8636c89648a ("PM /
Runtime: Don't allow to suspend a device with an active child") was because to get a consistent behavior.

Well, it causes the function to return an error in a non-error situation, which IMnsHO is a bug.

Quoted 7 lines
Quoted 3 lines

Because, setting the device's status to active (RPM_ACTIVE) via __pm_runtime_set_status(), requires its parent to also be active (in case the parent has runtime PM enabled).

No!!!

The check is in there, because the parent's usage_count is affected by that

Actually, the parent's child_count is affected, but that doesn't matter here.

Quoted 13 lines

code and incrementing it in case the parent has runtime PM enabled and is RPM_SUSPENDED leads to an inconsistent runtime PM state of the parent. IOW, it would confuse the framework.

There's no such issue if the runtime PM status of a child is set to RPM_SUSPENDED.

It is all consistent without the check I'm removing and is made inconsistent by that very check.

Quoted 4 lines

I would prefer to try maintain this consistency, but I also I realize that commit a8636c89648a, should also have been checking if the parent has runtime PM enabled (again for consistency), which it doesn't.

Quoted 7 lines
Quoted 1 line

What about fixing that instead?

Runtime PM is *disabled* for the parent at this point, guaranteed, so there's nothing to check, I'm afraid ...

OTOH, the runtime PM status of the children doesn't matter here, because their reference counters are not updated.

Thanks,
Rafael

#4 lore raw
In reply to Rafael J. Wysocki
Quoted 24 lines · Rafael J. Wysocki
Quoted 12 lines · CET Ulf Hansson
Quoted 10 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

Quoted 3 lines

The reason to why I changed this in commit a8636c89648a ("PM /
Runtime: Don't allow to suspend a device with an active child") was because to get a consistent behavior.

Well, it causes the function to return an error in a non-error situation, which IMnsHO is a bug.

Quoted 3 lines

Because, setting the device's status to active (RPM_ACTIVE) via __pm_runtime_set_status(), requires its parent to also be active (in case the parent has runtime PM enabled).

Quoted 6 lines

No!!!

The check is in there, because the parent's usage_count is affected by that code and incrementing it in case the parent has runtime PM enabled and is RPM_SUSPENDED leads to an inconsistent runtime PM state of the parent. IOW, it would confuse the framework.

Right, I do understand the reasons *why* it is like this.

Quoted 6 lines

There's no such issue if the runtime PM status of a child is set to RPM_SUSPENDED.

It is all consistent without the check I'm removing and is made inconsistent by that very check.

Quoted 8 lines
Quoted 5 lines

I would prefer to try maintain this consistency, but I also I realize that commit a8636c89648a, should also have been checking if the parent has runtime PM enabled (again for consistency), which it doesn't.

What about fixing that instead?

Runtime PM is *disabled* for the parent at this point, guaranteed, so there's nothing to check, I'm afraid ...

Where and how is that guarantee made?

[...]

Kind regards
Uffe

#5 lore raw
Quoted 44 lines · Ulf Hansson
Quoted 24 lines · Rafael J. Wysocki
Quoted 12 lines · CET Ulf Hansson
Quoted 10 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

Quoted 3 lines

The reason to why I changed this in commit a8636c89648a ("PM /
Runtime: Don't allow to suspend a device with an active child") was because to get a consistent behavior.

Well, it causes the function to return an error in a non-error situation, which IMnsHO is a bug.

Quoted 3 lines

Because, setting the device's status to active (RPM_ACTIVE) via __pm_runtime_set_status(), requires its parent to also be active (in case the parent has runtime PM enabled).

Quoted 6 lines

No!!!

The check is in there, because the parent's usage_count is affected by that code and incrementing it in case the parent has runtime PM enabled and is RPM_SUSPENDED leads to an inconsistent runtime PM state of the parent. IOW, it would confuse the framework.

Right, I do understand the reasons *why* it is like this.

Quoted 10 lines

There's no such issue if the runtime PM status of a child is set to RPM_SUSPENDED.

It is all consistent without the check I'm removing and is made inconsistent by that very check.

Quoted 4 lines

I would prefer to try maintain this consistency, but I also I realize that commit a8636c89648a, should also have been checking if the parent has runtime PM enabled (again for consistency), which it doesn't.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

What about fixing that instead?

Runtime PM is *disabled* for the parent at this point, guaranteed, so there's nothing to check, I'm afraid ...

Where and how is that guarantee made?

Oh, just realize that it should be "child" instead of "parent", in the above reasoning. Apologize for giving the wrong argument.

So, let's me take this once again, to make it clear.

When pm_runtime_set_suspended(dev) is called, dev's child device may still be runtime PM enabled and active.
I was suggesting to add a check for this scenario, to see if dev's child device is runtime PM is enabled, as and additional constraint before deciding to return an error code.

The idea was to get a consistent behavior, from the pm_runtime_set_active|suspended() APIs point of view, and not from the runtime PM core point of view.

Of course, because dev->power.child_count, is maintained properly even when runtime PM is disabled for dev's child device, it works as you have suggested in $subject patch as well.

[...]

Kind regards
Uffe

#6 lore raw
Quoted 55 lines · CET Ulf Hansson
Quoted 44 lines · Ulf Hansson
Quoted 24 lines · Rafael J. Wysocki
Quoted 12 lines · CET Ulf Hansson
Quoted 10 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

Quoted 3 lines

The reason to why I changed this in commit a8636c89648a ("PM /
Runtime: Don't allow to suspend a device with an active child") was because to get a consistent behavior.

Well, it causes the function to return an error in a non-error situation, which IMnsHO is a bug.

Quoted 3 lines

Because, setting the device's status to active (RPM_ACTIVE) via __pm_runtime_set_status(), requires its parent to also be active (in case the parent has runtime PM enabled).

Quoted 6 lines

No!!!

The check is in there, because the parent's usage_count is affected by that code and incrementing it in case the parent has runtime PM enabled and is RPM_SUSPENDED leads to an inconsistent runtime PM state of the parent. IOW, it would confuse the framework.

Right, I do understand the reasons *why* it is like this.

Quoted 10 lines

There's no such issue if the runtime PM status of a child is set to RPM_SUSPENDED.

It is all consistent without the check I'm removing and is made inconsistent by that very check.

Quoted 4 lines

I would prefer to try maintain this consistency, but I also I realize that commit a8636c89648a, should also have been checking if the parent has runtime PM enabled (again for consistency), which it doesn't.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

What about fixing that instead?

Runtime PM is *disabled* for the parent at this point, guaranteed, so there's nothing to check, I'm afraid ...

Where and how is that guarantee made?

Oh, just realize that it should be "child" instead of "parent", in the above reasoning. Apologize for giving the wrong argument.

Quoted 7 lines

So, let's me take this once again, to make it clear.

When pm_runtime_set_suspended(dev) is called, dev's child device may still be runtime PM enabled and active.
I was suggesting to add a check for this scenario, to see if dev's child device is runtime PM is enabled, as and additional constraint before deciding to return an error code.

Well, that's sort of difficult to do, however, because the code would need to walk all of the children of the device and the child power lock cannot be acquired under the one of the parent, so it would be fragile and ugly.

Quoted 3 lines

The idea was to get a consistent behavior, from the pm_runtime_set_active|suspended() APIs point of view, and not from the runtime PM core point of view.

Yes, but the cost is high and the benefit is shallow.

The enable-time WARN() should cover the really broken cases without that much complexity.

Thanks,
Rafael

Reviewed-by
#7 lore raw

[...]

Quoted 10 lines
Quoted 6 lines

When pm_runtime_set_suspended(dev) is called, dev's child device may still be runtime PM enabled and active.
I was suggesting to add a check for this scenario, to see if dev's child device is runtime PM is enabled, as and additional constraint before deciding to return an error code.

Well, that's sort of difficult to do, however, because the code would need to walk all of the children of the device and the child power lock cannot be acquired under the one of the parent, so it would be fragile and ugly.

Yeah, you have a point.

Quoted 9 lines
Quoted 4 lines

The idea was to get a consistent behavior, from the pm_runtime_set_active|suspended() APIs point of view, and not from the runtime PM core point of view.

Yes, but the cost is high and the benefit is shallow.

The enable-time WARN() should cover the really broken cases without that much complexity.

Fair enough!

Feel free to add:

Kind regards
Uffe

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

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

Quoted 5 lines

For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable().

Looks good to me, but you should also fix Documentation/power/runtime_pm.txt which was updated to reflect the constraint that is now being reverted.

Thanks,
Johan

#9 lore raw
Quoted 16 lines · CET Johan Hovold
Quoted 15 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable().

Quoted 5 lines
Quoted 1 line

Looks good to me, but you should also fix Documentation/power/runtime_pm.txt which was updated to reflect the constraint that is now being reverted.

Thanks for pointing that out.

Quoted 1 line

Thanks!

Rafael

#10 lore raw
In reply to Rafael J. Wysocki

Hi Rafael, Shimoda-san,

Quoted 30 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable().

---
 drivers/base/power/runtime.c |   30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c +1 -1
@@ -1101,29 +1101,13 @@ int __pm_runtime_set_status(struct devic
                goto out;
        }
 
-       if (dev->power.runtime_status == status)
+       if (dev->power.runtime_status == status || !parent)

drivers/base/power/runtime.c int __pm_runtime_set_status(struct devic · line 1114

Quoted 10 lines
drivers/base/power/runtime.c +0 -7
                goto out_set;
 
        if (status == RPM_SUSPENDED) {
-               /*
-                * It is invalid to suspend a device with an active child,
-                * unless it has been set to ignore its children.
-                */
-               if (!dev->power.ignore_children &&
-                       atomic_read(&dev->power.child_count)) {
-                       dev_err(dev, "runtime PM trying to suspend device but active child\n");

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

so this was an existing issue with USB before.

Quoted 19 lines
drivers/base/power/runtime.c +3 -12
-                       error = -EBUSY;
-                       goto out;
-               }
-
-               if (parent) {
-                       atomic_add_unless(&parent->power.child_count, -1, 0);
-                       notify_parent = !parent->power.ignore_children;
-               }
-               goto out_set;
-       }
-
-       if (parent) {
+               atomic_add_unless(&parent->power.child_count, -1, 0);
+               notify_parent = !parent->power.ignore_children;
+       } else {
                spin_lock_nested(&parent->power.lock, SINGLE_DEPTH_NESTING);
 
                /*

drivers/base/power/runtime.c void pm_runtime_enable(struct device *de · line 1298

Quoted 8 lines
drivers/base/power/runtime.c +5 -0
@@ -1307,6 +1291,12 @@ void pm_runtime_enable(struct device *de
        else
                dev_warn(dev, "Unbalanced %s!\n", __func__);
 
+       WARN(dev->power.runtime_status == RPM_SUSPENDED &&
+            !dev->power.ignore_children &&
+            atomic_read(&dev->power.child_count) > 0,
+            "Enabling runtime PM for inactive device (%s) with active children\n",
+            dev_name(dev));

And now it became a bit more noisy:

Enabling runtime PM for inactive device (ee0a0200.usb-phy) with active children

WARNING: CPU: 0 PID: 1697 at drivers/base/power/runtime.c:1299
pm_runtime_enable+0x94/0xd8
CPU: 0 PID: 1697 Comm: s2idle Not tainted
4.15.0-rc1-arm64-renesas-00381-g40d152b966c941dd #41
Hardware name: Renesas Salvator-X 2nd version board based on r8a7795 ES2.0+ (DT)
task: ffff8006f81bb100 task.stack: ffff00000aa80000
pstate: 60000085 (nZCv daIf -PAN -UAO)
pc : pm_runtime_enable+0x94/0xd8
lr : pm_runtime_enable+0x94/0xd8

sp : ffff00000aa83b50
x29: ffff00000aa83b50 x28: ffff8006f81bb100
x27: ffff000008841000 x26: ffff000008b4b640
x25: ffff000008b7f6e0 x24: ffff0000097a2f90
x23: ffff000008b7f000 x22: 0000000000000010
x21: 0000000000000000 x20: ffff8006fa9ad158
x19: ffff8006fa9ad010 x18: 00000000013c6577
x17: ffff00000947ea80 x16: 0000000000006370
x15: 000000000000636e x14: 646c696863206576
x13: 0000000000000001 x12: ffff8006f81bbaa8
x11: ffff8006f9479230 x10: ffff8006f97a63e0
x9 : 0000000000000000 x8 : ffff8006f97a6408
x7 : ffff8006f97a63c0 x6 : ffff00000975de80
x5 : 0000000000000000 x4 : 0000000000000000
x3 : ffffffffffffffff x2 : ffff000008b4bbf0
x1 : ffff8006f81bb100 x0 : 000000000000004f

Call trace:
 pm_runtime_enable+0x94/0xd8
 device_resume_early+0x50/0xec
 dpm_resume_early+0x118/0x204
 suspend_devices_and_enter+0x2a8/0x4b0
 pm_suspend+0x22c/0x27c
 state_store+0x84/0x108
 kobj_attr_store+0x14/0x24
 sysfs_kf_write+0x54/0x64
 kernfs_fop_write+0xd8/0x1ec
 __vfs_write+0x28/0x124
 vfs_write+0xa0/0x198
 SyS_write+0x44/0xa0
 el0_svc_naked+0x20/0x24
---[ end trace 965c08c229b62a65 ]---
------------[ cut here ]------------
Enabling runtime PM for inactive device (ee0c0200.usb-phy) with active children
WARNING: CPU: 0 PID: 1697 at drivers/base/power/runtime.c:1299
pm_runtime_enable+0x94/0xd8
CPU: 0 PID: 1697 Comm: s2idle Tainted: G        W
4.15.0-rc1-arm64-renesas-00381-g40d152b966c941dd #41
Hardware name: Renesas Salvator-X 2nd version board based on r8a7795 ES2.0+ (DT)
task: ffff8006f81bb100 task.stack: ffff00000aa80000
pstate: 60000085 (nZCv daIf -PAN -UAO)
pc : pm_runtime_enable+0x94/0xd8
lr : pm_runtime_enable+0x94/0xd8

sp : ffff00000aa83b50
x29: ffff00000aa83b50 x28: ffff8006f81bb100
x27: ffff000008841000 x26: ffff000008b4b640
x25: ffff000008b7f6e0 x24: ffff0000097a2f90
x23: ffff000008b7f000 x22: 0000000000000010
x21: 0000000000000000 x20: ffff8006fa9ad958
x19: ffff8006fa9ad810 x18: 00000000013c6577
x17: ffff00000947ea80 x16: 0000000000006370
x15: 000000000000636e x14: 0720072007200720
x13: 0000000000000001 x12: ffff8006f81bbaa8
x11: ffff8006f9478940 x10: ffff8006f97a7ad8
x9 : 0000000000000000 x8 : ffff8006f97a7b00
x7 : ffff8006f97a7ab8 x6 : ffff00000975de80
x5 : 0000000000000000 x4 : 0000000000000000
x3 : ffffffffffffffff x2 : ffff000008b4bbf0
x1 : ffff8006f81bb100 x0 : 000000000000004f

Call trace:
 pm_runtime_enable+0x94/0xd8
 device_resume_early+0x50/0xec
 dpm_resume_early+0x118/0x204
 suspend_devices_and_enter+0x2a8/0x4b0
 pm_suspend+0x22c/0x27c
 state_store+0x84/0x108
 kobj_attr_store+0x14/0x24
 sysfs_kf_write+0x54/0x64
 kernfs_fop_write+0xd8/0x1ec
 __vfs_write+0x28/0x124
 vfs_write+0xa0/0x198
 SyS_write+0x44/0xa0
 el0_svc_naked+0x20/0x24
---[ end trace 965c08c229b62a66 ]---
------------[ cut here ]------------
...

drivers/base/power/runtime.c void pm_runtime_enable(struct device *de · line 1302

Quoted 4 lines
drivers/base/power/runtime.c +1 -0
+
        spin_unlock_irqrestore(&dev->power.lock, flags);
 }
 EXPORT_SYMBOL_GPL(pm_runtime_enable);

Gr{oetje,eeting}s,

Geert

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

#11 lore raw

Hi Geert-san,

Quoted 62 lines

From: Geert Uytterhoeven, Sent: Tuesday, November 28, 2017 7:58 PM

Hi Rafael, Shimoda-san,

Quoted 30 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable().

---
 drivers/base/power/runtime.c |   30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c +1 -1
@@ -1101,29 +1101,13 @@ int __pm_runtime_set_status(struct devic
                goto out;
        }
 
-       if (dev->power.runtime_status == status)
+       if (dev->power.runtime_status == status || !parent)

drivers/base/power/runtime.c int __pm_runtime_set_status(struct devic · line 1114

Quoted 10 lines
drivers/base/power/runtime.c +0 -7
                goto out_set;
 
        if (status == RPM_SUSPENDED) {
-               /*
-                * It is invalid to suspend a device with an active child,
-                * unless it has been set to ignore its children.
-                */
-               if (!dev->power.ignore_children &&
-                       atomic_read(&dev->power.child_count)) {
-                       dev_err(dev, "runtime PM trying to suspend device but active child\n");

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

Quoted 1 line

so this was an existing issue with USB before.

Thank you for the report!
I know that, but since this didn't cause any trouble until now,
I postponed to investigate the issue... But, I investigate it today.
I don't find the root cause yet. However, it seems related to usb host and/or usb core. --> USB host related devices' child_count will be 1 in suspend timing.
--> I guess remote wakeup feature is enabled? But, I don't find the point yet.

The renesas_usbhs also uses the phy_rcar_gen3_usb2 driver.
--> If I only used the renesas_usbhs driver (in other words, I don't install
[eo]hci-{hcd,platform} drivers), the issue disappeared.
--> So, I think the phy_rcar_gen3_usb2 driver doesn't cause this issue.
(But, it is possible to be related though.)

I'll continue to investigate this issue tomorrow.

Best regards,
Yoshihiro Shimoda

#12 lore raw
Quoted 73 lines · Yoshihiro Shimoda

Hi Geert-san,

Quoted 62 lines

From: Geert Uytterhoeven, Sent: Tuesday, November 28, 2017 7:58 PM

Hi Rafael, Shimoda-san,

Quoted 30 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable().

---
 drivers/base/power/runtime.c |   30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c +1 -1
@@ -1101,29 +1101,13 @@ int __pm_runtime_set_status(struct devic
                goto out;
        }
 
-       if (dev->power.runtime_status == status)
+       if (dev->power.runtime_status == status || !parent)

drivers/base/power/runtime.c int __pm_runtime_set_status(struct devic · line 1114

Quoted 10 lines
drivers/base/power/runtime.c +0 -7
                goto out_set;
 
        if (status == RPM_SUSPENDED) {
-               /*
-                * It is invalid to suspend a device with an active child,
-                * unless it has been set to ignore its children.
-                */
-               if (!dev->power.ignore_children &&
-                       atomic_read(&dev->power.child_count)) {
-                       dev_err(dev, "runtime PM trying to suspend device but active child\n");

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

Quoted 1 line

so this was an existing issue with USB before.

Thank you for the report!
I know that, but since this didn't cause any trouble until now,
I postponed to investigate the issue... But, I investigate it today.
I don't find the root cause yet. However, it seems related to usb host and/or usb core. --> USB host related devices' child_count will be 1 in suspend timing.
--> I guess remote wakeup feature is enabled? But, I don't find the point yet.

Quoted 7 lines

The renesas_usbhs also uses the phy_rcar_gen3_usb2 driver.
--> If I only used the renesas_usbhs driver (in other words, I don't install
[eo]hci-{hcd,platform} drivers), the issue disappeared.
--> So, I think the phy_rcar_gen3_usb2 driver doesn't cause this issue.
(But, it is possible to be related though.)

I'll continue to investigate this issue tomorrow.

Does the phy_rcar_gen3_usb2 driver use runtime PM? It looks like the phy device somehow gets enabled for runtime PM when it shouldn't be.

(And by the way, what device is the child of ee0a0200.usb-phy?)

Alan Stern

#13 lore raw

Hi,

Quoted 12 lines

From: Alan Stern, Sent: Wednesday, November 29, 2017 12:07 AM

Quoted 8 lines · Yoshihiro Shimoda

Hi Geert-san,

Quoted 6 lines

From: Geert Uytterhoeven, Sent: Tuesday, November 28, 2017 7:58 PM

Hi Rafael, Shimoda-san,

Quoted 1 line · Rafael J. Wysocki

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

<snip>

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

so this was an existing issue with USB before.

Quoted 8 lines
Quoted 8 lines

Thank you for the report!
I know that, but since this didn't cause any trouble until now,
I postponed to investigate the issue... But, I investigate it today.
I don't find the root cause yet. However, it seems related to usb host and/or usb core. --> USB host related devices' child_count will be 1 in suspend timing.
--> I guess remote wakeup feature is enabled? But, I don't find the point yet.

The renesas_usbhs also uses the phy_rcar_gen3_usb2 driver.

I'm so sorry, but this is mistake.
The renesas_usbhs doesn't use the phy_rcar_gen3_usb2 driver. So,

Quoted 4 lines
Quoted 4 lines

--> If I only used the renesas_usbhs driver (in other words, I don't install
[eo]hci-{hcd,platform} drivers), the issue disappeared.
--> So, I think the phy_rcar_gen3_usb2 driver doesn't cause this issue.
(But, it is possible to be related though.)

They are also mistake.

Quoted 3 lines
Quoted 1 line

I'll continue to investigate this issue tomorrow.

Does the phy_rcar_gen3_usb2 driver use runtime PM?

Yes, the phy_rcar_gen3_usb2 uses runtime PM.

Quoted 2 lines

It looks like the
phy device somehow gets enabled for runtime PM when it shouldn't be.

I also think that now.
I don't find why for now, but the usage_count of a phy device was not 1 just before suspend. (This "a phy device" means the child of ee0a0200.usb-phy device.)

Quoted 1 line

(And by the way, what device is the child of ee0a0200.usb-phy?)

It's a phy device:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/phy/phy-core.c?h=v4.15-rc1#n773

Best regards,
Yoshihiro Shimoda

Quoted 1 line

Alan Stern

#14 lore raw
In reply to Yoshihiro Shimoda
Quoted 64 lines · Yoshihiro Shimoda

Hi Geert-san,

Quoted 62 lines

From: Geert Uytterhoeven, Sent: Tuesday, November 28, 2017 7:58 PM

Hi Rafael, Shimoda-san,

Quoted 30 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable().

---
 drivers/base/power/runtime.c |   30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c +1 -1
@@ -1101,29 +1101,13 @@ int __pm_runtime_set_status(struct devic
                goto out;
        }
 
-       if (dev->power.runtime_status == status)
+       if (dev->power.runtime_status == status || !parent)

drivers/base/power/runtime.c int __pm_runtime_set_status(struct devic · line 1114

Quoted 10 lines
drivers/base/power/runtime.c +0 -7
                goto out_set;
 
        if (status == RPM_SUSPENDED) {
-               /*
-                * It is invalid to suspend a device with an active child,
-                * unless it has been set to ignore its children.
-                */
-               if (!dev->power.ignore_children &&
-                       atomic_read(&dev->power.child_count)) {
-                       dev_err(dev, "runtime PM trying to suspend device but active child\n");

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

Quoted 8 lines
Quoted 1 line

so this was an existing issue with USB before.

Thank you for the report!
I know that, but since this didn't cause any trouble until now,
I postponed to investigate the issue... But, I investigate it today.
I don't find the root cause yet. However, it seems related to usb host and/or usb core. --> USB host related devices' child_count will be 1 in suspend timing.
--> I guess remote wakeup feature is enabled? But, I don't find the point yet.

I am guessing the issue is triggered by genpd in the suspend noirq phase (genpd_suspend_noirq()). In there, there is a call to pm_runtime_force_suspend() (which calls pm_runtime_set_suspended() and which triggered the earlier error messages being printed).

The reason why genpd calls pm_runtime_force_suspend(), is because when validating wakeup configurations for the device "if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))", it's thinks wakeup isn't configured while it probably should be.

An additional note, only when genpd has the GENPD_FLAG_PM_CLK set, which makes the genpd->dev_ops.stop|start() being assigned, genpd calls pm_runtime_force_suspend() - else it doesn't.

Perhaps try out the series I recently posted improving the code dealing with wakeups in genpd and the PM core:
https://www.spinics.net/lists/linux-renesas-soc/msg20122.html
To that, you need to set the new flag (invented in the above series) DPM_FLAG_IN_BAND_WAKEUP in the driver that configures wakeup of its device.

Hope this helps!

Quoted 8 lines

The renesas_usbhs also uses the phy_rcar_gen3_usb2 driver.
--> If I only used the renesas_usbhs driver (in other words, I don't install
[eo]hci-{hcd,platform} drivers), the issue disappeared.
--> So, I think the phy_rcar_gen3_usb2 driver doesn't cause this issue.
(But, it is possible to be related though.)

I'll continue to investigate this issue tomorrow.

Please keep me posted, I am interested about the why the problem exists. :-)

Kind regards
Uffe

#15 lore raw

Hi,

Quoted 12 lines

From: Ulf Hansson, Sent: Wednesday, November 29, 2017 2:23 AM

Quoted 8 lines · Yoshihiro Shimoda

Hi Geert-san,

Quoted 6 lines

From: Geert Uytterhoeven, Sent: Tuesday, November 28, 2017 7:58 PM

Hi Rafael, Shimoda-san,

Quoted 1 line · Rafael J. Wysocki

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

<snip>

Quoted 39 lines
Quoted 16 lines
Quoted 16 lines

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

Quoted 8 lines
Quoted 1 line

so this was an existing issue with USB before.

Thank you for the report!
I know that, but since this didn't cause any trouble until now,
I postponed to investigate the issue... But, I investigate it today.
I don't find the root cause yet. However, it seems related to usb host and/or usb core. --> USB host related devices' child_count will be 1 in suspend timing.
--> I guess remote wakeup feature is enabled? But, I don't find the point yet.

I am guessing the issue is triggered by genpd in the suspend noirq phase (genpd_suspend_noirq()). In there, there is a call to pm_runtime_force_suspend() (which calls pm_runtime_set_suspended() and which triggered the earlier error messages being printed).

The reason why genpd calls pm_runtime_force_suspend(), is because when validating wakeup configurations for the device "if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))", it's thinks wakeup isn't configured while it probably should be.

An additional note, only when genpd has the GENPD_FLAG_PM_CLK set, which makes the genpd->dev_ops.stop|start() being assigned, genpd calls pm_runtime_force_suspend() - else it doesn't.

Quoted 8 lines

Perhaps try out the series I recently posted improving the code dealing with wakeups in genpd and the PM core:
https://www.spinics.net/lists/linux-renesas-soc/msg20122.html
To that, you need to set the new flag (invented in the above series) DPM_FLAG_IN_BAND_WAKEUP in the driver that configures wakeup of its device.

Hope this helps!

Thank you for the comments!
I tried DPM_FLAG_IN_BAND_WAKEUP, but the issue still exists.
I added the flag in the [eo]hci-platform driver and usb/core/driver.c. I also added the flag in the phy_rcar_gen3_usb2 driver except usb host drivers.

Quoted 9 lines
Quoted 7 lines

The renesas_usbhs also uses the phy_rcar_gen3_usb2 driver.
--> If I only used the renesas_usbhs driver (in other words, I don't install
[eo]hci-{hcd,platform} drivers), the issue disappeared.
--> So, I think the phy_rcar_gen3_usb2 driver doesn't cause this issue.
(But, it is possible to be related though.)

I'll continue to investigate this issue tomorrow.

Please keep me posted, I am interested about the why the problem exists. :-)

Sure! :)

Best regards,
Yoshihiro Shimoda

Quoted 2 lines

Kind regards
Uffe

#16 lore raw
Quoted 61 lines · Yoshihiro Shimoda

Hi,

Quoted 12 lines

From: Ulf Hansson, Sent: Wednesday, November 29, 2017 2:23 AM

Quoted 8 lines · Yoshihiro Shimoda

Hi Geert-san,

Quoted 6 lines

From: Geert Uytterhoeven, Sent: Tuesday, November 28, 2017 7:58 PM

Hi Rafael, Shimoda-san,

Quoted 1 line · Rafael J. Wysocki

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

<snip>

Quoted 46 lines
Quoted 16 lines
Quoted 16 lines

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

Quoted 8 lines
Quoted 1 line

so this was an existing issue with USB before.

Thank you for the report!
I know that, but since this didn't cause any trouble until now,
I postponed to investigate the issue... But, I investigate it today.
I don't find the root cause yet. However, it seems related to usb host and/or usb core. --> USB host related devices' child_count will be 1 in suspend timing.
--> I guess remote wakeup feature is enabled? But, I don't find the point yet.

I am guessing the issue is triggered by genpd in the suspend noirq phase (genpd_suspend_noirq()). In there, there is a call to pm_runtime_force_suspend() (which calls pm_runtime_set_suspended() and which triggered the earlier error messages being printed).

The reason why genpd calls pm_runtime_force_suspend(), is because when validating wakeup configurations for the device "if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))", it's thinks wakeup isn't configured while it probably should be.

An additional note, only when genpd has the GENPD_FLAG_PM_CLK set, which makes the genpd->dev_ops.stop|start() being assigned, genpd calls pm_runtime_force_suspend() - else it doesn't.

Perhaps try out the series I recently posted improving the code dealing with wakeups in genpd and the PM core:
https://www.spinics.net/lists/linux-renesas-soc/msg20122.html
To that, you need to set the new flag (invented in the above series) DPM_FLAG_IN_BAND_WAKEUP in the driver that configures wakeup of its device.

Quoted 6 lines
Quoted 1 line

Hope this helps!

Thank you for the comments!
I tried DPM_FLAG_IN_BAND_WAKEUP, but the issue still exists.
I added the flag in the [eo]hci-platform driver and usb/core/driver.c. I also added the flag in the phy_rcar_gen3_usb2 driver except usb host drivers.

First, did you confirm that genpd was used? Then for what device?

Second, did you check the call to pm_runtime_force_suspend() called by genpd, is the reason to the error messages?

Third, it should be sufficient to add DPM_FLAG_IN_BAND_WAKEUP for the driver that is actually dealing with the wakeup. Although, does this driver's system ->suspend() callback check device_may_wakeup(), before it decides to enable wakeup?
If not, the PM core and genpd don't notice that wakeup is enabled for the device.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The renesas_usbhs also uses the phy_rcar_gen3_usb2 driver.
--> If I only used the renesas_usbhs driver (in other words, I don't install
[eo]hci-{hcd,platform} drivers), the issue disappeared.
--> So, I think the phy_rcar_gen3_usb2 driver doesn't cause this issue.
(But, it is possible to be related though.)

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I'll continue to investigate this issue tomorrow.

Please keep me posted, I am interested about the why the problem exists. :-)

Sure! :)

Great, thanks.

Kind regards
Uffe

#17 lore raw

Hi Ulf,

Quoted 55 lines · Ulf Hansson
Quoted 53 lines · Yoshihiro Shimoda
Quoted 6 lines

From: Ulf Hansson, Sent: Wednesday, November 29, 2017 2:23 AM

Quoted 3 lines · Yoshihiro Shimoda
Quoted 3 lines

From: Geert Uytterhoeven, Sent: Tuesday, November 28, 2017 7:58 PM

Quoted 1 line · Rafael J. Wysocki

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

<snip>

Quoted 46 lines
Quoted 16 lines
Quoted 16 lines

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

Quoted 8 lines
Quoted 1 line

so this was an existing issue with USB before.

Thank you for the report!
I know that, but since this didn't cause any trouble until now,
I postponed to investigate the issue... But, I investigate it today.
I don't find the root cause yet. However, it seems related to usb host and/or usb core. --> USB host related devices' child_count will be 1 in suspend timing.
--> I guess remote wakeup feature is enabled? But, I don't find the point yet.

I am guessing the issue is triggered by genpd in the suspend noirq phase (genpd_suspend_noirq()). In there, there is a call to pm_runtime_force_suspend() (which calls pm_runtime_set_suspended() and which triggered the earlier error messages being printed).

The reason why genpd calls pm_runtime_force_suspend(), is because when validating wakeup configurations for the device "if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))", it's thinks wakeup isn't configured while it probably should be.

An additional note, only when genpd has the GENPD_FLAG_PM_CLK set, which makes the genpd->dev_ops.stop|start() being assigned, genpd calls pm_runtime_force_suspend() - else it doesn't.

Perhaps try out the series I recently posted improving the code dealing with wakeups in genpd and the PM core:
https://www.spinics.net/lists/linux-renesas-soc/msg20122.html
To that, you need to set the new flag (invented in the above series) DPM_FLAG_IN_BAND_WAKEUP in the driver that configures wakeup of its device.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Hope this helps!

Thank you for the comments!
I tried DPM_FLAG_IN_BAND_WAKEUP, but the issue still exists.
I added the flag in the [eo]hci-platform driver and usb/core/driver.c. I also added the flag in the phy_rcar_gen3_usb2 driver except usb host drivers.

First, did you confirm that genpd was used? Then for what device?

All 6 devices are part of the SYSC PM Domain.

Quoted 9 lines

Second, did you check the call to pm_runtime_force_suspend() called by genpd, is the reason to the error messages?

Third, it should be sufficient to add DPM_FLAG_IN_BAND_WAKEUP for the driver that is actually dealing with the wakeup. Although, does this driver's system ->suspend() callback check device_may_wakeup(), before it decides to enable wakeup?
If not, the PM core and genpd don't notice that wakeup is enabled for the device.

Actually I saw this with my patches setting GENPD_FLAG_ACTIVE_WAKEUP for the SYSC PM Domain, which should trigger the same behavior.

Gr{oetje,eeting}s,

Geert

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

#18 lore raw
Quoted 60 lines · Geert Uytterhoeven

Hi Ulf,

Quoted 57 lines · Ulf Hansson
Quoted 55 lines · Yoshihiro Shimoda
Quoted 6 lines

From: Ulf Hansson, Sent: Wednesday, November 29, 2017 2:23 AM

Quoted 3 lines · Yoshihiro Shimoda
Quoted 3 lines

From: Geert Uytterhoeven, Sent: Tuesday, November 28, 2017 7:58 PM

Quoted 1 line · Rafael J. Wysocki

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

<snip>

Quoted 47 lines
Quoted 16 lines
Quoted 16 lines

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

Quoted 8 lines
Quoted 1 line

so this was an existing issue with USB before.

Thank you for the report!
I know that, but since this didn't cause any trouble until now,
I postponed to investigate the issue... But, I investigate it today.
I don't find the root cause yet. However, it seems related to usb host and/or usb core. --> USB host related devices' child_count will be 1 in suspend timing.
--> I guess remote wakeup feature is enabled? But, I don't find the point yet.

I am guessing the issue is triggered by genpd in the suspend noirq phase (genpd_suspend_noirq()). In there, there is a call to pm_runtime_force_suspend() (which calls pm_runtime_set_suspended() and which triggered the earlier error messages being printed).

The reason why genpd calls pm_runtime_force_suspend(), is because when validating wakeup configurations for the device "if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))", it's thinks wakeup isn't configured while it probably should be.

An additional note, only when genpd has the GENPD_FLAG_PM_CLK set, which makes the genpd->dev_ops.stop|start() being assigned, genpd calls pm_runtime_force_suspend() - else it doesn't.

Perhaps try out the series I recently posted improving the code dealing with wakeups in genpd and the PM core:
https://www.spinics.net/lists/linux-renesas-soc/msg20122.html
To that, you need to set the new flag (invented in the above series) DPM_FLAG_IN_BAND_WAKEUP in the driver that configures wakeup of its device.

Hope this helps!

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Thank you for the comments!
I tried DPM_FLAG_IN_BAND_WAKEUP, but the issue still exists.
I added the flag in the [eo]hci-platform driver and usb/core/driver.c. I also added the flag in the phy_rcar_gen3_usb2 driver except usb host drivers.

First, did you confirm that genpd was used? Then for what device?

All 6 devices are part of the SYSC PM Domain.

Okay!

Can you perhaps clarify which 6 devices/drivers that are involved, and perhaps also point out if their child devices?

Quoted 11 lines
Quoted 10 lines

Second, did you check the call to pm_runtime_force_suspend() called by genpd, is the reason to the error messages?

Third, it should be sufficient to add DPM_FLAG_IN_BAND_WAKEUP for the driver that is actually dealing with the wakeup. Although, does this driver's system ->suspend() callback check device_may_wakeup(), before it decides to enable wakeup?
If not, the PM core and genpd don't notice that wakeup is enabled for the device.

Quoted 2 lines

Actually I saw this with my patches setting GENPD_FLAG_ACTIVE_WAKEUP for the SYSC PM Domain, which should trigger the same behavior.

Okay, so the problem remains no matter which solution for wakeup you pick in genpd.

Then this seems to point to that the driver may be misbehaving in some way. I can help to check what is going on.

Kind regards
Uffe

#19 lore raw

Hi Ulf,

Quoted 64 lines · Ulf Hansson
Quoted 63 lines · Geert Uytterhoeven
Quoted 62 lines · Ulf Hansson
Quoted 59 lines · Yoshihiro Shimoda
Quoted 6 lines

From: Ulf Hansson, Sent: Wednesday, November 29, 2017 2:23 AM

Quoted 3 lines · Yoshihiro Shimoda
Quoted 3 lines

From: Geert Uytterhoeven, Sent: Tuesday, November 28, 2017 7:58 PM

Quoted 1 line · Rafael J. Wysocki

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

<snip>

Quoted 39 lines
Quoted 16 lines
Quoted 16 lines

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

Quoted 8 lines
Quoted 1 line

so this was an existing issue with USB before.

Thank you for the report!
I know that, but since this didn't cause any trouble until now,
I postponed to investigate the issue... But, I investigate it today.
I don't find the root cause yet. However, it seems related to usb host and/or usb core. --> USB host related devices' child_count will be 1 in suspend timing.
--> I guess remote wakeup feature is enabled? But, I don't find the point yet.

I am guessing the issue is triggered by genpd in the suspend noirq phase (genpd_suspend_noirq()). In there, there is a call to pm_runtime_force_suspend() (which calls pm_runtime_set_suspended() and which triggered the earlier error messages being printed).

The reason why genpd calls pm_runtime_force_suspend(), is because when validating wakeup configurations for the device "if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))", it's thinks wakeup isn't configured while it probably should be.

An additional note, only when genpd has the GENPD_FLAG_PM_CLK set, which makes the genpd->dev_ops.stop|start() being assigned, genpd calls pm_runtime_force_suspend() - else it doesn't.

Quoted 8 lines

Perhaps try out the series I recently posted improving the code dealing with wakeups in genpd and the PM core:
https://www.spinics.net/lists/linux-renesas-soc/msg20122.html
To that, you need to set the new flag (invented in the above series) DPM_FLAG_IN_BAND_WAKEUP in the driver that configures wakeup of its device.

Hope this helps!

Thank you for the comments!
I tried DPM_FLAG_IN_BAND_WAKEUP, but the issue still exists.
I added the flag in the [eo]hci-platform driver and usb/core/driver.c. I also added the flag in the phy_rcar_gen3_usb2 driver except usb host drivers.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

First, did you confirm that genpd was used? Then for what device?

All 6 devices are part of the SYSC PM Domain.

Okay!

Can you perhaps clarify which 6 devices/drivers that are involved, and perhaps also point out if their child devices?

/sys/devices/platform/soc/ee080000.usb
/sys/devices/platform/soc/ee0c0000.usb
/sys/devices/platform/soc/ee0a0000.usb

Driver: ohci-platform

The children are usb6/6-0:1.0, usb3/3-0:1.0, resp. usb4/4-0:1.0, all using the usb "hub" driver

/sys/devices/platform/soc/ee080200.usb-phy
/sys/devices/platform/soc/ee0a0200.usb-phy
/sys/devices/platform/soc/ee0c0200.usb-phy

Driver: phy_rcar_gen3_usb2

The children are:

phy/phy-ee080200.usb-phy.2
phy/phy-ee0a0200.usb-phy.0
phy/phy-ee0c0200.usb-phy.1

all without a driver, according to sysfs.

Note that at first I had missed them, as printing the children using device_for_each_child() does not print them, unlike the hub devices that are children of the usb hosts.

With some debug code added, logging inc/dec of child_count:

USB driver init:

ehci-pci: EHCI PCI platform driver
ehci-platform: EHCI generic platform driver
+phy_rcar_gen3_usb2 ee0a0200.usb-phy: rpm_resume:830: inc child_count of parent soc
+phy phy-ee0a0200.usb-phy.0: rpm_resume:830: inc child_count of parent ee0a0200.usb-phy
+phy phy-ee0a0200.usb-phy.0: rpm_suspend:606: dec child_count of parent ee0a0200.usb-phy
+phy phy-ee0a0200.usb-phy.0: rpm_resume:759: inc child_count of parent ee0a0200.usb-phy

+phy_rcar_gen3_usb2 ee0c0200.usb-phy: rpm_resume:830: inc child_count of parent soc
+phy phy-ee0c0200.usb-phy.1: rpm_resume:830: inc child_count of parent ee0c0200.usb-phy
+phy phy-ee0c0200.usb-phy.1: rpm_suspend:606: dec child_count of parent ee0c0200.usb-phy
+phy phy-ee0c0200.usb-phy.1: rpm_resume:759: inc child_count of parent ee0c0200.usb-phy

+phy phy-ee080200.usb-phy.2: rpm_resume:830: inc child_count of parent ee080200.usb-phy
+phy phy-ee080200.usb-phy.2: rpm_suspend:606: dec child_count of parent ee080200.usb-phy
+phy phy-ee080200.usb-phy.2: rpm_resume:759: inc child_count of parent ee080200.usb-phy

Somehow the phy class phy-ee0*0200.usb-phy.* devices have the platform ee0*0200.usb-phy devices as parent, but they're not part of the list of children? Looks like a bug in the USB PHY driver or subsystem.

USB hub instantiation:

+usb usb3: __pm_runtime_set_status:1131: inc child_count of parent ee0a0000.usb +usb usb3: rpm_suspend:606: dec child_count of parent ee0a0000.usb

+usb usb4: __pm_runtime_set_status:1131: inc child_count of parent ee0c0000.usb +usb usb4: rpm_suspend:606: dec child_count of parent ee0c0000.usb

+usb usb6: __pm_runtime_set_status:1131: inc child_count of parent ee080000.usb +usb usb6: rpm_suspend:606: dec child_count of parent ee080000.usb

System suspend:

+usb usb6: rpm_resume:830: inc child_count of parent ee080000.usb +usb usb3: rpm_resume:830: inc child_count of parent ee0a0000.usb +usb usb4: rpm_resume:830: inc child_count of parent ee0c0000.usb

System resume:

Enabling runtime PM for inactive device (ee0c0200.usb-phy) with active children Enabling runtime PM for inactive device (ee0c0200.usb-phy) with active children Enabling runtime PM for inactive device (ee0a0000.usb) with active children Enabling runtime PM for inactive device (ee0c0000.usb) with active children Enabling runtime PM for inactive device (ee080200.usb-phy) with active children Enabling runtime PM for inactive device (ee080000.usb) with active children

+usb usb4: rpm_suspend:606: dec child_count of parent ee0c0000.usb +usb usb6: rpm_suspend:606: dec child_count of parent ee080000.usb +usb usb3: rpm_suspend:606: dec child_count of parent ee0a0000.usb

Gr{oetje,eeting}s,

Geert

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

#20 lore raw
In reply to Ulf Hansson

Hi,

Quoted 4 lines

From: Ulf Hansson, Sent: Wednesday, November 29, 2017 6:59 PM

Quoted 1 line · Geert Uytterhoeven

Hi Ulf,

<snip>

Quoted 2 lines

Okay, so the problem remains no matter which solution for wakeup you pick in genpd.

Yes. Today I could reproduce this issue without usb host driver.
- The renesas_usb3 usb peripheral driver has generic phy handling.
(The peripheral driver uses different generic phy driver (phy-rcar-gen3-usb3.c) though.)
--> If I used the current renesas_usb3 (this means doesn't call phy_power_{on,off}(),
the issue didn't happen.
--> If I added phy_power_{on,off}() calling, the issue happened.
--> So, I'm thinking the APIs are related to the issue.

- The generic phy APIs are in drivers/phy/phy-core.c.
--> The phy-rcar-gen3-usb[23] drivers call only pm_runtime_enable() before devm_phy_create().
--> The phy-core will call pm_runtime_{get_sync,put}() in phy_{init,exit,power_{on,off}}.
--> So, IIUC, both devices of phy-<dev_name>.<id> and <dev_name> will be handled by runtime PM APIs.
--> The runtime PM implementation of phy-core seems good to me. But...?

Quoted 2 lines

Then this seems to point to that the driver may be misbehaving in some way. I can help to check what is going on.

I guess so. But, I don't find yet...

Best regards,
Yoshihiro Shimoda

Quoted 2 lines

Kind regards
Uffe

#21 lore raw

+ Kishon

Quoted 10 lines · Yoshihiro Shimoda

Hi,

Quoted 4 lines

From: Ulf Hansson, Sent: Wednesday, November 29, 2017 6:59 PM

Quoted 1 line · Geert Uytterhoeven

Hi Ulf,

<snip>

Quoted 2 lines

Okay, so the problem remains no matter which solution for wakeup you pick in genpd.

Quoted 7 lines

Yes. Today I could reproduce this issue without usb host driver.
- The renesas_usb3 usb peripheral driver has generic phy handling.
(The peripheral driver uses different generic phy driver (phy-rcar-gen3-usb3.c) though.)
--> If I used the current renesas_usb3 (this means doesn't call phy_power_{on,off}(),
the issue didn't happen.
--> If I added phy_power_{on,off}() calling, the issue happened.
--> So, I'm thinking the APIs are related to the issue.

Yes.

Quoted 6 lines

- The generic phy APIs are in drivers/phy/phy-core.c.
--> The phy-rcar-gen3-usb[23] drivers call only pm_runtime_enable() before devm_phy_create().
--> The phy-core will call pm_runtime_{get_sync,put}() in phy_{init,exit,power_{on,off}}.
--> So, IIUC, both devices of phy-<dev_name>.<id> and <dev_name> will be handled by runtime PM APIs.
--> The runtime PM implementation of phy-core seems good to me. But...?

I have digested the information that you and Geert provided, thanks!

So, my conclusions so far is:

The phy core is using runtime PM reference counting at phy_power_on|off(). Although it does that on the phy core device, which is a child device of the phy provider device.

Because phy_power_off() is called during system suspend from phy consumer drivers like usb, the phy core device (child) and the phy provider device (parent) will never become runtime suspended (because the PM core has invoked pm_runtime_get_no_resume() for all device in the device prepare phase).

Then, when genpd calls pm_runtime_force_suspend() at the suspend noirq phase for the phy provider device, the call to pm_runtime_set_suspended() in there, triggers the earlier error message, which is because the child (phy core device) is still runtime resumed.

Quoted 5 lines
Quoted 3 lines

Then this seems to point to that the driver may be misbehaving in some way. I can help to check what is going on.

I guess so. But, I don't find yet...

I think the below patch will help, although I am not sure if that is sufficient as a long term fix.

Can you please try and see if it solves the problems?

From: Ulf Hansson <[email protected]>
Date: Fri, 1 Dec 2017 09:07:54 +0100
Subject: [PATCH] phy: core: Move runtime PM reference counting to be done on
the parent

This is temporary hack, do not merge!

The runtime PM deployment in the phy core is a bit unnecessary complicated, due to enabling runtime PM for the phy device. Moreover it causes problems for parent devices (phy providers) when dealing with system wide PM.

Therefore, move the runtime PM reference counting to be done on the phy's parent device and drop to enable runtime PM for the phy device altogether. This simplifies for the phy provider driver, to deal with system wide PM, in case it also cares about keeping the runtime PM status of the device in sync with the state of the HW.

---
 drivers/phy/phy-core.c | 35 +++++++++--------------------------
 1 file changed, 9 insertions(+), 26 deletions(-)
drivers/phy/phy-core.c +9 -20
index b4964b0..837e50d 100644
@@ -217,15 +217,12 @@ EXPORT_SYMBOL_GPL(phy_pm_runtime_forbid);
 
 int phy_init(struct phy *phy)
 {
-       int ret;
+       int ret = 0;
 
        if (!phy)
                return 0;
 
-       ret = phy_pm_runtime_get_sync(phy);
-       if (ret < 0 && ret != -ENOTSUPP)
-               return ret;
-       ret = 0; /* Override possible ret == -ENOTSUPP */
+       pm_runtime_get_sync(phy->dev.parent);
 
        mutex_lock(&phy->mutex);
        if (phy->init_count == 0 && phy->ops->init) {
@@ -239,22 +236,19 @@ int phy_init(struct phy *phy)
 
 out:
        mutex_unlock(&phy->mutex);
-       phy_pm_runtime_put(phy);
+       pm_runtime_put(phy->dev.parent);
        return ret;
 }
 EXPORT_SYMBOL_GPL(phy_init);
 
 int phy_exit(struct phy *phy)
 {
-       int ret;
+       int ret = 0;
 
        if (!phy)
                return 0;
 
-       ret = phy_pm_runtime_get_sync(phy);
-       if (ret < 0 && ret != -ENOTSUPP)
-               return ret;
-       ret = 0; /* Override possible ret == -ENOTSUPP */
+       pm_runtime_get_sync(phy->dev.parent);
 
        mutex_lock(&phy->mutex);
        if (phy->init_count == 1 && phy->ops->exit) {
@@ -268,7 +262,7 @@ int phy_exit(struct phy *phy)
 
 out:
        mutex_unlock(&phy->mutex);
-       phy_pm_runtime_put(phy);
+       pm_runtime_put(phy->dev.parent);
        return ret;
 }
 EXPORT_SYMBOL_GPL(phy_exit);
@@ -286,11 +280,7 @@ int phy_power_on(struct phy *phy)
                        goto out;
        }
 
-       ret = phy_pm_runtime_get_sync(phy);
-       if (ret < 0 && ret != -ENOTSUPP)
-               goto err_pm_sync;
-
-       ret = 0; /* Override possible ret == -ENOTSUPP */
+       pm_runtime_get_sync(phy->dev.parent);
 
        mutex_lock(&phy->mutex);
        if (phy->power_count == 0 && phy->ops->power_on) {
@@ -306,8 +296,7 @@ int phy_power_on(struct phy *phy)
 
 err_pwr_on:
        mutex_unlock(&phy->mutex);
-       phy_pm_runtime_put_sync(phy);
-err_pm_sync:
+       pm_runtime_put(phy->dev.parent);
        if (phy->pwr)
                regulator_disable(phy->pwr);
 out:
@@ -333,7 +322,7 @@ int phy_power_off(struct phy *phy)
        }
        --phy->power_count;
        mutex_unlock(&phy->mutex);
-       phy_pm_runtime_put(phy);
+       pm_runtime_put(phy->dev.parent);
 
        if (phy->pwr)
                regulator_disable(phy->pwr);
@@ -774,11 +763,6 @@ struct phy *phy_create(struct device *dev, struct

device_node *node,

        if (ret)
                goto put_dev;

- if (pm_runtime_enabled(dev)) {
- pm_runtime_enable(&phy->dev);
- pm_runtime_no_callbacks(&phy->dev);
- }
-

        return phy;

put_dev:
@@ -831,7 +815,6 @@ EXPORT_SYMBOL_GPL(devm_phy_create);
*/
void phy_destroy(struct phy *phy)
{

-       pm_runtime_disable(&phy->dev);
        device_unregister(&phy->dev);

}
EXPORT_SYMBOL_GPL(phy_destroy);

Signature · 4 lines
2.7.4

Kind regards
Uffe
#22 lore raw

Hi,

Quoted 48 lines

From: Ulf Hansson, Sent: Friday, December 1, 2017 6:22 PM

+ Kishon

Quoted 10 lines · Yoshihiro Shimoda

Hi,

Quoted 4 lines

From: Ulf Hansson, Sent: Wednesday, November 29, 2017 6:59 PM

Quoted 1 line · Geert Uytterhoeven

Hi Ulf,

<snip>

Quoted 2 lines

Okay, so the problem remains no matter which solution for wakeup you pick in genpd.

Quoted 7 lines

Yes. Today I could reproduce this issue without usb host driver.
- The renesas_usb3 usb peripheral driver has generic phy handling.
(The peripheral driver uses different generic phy driver (phy-rcar-gen3-usb3.c) though.)
--> If I used the current renesas_usb3 (this means doesn't call phy_power_{on,off}(),
the issue didn't happen.
--> If I added phy_power_{on,off}() calling, the issue happened.
--> So, I'm thinking the APIs are related to the issue.

Yes.

Quoted 6 lines

- The generic phy APIs are in drivers/phy/phy-core.c.
--> The phy-rcar-gen3-usb[23] drivers call only pm_runtime_enable() before devm_phy_create().
--> The phy-core will call pm_runtime_{get_sync,put}() in phy_{init,exit,power_{on,off}}.
--> So, IIUC, both devices of phy-<dev_name>.<id> and <dev_name> will be handled by runtime PM APIs.
--> The runtime PM implementation of phy-core seems good to me. But...?

I have digested the information that you and Geert provided, thanks!

So, my conclusions so far is:

The phy core is using runtime PM reference counting at phy_power_on|off(). Although it does that on the phy core device, which is a child device of the phy provider device.

Because phy_power_off() is called during system suspend from phy consumer drivers like usb, the phy core device (child) and the phy provider device (parent) will never become runtime suspended (because the PM core has invoked pm_runtime_get_no_resume() for all device in the device prepare phase).

Quoted 5 lines

Then, when genpd calls pm_runtime_force_suspend() at the suspend noirq phase for the phy provider device, the call to pm_runtime_set_suspended() in there, triggers the earlier error message, which is because the child (phy core device) is still runtime resumed.

Thank you very much for the conclusions!
It's helpful to me about runtime PM behavior.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Then this seems to point to that the driver may be misbehaving in some way. I can help to check what is going on.

I guess so. But, I don't find yet...

I think the below patch will help, although I am not sure if that is sufficient as a long term fix.

Thank you very much for your help!
Also, I'm not sure how to fix for a long term kernels though...

Quoted 1 line

Can you please try and see if it solves the problems?

Sure! I tested your patch, and then the following message disappeared!

Enabling runtime PM for inactive device (ee080200.usb-phy) with active children

However, the following message still exists.

Enabling runtime PM for inactive device (ee080000.usb) with active children

So, I guess ohci-platform.c also has similar issue.

JFYI, the ehci-platform.c doesn't have runtime PM handling. So, I think that error message doesn't output from ehci devices.

Best regards,
Yoshihiro Shimoda

#23 lore raw

Hi again,

Quoted 4 lines

From: Yoshihiro Shimoda, Sent: Friday, December 1, 2017 8:04 PM

Hi,

<snip>

Quoted 8 lines

However, the following message still exists.

Enabling runtime PM for inactive device (ee080000.usb) with active children

So, I guess ohci-platform.c also has similar issue.

JFYI, the ehci-platform.c doesn't have runtime PM handling. So, I think that error message doesn't output from ehci devices.

I have update.
If I added to call pm_runtime_forbid() in ohci-platform.c like xhci-plat.c, the issue disappeared. I don't understand the pm_runtime_forbid() behavior yet, but is this acceptable?

Best regards,
Yoshihiro Shimoda

Quoted 2 lines

Best regards,
Yoshihiro Shimoda

#24 lore raw
In reply to Yoshihiro Shimoda
Quoted 67 lines · Yoshihiro Shimoda

Hi,

Quoted 48 lines

From: Ulf Hansson, Sent: Friday, December 1, 2017 6:22 PM

+ Kishon

Quoted 10 lines · Yoshihiro Shimoda

Hi,

Quoted 4 lines

From: Ulf Hansson, Sent: Wednesday, November 29, 2017 6:59 PM

Quoted 1 line · Geert Uytterhoeven

Hi Ulf,

<snip>

Quoted 2 lines

Okay, so the problem remains no matter which solution for wakeup you pick in genpd.

Quoted 7 lines

Yes. Today I could reproduce this issue without usb host driver.
- The renesas_usb3 usb peripheral driver has generic phy handling.
(The peripheral driver uses different generic phy driver (phy-rcar-gen3-usb3.c) though.)
--> If I used the current renesas_usb3 (this means doesn't call phy_power_{on,off}(),
the issue didn't happen.
--> If I added phy_power_{on,off}() calling, the issue happened.
--> So, I'm thinking the APIs are related to the issue.

Yes.

Quoted 6 lines

- The generic phy APIs are in drivers/phy/phy-core.c.
--> The phy-rcar-gen3-usb[23] drivers call only pm_runtime_enable() before devm_phy_create().
--> The phy-core will call pm_runtime_{get_sync,put}() in phy_{init,exit,power_{on,off}}.
--> So, IIUC, both devices of phy-<dev_name>.<id> and <dev_name> will be handled by runtime PM APIs.
--> The runtime PM implementation of phy-core seems good to me. But...?

I have digested the information that you and Geert provided, thanks!

So, my conclusions so far is:

The phy core is using runtime PM reference counting at phy_power_on|off(). Although it does that on the phy core device, which is a child device of the phy provider device.

Because phy_power_off() is called during system suspend from phy consumer drivers like usb, the phy core device (child) and the phy provider device (parent) will never become runtime suspended (because the PM core has invoked pm_runtime_get_no_resume() for all device in the device prepare phase).

Quoted 5 lines

Then, when genpd calls pm_runtime_force_suspend() at the suspend noirq phase for the phy provider device, the call to pm_runtime_set_suspended() in there, triggers the earlier error message, which is because the child (phy core device) is still runtime resumed.

Thank you very much for the conclusions!
It's helpful to me about runtime PM behavior.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Then this seems to point to that the driver may be misbehaving in some way. I can help to check what is going on.

I guess so. But, I don't find yet...

I think the below patch will help, although I am not sure if that is sufficient as a long term fix.

Quoted 8 lines

Thank you very much for your help!
Also, I'm not sure how to fix for a long term kernels though...

Quoted 1 line

Can you please try and see if it solves the problems?

Sure! I tested your patch, and then the following message disappeared!

Enabling runtime PM for inactive device (ee080200.usb-phy) with active children

Great, that confirms my theory.

I will re-work the patch and re-post it to see what people thinks about it.

Quoted 6 lines

However, the following message still exists.

Enabling runtime PM for inactive device (ee080000.usb) with active children

So, I guess ohci-platform.c also has similar issue.

Yes, very likely!

However, I need some more time to look into this to be able to suggest a solution.

Quoted 3 lines

JFYI, the ehci-platform.c doesn't have runtime PM handling. So, I think that error message doesn't output from ehci devices.

Right, thanks!

Kind regards
Uffe

#25 lore raw

SGksDQoNCj4gRnJvbTogVWxmIEhhbnNzb24sIFNlbnQ6IE1vbmRheSwgRGVjZW1iZXIgNCwgMjAx NyA3OjQxIFBNDQo+IA0KPiBPbiAxIERlY2VtYmVyIDIwMTcgYXQgMTI6MDMsIFlvc2hpaGlybyBT aGltb2RhDQo+IDx5b3NoaWhpcm8uc2hpbW9kYS51aEByZW5lc2FzLmNvbT4gd3JvdGU6DQo8c25p cD4NCj4gPiBTdXJlISBJIHRlc3RlZCB5b3VyIHBhdGNoLCBhbmQgdGhlbiB0aGUgZm9sbG93aW5n IG1lc3NhZ2UgZGlzYXBwZWFyZWQhDQo+ID4NCj4gPiAgICBFbmFibGluZyBydW50aW1lIFBNIGZv ciBpbmFjdGl2ZSBkZXZpY2UgKGVlMDgwMjAwLnVzYi1waHkpIHdpdGggYWN0aXZlIGNoaWxkcmVu DQo+IA0KPiBHcmVhdCwgdGhhdCBjb25maXJtcyBteSB0aGVvcnkuDQo+IA0KPiBJIHdpbGwgcmUt d29yayB0aGUgcGF0Y2ggYW5kIHJlLXBvc3QgaXQgdG8gc2VlIHdoYXQgcGVvcGxlIHRoaW5rcyBh Ym91dCBpdC4NCg0KVGhhbmsgeW91IQ0KDQo+ID4NCj4gPiBIb3dldmVyLCB0aGUgZm9sbG93aW5n IG1lc3NhZ2Ugc3RpbGwgZXhpc3RzLg0KPiA+DQo+ID4gICAgRW5hYmxpbmcgcnVudGltZSBQTSBm b3IgaW5hY3RpdmUgZGV2aWNlIChlZTA4MDAwMC51c2IpIHdpdGggYWN0aXZlIGNoaWxkcmVuDQo+ ID4NCj4gPiBTbywgSSBndWVzcyBvaGNpLXBsYXRmb3JtLmMgYWxzbyBoYXMgc2ltaWxhciBpc3N1 ZS4NCj4gDQo+IFllcywgdmVyeSBsaWtlbHkhDQo+IA0KPiBIb3dldmVyLCBJIG5lZWQgc29tZSBt b3JlIHRpbWUgdG8gbG9vayBpbnRvIHRoaXMgdG8gYmUgYWJsZSB0byBzdWdnZXN0DQo+IGEgc29s dXRpb24uDQoNCkkgZm91bmQgYSBzb2x1dGlvbiBhbmQgc2VudCBhIHJlcG9ydCBhcyBiZWxvdzoN Cmh0dHBzOi8vd3d3Lm1haWwtYXJjaGl2ZS5jb20vbGludXgta2VybmVsQHZnZXIua2VybmVsLm9y Zy9tc2cxNTUxMTQ2Lmh0bWwNCg0KV2hhdCBkbyB5b3UgdGhpbmsgYWJvdXQgdXNpbmcgcG1fcnVu dGltZV9mb3JiaWQoKT8NCg0KQmVzdCByZWdhcmRzLA0KWW9zaGloaXJvIFNoaW1vZGENCg0K --
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#26 lore raw
Quoted 26 lines · Yoshihiro Shimoda

Hi,

Quoted 4 lines

From: Ulf Hansson, Sent: Monday, December 4, 2017 7:41 PM

On 1 December 2017 at 12:03, Yoshihiro Shimoda
<[email protected]> wrote:

<snip>

Quoted 7 lines
Quoted 3 lines

Sure! I tested your patch, and then the following message disappeared!

Enabling runtime PM for inactive device (ee080200.usb-phy) with active children

Great, that confirms my theory.

I will re-work the patch and re-post it to see what people thinks about it.

Thank you!

Quoted 9 lines
Quoted 6 lines

However, the following message still exists.

Enabling runtime PM for inactive device (ee080000.usb) with active children

So, I guess ohci-platform.c also has similar issue.

Yes, very likely!

Quoted 7 lines
Quoted 2 lines

However, I need some more time to look into this to be able to suggest a solution.

I found a solution and sent a report as below:
https://www.mail-archive.com/[email protected]/msg1551146.html

What do you think about using pm_runtime_forbid()?

In general, drivers should not use pm_runtime_forbid().

It is meant for use by userspace, through the /sys/.../power/control file. Drivers cannot rely on the result of calling pm_runtime_forbid() or pm_runtime_allow(), because the user can change it at any time.

If you really want to prevent the OHCI controller from going into runtime suspend, the proper approach is to call pm_runtime_get() in the probe routine and pm_runtime_put() in the release routine. However, this will waste energy because it will force the controller to remain at full power even when no active devices are attached.

In this case, there probably is a better to solution to your problem (such as fixing the runtime PM support in the phy driver).

Alan Stern

#27 lore raw
Quoted 31 lines · Alan Stern
Quoted 29 lines · Yoshihiro Shimoda

Hi,

Quoted 4 lines

From: Ulf Hansson, Sent: Monday, December 4, 2017 7:41 PM

On 1 December 2017 at 12:03, Yoshihiro Shimoda
<[email protected]> wrote:

<snip>

Quoted 7 lines
Quoted 3 lines

Sure! I tested your patch, and then the following message disappeared!

Enabling runtime PM for inactive device (ee080200.usb-phy) with active children

Great, that confirms my theory.

I will re-work the patch and re-post it to see what people thinks about it.

Thank you!

Quoted 11 lines
Quoted 6 lines

However, the following message still exists.

Enabling runtime PM for inactive device (ee080000.usb) with active children

So, I guess ohci-platform.c also has similar issue.

Yes, very likely!

However, I need some more time to look into this to be able to suggest a solution.

Quoted 6 lines
Quoted 4 lines

I found a solution and sent a report as below:
https://www.mail-archive.com/[email protected]/msg1551146.html

What do you think about using pm_runtime_forbid()?

In general, drivers should not use pm_runtime_forbid().

I'd rather say that it's not very useful to them. :-)

Quoted 1 line

It is meant for use by userspace, through the /sys/.../power/control file.

Or when the driver wants to change the default setting.

Quoted 2 lines

Drivers cannot rely on the result of calling pm_runtime_forbid() or pm_runtime_allow(), because the user can change it at any time.

Right.

Quoted 8 lines

If you really want to prevent the OHCI controller from going into runtime suspend, the proper approach is to call pm_runtime_get() in the probe routine and pm_runtime_put() in the release routine. However, this will waste energy because it will force the controller to remain at full power even when no active devices are attached.

In this case, there probably is a better to solution to your problem (such as fixing the runtime PM support in the phy driver).

Agreed.

Thanks,
Rafael

#28 lore raw
In reply to Yoshihiro Shimoda
Quoted 26 lines · Yoshihiro Shimoda

Hi,

Quoted 4 lines

From: Ulf Hansson, Sent: Monday, December 4, 2017 7:41 PM

On 1 December 2017 at 12:03, Yoshihiro Shimoda
<[email protected]> wrote:

<snip>

Quoted 7 lines
Quoted 3 lines

Sure! I tested your patch, and then the following message disappeared!

Enabling runtime PM for inactive device (ee080200.usb-phy) with active children

Great, that confirms my theory.

I will re-work the patch and re-post it to see what people thinks about it.

Thank you!

Quoted 9 lines
Quoted 6 lines

However, the following message still exists.

Enabling runtime PM for inactive device (ee080000.usb) with active children

So, I guess ohci-platform.c also has similar issue.

Yes, very likely!

Quoted 7 lines
Quoted 2 lines

However, I need some more time to look into this to be able to suggest a solution.

I found a solution and sent a report as below:
https://www.mail-archive.com/[email protected]/msg1551146.html

What do you think about using pm_runtime_forbid()?

As both Alan and Rafael pointed out in their replies, this is not the right solution.

However, what is indeed interesting is how it can silence the error messages. I keep this is mind while later moving forward.

Kind regards
Uffe

#29 lore raw
In reply to Geert Uytterhoeven
Quoted 84 lines · Geert Uytterhoeven

Hi Rafael, Shimoda-san,

Quoted 30 lines · Rafael J. Wysocki

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

The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation.

For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable().

---
 drivers/base/power/runtime.c |   30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c +1 -1
@@ -1101,29 +1101,13 @@ int __pm_runtime_set_status(struct devic
                goto out;
        }
 
-       if (dev->power.runtime_status == status)
+       if (dev->power.runtime_status == status || !parent)

drivers/base/power/runtime.c int __pm_runtime_set_status(struct devic · line 1114

Quoted 10 lines
drivers/base/power/runtime.c +0 -7
                goto out_set;
 
        if (status == RPM_SUSPENDED) {
-               /*
-                * It is invalid to suspend a device with an active child,
-                * unless it has been set to ignore its children.
-                */
-               if (!dev->power.ignore_children &&
-                       atomic_read(&dev->power.child_count)) {
-                       dev_err(dev, "runtime PM trying to suspend device but active child\n");

JFTR, this triggered before during system resume on e.g. Salvator-XS with R-Car H3:

ohci-platform ee080000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee080200.usb-phy: runtime PM trying to suspend
device but active child
ohci-platform ee0c0000.usb: runtime PM trying to suspend device
but active child
ohci-platform ee0a0000.usb: runtime PM trying to suspend device
but active child
phy_rcar_gen3_usb2 ee0c0200.usb-phy: runtime PM trying to suspend
device but active child
phy_rcar_gen3_usb2 ee0a0200.usb-phy: runtime PM trying to suspend
device but active child

so this was an existing issue with USB before.

Quoted 22 lines
drivers/base/power/runtime.c +3 -12
-                       error = -EBUSY;
-                       goto out;
-               }
-
-               if (parent) {
-                       atomic_add_unless(&parent->power.child_count, -1, 0);
-                       notify_parent = !parent->power.ignore_children;
-               }
-               goto out_set;
-       }
-
-       if (parent) {
+               atomic_add_unless(&parent->power.child_count, -1, 0);
+               notify_parent = !parent->power.ignore_children;
+       } else {
                spin_lock_nested(&parent->power.lock, SINGLE_DEPTH_NESTING);
 
                /*
@@ -1307,6 +1291,12 @@ void pm_runtime_enable(struct device *de
        else
                dev_warn(dev, "Unbalanced %s!\n", __func__);
 
Quoted 7 lines

drivers/base/power/runtime.c void pm_runtime_enable(struct device *de · line 1298

Quoted 5 lines
drivers/base/power/runtime.c +5 -0
+       WARN(dev->power.runtime_status == RPM_SUSPENDED &&
+            !dev->power.ignore_children &&
+            atomic_read(&dev->power.child_count) > 0,
+            "Enabling runtime PM for inactive device (%s) with active children\n",
+            dev_name(dev));

And now it became a bit more noisy:

Well, it's all existing issues, although the WARN() doesn't provide additional information in this particular case.

I'm considering changing it to print a message without a stack trace.

Thanks,
Rafael