drivers: thermal: fix race on workqueue
A deadlock might happen when fan_ramp_work are started right after the
therm_fan_est_work has started with the mutex "fan_state_lock" held and
would like to flush the fan_ramp_work, similar call trace can be seen as
the below.
nvidia.NvCPLSvc D
ffffffc00008691c 0 1141 253 0x00000001
Call trace:
[<
ffffffc00008691c>] __switch_to+0xc8/0xd4
[<
ffffffc000c34c8c>] __schedule+0x62c/0x7bc
[<
ffffffc000c34e74>] schedule+0x58/0x60
[<
ffffffc000c352b8>] schedule_preempt_disabled+0x14/0x24
[<
ffffffc000c33aec>] __mutex_lock_slowpath+0x174/0x240
[<
ffffffc000c33bfc>] mutex_lock+0x44/0x60
[<
ffffffc000880204>] set_fan_pwm_state_map_sysfs+0x90/0x114
[<
ffffffc00053656c>] dev_attr_store+0x18/0x28
[<
ffffffc0001ff818>] sysfs_write_file+0xfc/0x154
[<
ffffffc0001987bc>] vfs_write+0xc0/0x184
[<
ffffffc000199030>] SyS_write+0x94/0x164
kworker/u9:2 D
ffffffc00008691c 0 1732 2 0x00000000
Workqueue: thermal-fan-est.47 therm_fan_est_work_func
Call trace:
[<
ffffffc00008691c>] __switch_to+0xc8/0xd4
[<
ffffffc000c34c8c>] __schedule+0x62c/0x7bc
[<
ffffffc000c34e74>] schedule+0x58/0x60
[<
ffffffc000c32d78>] schedule_timeout+0x2c/0x254
[<
ffffffc000c34434>] wait_for_common+0x134/0x170
[<
ffffffc000c34484>] wait_for_completion+0x14/0x1c
[<
ffffffc0000c7b88>] flush_workqueue+0x1d0/0x528
[<
ffffffc000880144>] fan_update_target_pwm+0x4c/0x7c
[<
ffffffc0008802f0>] pwm_fan_set_cur_state+0x68/0x8c
[<
ffffffc00087a570>] thermal_cdev_update+0xa0/0x12c
[<
ffffffc00087e528>] pid_thermal_gov_throttle+0x308/0x394
[<
ffffffc00087bc9c>] handle_thermal_trip+0xd4/0x12c
[<
ffffffc00087bde0>] thermal_zone_device_update+0xec/0x14c
[<
ffffffc00056d1dc>] therm_fan_est_work_func+0x1c4/0x220
[<
ffffffc0000c9b1c>] process_one_work+0x260/0x410
[<
ffffffc0000cac5c>] worker_thread+0x204/0x378
[<
ffffffc0000d1350>] kthread+0xc0/0xc8
Bug
200214795
Change-Id: Iab0a8ce6b334f478e681320d5d64a43667e30c02
Signed-off-by: Bill Huang <bilhuang@nvidia.com>
Reviewed-on: http://git-master/r/
1181093
(cherry picked from commit
7544902b2c55d8ad5fb561911977367b1e9b19ea)
Reviewed-on: http://git-master/r/
1184611
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Vinayak Pane <vpane@nvidia.com>