Skip to contentSkip to conversation

PM / Domains: Fix error path during attach in genpd

PATCH In review Leonard Crestez 2 participants 3 messages Sep 3, 2018 1 message not in the archive

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

PATCH 1/2 PM / Domains: Fix error path during attach in genpd

In reply to a message not in the archive

From: Ulf Hansson <[email protected]>

In case the PM domain fails to be powered on in genpd_dev_pm_attach(), it returns -EPROBE_DEFER, but keeping the device attached to its PM domain. This leads to problems when the next attempt to attach is re-tried. More precisely, in that situation an -EEXIST error code is returned, because the device already has its PM domain pointer assigned, from the first attempt.

Now, because of the sloppy error handling by the existing callers of dev_pm_domain_attach(), probing is allowed to continue when -EEXIST is returned. However, in such case there are no guarantees that the PM domain is powered on by genpd, which may lead to hangs when buses/drivers tried to access their devices.

Let's fix this behaviour, simply by detaching the device when powering on fails in genpd_dev_pm_attach().

(cherry picked from commit 72038df3c580c4c326b83c86149d7ac34007532a)

Cherry-picked to imx_4.9.y with minimal conflicts so that we can properly handle errors from SCFW pm calls

---
 drivers/base/power/domain.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/base/power/domain.c +3 -0
index 9c3e535795a0..d9681d372997 100644
@@ -1936,10 +1936,13 @@ int genpd_dev_pm_attach(struct device *dev)
 	dev->pm_domain->sync = genpd_dev_pm_sync;
 
 	mutex_lock(&pd->lock);
 	ret = genpd_poweron(pd, 0);
 	mutex_unlock(&pd->lock);
+
+	if (ret)
+		genpd_remove_device(pd, dev);
 out:
 	return ret ? -EPROBE_DEFER : 0;
 }
 EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
Signature · 1 line
2.17.1
Reviewed-by on v1 1/2
#2 lore raw
Quoted 27 lines

-----Original Message-----
From: Leonard Crestez
Sent: Monday, September 3, 2018 6:16 PM
To: Anson Huang <[email protected]>; A.s. Dong <[email protected]>
Cc: Ranjani Vaidyanathan <[email protected]>; Nitin Garg <[email protected]>; Jason Liu <[email protected]>; Pete Zhang <[email protected]>; Eagle Zhou <[email protected]>; LnxRevLi <[email protected]>; Ulf Hansson <[email protected]>; v4 . 11+ <[email protected]>; Rafael J . Wysocki <[email protected]>
Subject: [PATCH imx_4.9.y 1/2] PM / Domains: Fix error path during attach in genpd

From: Ulf Hansson <[email protected]>

In case the PM domain fails to be powered on in genpd_dev_pm_attach(), it returns -EPROBE_DEFER, but keeping the device attached to its PM domain. This leads to problems when the next attempt to attach is re-tried. More precisely, in that situation an -EEXIST error code is returned, because the device already has its PM domain pointer assigned, from the first attempt.

Now, because of the sloppy error handling by the existing callers of dev_pm_domain_attach(), probing is allowed to continue when -EEXIST is returned. However, in such case there are no guarantees that the PM domain is powered on by genpd, which may lead to hangs when buses/drivers tried to access their devices.

Quoted 4 lines

Let's fix this behaviour, simply by detaching the device when powering on fails in genpd_dev_pm_attach().

Cc v4.11+ <[email protected]> # v4.11+

Although this patch is stated only needed for v4.11+, but it seems to me 4.9 has the same issue and also needs it.

Hi Leonard,
I guess you could also try to send it to 4.9 LTS kernel maillist to test maintainer later.

Regards
Dong Aisheng

Quoted 32 lines

(cherry picked from commit 72038df3c580c4c326b83c86149d7ac34007532a)

Cherry-picked to imx_4.9.y with minimal conflicts so that we can properly handle errors from SCFW pm calls

