All of lore.kernel.org
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kevin Hilman <khilman@kernel.org>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Sudeep Holla <sudeep.holla@arm.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	Adrien Thierry <athierry@redhat.com>,
	Brian Masney <bmasney@redhat.com>,
	linux-rt-users@vger.kernel.org
Subject: [PATCH v2 4/5] PM: Allow calling dev_pm_domain_set() with raw spinlock
Date: Mon, 19 Dec 2022 16:15:02 +0100	[thread overview]
Message-ID: <20221219151503.385816-5-krzysztof.kozlowski@linaro.org> (raw)
In-Reply-To: <20221219151503.385816-1-krzysztof.kozlowski@linaro.org>

device_pm_check_callbacks() uses dev->power spinlock, which on
PREEMPT_RT sleeps.  However some PM domains on PREEMPT_RT might be using
raw spinlocks as genpd_lock(), thus dev_pm_domain_set() must not call
device_pm_check_callbacks().  In fact device_pm_check_callbacks() is not
strictly related to dev_pm_domain_set() and calls for these two can be
made separately.

Add new helper dev_pm_domain_set_no_cb() which will only set PM domain
but will not check the callbacks, leaving the checl to the caller.

Cc: Adrien Thierry <athierry@redhat.com>
Cc: Brian Masney <bmasney@redhat.com>
Cc: linux-rt-users@vger.kernel.org
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/base/power/common.c | 27 +++++++++++++++++++++++++--
 include/linux/pm_domain.h   |  3 +++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index 72115917e0bd..f81cab6990ad 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -218,6 +218,30 @@ EXPORT_SYMBOL_GPL(dev_pm_domain_start);
  * This function must be called with the device lock held.
  */
 void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd)
+{
+	if (dev->pm_domain == pd)
+		return;
+
+	dev_pm_domain_set_no_cb(dev, pd);
+	device_pm_check_callbacks(dev);
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_set);
+
+/**
+ * dev_pm_domain_set_no_cb - Set PM domain of a device.
+ * @dev: Device whose PM domain is to be set.
+ * @pd: PM domain to be set, or NULL.
+ *
+ * Sets the PM domain the device belongs to. The PM domain of a device needs
+ * to be set before its probe finishes (it's bound to a driver).
+ *
+ * This is exactly like dev_pm_domain_set(), however device_pm_check_callbacks()
+ * is not called and the caller is responsible to invoke
+ * device_pm_check_callbacks() with device lock held.
+ *
+ * This function must be called with the device lock held.
+ */
+void dev_pm_domain_set_no_cb(struct device *dev, struct dev_pm_domain *pd)
 {
 	if (dev->pm_domain == pd)
 		return;
@@ -225,6 +249,5 @@ void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd)
 	WARN(pd && device_is_bound(dev),
 	     "PM domains can only be changed for unbound devices\n");
 	dev->pm_domain = pd;
-	device_pm_check_callbacks(dev);
 }
-EXPORT_SYMBOL_GPL(dev_pm_domain_set);
+EXPORT_SYMBOL_GPL(dev_pm_domain_set_no_cb);
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 0a1600244963..352d0c76bfec 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -438,6 +438,7 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev,
 void dev_pm_domain_detach(struct device *dev, bool power_off);
 int dev_pm_domain_start(struct device *dev);
 void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
+void dev_pm_domain_set_no_cb(struct device *dev, struct dev_pm_domain *pd);
 #else
 static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
 {
@@ -460,6 +461,8 @@ static inline int dev_pm_domain_start(struct device *dev)
 }
 static inline void dev_pm_domain_set(struct device *dev,
 				     struct dev_pm_domain *pd) {}
+static inline void dev_pm_domain_set_no_cb(struct device *dev,
+					   struct dev_pm_domain *pd) {}
 #endif
 
 #endif /* _LINUX_PM_DOMAIN_H */
-- 
2.34.1


WARNING: multiple messages have this Message-ID (diff)
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kevin Hilman <khilman@kernel.org>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Sudeep Holla <sudeep.holla@arm.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	Adrien Thierry <athierry@redhat.com>,
	Brian Masney <bmasney@redhat.com>,
	linux-rt-users@vger.kernel.org
