linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PM: runtime: Simplify locking in pm_runtime_put_suppliers()
@ 2021-12-17 19:16 Rafael J. Wysocki
  2021-12-21 11:46 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Rafael J. Wysocki @ 2021-12-17 19:16 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Ulf Hansson

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Notice that pm_runtime_put_suppliers() cannot be called with
disabled interrupts, because it may sleep (due to the device
links read locking in the non-SRCU case), and so it can use
spin_lock_irq() and spin_unlock_irq() for the locking.

Update the function accordingly and while at it move the "put"
local variable in it into the inner block where it is used.

This change is not expected to have any visible functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/base/power/runtime.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================
--- linux-pm.orig/drivers/base/power/runtime.c
+++ linux-pm/drivers/base/power/runtime.c
@@ -1748,8 +1748,6 @@ void pm_runtime_get_suppliers(struct dev
 void pm_runtime_put_suppliers(struct device *dev)
 {
 	struct device_link *link;
-	unsigned long flags;
-	bool put;
 	int idx;
 
 	idx = device_links_read_lock();
@@ -1757,11 +1755,17 @@ void pm_runtime_put_suppliers(struct dev
 	list_for_each_entry_rcu(link, &dev->links.suppliers, c_node,
 				device_links_read_lock_held())
 		if (link->supplier_preactivated) {
+			bool put;
+
 			link->supplier_preactivated = false;
-			spin_lock_irqsave(&dev->power.lock, flags);
+
+			spin_lock_irq(&dev->power.lock);
+
 			put = pm_runtime_status_suspended(dev) &&
 			      refcount_dec_not_one(&link->rpm_active);
-			spin_unlock_irqrestore(&dev->power.lock, flags);
+
+			spin_unlock_irq(&dev->power.lock);
+
 			if (put)
 				pm_runtime_put(link->supplier);
 		}




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

* Re: [PATCH] PM: runtime: Simplify locking in pm_runtime_put_suppliers()
  2021-12-17 19:16 [PATCH] PM: runtime: Simplify locking in pm_runtime_put_suppliers() Rafael J. Wysocki
@ 2021-12-21 11:46 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2021-12-21 11:46 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Linux PM, LKML

On Fri, 17 Dec 2021 at 20:16, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Notice that pm_runtime_put_suppliers() cannot be called with
> disabled interrupts, because it may sleep (due to the device
> links read locking in the non-SRCU case), and so it can use
> spin_lock_irq() and spin_unlock_irq() for the locking.
>
> Update the function accordingly and while at it move the "put"
> local variable in it into the inner block where it is used.
>
> This change is not expected to have any visible functional impact.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

Kind regards
Uffe

> ---
>  drivers/base/power/runtime.c |   12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> Index: linux-pm/drivers/base/power/runtime.c
> ===================================================================
> --- linux-pm.orig/drivers/base/power/runtime.c
> +++ linux-pm/drivers/base/power/runtime.c
> @@ -1748,8 +1748,6 @@ void pm_runtime_get_suppliers(struct dev
>  void pm_runtime_put_suppliers(struct device *dev)
>  {
>         struct device_link *link;
> -       unsigned long flags;
> -       bool put;
>         int idx;
>
>         idx = device_links_read_lock();
> @@ -1757,11 +1755,17 @@ void pm_runtime_put_suppliers(struct dev
>         list_for_each_entry_rcu(link, &dev->links.suppliers, c_node,
>                                 device_links_read_lock_held())
>                 if (link->supplier_preactivated) {
> +                       bool put;
> +
>                         link->supplier_preactivated = false;
> -                       spin_lock_irqsave(&dev->power.lock, flags);
> +
> +                       spin_lock_irq(&dev->power.lock);
> +
>                         put = pm_runtime_status_suspended(dev) &&
>                               refcount_dec_not_one(&link->rpm_active);
> -                       spin_unlock_irqrestore(&dev->power.lock, flags);
> +
> +                       spin_unlock_irq(&dev->power.lock);
> +
>                         if (put)
>                                 pm_runtime_put(link->supplier);
>                 }
>
>
>

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

end of thread, other threads:[~2021-12-21 11:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17 19:16 [PATCH] PM: runtime: Simplify locking in pm_runtime_put_suppliers() Rafael J. Wysocki
2021-12-21 11:46 ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).