linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] cpufreq: unlock correct rwsem while updating policy->cpu
@ 2013-09-16 15:10 Viresh Kumar
  2013-09-16 15:10 ` [PATCH 2/2] cpufreq: make return type of lock_policy_rwsem_{read|write}() as void Viresh Kumar
  2013-09-16 16:27 ` [PATCH 1/2] cpufreq: unlock correct rwsem while updating policy->cpu Jon Medhurst (Tixy)
  0 siblings, 2 replies; 13+ messages in thread
From: Viresh Kumar @ 2013-09-16 15:10 UTC (permalink / raw)
  To: rjw, tixy
  Cc: linaro-kernel, patches, cpufreq, linux-pm, linux-kernel,
	srivatsa.bhat, Viresh Kumar

Current code looks like this:

        WARN_ON(lock_policy_rwsem_write(cpu));
        update_policy_cpu(policy, new_cpu);
        unlock_policy_rwsem_write(cpu);

{lock|unlock}_policy_rwsem_write(cpu) takes/releases policy->cpu's rwsem.
Because cpu is changing with the call to update_policy_cpu(), the
unlock_policy_rwsem_write() will release the incorrect lock.

The right solution would be to take rwsem lock/unlock for both old and new cpu.
This patch fixes this bug by taking both locks directly instead of calling
lock_policy_rwsem_write().

Reported-by: Jon Medhurst<tixy@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
Hi Rafael,

Probably we can get this patch in for 3.12? The second one can go in 3.13.

These are compile tested only at my end. Tixy reported these and probably can
give his tested-by once he is done testing them.

 drivers/cpufreq/cpufreq.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 43c24aa..c18bf7b 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -952,9 +952,16 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
 	if (cpu == policy->cpu)
 		return;
 
+	/* take direct locks as lock_policy_rwsem_write wouldn't work here */
+	down_write(&per_cpu(cpu_policy_rwsem, policy->cpu));
+	down_write(&per_cpu(cpu_policy_rwsem, cpu));
+
 	policy->last_cpu = policy->cpu;
 	policy->cpu = cpu;
 
+	up_write(&per_cpu(cpu_policy_rwsem, cpu));
+	up_write(&per_cpu(cpu_policy_rwsem, policy->cpu));
+
 #ifdef CONFIG_CPU_FREQ_TABLE
 	cpufreq_frequency_table_update_policy_cpu(policy);
 #endif
@@ -1203,9 +1210,7 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
 
 		new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu, frozen);
 		if (new_cpu >= 0) {
-			WARN_ON(lock_policy_rwsem_write(cpu));
 			update_policy_cpu(policy, new_cpu);
-			unlock_policy_rwsem_write(cpu);
 
 			if (!frozen) {
 				pr_debug("%s: policy Kobject moved to cpu: %d "
-- 
1.7.12.rc2.18.g61b472e


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-10-02 16:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-16 15:10 [PATCH 1/2] cpufreq: unlock correct rwsem while updating policy->cpu Viresh Kumar
2013-09-16 15:10 ` [PATCH 2/2] cpufreq: make return type of lock_policy_rwsem_{read|write}() as void Viresh Kumar
2013-09-17  8:28   ` Jon Medhurst (Tixy)
2013-09-30 18:28   ` Rafael J. Wysocki
2013-10-02  8:43     ` Viresh Kumar
2013-10-02 16:38       ` Rafael J. Wysocki
2013-10-02 16:49         ` Viresh Kumar
2013-09-16 16:27 ` [PATCH 1/2] cpufreq: unlock correct rwsem while updating policy->cpu Jon Medhurst (Tixy)
2013-09-16 17:08   ` Viresh Kumar
2013-09-16 18:34     ` Rafael J. Wysocki
2013-09-17  4:38       ` Viresh Kumar
2013-09-16 18:42     ` Jon Medhurst (Tixy)
2013-09-17  4:46       ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).