From d8ea382c8ab40dedc14cbbbdf7a75787eaed2690 Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Mon, 16 Aug 2021 17:18:33 +0530 Subject: [PATCH] devfreq: govener_memlat: fix cpu_hotplug_lock recursive lock warning Possible unsafe locking scenario: CPU0 ---- lock(cpu_hotplug_lock.rw_sem); lock(cpu_hotplug_lock.rw_sem); *** DEADLOCK *** Below code under start_hwmon may cause this recursive locking. get_online_cpus(); for_each_cpu(cpu, cpu_possible_mask) { if (!cpumask_test_cpu(cpu, cpu_online_mask)) per_cpu(cpu_is_hp, cpu) = true; } ret = memlat_event_cpu_hp_init(); put_online_cpus(); get_online_cpus() acquires cpu_hotplug_lock.rw_sem lock. Then memlat_event_cpu_hp_init() -> __cpuhp_setup_state() tries to acquire the same lock again. Use cpuslocked version of __cpuhp_setup_state() to avoid this warning. Change-Id: Ied9fe53d02c74816f38c1efe954cea91f9831cc7 Signed-off-by: Abhishek Shah --- drivers/devfreq/arm-memlat-mon.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/devfreq/arm-memlat-mon.c b/drivers/devfreq/arm-memlat-mon.c index 7cf6d701a496..1ab4a88e4fa0 100644 --- a/drivers/devfreq/arm-memlat-mon.c +++ b/drivers/devfreq/arm-memlat-mon.c @@ -519,11 +519,15 @@ static int memlat_event_hotplug_going_down(unsigned int cpu) return ret; } +/* + * Note: We must be holding cpus_read_lock() before calling this function + * since we are using cpuslocked version of function inside it + */ static int memlat_event_cpu_hp_init(void) { int ret = 0; - ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, + ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN, "MEMLAT_EVENT", memlat_event_hotplug_coming_up, memlat_event_hotplug_going_down);