diff mbox series

[v2,05/11] thermal: core: Call thermal_governor_update_tz() outside of cdev lock

Message ID 7749552.EvYhyI6sBW@rjwysocki.net (mailing list archive)
State In Next
Delegated to: Rafael Wysocki
Headers show
Series thermal: core: Reimplement locking through guards | expand

Commit Message

Rafael J. Wysocki Oct. 10, 2024, 10:12 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Holding a cooling device lock under thermal_governor_update_tz() is not
necessary and it may cause lockdep to complain if any governor's
.update_tz() callback attempts to lock a cdev.

For this reason, move the thermal_governor_update_tz() calls in
thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip() from
under the cdev lock.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

This is a resend of

https://lore.kernel.org/linux-pm/1921484.CQOukoFCf9@rjwysocki.net/

---
 drivers/thermal/thermal_core.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Lukasz Luba Oct. 22, 2024, 9:10 p.m. UTC | #1
On 10/10/24 23:12, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Holding a cooling device lock under thermal_governor_update_tz() is not
> necessary and it may cause lockdep to complain if any governor's
> .update_tz() callback attempts to lock a cdev.
> 
> For this reason, move the thermal_governor_update_tz() calls in
> thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip() from
> under the cdev lock.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> 
> This is a resend of
> 
> https://lore.kernel.org/linux-pm/1921484.CQOukoFCf9@rjwysocki.net/
> 
> ---
>   drivers/thermal/thermal_core.c |   11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
> 
> Index: linux-pm/drivers/thermal/thermal_core.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/thermal_core.c
> +++ linux-pm/drivers/thermal/thermal_core.c
> @@ -832,13 +832,13 @@ static int thermal_bind_cdev_to_trip(str
>   	if (!result) {
>   		list_add_tail(&dev->trip_node, &td->thermal_instances);
>   		list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
> -
> -		thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
>   	}
>   	mutex_unlock(&cdev->lock);
>   
> -	if (!result)
> +	if (!result) {
> +		thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
>   		return 0;
> +	}
>   
>   	device_remove_file(&tz->device, &dev->weight_attr);
>   remove_trip_file:
> @@ -873,9 +873,6 @@ static void thermal_unbind_cdev_from_tri
>   		if (pos->cdev == cdev) {
>   			list_del(&pos->trip_node);
>   			list_del(&pos->cdev_node);
> -
> -			thermal_governor_update_tz(tz, THERMAL_TZ_UNBIND_CDEV);
> -
>   			mutex_unlock(&cdev->lock);
>   			goto unbind;
>   		}
> @@ -885,6 +882,8 @@ static void thermal_unbind_cdev_from_tri
>   	return;
>   
>   unbind:
> +	thermal_governor_update_tz(tz, THERMAL_TZ_UNBIND_CDEV);
> +
>   	device_remove_file(&tz->device, &pos->weight_attr);
>   	device_remove_file(&tz->device, &pos->attr);
>   	sysfs_remove_link(&tz->device.kobj, pos->name);
> 
> 
> 

Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
diff mbox series

Patch

Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -832,13 +832,13 @@  static int thermal_bind_cdev_to_trip(str
 	if (!result) {
 		list_add_tail(&dev->trip_node, &td->thermal_instances);
 		list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
-
-		thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
 	}
 	mutex_unlock(&cdev->lock);
 
-	if (!result)
+	if (!result) {
+		thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
 		return 0;
+	}
 
 	device_remove_file(&tz->device, &dev->weight_attr);
 remove_trip_file:
@@ -873,9 +873,6 @@  static void thermal_unbind_cdev_from_tri
 		if (pos->cdev == cdev) {
 			list_del(&pos->trip_node);
 			list_del(&pos->cdev_node);
-
-			thermal_governor_update_tz(tz, THERMAL_TZ_UNBIND_CDEV);
-
 			mutex_unlock(&cdev->lock);
 			goto unbind;
 		}
@@ -885,6 +882,8 @@  static void thermal_unbind_cdev_from_tri
 	return;
 
 unbind:
+	thermal_governor_update_tz(tz, THERMAL_TZ_UNBIND_CDEV);
+
 	device_remove_file(&tz->device, &pos->weight_attr);
 	device_remove_file(&tz->device, &pos->attr);
 	sysfs_remove_link(&tz->device.kobj, pos->name);