Subject: [PATCH v2 4/5] PM: Allow calling dev_pm_domain_set() with raw spinlock
Date: Mon, 19 Dec 2022 16:15:02 +0100	[thread overview]
Message-ID: <20221219151503.385816-5-krzysztof.kozlowski@linaro.org> (raw)
In-Reply-To: <20221219151503.385816-1-krzysztof.kozlowski@linaro.org>

device_pm_check_callbacks() uses dev->power spinlock, which on
PREEMPT_RT sleeps.  However some PM domains on PREEMPT_RT might be using
raw spinlocks as genpd_lock(), thus dev_pm_domain_set() must not call
device_pm_check_callbacks().  In fact device_pm_check_callbacks() is not
strictly related to dev_pm_domain_set() and calls for these two can be
made separately.

Add new helper dev_pm_domain_set_no_cb() which will only set PM domain
but will not check the callbacks, leaving the checl to the caller.

Cc: Adrien Thierry <athierry@redhat.com>
Cc: Brian Masney <bmasney@redhat.com>
Cc: linux-rt-users@vger.kernel.org
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/base/power/common.c | 27 +++++++++++++++++++++++++--
 include/linux/pm_domain.h   |  3 +++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index 72115917e0bd..f81cab6990ad 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -218,6 +218,30 @@ EXPORT_SYMBOL_GPL(dev_pm_domain_start);
  * This function must be called with the device lock held.
  */
 void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd)
+{
+	if (dev->pm_domain == pd)
+		return;
+
+	dev_pm_domain_set_no_cb(dev, pd);
+	device_pm_check_callbacks(dev);
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_set);
+
+/**
+ * dev_pm_domain_set_no_cb - Set PM domain of a device.
+ * @dev: Device whose PM domain is to be set.
+ * @pd: PM domain to be set, or NULL.
+ *
+ * Sets the PM domain the device belongs to. The PM domain of a device needs
+ * to be set before its probe finishes (it's bound to a driver).
+ *
+ * This is exactly like dev_pm_domain_set(), however device_pm_check_callbacks()
+ * is not called and the caller is responsible to invoke
+ * device_pm_check_callbacks() with device lock held.
+ *
+ * This function must be called with the device lock held.
+ */
+void dev_pm_domain_set_no_cb(struct device *dev, struct dev_pm_domain *pd)
 {
 	if (dev->pm_domain == pd)
 		return;
@@ -225,6 +249,5 @@ void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd)
 	WARN(pd && device_is_bound(dev),
 	     "PM domains can only be changed for unbound devices\n");
 	dev->pm_domain = pd;
-	device_pm_check_callbacks(dev);
 }
-EXPORT_SYMBOL_GPL(dev_pm_domain_set);
+EXPORT_SYMBOL_GPL(dev_pm_domain_set_no_cb);
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 0a1600244963..352d0c76bfec 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -438,6 +438,7 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev,
 void dev_pm_domain_detach(struct device *dev, bool power_off);
 int dev_pm_domain_start(struct device *dev);
 void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
+void dev_pm_domain_set_no_cb(struct device *dev, struct dev_pm_domain *pd);
 #else
 static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
 {
@@ -460,6 +461,8 @@ static inline int dev_pm_domain_start(struct device *dev)
 }
 static inline void dev_pm_domain_set(struct device *dev,
 				     struct dev_pm_domain *pd) {}
