linux/drivers/thermal
Thomas Gleixner ab47bd964a thermal/x86_pkg_temp: Sanitize locking
The work cancellation code, the thermal zone unregistering, the work code
and the interrupt notification function are racy against each other and
against cpu hotplug and module exit. The random locking sprinkeled all
over the place does not help anything and probably exists to make people
feel good. The resulting issues (mainly use after free) are probably
hard to trigger, but they clearly exist

Protect the package list with a spinlock so it can be accessed from the
interrupt notifier and also from the work function. The add/removal code in
the hotplug callbacks take the lock for list manipulation. That makes sure
that on removal neither the interrupt notifier nor the work function can
access the about to be freed package structure anymore.

The thermal zone unregistering is another trainwreck. It's not serialized
against the work function. So unregistering the zone device can race with
the work function and cause havoc.

Protect the thermal zone with a mutex, which is held in the work
function to make sure that the zone device is not being unregistered
concurrently.

To solve the module exit issues, we simply invoke the cpu offline callback
and let it work its magic. For that it's required to keep track of the
participating cpus in a package, because topology_core_mask is not affected
by calling the offline callback for teardown of the driver, so it would
never free the package as there is always a valid target in
topology_core_mask.

Use proper names for the locks so it's clear what they are for and add a
pile of comments to explain the protection rules.

It's amazing that fixing the locking and adding 30 lines of comments
explaining it still removes more lines than it adds.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30 10:25:19 +08:00
..
int340x_thermal thermal: int3403: Process trip change notification 2016-09-27 14:37:17 +08:00
qcom thermal: qcom: tsens: Fix return value check in init_common() 2016-09-27 14:02:16 +08:00
samsung thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
st thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
tegra thermal: tegra: add hw-throttle for Tegra132 2016-09-27 14:02:32 +08:00
ti-soc-thermal thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
Kconfig Merge branches 'thermal-soc', 'thermal-core', 'thermal-intel' and 'thermal-tegra-hw-throttle' into next 2016-09-27 14:03:19 +08:00
Makefile Merge branches 'thermal-soc', 'thermal-core', 'thermal-intel' and 'thermal-tegra-hw-throttle' into next 2016-09-27 14:03:19 +08:00
armada_thermal.c thermal: armada: Fix possible overflow in the Armada 380 thermal sensor formula 2015-10-30 11:33:23 -07:00
clock_cooling.c thermal: clock_cooling: Fix missing mutex_init() 2016-08-08 10:57:39 +08:00
cpu_cooling.c thermal: cpu_cooling: Fix wrong comment call function name 2016-09-27 09:38:17 +08:00
db8500_cpufreq_cooling.c thermal: db8500_cpufreq_cooling: Fix module autoload for OF platform driver 2015-09-13 20:26:19 -07:00
db8500_thermal.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
devfreq_cooling.c devfreq_cooling: no need to check state with negative number 2016-09-27 14:02:16 +08:00
dove_thermal.c thermal: consistently use int for temperatures 2015-08-03 23:15:50 +08:00
fair_share.c thermal: fix race condition when updating cooling device 2016-08-08 10:57:39 +08:00
gov_bang_bang.c thermal: bang-bang governor: act on lower trip boundary 2016-09-27 14:02:16 +08:00
hisi_thermal.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
imx_thermal.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
intel_bxt_pmic_thermal.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
intel_pch_thermal.c thermal: intel_pch_thermal: Support skylake PCH 100 series thermal 2016-11-23 10:05:52 +08:00
intel_powerclamp.c thermal/powerclamp: add back module device table 2016-11-21 20:54:40 +08:00
intel_quark_dts_thermal.c x86/platform/iosf_mbi: Remove duplicate definitions 2015-12-09 01:18:34 +01:00
intel_soc_dts_iosf.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
intel_soc_dts_iosf.h Thermal: Intel SoC: DTS thermal IOSF core 2015-05-01 11:20:42 +08:00
intel_soc_dts_thermal.c x86, thermal: Clean up and fix CPU model detection for intel_soc_dts_thermal 2016-06-08 13:03:26 +02:00
kirkwood_thermal.c thermal: consistently use int for temperatures 2015-08-03 23:15:50 +08:00
max77620_thermal.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
mtk_thermal.c thermal: mtk_thermal: Check return value of devm_thermal_zone_of_sensor_register 2016-09-27 14:02:16 +08:00
of-thermal.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
power_allocator.c thermal: fix race condition when updating cooling device 2016-08-08 10:57:39 +08:00
qcom-spmi-temp-alarm.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
qoriq_thermal.c thermal: qoriq: Add thermal management support 2016-09-27 14:02:16 +08:00
rcar_thermal.c Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux 2016-10-12 11:05:23 -07:00
rockchip_thermal.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
spear_thermal.c thermal: spear: use __maybe_unused for PM functions 2016-02-09 14:12:08 -08:00
step_wise.c thermal: fix race condition when updating cooling device 2016-08-08 10:57:39 +08:00
tango_thermal.c thermal: tango: add resume support 2016-09-27 14:02:16 +08:00
thermal-generic-adc.c thermal: generic-adc: Add ADC based thermal sensor driver 2016-05-17 07:28:31 -07:00
thermal_core.c thermal: Enhance thermal_zone_device_update for events 2016-09-27 14:35:21 +08:00
thermal_core.h Thermal: initialize thermal zone device correctly 2015-12-29 15:59:44 +08:00
thermal_hwmon.c thermal: hwmon: EXPORT_SYMBOL_GPL for thermal hwmon sysfs 2016-08-08 10:57:39 +08:00
thermal_hwmon.h thermal: hwmon: move hwmon support to single file 2013-09-03 09:09:12 -04:00
user_space.c thermal: user_space gov: Add additional information in uevent 2016-09-27 14:37:10 +08:00
x86_pkg_temp_thermal.c thermal/x86_pkg_temp: Sanitize locking 2016-11-30 10:25:19 +08:00