---
 drivers/base/power/domain.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/base/power/domain.c index renamed from drivers/base/power/domain.c +0 -0

9c3e535795a0..d9681d372997 100644

drivers/base/power/domain.c +3 -1
@@ -1936,10 +1936,13 @@ int genpd_dev_pm_attach(struct device *dev)
 	dev->pm_domain->sync = genpd_dev_pm_sync;
 
 	mutex_lock(&pd->lock);
 	ret = genpd_poweron(pd, 0);
 	mutex_unlock(&pd->lock);
+
+	if (ret)
+		genpd_remove_device(pd, dev);
 out:
 	return ret ? -EPROBE_DEFER : 0;
 }
 EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
--

2.17.1

#3 lore raw
In reply to Leonard Crestez
Quoted 51 lines

-----Original Message-----
From: Leonard Crestez
Sent: Monday, September 3, 2018 6:16 PM
To: Anson Huang <[email protected]>; A.s. Dong <[email protected]>
Cc: Ranjani Vaidyanathan <[email protected]>; Nitin Garg <[email protected]>; Jason Liu <[email protected]>; Pete Zhang <[email protected]>; Eagle Zhou <[email protected]>; LnxRevLi <[email protected]>; Ulf Hansson <[email protected]>; v4 . 11+ <[email protected]>; Rafael J . Wysocki <[email protected]>
Subject: [PATCH imx_4.9.y 1/2] PM / Domains: Fix error path during attach in genpd

From: Ulf Hansson <[email protected]>

In case the PM domain fails to be powered on in genpd_dev_pm_attach(), it returns -EPROBE_DEFER, but keeping the device attached to its PM domain. This leads to problems when the next attempt to attach is re-tried. More precisely, in that situation an -EEXIST error code is returned, because the device already has its PM domain pointer assigned, from the first attempt.

Now, because of the sloppy error handling by the existing callers of dev_pm_domain_attach(), probing is allowed to continue when -EEXIST is returned. However, in such case there are no guarantees that the PM domain is powered on by genpd, which may lead to hangs when buses/drivers tried to access their devices.

Let's fix this behaviour, simply by detaching the device when powering on fails in genpd_dev_pm_attach().

(cherry picked from commit 72038df3c580c4c326b83c86149d7ac34007532a)

Cherry-picked to imx_4.9.y with minimal conflicts so that we can properly handle errors from SCFW pm calls

---
 drivers/base/power/domain.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/base/power/domain.c index renamed from drivers/base/power/domain.c +0 -0

9c3e535795a0..d9681d372997 100644

drivers/base/power/domain.c +0 -0
@@ -1936,10 +1936,13 @@ int genpd_dev_pm_attach(struct device *dev)
 	dev->pm_domain->sync = genpd_dev_pm_sync;
 
 	mutex_lock(&pd->lock);

drivers/base/power/domain.c int genpd_dev_pm_attach(struct device *dev) · line 1948

Quoted 10 lines
drivers/base/power/domain.c +3 -0
 	ret = genpd_poweron(pd, 0);
 	mutex_unlock(&pd->lock);
+
+	if (ret)
+		genpd_remove_device(pd, dev);
 out:
 	return ret ? -EPROBE_DEFER : 0;
 }
 EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */

BTW, it looks to me this is not a complete fix.

static int platform_drv_probe(struct device *_dev) {

        ret = dev_pm_domain_attach(_dev, true);
        if (ret != -EPROBE_DEFER) {	<---- here is risk as it's only hanlle EPROBE_DEFFER. Latest upstream is already changed. However, it may not cause real issue for our case.
                if (drv->probe) {
                        ret = drv->probe(dev);
                        if (ret)
                                dev_pm_domain_detach(_dev, true);
                } else {
                        /* don't fail if just dev_pm_domain_attach failed */
                        ret = 0;
                }
        }       
        ...

        return ret; 
}
Quoted 2 lines

--
2.17.1