+static inline void dev_pm_domain_set_no_cb(struct device *dev,
+					   struct dev_pm_domain *pd) {}
 #endif
 
 #endif /* _LINUX_PM_DOMAIN_H */
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-12-19 15:15 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19 15:14 [PATCH v2 0/5] PM: Fixes for Realtime systems Krzysztof Kozlowski
2022-12-19 15:14 ` Krzysztof Kozlowski
2022-12-19 15:14 ` [PATCH v2 1/5] PM: domains: Add GENPD_FLAG_RT_SAFE for PREEMPT_RT Krzysztof Kozlowski
2022-12-19 15:14   ` Krzysztof Kozlowski
2023-01-04 15:45   ` Ulf Hansson
2023-01-04 15:45     ` Ulf Hansson
2023-01-06 14:52     ` Krzysztof Kozlowski
2023-01-06 14:52       ` Krzysztof Kozlowski
2023-01-12 10:36       ` Sebastian Andrzej Siewior
2023-01-12 10:36         ` Sebastian Andrzej Siewior
2023-01-12 11:27         ` Krzysztof Kozlowski
2023-01-12 11:27           ` Krzysztof Kozlowski
2023-01-12 10:32   ` Sebastian Andrzej Siewior
2023-01-12 10:32     ` Sebastian Andrzej Siewior
2023-01-12 11:31     ` Krzysztof Kozlowski
2023-01-12 11:31       ` Krzysztof Kozlowski
2022-12-19 15:15 ` [PATCH v2 2/5] cpuidle: psci: Mark as PREEMPT_RT safe Krzysztof Kozlowski
2022-12-19 15:15   ` Krzysztof Kozlowski
2023-01-12 11:00   ` Sebastian Andrzej Siewior
2023-01-12 11:00     ` Sebastian Andrzej Siewior
2023-01-12 11:32     ` Krzysztof Kozlowski
2023-01-12 11:32       ` Krzysztof Kozlowski
2023-01-17 15:27   ` Ulf Hansson
2023-01-17 15:27     ` Ulf Hansson
2023-01-19 15:40     ` Krzysztof Kozlowski
2023-01-19 15:40       ` Krzysztof Kozlowski
2023-01-19 17:06       ` Krzysztof Kozlowski
2023-01-19 17:06         ` Krzysztof Kozlowski
2022-12-19 15:15 ` [PATCH v2 3/5] cpuidle: psci: Do not suspend topology CPUs on PREEMPT_RT Krzysztof Kozlowski
2022-12-19 15:15   ` Krzysztof Kozlowski
2023-01-12 11:09   ` Sebastian Andrzej Siewior
2023-01-12 11:09     ` Sebastian Andrzej Siewior
2023-01-12 11:34     ` Krzysztof Kozlowski
2023-01-12 11:34       ` Krzysztof Kozlowski
2023-01-30  9:51       ` Sebastian Andrzej Siewior
2023-01-30  9:51         ` Sebastian Andrzej Siewior
2022-12-19 15:15 ` Krzysztof Kozlowski [this message]
2022-12-19 15:15   ` [PATCH v2 4/5] PM: Allow calling dev_pm_domain_set() with raw spinlock Krzysztof Kozlowski
2023-01-12 11:13   ` Sebastian Andrzej Siewior
2023-01-12 11:13     ` Sebastian Andrzej Siewior
2022-12-19 15:15 ` [PATCH v2 5/5] PM: domains: Do not call device_pm_check_callbacks() when holding genpd_lock() Krzysztof Kozlowski
2022-12-19 15:15   ` Krzysztof Kozlowski
2023-01-12 11:31   ` Sebastian Andrzej Siewior
2023-01-12 11:31     ` Sebastian Andrzej Siewior
2023-01-12 11:37     ` Krzysztof Kozlowski
2023-01-12 11:37       ` Krzysztof Kozlowski
2023-01-17 15:11   ` Ulf Hansson
2023-01-17 15:11     ` Ulf Hansson
2023-01-19 15:58     ` Krzysztof Kozlowski
2023-01-19 15:58       ` Krzysztof Kozlowski
2022-12-20 21:36 ` [PATCH v2 0/5] PM: Fixes for Realtime systems Adrien Thierry
2022-12-20 21:36   ` Adrien Thierry
2023-01-04 15:15   ` Ulf Hansson
2023-01-04 15:15     ` Ulf Hansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221219151503.385816-5-krzysztof.kozlowski@linaro.org \
    --to=krzysztof.kozlowski@linaro.org \
    --cc=athierry@redhat.com \
    --cc=bmasney@redhat.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=khilman@kernel.org \
    --cc=len.brown@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.