Skip to content

Commit

Permalink
thermal/sysfs: Update instance->weight under tz lock
Browse files Browse the repository at this point in the history
User space can change the weight of a thermal instance via sysfs while the
.throttle() callback is running for a governor, because weight_store()
does not use the zone lock.

The IPA governor uses instance weight values for power calculations and
caches the sum of them as total_weight, so it gets confused when one of
them changes while its .throttle() callback is running.

To prevent that from happening, use thermal zone locking in
weight_store().

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Lukasz Luba authored and Rafael J. Wysocki committed Dec 29, 2023
1 parent e3ecd57 commit 879c9dc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/thermal/thermal_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,11 @@ ssize_t weight_store(struct device *dev, struct device_attribute *attr,
return ret;

instance = container_of(attr, struct thermal_instance, weight_attr);

/* Don't race with governors using the 'weight' value */
mutex_lock(&instance->tz->lock);
instance->weight = weight;
mutex_unlock(&instance->tz->lock);

return count;
}

0 comments on commit 879c9dc

Please sign in to comment.