thermal: sysfs: add locking
Subsystems (7)
Eduardo Valentin
maintainercover thermal: sysfs: add locking
Hello,
Several thermal sysfs entries are currently being called from userspace without locking. Data and calls to ops are accessed deliberated without any care for locking.
This patch series attempts to fix this.
Now that sysfs handlers are on the same place it is easier to visualize this issue and fix it. The strategy is essentially to lock any access. Also, functions in thermal core and thermal helpers are assumed to do the proper locking already.
This patch series is based on the thermal core reorganization.
There is no change in the ABI to userspace. The difference is that now serialization to data will be done.
For your consideration, I am also adding this to this branch:
git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal sysfs_locking
Comments are welcome.
BR,
Eduardo Valentin (15):
thermal: sysfs: lock tz in type_show
thermal: sysfs: lock tz while on access to mode properties
thermal: sysfs: lock tz while on trip_point_type properties
thermal: sysfs: lock tz while on trip_point_temp properties
thermal: sysfs: lock tz while on trip_point_hyst properties
thermal: sysfs: lock tz while on passive properties
thermal: sysfs: lock tz while on policy properties
thermal: sysfs: improve locking of emul_temp_store()
thermal: sysfs: lock tz when access sustainable power properties
thermal: sysfs: lock tz when access tzp properties
thermal: sysfs: lock cdev while accessing type
thermal: sysfs: lock cdev while accessing max_state
thermal: sysfs: lock cdev while accessing cur_state
thermal: sysfs: serialize access to instances
thermal: sysfs: add comments describing locking strategy
drivers/thermal/thermal_sysfs.c | 133 ++++++++++++++++++++++++++++++++++------ include/linux/thermal.h | 2 +- 2 files changed, 115 insertions(+), 20 deletions(-)
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 1/15 thermal: sysfs: lock tz in type_show
Avoid race while accessing tz->type.
--- drivers/thermal/thermal_sysfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/thermal/thermal_sysfs.c +6 -1
@@ -29,8 +29,13 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); +char *type; -return sprintf (buf,"%s\n" , tz->type); +mutex_lock (&tz->lock); + type = tz->type; +mutex_unlock (&tz->lock); + +return sprintf (buf,"%s\n" , type); } static ssize_t
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 2/15 thermal: sysfs: lock tz while on access to mode properties
In reply to Eduardo ValentinSerialized calls to tz.ops in user facing
sysfs handler mode_show() and mode_store().
--- drivers/thermal/thermal_sysfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/thermal/thermal_sysfs.c +10 -3
@@ -62,7 +62,9 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf)if (!tz->ops->get_mode)return -EPERM ; +mutex_lock (&tz->lock); result = tz->ops->get_mode (tz, &mode); +mutex_unlock (&tz->lock);if (result)return result;
@@ -75,17 +77,22 @@ mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) {struct thermal_zone_device *tz =to_thermal_zone (dev); +enum thermal_device_mode mode =THERMAL_DEVICE_DISABLED ;int result;if (!tz->ops->set_mode)return -EPERM ;if (!strncmp (buf,"enabled" ,sizeof ("enabled" ) -1 )) - result = tz->ops->set_mode (tz,THERMAL_DEVICE_ENABLED ); + mode =THERMAL_DEVICE_ENABLED ;else if (!strncmp (buf,"disabled" ,sizeof ("disabled" ) -1 )) - result = tz->ops->set_mode (tz,THERMAL_DEVICE_DISABLED ); + mode =THERMAL_DEVICE_DISABLED ;else - result = -EINVAL ; +return -EINVAL ; + +mutex_lock (&tz->lock); + result = tz->ops->set_mode (tz, mode); +mutex_unlock (&tz->lock);if (result)return result;
Signature · 1 line
2.1.4
Re: [PATCH 02/15] thermal: sysfs: lock tz while on access to mode properties
Hi Eduardo,
Quoted 2 lines · Eduardo Valentin
Serialized calls to tz.ops in user facing
sysfs handlermode_show()andmode_store().
This seems to be causing a deadlock at boot time during the ending stages of boot:
http://pastebin.ubuntu.com/17085291/
It took a while to git bisect on linux-next.
Seems like you introduced new locking at the sysfs layer which causes this deadlock as the underlying code again tries to acquire the same tz->lock.
Regards,
Keerthy
Quoted 50 lines
Cc Zhang Rui <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>--- drivers/thermal/thermal_sysfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/thermal/thermal_sysfs.c +10
-3@@ -62,7 +62,9 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf)if (!tz->ops->get_mode)return -EPERM ; +mutex_lock (&tz->lock); result = tz->ops->get_mode (tz, &mode); +mutex_unlock (&tz->lock);if (result)return result;@@ -75,17 +77,22 @@ mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) {struct thermal_zone_device *tz =to_thermal_zone (dev); +enum thermal_device_mode mode =THERMAL_DEVICE_DISABLED ;int result;if (!tz->ops->set_mode)return -EPERM ;if (!strncmp (buf,"enabled" ,sizeof ("enabled" ) -1 )) - result = tz->ops->set_mode (tz,THERMAL_DEVICE_ENABLED ); + mode =THERMAL_DEVICE_ENABLED ;else if (!strncmp (buf,"disabled" ,sizeof ("disabled" ) -1 )) - result = tz->ops->set_mode (tz,THERMAL_DEVICE_DISABLED ); + mode =THERMAL_DEVICE_DISABLED ;else - result = -EINVAL ; +return -EINVAL ; + +mutex_lock (&tz->lock); + result = tz->ops->set_mode (tz, mode); +mutex_unlock (&tz->lock);if (result)return result;
Re: [PATCH 02/15] thermal: sysfs: lock tz while on access to mode properties
Quoted 9 lines · Keerthy
Hi Eduardo,
Quoted 2 lines · Eduardo Valentin
Serialized calls to tz.ops in user facing
sysfs handlermode_show()andmode_store().This seems to be causing a deadlock at boot time during the ending stages of boot:
Quoted 7 lines
http://pastebin.ubuntu.com/17085291/
It took a while to git bisect on linux-next.
Seems like you introduced new locking at the sysfs layer which causes this deadlock as the underlying code again tries to acquire the same
tz->lock.
I confirm reverting this patch helps me boot on linux-next. This patch can be dropped as the lower layer functions are already acquiring tz->lock.
Thanks Vignesh for reporting the deadlock.
Regards,
Keerthy
Quoted 61 lines
Regards,
KeerthyQuoted 51 lines
Cc Zhang Rui <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>--- drivers/thermal/thermal_sysfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/thermal/thermal_sysfs.c +10
-3@@ -62,7 +62,9 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf)if (!tz->ops->get_mode)return -EPERM ; +mutex_lock (&tz->lock); result = tz->ops->get_mode (tz, &mode); +mutex_unlock (&tz->lock);if (result)return result;@@ -75,17 +77,22 @@ mode_store(struct device *dev, structdevice_attribute *attr, const char *buf, size_t count) { struct thermal_zone_device *tz = to_thermal_zone(dev); +enum thermal_device_mode mode =THERMAL_DEVICE_DISABLED ;int result;if (!tz->ops->set_mode)return -EPERM ;if (!strncmp (buf,"enabled" ,sizeof ("enabled" ) -1 )) - result = tz->ops->set_mode (tz,THERMAL_DEVICE_ENABLED ); + mode =THERMAL_DEVICE_ENABLED ;else if (!strncmp (buf,"disabled" ,sizeof ("disabled" ) -1 )) - result = tz->ops->set_mode (tz,THERMAL_DEVICE_DISABLED ); + mode =THERMAL_DEVICE_DISABLED ;else - result = -EINVAL ; +return -EINVAL ; + +mutex_lock (&tz->lock); + result = tz->ops->set_mode (tz, mode); +mutex_unlock (&tz->lock);if (result)Quoted 2 lines
return result;--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Zhang Rui
reviewerRe: [PATCH 02/15] thermal: sysfs: lock tz while on access to mode properties
Quoted 21 lines · Keerthy
Quoted 12 lines · Keerthy
Hi Eduardo,
Quoted 3 lines · Eduardo Valentin
Serialized calls to tz.ops in user facing
sysfs handler mode_show() andmode_store().This seems to be causing a deadlock at boot time during the ending stages of boot:
Quoted 7 lines
It took a while to git bisect on linux-next.
Seems like you introduced new locking at the sysfs layer which causes
this deadlock as the underlying code again tries to acquire the sametz->lock.
Quoted 7 lines
I confirm reverting this patch helps me boot on linux-next. This patch
can be dropped as the lower layer functions are already acquiring tz-Quoted 1 line
lock.
Thanks Vignesh for reporting the deadlock.
the root cause of the deadlock is that some platform driver invokes thermal_zone_device_update() in .set_mode(), after mode changed.
If we wants to lock tz->ops->set_mode(), we should cleanup all the platform thermal drivers, and deliver a thermal_zone_device_update() in mode_store(), at the same time.
thanks,
rui
Quoted 67 lines
Regards,
KeerthyQuoted 64 lines
Regards,
KeerthyQuoted 51 lines
Cc Zhang Rui <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>---
drivers/thermal/thermal_sysfs.c| 13 ++++++++++---1 file changed, 10 insertions(+), 3 deletions(-)drivers/thermal/thermal_sysfs.c +5
-2@@ -62,7 +62,9 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) if (!tz->ops->get_mode) return -EPERM; + mutex_lock(&tz->lock); result = tz->ops->get_mode(tz, &mode); + mutex_unlock(&tz->lock); if (result) return result;@@ -75,17 +77,22 @@ mode_store(struct device *dev, structdevice_attribute *attr, const char *buf, size_t count) { struct thermal_zone_device *tz = to_thermal_zone(dev); + enum thermal_device_mode mode = THERMAL_DEVICE_DISABLED; int result; if (!tz->ops->set_mode) return -EPERM; if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + mode = THERMAL_DEVICE_ENABLED; else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + mode = THERMAL_DEVICE_DISABLED;else
- result =-EINVAL;
+ return-EINVAL;
+
+ mutex_lock(&tz->lock);
+ result =tz->ops->set_mode(tz, mode);
+ mutex_unlock(&tz->lock);Quoted 3 lines
if (result)
return result;--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Eduardo Valentin
maintainerPATCH 1/1 thermal: core: call thermal_zone_device_update() after mode update
Because several drivers do the following pattern:
.set_mode()
...
local_data->mode = new_mode;
thermal_zone_device_update(tz);
makes sense to simply do the thermal_zone_device_update() in thermal core, after setting the new mode.
Also, this patch also remove deadlocks on drivers that call thermal_zone_device_update() on .set_mode(), as .set_mode() is now called always with tz->lock held.
---
Rui, Keerthy,
I think this patch should take care of the introduced deadlock.
Let me know if solves on your end.
BR,
Eduardo
---
drivers/acpi/thermal.c | 2 -- drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 8 ++--- drivers/thermal/thermal_core.c | 41 +++++++++++++++++----- drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 1 - 7 files changed, 36 insertions(+), 19 deletions(-)
drivers/acpi/thermal.c +0 -2
@@ -519,8 +519,6 @@ static void acpi_thermal_check(void *data)if (!tz->tz_enabled)return ; - -thermal_zone_device_update (tz->thermal_zone); }/* sys I/F for generic thermal sysfs support */
drivers/platform/x86/acerhdf.c +0 -1
@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }
drivers/thermal/imx_thermal.c +0 -1
@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
drivers/thermal/of-thermal.c +3 -5
@@ -181,9 +181,6 @@ static int of_thermal_set_emul_temp(struct thermal_zone_device *tz, {struct __thermal_zone *data = tz->devdata; -if (!data->ops || !data->ops->set_emul_temp) -return -EINVAL ; -return data->ops->set_emul_temp (data->sensor_data, temp); }
@@ -292,7 +289,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,mutex_unlock (&tz->lock); data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
@@ -427,7 +423,9 @@ thermal_zone_of_add_sensor(struct device_node *zone, tzd->ops->get_temp = of_thermal_get_temp; tzd->ops->get_trend = of_thermal_get_trend; - tzd->ops->set_emul_temp = of_thermal_set_emul_temp; +if (ops->set_emul_temp) + tzd->ops->set_emul_temp = of_thermal_set_emul_temp; +mutex_unlock (&tzd->lock);return tzd;
drivers/thermal/thermal_core.c +32 -9
92 lines not on this page · raw message
drivers/thermal/thermal_sysfs.c +1 -0
@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0 -1
@@ -205,7 +205,6 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal, data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);
Signature · 1 line
2.1.4
Rafael J. Wysocki
maintainerRe: [PATCH 1/1] thermal: core: call thermal_zone_device_update() after mode update
Quoted 6 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()
...local_data->mode = new_mode; thermal_zone_device_update(tz);
Quoted 6 lines
makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.
To me, this part of the patch is way more important than the optimization mentioned before.
Apparently, the problem is that drivers deadlock, because the thermal_zone_device_update() invoked from ->set_mode() is called under tz->lock.
So to address that problem you make the core call thermal_zone_device_update() after ->set_mode() outside of tz->lock and the drivers don't have to do it any more.
Is that correct?
Thanks,
Rafael
Re: [PATCH 1/1] thermal: core: call thermal_zone_device_update() after mode update
Quoted 21 lines · Rafael J. Wysocki
Quoted 6 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()... local_data->mode = new_mode; thermal_zone_device_update(tz);Quoted 6 lines
makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.To me, this part of the patch is way more important than the optimization mentioned before.
Apparently, the problem is that drivers deadlock, because the
thermal_zone_device_update()invoked from ->set_mode() is called undertz->lock.
Quoted 5 lines
So to address that problem you make the core call
thermal_zone_device_update()after ->set_mode() outside oftz->lockand the drivers don't have to do it any more.Is that correct?
Rafael,
On my set up, mode_store locks tz->lock and eventually ends up calling of_thermal_set_mode before releasing tz->lock which again tries to lock tz->lock and ends up in a deadlock.
http://pastebin.ubuntu.com/17687601/
Regards,
Keerthy
Quoted 4 lines
Thanks,
Rafael
Eduardo Valentin
maintainerRe: [PATCH 1/1] thermal: core: call thermal_zone_device_update() after mode update
In reply to Rafael J. WysockiQuoted 21 lines · Rafael J. Wysocki
Quoted 6 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()
...local_data->mode = new_mode; thermal_zone_device_update(tz);Quoted 6 lines
makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.To me, this part of the patch is way more important than the optimization mentioned before.
Apparently, the problem is that drivers deadlock, because the
thermal_zone_device_update()invoked from ->set_mode() is called undertz->lock.
Quoted 5 lines
So to address that problem you make the core call
thermal_zone_device_update()after ->set_mode() outside oftz->lockand the drivers don't have to do it any more.Is that correct?
Yes this is correct. The optimization is simply a consequence of the bug fix, as reported by Keerthy.
Quoted 3 lines
Thanks,
Rafael
Eduardo Valentin
maintainerPATCH v2 1/1 thermal: core: call thermal_zone_device_update() after mode update
In reply to Zhang RuiBecause several drivers do the following pattern:
.set_mode()
...
local_data->mode = new_mode;
thermal_zone_device_update(tz);
makes sense to simply do the thermal_zone_device_update() in thermal core, after setting the new mode.
Also, this patch also remove deadlocks on drivers that call thermal_zone_device_update() on .set_mode(), as .set_mode() is now called always with tz->lock held.
---
Please ignore last version.
V1-> V2:
Cleaned the patch and remove unrelated changes.
---
drivers/acpi/thermal.c | 2 -- drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 1 - drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 1 - 6 files changed, 1 insertion(+), 6 deletions(-)
drivers/acpi/thermal.c +0 -2
@@ -519,8 +519,6 @@ static void acpi_thermal_check(void *data)if (!tz->tz_enabled)return ; - -thermal_zone_device_update (tz->thermal_zone); }/* sys I/F for generic thermal sysfs support */
drivers/platform/x86/acerhdf.c +0 -1
@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }
drivers/thermal/imx_thermal.c +0 -1
@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
drivers/thermal/of-thermal.c +0 -1
@@ -292,7 +292,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,mutex_unlock (&tz->lock); data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
drivers/thermal/thermal_sysfs.c +1 -0
@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0 -1
@@ -205,7 +205,6 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal, data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);
Signature · 1 line
2.1.4
Re: [PATCHv2 1/1] thermal: core: call thermal_zone_device_update() after mode update
Quoted 8 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()... local_data->mode = new_mode; thermal_zone_device_update(tz);makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.
http://pastebin.ubuntu.com/17687601/
linux-next + current v2 of the patch.
The back trace still comes.
Regards,
Keerthy
Quoted 106 lines
Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Darren Hart <[email protected]>Cc Zhang Rui <[email protected]>Cc Keerthy <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>---
Please ignore last version.V1-> V2:
Cleaned the patch and remove unrelated changes.
---drivers/acpi/thermal.c | 2 -- drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 1 - drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 1 - 6 files changed, 1 insertion(+), 6 deletions(-)drivers/acpi/thermal.c +0
-2@@ -519,8 +519,6 @@ static void acpi_thermal_check(void *data)if (!tz->tz_enabled)return ; - -thermal_zone_device_update (tz->thermal_zone); }/* sys I/F for generic thermal sysfs support */ drivers/platform/x86/acerhdf.c +0
-1@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }drivers/thermal/imx_thermal.c +0
-1@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/of-thermal.c +0
-1@@ -292,7 +292,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,mutex_unlock (&tz->lock); data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/thermal_sysfs.c +1
-0@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-1@@ -205,7 +205,6 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal, data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);
Eduardo Valentin
maintainerRe: [PATCHv2 1/1] thermal: core: call thermal_zone_device_update() after mode update
Quoted 9 lines · Keerthy
Quoted 6 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()
...local_data->mode = new_mode; thermal_zone_device_update(tz);
Quoted 7 lines
Quoted 2 lines
makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.http://pastebin.ubuntu.com/17687601/
linux-next + current v2 of the patch.
The back trace still comes.
I confirm this. Please check V3 I just sent. On V2 I focused on thermal_zone_device_update(), but for OF thermal specifically, we also hold the lock for protecting other accesses. Now they are removed.
Quoted 110 lines
Regards,
KeerthyQuoted 106 lines
Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Darren Hart <[email protected]>Cc Zhang Rui <[email protected]>Cc Keerthy <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>---
Please ignore last version.V1-> V2:
Cleaned the patch and remove unrelated changes.
---drivers/acpi/thermal.c | 2 -- drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 1 - drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 1 - 6 files changed, 1 insertion(+), 6 deletions(-)drivers/acpi/thermal.c +0
-2@@ -519,8 +519,6 @@ static void acpi_thermal_check(void *data)if (!tz->tz_enabled)return ; - -thermal_zone_device_update (tz->thermal_zone); }/* sys I/F for generic thermal sysfs support */ drivers/platform/x86/acerhdf.c +0
-1@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }drivers/thermal/imx_thermal.c +0
-1@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/of-thermal.c +0
-1@@ -292,7 +292,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,mutex_unlock (&tz->lock); data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/thermal_sysfs.c +1
-0@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-1@@ -205,7 +205,6 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal, data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);
Eduardo Valentin
maintainerRe: [PATCHv2 1/1] thermal: core: call thermal_zone_device_update() after mode update
Quoted 15 lines · Eduardo Valentin
Quoted 14 lines · Keerthy
Quoted 8 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()
...local_data->mode = new_mode; thermal_zone_device_update(tz);makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.
Quoted 7 lines
Quoted 2 lines
linux-next + current v2 of the patch.
The back trace still comes.I confirm this. Please check V3 I just sent. On V2 I focused on
thermal_zone_device_update(), but for OF thermal specifically, we also hold the lock for protecting other accesses. Now they are removed.
Please use v4. I removed extra non needed locking in ti SoC driver for case which boots without DT (not sure if this is still used though). Also, improved acpi thermal, as it was remove the update from other needed cases.
Quoted 111 lines
Quoted 111 lines
Regards,
KeerthyQuoted 106 lines
Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Darren Hart <[email protected]>Cc Zhang Rui <[email protected]>Cc Keerthy <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>---
Please ignore last version.V1-> V2:
Cleaned the patch and remove unrelated changes.
---drivers/acpi/thermal.c | 2 -- drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 1 - drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 1 - 6 files changed, 1 insertion(+), 6 deletions(-)drivers/acpi/thermal.c +0
-2@@ -519,8 +519,6 @@ static void acpi_thermal_check(void *data)if (!tz->tz_enabled)return ; - -thermal_zone_device_update (tz->thermal_zone); }/* sys I/F for generic thermal sysfs support */ drivers/platform/x86/acerhdf.c +0
-1@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }drivers/thermal/imx_thermal.c +0
-1@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/of-thermal.c +0
-1@@ -292,7 +292,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,mutex_unlock (&tz->lock); data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/thermal_sysfs.c +1
-0@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-1@@ -205,7 +205,6 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal, data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);
Eduardo Valentin
maintainerPATCH v3 1/1 thermal: core: call thermal_zone_device_update() after mode update
In reply to Zhang RuiBecause several drivers do the following pattern:
.set_mode()
...
local_data->mode = new_mode;
thermal_zone_device_update(tz);
makes sense to simply do the thermal_zone_device_update() in thermal core, after setting the new mode.
Also, this patch also remove deadlocks on drivers that call thermal_zone_device_update() on .set_mode(), as .set_mode() is now called always with tz->lock held.
---
Hey,
V2--> V3: Remove locking from OF thermal set mode. The locking is done from thermal core already.
BR,
Eduardo
drivers/acpi/thermal.c | 2 -- drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 5 ----- drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 1 - 6 files changed, 1 insertion(+), 10 deletions(-)
drivers/acpi/thermal.c +0 -2
@@ -519,8 +519,6 @@ static void acpi_thermal_check(void *data)if (!tz->tz_enabled)return ; - -thermal_zone_device_update (tz->thermal_zone); }/* sys I/F for generic thermal sysfs support */
drivers/platform/x86/acerhdf.c +0 -1
@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }
drivers/thermal/imx_thermal.c +0 -1
@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
drivers/thermal/of-thermal.c +0 -5
@@ -282,17 +282,12 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, {struct __thermal_zone *data = tz->devdata; -mutex_lock (&tz->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) tz->polling_delay = data->polling_delay;else tz->polling_delay =0 ; -mutex_unlock (&tz->lock); - data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
drivers/thermal/thermal_sysfs.c +1 -0
@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0 -1
@@ -205,7 +205,6 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal, data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH v4 1/1 thermal: core: call thermal_zone_device_update() after mode update
In reply to Zhang RuiBecause several drivers do the following pattern:
.set_mode()
...
local_data->mode = new_mode;
thermal_zone_device_update(tz);
makes sense to simply do the thermal_zone_device_update() in thermal core, after setting the new mode.
Also, this patch also remove deadlocks on drivers that call thermal_zone_device_update() on .set_mode(), as .set_mode() is now called always with tz->lock held.
---
Hello,
V3->V4:
- ti-soc: Removed extra locking from TI SoC in set_mode
- ACPI: Kept the update on check as it is called on other places
BR,
Eduardo
drivers/acpi/thermal.c | 1 - drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 5 ----- drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 5 ----- 6 files changed, 1 insertion(+), 13 deletions(-)
drivers/acpi/thermal.c +0 -1
@@ -581,7 +581,6 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"%s kernel ACPI thermal control\n" , tz->tz_enabled ?"Enable" :"Disable" )); -acpi_thermal_check (tz); }return 0 ; }
drivers/platform/x86/acerhdf.c +0 -1
@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }
drivers/thermal/imx_thermal.c +0 -1
@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
drivers/thermal/of-thermal.c +0 -5
@@ -282,17 +282,12 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, {struct __thermal_zone *data = tz->devdata; -mutex_lock (&tz->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) tz->polling_delay = data->polling_delay;else tz->polling_delay =0 ; -mutex_unlock (&tz->lock); - data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
drivers/thermal/thermal_sysfs.c +1 -0
@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0 -5
@@ -193,19 +193,14 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal,return 0 ; } -mutex_lock (&data->ti_thermal->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) data->ti_thermal->polling_delay =FAST_TEMP_MONITORING_RATE ;else data->ti_thermal->polling_delay =0 ; -mutex_unlock (&data->ti_thermal->lock); - data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);
Signature · 1 line
2.1.4
Re: [PATCHv4 1/1] thermal: core: call thermal_zone_device_update() after mode update
Quoted 6 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()... local_data->mode = new_mode; thermal_zone_device_update(tz);
Quoted 6 lines
makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.
I do not see the issue anymore. Boot Tested multiple times on DRA72-EVM.
Quoted 127 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Darren Hart <[email protected]>Cc Zhang Rui <[email protected]>Cc Keerthy <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>---
Hello,
V3->V4:
- ti-soc: Removed extra locking from TI SoC inset_mode
- ACPI: Kept the update on check as it is called on other placesBR,
Eduardo
drivers/acpi/thermal.c | 1 - drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 5 ----- drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 5 ----- 6 files changed, 1 insertion(+), 13 deletions(-)drivers/acpi/thermal.c +0
-1@@ -581,7 +581,6 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"%s kernel ACPI thermal control\n" , tz->tz_enabled ?"Enable" :"Disable" )); -acpi_thermal_check (tz); }return 0 ; }drivers/platform/x86/acerhdf.c +0
-1@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }drivers/thermal/imx_thermal.c +0
-1@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/of-thermal.c +0
-5@@ -282,17 +282,12 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, {struct __thermal_zone *data = tz->devdata; -mutex_lock (&tz->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) tz->polling_delay = data->polling_delay;else tz->polling_delay =0 ; -mutex_unlock (&tz->lock); - data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/thermal_sysfs.c +1
-0@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-5@@ -193,19 +193,14 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal,return 0 ; } -mutex_lock (&data->ti_thermal->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) data->ti_thermal->polling_delay =FAST_TEMP_MONITORING_RATE ;else data->ti_thermal->polling_delay =0 ; -mutex_unlock (&data->ti_thermal->lock); - data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);
Re: [PATCHv4 1/1] thermal: core: call thermal_zone_device_update() after mode update
In reply to Eduardo ValentinQuoted 13 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()
...local_data->mode = new_mode; thermal_zone_device_update(tz);makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.
Quoted 12 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Darren Hart <[email protected]>Cc Zhang Rui <[email protected]>Cc Keerthy <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>
+Peter Feuerer <[email protected]>
Peter, any concerns regarding the acerhdf driver?
Quoted 117 lines
---
Hello,
V3->V4:
- ti-soc: Removed extra locking from TI SoC inset_mode
- ACPI: Kept the update on check as it is called on other placesBR,
Eduardo
drivers/acpi/thermal.c | 1 - drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 5 ----- drivers/thermal/thermal_sysfs.c | 1 + drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 5 ----- 6 files changed, 1 insertion(+), 13 deletions(-)drivers/acpi/thermal.c +0
-1@@ -581,7 +581,6 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"%s kernel ACPI thermal control\n" , tz->tz_enabled ?"Enable" :"Disable" )); -acpi_thermal_check (tz); }return 0 ; }drivers/platform/x86/acerhdf.c +0
-1@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }drivers/thermal/imx_thermal.c +0
-1@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/of-thermal.c +0
-5@@ -282,17 +282,12 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, {struct __thermal_zone *data = tz->devdata; -mutex_lock (&tz->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) tz->polling_delay = data->polling_delay;else tz->polling_delay =0 ; -mutex_unlock (&tz->lock); - data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/thermal_sysfs.c +1
-0@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-5@@ -193,19 +193,14 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal,return 0 ; } -mutex_lock (&data->ti_thermal->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) data->ti_thermal->polling_delay =FAST_TEMP_MONITORING_RATE ;else data->ti_thermal->polling_delay =0 ; -mutex_unlock (&data->ti_thermal->lock); - data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);Signature · 1 line
2.1.4
Signature · 2 lines
Darren Hart Intel Open Source Technology Center
Peter Feuerer
maintainerRe: [PATCHv4 1/1] thermal: core: call thermal_zone_device_update() after mode update
Hi,
Quoted 28 lines · Darren Hart
Quoted 13 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()
...local_data->mode=new_mode;thermal_zone_device_update(tz);makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.Quoted 12 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Darren Hart <[email protected]>Cc Zhang Rui <[email protected]>Cc Keerthy <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>
Quoted 3 lines
+Peter Feuerer <[email protected]>
Peter, any concerns regarding the acerhdf driver?
Yes, please see below.
Quoted 9 lines
Quoted 9 lines
---
Hello,
V3->V4:
- ti-soc: Removed extra locking from TI SoC inset_mode
- ACPI: Kept the update on check as it is called on other placesBR,
Quoted 7 lines
Quoted 7 lines
Eduardo
drivers/acpi/thermal.c| 1 -drivers/platform/x86/acerhdf.c| 1 -drivers/thermal/imx_thermal.c| 1 -drivers/thermal/of-thermal.c| 5 -----drivers/thermal/thermal_sysfs.c| 1 +
This file does not exist in Linus git master branch. Which git repo / branch do you base your changes on? Or are there any patches I need to apply first?
Quoted 22 lines
Quoted 22 lines
drivers/thermal/ti-soc-thermal/ti-thermal-common.c| 5 -----6 files changed, 1 insertion(+), 13 deletions(-)drivers/acpi/thermal.c +0
-1@@ -581,7 +581,6 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"%s kernel ACPI thermal control\n" , tz->tz_enabled ?"Enable" :"Disable" )); -acpi_thermal_check (tz); }return 0 ; }drivers/platform/x86/acerhdf.c +0
-0@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ;
Quoted 2 lines
drivers/platform/x86/acerhdf.c static inline void acerhdf_enable_kernelmode(void) · line 408
Quoted 2 lines
drivers/platform/x86/acerhdf.c +0
-1thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);
This call is used to inform the thermal zone about the changed polling_delay from 0 (polling disabled) to some user defined interval at runtime - not initialization time.
Quoted 79 lines
From just reading your patch I don't understand, how this is intended to work afterwards. - I'm clearly missing some further info / patches to give my ok.
Quoted 76 lines
drivers/platform/x86/acerhdf.c +0
-0pr_notice ("kernel mode fan control ON\n" ); }drivers/thermal/imx_thermal.c +0
-1@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }drivers/thermal/of-thermal.c +0
-2@@ -282,17 +282,12 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, {struct __thermal_zone *data = tz->devdata; -mutex_lock (&tz->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) tz->polling_delay = data->polling_delay;else
tz->polling_delay= 0;-
mutex_unlock(&tz->lock);
-data->mode= mode;
-thermal_zone_device_update(tz);return 0;
}drivers/thermal/thermal_sysfs.c +1
-0@@ -100,6 +100,7 @@ mode_store(struct device *dev, struct device_attribute *attr,mutex_lock (&tz->lock); result = tz->ops->set_mode (tz, mode);mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-2@@ -193,19 +193,14 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal,return 0 ; } -mutex_lock (&data->ti_thermal->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) data->ti_thermal->polling_delay =FAST_TEMP_MONITORING_RATE ;else
data->ti_thermal->polling_delay= 0;-
mutex_unlock(&data->ti_thermal->lock);
-data->mode= mode;ti_bandgap_write_update_interval(bgp, data->sensor_id, data->ti_thermal->polling_delay);
-thermal_zone_device_update(data->ti_thermal);dev_dbg(&thermal->device, "thermal polling set for duration=%d msec\n", data->ti_thermal->polling_delay);--
2.1.4
Signature · 1 line
--peter;
Zhang Rui
reviewerRe: [PATCHv4 1/1] thermal: core: call thermal_zone_device_update() after mode update
In reply to Eduardo ValentinHi, Eduardo,
as the locking patch set has not been in upstream yet, you should either fold this fix into patch 02/15, or rebase your locking patch series on top of this fix.
thanks,
rui
Quoted 148 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()
...
local_data->mode =new_mode;
thermal_zone_device_update(tz);makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Darren Hart <[email protected]>Cc Zhang Rui <[email protected]>Cc Keerthy <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>---
Hello,
V3->V4:
- ti-soc: Removed extra locking from TI SoC inset_mode
- ACPI: Kept the update on check as it is called on other placesBR,
Eduardo
drivers/acpi/thermal.c | 1 - drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 5 ----- drivers/thermal/thermal_sysfs.c | 1 +
drivers/thermal/ti-soc-thermal/ti-thermal-common.c| 5 -----6 files changed, 1 insertion(+), 13 deletions(-)drivers/acpi/thermal.c +0
-1@@ -581,7 +581,6 @@ static int thermal_set_mode(structthermal_zone_device *thermal, ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", tz->tz_enabled ? "Enable" : "Disable")); -acpi_thermal_check (tz); } return 0;}
drivers/platform/x86/acerhdf.c +0
-0@@ -405,7 +405,6 @@ static inline voidacerhdf_enable_kernelmode (void ) kernelmode = 1;
thz_dev->polling_delay= interval*1000;drivers/platform/x86/acerhdf.c +0
-1-thermal_zone_device_update (thz_dev);
pr_notice("kernel mode fan control ON\n"); }drivers/thermal/imx_thermal.c +0
-0@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, }
data->mode= mode;drivers/thermal/imx_thermal.c +0
-1-thermal_zone_device_update (tz);
return 0;
}drivers/thermal/of- renamed from drivers/thermal/of-thermal.c +0
-0
thermal.c
index b8e509c..95c47da 100644drivers/thermal/of-thermal.c +0
-0@@ -282,17 +282,12 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, { struct __thermal_zone *data = tz->devdata;drivers/thermal/of-thermal.c +0
-2-mutex_lock (&tz->lock); -if (mode ==
THERMAL_DEVICE_ENABLED)tz->polling_delay=data->polling_delay; else
tz->polling_delay= 0;drivers/thermal/of-thermal.c +0
-2-mutex_unlock (&tz->lock); -
data->mode= mode;drivers/thermal/of-thermal.c +0
-1-thermal_zone_device_update (tz);
return 0;
}drivers/thermal/thermal_sysfs.c +1
-0@@ -100,6 +100,7 @@ mode_store(struct device *dev, structdevice_attribute *attr, mutex_lock(&tz->lock); result = tz->ops->set_mode(tz, mode); mutex_unlock(&tz->lock); +thermal_zone_device_update (tz);
if (result)
return result;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-0@@ -193,19 +193,14 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal, return 0; }drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-2-mutex_lock (&data->ti_thermal->lock); -if (mode ==
THERMAL_DEVICE_ENABLED)data->ti_thermal->polling_delay=FAST_TEMP_MONITORING_RATE;
else
data->ti_thermal->polling_delay= 0;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-2-mutex_unlock (&data->ti_thermal->lock); -
data->mode= mode; ti_bandgap_write_update_interval(bgp,data->sensor_id, data->ti_thermal-Quoted 1 line
polling_delay);drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-1-thermal_zone_device_update (data->ti_thermal);
Quoted 4 lines
dev_dbg(&thermal->device, "thermal polling set for duration=%d msec\n", data->ti_thermal->polling_delay);
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Eduardo Valentin
maintainerRe: [PATCHv4 1/1] thermal: core: call thermal_zone_device_update() after mode update
Quoted 5 lines · Zhang Rui
Hi, Eduardo,
as the locking patch set has not been in upstream yet, you should either fold this fix into patch 02/15, or rebase your locking patch series on top of this fix.
I am folding into 02/15 and resending only the new version of that patch. Are you OK to pick it up like that?
Quoted 157 lines
thanks,
ruiQuoted 152 lines · Eduardo Valentin
Because several drivers do the following pattern:
.set_mode()
...
local_data->mode =new_mode;
thermal_zone_device_update(tz);makes sense to simply do the
thermal_zone_device_update()in thermal core, after setting the new mode.Also, this patch also remove deadlocks on drivers that call
thermal_zone_device_update()on .set_mode(), as .set_mode() is now called always withtz->lockheld.Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Cc "Lee, Chun-Yi" <[email protected]>Cc Darren Hart <[email protected]>Cc Zhang Rui <[email protected]>Cc Keerthy <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>---
Hello,
V3->V4:
- ti-soc: Removed extra locking from TI SoC inset_mode
- ACPI: Kept the update on check as it is called on other placesBR,
Eduardo
drivers/acpi/thermal.c | 1 - drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 5 ----- drivers/thermal/thermal_sysfs.c | 1 +
drivers/thermal/ti-soc-thermal/ti-thermal-common.c| 5 -----6 files changed, 1 insertion(+), 13 deletions(-)drivers/acpi/thermal.c +0
-1@@ -581,7 +581,6 @@ static int thermal_set_mode(structthermal_zone_device *thermal, ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s kernel ACPI thermal control\n", tz->tz_enabled ? "Enable" : "Disable")); -acpi_thermal_check (tz); } return 0;}
drivers/platform/x86/acerhdf.c +0
-0@@ -405,7 +405,6 @@ static inline voidacerhdf_enable_kernelmode (void ) kernelmode = 1;
thz_dev->polling_delay= interval*1000;drivers/platform/x86/acerhdf.c +0
-1-thermal_zone_device_update (thz_dev);
pr_notice("kernel mode fan control ON\n"); }drivers/thermal/imx_thermal.c +0
-0@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, }
data->mode= mode;drivers/thermal/imx_thermal.c +0
-1-thermal_zone_device_update (tz);
return 0;
}drivers/thermal/of- renamed from drivers/thermal/of-thermal.c +0
-0
thermal.c
index b8e509c..95c47da 100644drivers/thermal/of-thermal.c +0
-0@@ -282,17 +282,12 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, { struct __thermal_zone *data = tz->devdata;drivers/thermal/of-thermal.c +0
-2-mutex_lock (&tz->lock); -if (mode ==
THERMAL_DEVICE_ENABLED)tz->polling_delay=data->polling_delay; else
tz->polling_delay= 0;drivers/thermal/of-thermal.c +0
-2-mutex_unlock (&tz->lock); -
data->mode= mode;drivers/thermal/of-thermal.c +0
-1-thermal_zone_device_update (tz);
return 0;
}drivers/thermal/thermal_sysfs.c +1
-0@@ -100,6 +100,7 @@ mode_store(struct device *dev, structdevice_attribute *attr, mutex_lock(&tz->lock); result = tz->ops->set_mode(tz, mode); mutex_unlock(&tz->lock); +thermal_zone_device_update (tz);
if (result)
return result;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-0@@ -193,19 +193,14 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal, return 0; }drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-2-mutex_lock (&data->ti_thermal->lock); -if (mode ==
THERMAL_DEVICE_ENABLED)data->ti_thermal->polling_delay=FAST_TEMP_MONITORING_RATE;
else
data->ti_thermal->polling_delay= 0;drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-2-mutex_unlock (&data->ti_thermal->lock); -
data->mode= mode; ti_bandgap_write_update_interval(bgp,data->sensor_id, data->ti_thermal-Quoted 1 line
polling_delay);drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0
-1-thermal_zone_device_update (data->ti_thermal);
dev_dbg(&thermal->device, "thermal polling set for duration=%d msec\n", data->ti_thermal->polling_delay);
Eduardo Valentin
maintainerPATCH v2 1/1 thermal: sysfs: lock tz while on access to mode properties
In reply to Eduardo ValentinSerialized calls to tz.ops in user facing
sysfs handler mode_show() and mode_store().
Because several drivers do the following pattern:
.set_mode()
...
local_data->mode = new_mode;
thermal_zone_device_update(tz);
makes sense to simply do the thermal_zone_device_update() in thermal core, after setting the new mode.
as .set_mode() is now called always with tz->lock held.
--- drivers/acpi/thermal.c | 1 - drivers/platform/x86/acerhdf.c | 1 - drivers/thermal/imx_thermal.c | 1 - drivers/thermal/of-thermal.c | 5 ----- drivers/thermal/thermal_sysfs.c | 14 +++++++++++--- drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 5 ----- 6 files changed, 11 insertions(+), 16 deletions(-)
drivers/acpi/thermal.c +0 -1
@@ -581,7 +581,6 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"%s kernel ACPI thermal control\n" , tz->tz_enabled ?"Enable" :"Disable" )); -acpi_thermal_check (tz); }return 0 ; }
drivers/platform/x86/acerhdf.c +0 -1
@@ -405,7 +405,6 @@ static inline void acerhdf_enable_kernelmode(void) kernelmode =1 ; thz_dev->polling_delay = interval*1000 ; -thermal_zone_device_update (thz_dev);pr_notice ("kernel mode fan control ON\n" ); }
drivers/thermal/imx_thermal.c +0 -1
@@ -246,7 +246,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, } data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
drivers/thermal/of-thermal.c +0 -5
@@ -282,17 +282,12 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, {struct __thermal_zone *data = tz->devdata; -mutex_lock (&tz->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) tz->polling_delay = data->polling_delay;else tz->polling_delay =0 ; -mutex_unlock (&tz->lock); - data->mode = mode; -thermal_zone_device_update (tz);return 0 ; }
drivers/thermal/thermal_sysfs.c +11 -3
@@ -62,7 +62,9 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf)if (!tz->ops->get_mode)return -EPERM ; +mutex_lock (&tz->lock); result = tz->ops->get_mode (tz, &mode); +mutex_unlock (&tz->lock);if (result)return result;
@@ -75,17 +77,23 @@ mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) {struct thermal_zone_device *tz =to_thermal_zone (dev); +enum thermal_device_mode mode =THERMAL_DEVICE_DISABLED ;int result;if (!tz->ops->set_mode)return -EPERM ;if (!strncmp (buf,"enabled" ,sizeof ("enabled" ) -1 )) - result = tz->ops->set_mode (tz,THERMAL_DEVICE_ENABLED ); + mode =THERMAL_DEVICE_ENABLED ;else if (!strncmp (buf,"disabled" ,sizeof ("disabled" ) -1 )) - result = tz->ops->set_mode (tz,THERMAL_DEVICE_DISABLED ); + mode =THERMAL_DEVICE_DISABLED ;else - result = -EINVAL ; +return -EINVAL ; + +mutex_lock (&tz->lock); + result = tz->ops->set_mode (tz, mode); +mutex_unlock (&tz->lock); +thermal_zone_device_update (tz);if (result)return result;
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0 -5
@@ -193,19 +193,14 @@ static int ti_thermal_set_mode(struct thermal_zone_device *thermal,return 0 ; } -mutex_lock (&data->ti_thermal->lock); -if (mode ==THERMAL_DEVICE_ENABLED ) data->ti_thermal->polling_delay =FAST_TEMP_MONITORING_RATE ;else data->ti_thermal->polling_delay =0 ; -mutex_unlock (&data->ti_thermal->lock); - data->mode = mode;ti_bandgap_write_update_interval (bgp, data->sensor_id, data->ti_thermal->polling_delay); -thermal_zone_device_update (data->ti_thermal);dev_dbg (&thermal->device,"thermal polling set for duration=%d msec\n" , data->ti_thermal->polling_delay);
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 3/15 thermal: sysfs: lock tz while on trip_point_type properties
In reply to Eduardo ValentinSerialized calls to tz.ops in user facing
sysfs handler trip_point_type_show() and trip_point_temp_store().
--- drivers/thermal/thermal_sysfs.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/thermal/thermal_sysfs.c +2 -0
@@ -114,7 +114,9 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,if (sscanf (attr->attr.name,"trip_point_%d_type" , &trip) !=1 )return -EINVAL ; +mutex_lock (&tz->lock); result = tz->ops->get_trip_type (tz, trip, &type); +mutex_unlock (&tz->lock);if (result)return result;
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 4/15 thermal: sysfs: lock tz while on trip_point_temp properties
In reply to Eduardo ValentinSerialized calls to tz.ops in user facing
sysfs handler trip_point_temp_show() and trip_point_temp_store().
--- drivers/thermal/thermal_sysfs.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/thermal/thermal_sysfs.c +4 -0
@@ -151,7 +151,9 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,if (kstrtoint (buf,10 , &temperature))return -EINVAL ; +mutex_lock (&tz->lock); ret = tz->ops->set_trip_temp (tz, trip, temperature); +mutex_unlock (&tz->lock);if (ret)return ret;
@@ -174,7 +176,9 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,if (sscanf (attr->attr.name,"trip_point_%d_temp" , &trip) !=1 )return -EINVAL ; +mutex_lock (&tz->lock); ret = tz->ops->get_trip_temp (tz, trip, &temperature); +mutex_unlock (&tz->lock);if (ret)return ret;
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 5/15 thermal: sysfs: lock tz while on trip_point_hyst properties
In reply to Eduardo ValentinSerialized calls to tz.ops in user facing
sysfs handler trip_point_hyst_store() andtrip_point_hyst_show().
--- drivers/thermal/thermal_sysfs.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/thermal/thermal_sysfs.c +4 -0
@@ -208,7 +208,9 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,* here. The driver implementing 'set_trip_hyst' has to * take care of this. */ +mutex_lock (&tz->lock); ret = tz->ops->set_trip_hyst (tz, trip, temperature); +mutex_unlock (&tz->lock);return ret ? ret : count; }
@@ -227,7 +229,9 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,if (sscanf (attr->attr.name,"trip_point_%d_hyst" , &trip) !=1 )return -EINVAL ; +mutex_lock (&tz->lock); ret = tz->ops->get_trip_hyst (tz, trip, &temperature); +mutex_unlock (&tz->lock);return ret ? ret :sprintf (buf,"%d\n" , temperature); }
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 6/15 thermal: sysfs: lock tz while on passive properties
In reply to Eduardo ValentinSerialized calls to tz.ops in user facing
sysfs handler passive_store() andpassive_show().
--- drivers/thermal/thermal_sysfs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/thermal/thermal_sysfs.c +14 -1
@@ -252,18 +252,24 @@ passive_store(struct device *dev, struct device_attribute *attr,if (state && state <1000 )return -EINVAL ; +mutex_lock (&tz->lock);if (state && !tz->forced_passive) {if (!tz->passive_delay) tz->passive_delay =1000 ; +mutex_unlock (&tz->lock);thermal_zone_device_rebind_exception (tz,"Processor" ,sizeof ("Processor" )); +mutex_lock (&tz->lock); }else if (!state && tz->forced_passive) { tz->passive_delay =0 ; +mutex_unlock (&tz->lock);thermal_zone_device_unbind_exception (tz,"Processor" ,sizeof ("Processor" )); +mutex_lock (&tz->lock); } tz->forced_passive = state; +mutex_unlock (&tz->lock);thermal_zone_device_update (tz);
@@ -275,8 +281,13 @@ passive_show(struct device *dev, struct device_attribute *attr, char *buf) {struct thermal_zone_device *tz =to_thermal_zone (dev); +unsigned int passive; -return sprintf (buf,"%d\n" , tz->forced_passive); +mutex_lock (&tz->lock); + passive = tz->forced_passive; +mutex_unlock (&tz->lock); + +return sprintf (buf,"%u\n" , passive); } static ssize_t
@@ -494,7 +505,9 @@ static umode_t thermal_zone_passive_is_visible(struct kobject *kobj, tz = container_of(dev, struct thermal_zone_device, device);for (count =0 ; count < tz->trips; count++) { +mutex_lock (&tz->lock); tz->ops->get_trip_type (tz, count, &trip_type); +mutex_unlock (&tz->lock);if (trip_type ==THERMAL_TRIP_PASSIVE )return attr->mode;
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 7/15 thermal: sysfs: lock tz while on policy properties
In reply to Eduardo ValentinSerialized calls to tz.ops in user facing
sysfs handler policy_show().policy_store() is already locked by
the thermal core.
--- drivers/thermal/thermal_sysfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/thermal/thermal_sysfs.c +7 -1
@@ -311,8 +311,14 @@ static ssize_t policy_show(struct device *dev, struct device_attribute *devattr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); +char *name; -return sprintf (buf,"%s\n" , tz->governor->name); +/* locking the zone because governor->name does not change */ +mutex_lock (&tz->lock); + name = tz->governor->name; +mutex_unlock (&tz->lock); + +return sprintf (buf,"%s\n" , name); } static ssize_t
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 8/15 thermal: sysfs: improve locking of emul_temp_store()
In reply to Eduardo Valentinemul_temp_store locks only for setting temperature, but it must lock also for calls to tz.ops.
--- drivers/thermal/thermal_sysfs.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/thermal/thermal_sysfs.c +4 -5
@@ -340,13 +340,12 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,if (kstrtoint (buf,10 , &temperature))return -EINVAL ; -if (!tz->ops->set_emul_temp) { -mutex_lock (&tz->lock); +mutex_lock (&tz->lock); +if (!tz->ops->set_emul_temp) tz->emul_temperature = temperature; -mutex_unlock (&tz->lock); - }else { +else ret = tz->ops->set_emul_temp (tz, temperature); - } +mutex_unlock (&tz->lock);if (!ret)thermal_zone_device_update (tz);
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 9/15 thermal: sysfs: lock tz when access sustainable power properties
In reply to Eduardo ValentinLock tz when in user facing sysfs handlers to expose sustainable power properties. This includes:sustainable_power_show() sustainable_power_store()
--- drivers/thermal/thermal_sysfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/thermal/thermal_sysfs.c +8 -1
@@ -360,9 +360,14 @@ sustainable_power_show(struct device *dev, struct device_attribute *devattr, char *buf) {struct thermal_zone_device *tz =to_thermal_zone (dev); +unsigned int sustainable_power; + +mutex_lock (&tz->lock); + sustainable_power = tz->tzp->sustainable_power; +mutex_unlock (&tz->lock);if (tz->tzp) -return sprintf (buf,"%u\n" , tz->tzp->sustainable_power); +return sprintf (buf,"%u\n" , sustainable_power);else return -EIO ; }
@@ -380,7 +385,9 @@ sustainable_power_store(struct device *dev, struct device_attribute *devattr,if (kstrtou32 (buf,10 , &sustainable_power))return -EINVAL ; +mutex_lock (&tz->lock); tz->tzp->sustainable_power = sustainable_power; +mutex_unlock (&tz->lock);return count; }
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 10/15 thermal: sysfs: lock tz when access tzp properties
In reply to Eduardo ValentinLock tz when in user facing sysfs handlers to expose tzp properties. This includes changing the macro create_s32_tzp_attr(), which is used in the tzp properties:k_po, k_pu, k_i, k_d, integral_cutoff, slope, offset.
--- drivers/thermal/thermal_sysfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/thermal/thermal_sysfs.c +10 -3
@@ -398,11 +398,16 @@ sustainable_power_store(struct device *dev, struct device_attribute *devattr, char *buf) \ { \struct thermal_zone_device *tz =to_thermal_zone (dev); \ +int value; \ \ -if (tz->tzp) \ -return sprintf (buf,"%d\n" , tz->tzp->name); \ -else \ +if (!tz->tzp) \return -EIO ; \ + \ +mutex_lock (&tz->lock); \ + value = tz->tzp->name; \ +mutex_unlock (&tz->lock); \ + \ +return sprintf (buf,"%d\n" , value); \ } \ \ static ssize_t \
@@ -418,7 +423,9 @@ sustainable_power_store(struct device *dev, struct device_attribute *devattr,if (kstrtos32 (buf,10 , &value)) \return -EINVAL ; \ \ +mutex_lock (&tz->lock); \ tz->tzp->name = value; \ +mutex_unlock (&tz->lock); \ \return count; \ } \
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 11/15 thermal: sysfs: lock cdev while accessing type
In reply to Eduardo ValentinSerialized data access to cdev->type in user facing sysfs handler thermal_cooling_device_type_show().
The existing cdev lock is used. Updating comment
on the lock definition.
--- drivers/thermal/thermal_sysfs.c | 7 ++++++- include/linux/thermal.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/thermal/thermal_sysfs.c +6 -1
@@ -682,8 +682,13 @@ thermal_cooling_device_type_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_cooling_device *cdev = to_cooling_device(dev); +char *type; + +mutex_lock (&cdev->lock); + type = cdev->type; +mutex_unlock (&cdev->lock); -return sprintf (buf,"%s\n" , cdev->type); +return sprintf (buf,"%s\n" , type); } static ssize_t
include/linux/thermal.h +1 -1
@@ -137,7 +137,7 @@ struct thermal_cooling_device {void *devdata;const struct thermal_cooling_device_ops *ops;bool updated;/* true if the cooling device does not need update */ -struct mutex lock;/* protect thermal_instances list */ +struct mutex lock;/* protect thermal_cooling_device */ struct list_head thermal_instances;struct list_head node; };
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 12/15 thermal: sysfs: lock cdev while accessing max_state
In reply to Eduardo ValentinSerialized calls to cdev->ops in user facing sysfs handler thermal_cooling_device_max_state_show().
--- drivers/thermal/thermal_sysfs.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/thermal/thermal_sysfs.c +2 -0
@@ -699,7 +699,9 @@ thermal_cooling_device_max_state_show(struct device *dev,unsigned long state;int ret; +mutex_lock (&cdev->lock); ret = cdev->ops->get_max_state (cdev, &state); +mutex_unlock (&cdev->lock);if (ret)return ret;return sprintf (buf,"%ld\n" , state);
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 13/15 thermal: sysfs: lock cdev while accessing cur_state
In reply to Eduardo ValentinSerialized calls to cdev->ops in user facing sysfs handlers thermal_cooling_device_cur_state_show() and thermal_cooling_device_cur_state_store().
--- drivers/thermal/thermal_sysfs.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/thermal/thermal_sysfs.c +4 -0
@@ -715,7 +715,9 @@ thermal_cooling_device_cur_state_show(struct device *dev,unsigned long state;int ret; +mutex_lock (&cdev->lock); ret = cdev->ops->get_cur_state (cdev, &state); +mutex_unlock (&cdev->lock);if (ret)return ret;return sprintf (buf,"%ld\n" , state);
@@ -736,7 +738,9 @@ thermal_cooling_device_cur_state_store(struct device *dev,if ((long )state <0 )return -EINVAL ; +mutex_lock (&cdev->lock); result = cdev->ops->set_cur_state (cdev, state); +mutex_unlock (&cdev->lock);if (result)return result;return count;
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 14/15 thermal: sysfs: serialize access to instances
In reply to Eduardo ValentinBecause instances are the result of a matching between cdev and tz, we need to lock both in order to access the instance reliably.
This patch locks both tz and cdev in user facing sysfs handlers when accessing thermal zone instance.
--- drivers/thermal/thermal_sysfs.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/thermal/thermal_sysfs.c +18 -2
@@ -781,14 +781,20 @@ thermal_cooling_device_trip_point_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_instance *instance; +int trip; instance = container_of(attr, struct thermal_instance, attr); +mutex_lock (&instance->tz->lock); +mutex_lock (&instance->cdev->lock); + trip = instance->trip; +mutex_unlock (&instance->cdev->lock); +mutex_unlock (&instance->tz->lock);if (instance->trip ==THERMAL_TRIPS_NONE )return sprintf (buf,"-1\n" );else -return sprintf (buf,"%d\n" , instance->trip); +return sprintf (buf,"%d\n" , trip); }ssize_t
@@ -796,10 +802,16 @@ thermal_cooling_device_weight_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_instance *instance; +int weight; instance = container_of(attr, struct thermal_instance, weight_attr); +mutex_lock (&instance->tz->lock); +mutex_lock (&instance->cdev->lock); + weight = instance->weight; +mutex_unlock (&instance->cdev->lock); +mutex_unlock (&instance->tz->lock); -return sprintf (buf,"%d\n" , instance->weight); +return sprintf (buf,"%d\n" , weight); }ssize_t
@@ -815,7 +827,11 @@ thermal_cooling_device_weight_store(struct device *dev,return ret; instance = container_of(attr, struct thermal_instance, weight_attr); +mutex_lock (&instance->tz->lock); +mutex_lock (&instance->cdev->lock); instance->weight = weight; +mutex_unlock (&instance->cdev->lock); +mutex_unlock (&instance->tz->lock);return count; }
Signature · 1 line
2.1.4
Eduardo Valentin
maintainerPATCH 15/15 thermal: sysfs: add comments describing locking strategy
In reply to Eduardo ValentinThe locking strategy of sysfs entries in thermal subsystem is to hold a lock to serialize access to struct thermal_zone_device and struct thermal_cooling_device data. Besides, the respective locks will also be held if calls to ops need to be done to fetch data or to trigger driver actions.
The exception of the locking strategy are functions called during initialization of cdev and tz.
--- drivers/thermal/thermal_sysfs.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/thermal/thermal_sysfs.c +15 -1
@@ -23,7 +23,14 @@#include "thermal_core.h" -/* sys I/F for thermal zone */ +/* +* sys I/F for thermal zone +* +* Note on locking. The sysfs interface will always first +* lock the zone to serialize data access and ops calls. +* All calls to thermal_core and thermal_helpers are assumed +* to handle locking properly. +*/ static ssize_t type_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -555,6 +562,9 @@ static const struct attribute_group *thermal_zone_attribute_groups[] = {* helper function to instantiate sysfs entries for every trip * point and its properties of a struct thermal_zone_device. * +* This function is assumed to be called only during probe, +* and therefore no locking in the thermal zone device is done. +* * Return: 0 on success, the proper error value otherwise. */ static int create_trip_attrs (struct thermal_zone_device *tz,int mask)
@@ -770,6 +780,10 @@ static const struct attribute_group *cooling_device_attr_groups[] = { NULL, }; +/* +* Assumed to be called at the creation of the cooling device +* and for this reason, no locking is done +*/ void thermal_cooling_device_setup_sysfs (struct thermal_cooling_device *cdev) { cdev->device.groups = cooling_device_attr_groups;
Signature · 1 line
2.1.4
Quoted 13 lines · Eduardo Valentin
Hello,
Several thermal sysfs entries are currently being called from userspace without locking. Data and calls to ops are accessed deliberated without any care for locking.
This patch series attempts to fix this.
Now that sysfs handlers are on the same place it is easier to visualize this issue and fix it. The strategy is essentially to lock any access. Also, functions in thermal core and thermal helpers are assumed to do the proper locking already.
Quoted 7 lines
This patch series is based on the thermal core reorganization.
There is no change in the ABI to userspace. The difference is that now serialization to data will be done.
For your consideration, I am also adding this to this branch:
git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermalsysfs_locking
Tested and checked for reading temperatures from all the thermal zones on DRA7/DRA72 and AM57XX-BEAGLE-X15 boards.
Also tested emulation using a rebased version of
https://lkml.org/lkml/2016/5/10/346
For DRA7/DRA72 and BEAGLE-X15:
Quoted 26 lines
Comments are welcome.
BR,
Eduardo Valentin (15):
thermal: sysfs: lock tz intype_show
thermal: sysfs: lock tz while on access to mode properties
thermal: sysfs: lock tz while ontrip_point_typeproperties
thermal: sysfs: lock tz while ontrip_point_tempproperties
thermal: sysfs: lock tz while ontrip_point_hystproperties
thermal: sysfs: lock tz while on passive properties
thermal: sysfs: lock tz while on policy properties
thermal: sysfs: improve locking ofemul_temp_store()
thermal: sysfs: lock tz when access sustainable power properties
thermal: sysfs: lock tz when access tzp properties
thermal: sysfs: lock cdev while accessing type
thermal: sysfs: lock cdev while accessingmax_state
thermal: sysfs: lock cdev while accessingcur_state
thermal: sysfs: serialize access to instances
thermal: sysfs: add comments describing locking strategydrivers/thermal/thermal_sysfs.c | 133 ++++++++++++++++++++++++++++++++++------ include/linux/thermal.h | 2 +- 2 files changed, 115 insertions(+), 20 deletions(-)