The patch below does not apply to the 5.15-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <stable@xxxxxxxxxxxxxxx>. To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y git checkout FETCH_HEAD git cherry-pick -x e95fa7404716f6e25021e66067271a4ad8eb1486 # <resolve conflicts, build, test, etc.> git commit -s git send-email --to '<stable@xxxxxxxxxxxxxxx>' --in-reply-to '2024012650-unfrozen-jukebox-4be8@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^.. Possible dependencies: e95fa7404716 ("thermal: gov_power_allocator: avoid inability to reset a cdev") 94be1d27aa8d ("thermal: gov_power_allocator: Use trip pointers instead of trip indices") 2c7b4bfadef0 ("thermal: core: Store trip pointer in struct thermal_instance") 790930f44289 ("thermal: core: Introduce thermal_cooling_device_update()") c43198af05cf ("thermal: core: Introduce thermal_cooling_device_present()") 5b8de18ee902 ("thermal/core: Move the thermal trip code to a dedicated file") e6ec64f85237 ("thermal/drivers/qcom: Fix set_trip_temp() deadlock") 1fa86b0a3692 ("thermal/drivers/qcom: Use generic thermal_zone_get_trip() function") 7f725a23f2b7 ("thermal/core/governors: Use thermal_zone_get_trip() instead of ops functions") 2e38a2a981b2 ("thermal/core: Add a generic thermal_zone_set_trip() function") 7c3d5c20dc16 ("thermal/core: Add a generic thermal_zone_get_trip() function") 91b3aafc2238 ("thermal/core: Remove thermal_zone_set_trips()") 05eeee2b51b4 ("thermal/core: Protect sysfs accesses to thermal operations with thermal zone mutex") 1c439dec359c ("thermal/core: Introduce locked version of thermal_zone_device_update") a365105c685c ("thermal: sysfs: Reuse cdev->max_state") c408b3d1d9bb ("thermal: Validate new state in cur_state_store()") 597f500fde76 ("thermal/core: Add a check before calling set_trip_temp()") a930da9bf583 ("thermal/core: Move the mutex inside the thermal_zone_device_update() function") 670a5e356cb6 ("thermal/core: Move the thermal zone lock out of the governors") 63561fe36b09 ("thermal/governors: Group the thermal zone lock inside the throttle function") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From e95fa7404716f6e25021e66067271a4ad8eb1486 Mon Sep 17 00:00:00 2001 From: Di Shen <di.shen@xxxxxxxxxx> Date: Wed, 10 Jan 2024 19:55:26 +0800 Subject: [PATCH] thermal: gov_power_allocator: avoid inability to reset a cdev Commit 0952177f2a1f ("thermal/core/power_allocator: Update once cooling devices when temp is low") adds an update flag to avoid triggering a thermal event when there is no need, and the thermal cdev is updated once when the temperature is low. But when the trips are writable, and switch_on_temp is set to be a higher value, the cooling device state may not be reset to 0, because last_temperature is smaller than switch_on_temp. For example: First: switch_on_temp=70 control_temp=85; Then userspace change the trip_temp: switch_on_temp=45 control_temp=55 cur_temp=54 Then userspace reset the trip_temp: switch_on_temp=70 control_temp=85 cur_temp=57 last_temp=54 At this time, the cooling device state should be reset to 0. However, because cur_temp(57) < switch_on_temp(70) last_temp(54) < switch_on_temp(70) ----> update = false, update is false, the cooling device state can not be reset. Using the observation that tz->passive can also be regarded as the temperature status, set the update flag to the tz->passive value. When the temperature drops below switch_on for the first time, the states of cooling devices can be reset once, and tz->passive is updated to 0. In the next round, because tz->passive is 0, cdev->state will not be updated. By using the tz->passive value as the "update" flag, the issue above can be solved, and the cooling devices can be updated only once when the temperature is low. Fixes: 0952177f2a1f ("thermal/core/power_allocator: Update once cooling devices when temp is low") Cc: 5.13+ <stable@xxxxxxxxxxxxxxx> # 5.13+ Suggested-by: Wei Wang <wvw@xxxxxxxxxx> Signed-off-by: Di Shen <di.shen@xxxxxxxxxx> Reviewed-by: Lukasz Luba <lukasz.luba@xxxxxxx> [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx> diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 7b6aa265ff6a..81e061f183ad 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -762,7 +762,7 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, trip = params->trip_switch_on; if (trip && tz->temperature < trip->temperature) { - update = tz->last_temperature >= trip->temperature; + update = tz->passive; tz->passive = 0; reset_pid_controller(params); allow_maximum_power(tz, update);