The patch titled cpufreq: ondemand vs suspend deadlock fix has been added to the -mm tree. Its filename is cpufreq-ondemand-vs-suspend-deadlock-fix.patch See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: cpufreq: ondemand vs suspend deadlock fix From: Venkatesh Pallipadi <venkatesh.pallipadi@xxxxxxxxx> Root caused this to a deadlock in cpufreq and ondemand. The deadlock is due to non-existant ordering between cpu_hotplug lock and dbs_mutex. Basically a race condition between cpu_down() and do_dbs_timer(). cpu_down() flow: 1 cpu_down() for CPU 1 2 Takes the cpu_hotplug lock 3 Calls pre-down notifiers 4 notifier handler in cpufreq calls cpufreq_driver_target 5 cpufreq_driver_target calls cpu_hotplu lock/unlock It is OK as cpu_hotplug lock is recusive for same process 6 CPU 1 goes down 7 CPU 0 calls post down notifiers for CPU 1 8 notifier handler in cpufreq calls governor event for stop 9 this ondemand governor routine takes dbs_mutex Basically cpu_hotplug lock being taken before dbs_mutex in this path. There is another event that gets triggered periodically in do_dbs_timer(). This runs in the context of ondemand workqueue and it takes dbs_mutex first and takes cpu_hotplug later, inside __cpufreq_driver_target() call. This ordering conflicts with mutex ordering in cpu_down and causes a deadlock. Attached patch fixes the issue for both ondemand and conservative governors. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@xxxxxxxxx> Cc: Dave Jones <davej@xxxxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxx> --- drivers/cpufreq/cpufreq_conservative.c | 12 ++++++++++++ drivers/cpufreq/cpufreq_ondemand.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff -puN drivers/cpufreq/cpufreq_conservative.c~cpufreq-ondemand-vs-suspend-deadlock-fix drivers/cpufreq/cpufreq_conservative.c --- a/drivers/cpufreq/cpufreq_conservative.c~cpufreq-ondemand-vs-suspend-deadlock-fix +++ a/drivers/cpufreq/cpufreq_conservative.c @@ -72,6 +72,14 @@ static DEFINE_PER_CPU(struct cpu_dbs_inf static unsigned int dbs_enable; /* number of CPUs using this policy */ +/* + * DEADLOCK ALERT! There is a ordering requirement between cpu_hotplug + * lock and dbs_mutex. cpu_hotplug lock should always be held before + * dbs_mutex. If any function that can potentially take cpu_hotplug lock + * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then + * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock + * is recursive for the same process. -Venki + */ static DEFINE_MUTEX (dbs_mutex); static DECLARE_WORK (dbs_work, do_dbs_timer, NULL); @@ -414,12 +422,14 @@ static void dbs_check_cpu(int cpu) static void do_dbs_timer(void *data) { int i; + lock_cpu_hotplug(); mutex_lock(&dbs_mutex); for_each_online_cpu(i) dbs_check_cpu(i); schedule_delayed_work(&dbs_work, usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); mutex_unlock(&dbs_mutex); + unlock_cpu_hotplug(); } static inline void dbs_timer_init(void) @@ -514,6 +524,7 @@ static int cpufreq_governor_dbs(struct c break; case CPUFREQ_GOV_LIMITS: + lock_cpu_hotplug(); mutex_lock(&dbs_mutex); if (policy->max < this_dbs_info->cur_policy->cur) __cpufreq_driver_target( @@ -524,6 +535,7 @@ static int cpufreq_governor_dbs(struct c this_dbs_info->cur_policy, policy->min, CPUFREQ_RELATION_L); mutex_unlock(&dbs_mutex); + unlock_cpu_hotplug(); break; } return 0; diff -puN drivers/cpufreq/cpufreq_ondemand.c~cpufreq-ondemand-vs-suspend-deadlock-fix drivers/cpufreq/cpufreq_ondemand.c --- a/drivers/cpufreq/cpufreq_ondemand.c~cpufreq-ondemand-vs-suspend-deadlock-fix +++ a/drivers/cpufreq/cpufreq_ondemand.c @@ -71,6 +71,14 @@ static DEFINE_PER_CPU(struct cpu_dbs_inf static unsigned int dbs_enable; /* number of CPUs using this policy */ +/* + * DEADLOCK ALERT! There is a ordering requirement between cpu_hotplug + * lock and dbs_mutex. cpu_hotplug lock should always be held before + * dbs_mutex. If any function that can potentially take cpu_hotplug lock + * (like __cpufreq_driver_target()) is being called with dbs_mutex taken, then + * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock + * is recursive for the same process. -Venki + */ static DEFINE_MUTEX (dbs_mutex); static DECLARE_WORK (dbs_work, do_dbs_timer, NULL); @@ -363,12 +371,14 @@ static void dbs_check_cpu(int cpu) static void do_dbs_timer(void *data) { int i; + lock_cpu_hotplug(); mutex_lock(&dbs_mutex); for_each_online_cpu(i) dbs_check_cpu(i); queue_delayed_work(dbs_workq, &dbs_work, usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); mutex_unlock(&dbs_mutex); + unlock_cpu_hotplug(); } static inline void dbs_timer_init(void) @@ -469,6 +479,7 @@ static int cpufreq_governor_dbs(struct c break; case CPUFREQ_GOV_LIMITS: + lock_cpu_hotplug(); mutex_lock(&dbs_mutex); if (policy->max < this_dbs_info->cur_policy->cur) __cpufreq_driver_target( @@ -479,6 +490,7 @@ static int cpufreq_governor_dbs(struct c this_dbs_info->cur_policy, policy->min, CPUFREQ_RELATION_L); mutex_unlock(&dbs_mutex); + unlock_cpu_hotplug(); break; } return 0; _ Patches currently in -mm which might be from venkatesh.pallipadi@xxxxxxxxx are git-acpi.patch cpufreq-ondemand-vs-suspend-deadlock-fix.patch hpet-rtc-emulation-add-watchdog-timer.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html