Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1306538 > unrolled thread

[RFC PATCH 13/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_prepare

Started byJuri Lelli <juri.lelli@arm.com>
First post2016-01-11 18:40 +0100
Last post2016-01-12 12:00 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [RFC PATCH 13/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_prepare Juri Lelli <juri.lelli@arm.com> - 2016-01-11 18:40 +0100
    Re: [RFC PATCH 13/19] cpufreq: fix locking of policy->rwsem in  cpufreq_offline_prepare Viresh Kumar <viresh.kumar@linaro.org> - 2016-01-12 12:00 +0100

#1306538 — [RFC PATCH 13/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_prepare

FromJuri Lelli <juri.lelli@arm.com>
Date2016-01-11 18:40 +0100
Subject[RFC PATCH 13/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_prepare
Message-ID<qPOBH-5zs-7@gated-at.bofh.it>
There are paths in cpufreq_offline_prepare where policy is used, but its
rwsem is not held.

Fix it.

Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Juri Lelli <juri.lelli@arm.com>
---
 drivers/cpufreq/cpufreq.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 2c7cc6c73..91158b0 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1332,13 +1332,13 @@ static void cpufreq_offline_prepare(unsigned int cpu)
 		return;
 	}
 
+	down_write(&policy->rwsem);
 	if (has_target()) {
 		int ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
 		if (ret)
 			pr_err("%s: Failed to stop governor\n", __func__);
 	}
 
-	down_write(&policy->rwsem);
 	cpumask_clear_cpu(cpu, policy->cpus);
 
 	if (policy_is_inactive(policy)) {
@@ -1356,12 +1356,16 @@ static void cpufreq_offline_prepare(unsigned int cpu)
 	/* Start governor again for active policy */
 	if (!policy_is_inactive(policy)) {
 		if (has_target()) {
-			int ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
+			int ret;
+
+			down_write(&policy->rwsem);
+			ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
 			if (!ret)
 				ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
 
 			if (ret)
 				pr_err("%s: Failed to start governor\n", __func__);
+			up_write(&policy->rwsem);
 		}
 	} else if (cpufreq_driver->stop_cpu) {
 		cpufreq_driver->stop_cpu(policy);
-- 
2.2.2

[toc] | [next] | [standalone]


#1307259 — Re: [RFC PATCH 13/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_prepare

FromViresh Kumar <viresh.kumar@linaro.org>
Date2016-01-12 12:00 +0100
SubjectRe: [RFC PATCH 13/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_prepare
Message-ID<qQ4Qa-8ey-19@gated-at.bofh.it>
In reply to#1306538
On 11-01-16, 17:35, Juri Lelli wrote:
> There are paths in cpufreq_offline_prepare where policy is used, but its
> rwsem is not held.
> 
> Fix it.
> 
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Signed-off-by: Juri Lelli <juri.lelli@arm.com>
> ---
>  drivers/cpufreq/cpufreq.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

I know the locking in general in cpufreq core is poor. We recently
fixed lots of issues in governors ..

> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 2c7cc6c73..91158b0 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1332,13 +1332,13 @@ static void cpufreq_offline_prepare(unsigned int cpu)
>  		return;
>  	}
>  
> +	down_write(&policy->rwsem);
>  	if (has_target()) {
>  		int ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
>  		if (ret)
>  			pr_err("%s: Failed to stop governor\n", __func__);
>  	}
>  
> -	down_write(&policy->rwsem);
>  	cpumask_clear_cpu(cpu, policy->cpus);
>  
>  	if (policy_is_inactive(policy)) {
> @@ -1356,12 +1356,16 @@ static void cpufreq_offline_prepare(unsigned int cpu)
>  	/* Start governor again for active policy */
>  	if (!policy_is_inactive(policy)) {

Why shouldn't this be under the lock?

>  		if (has_target()) {
> -			int ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
> +			int ret;
> +
> +			down_write(&policy->rwsem);
> +			ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
>  			if (!ret)
>  				ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
>  
>  			if (ret)
>  				pr_err("%s: Failed to start governor\n", __func__);
> +			up_write(&policy->rwsem);
>  		}
>  	} else if (cpufreq_driver->stop_cpu) {
>  		cpufreq_driver->stop_cpu(policy);

And this ?

-- 
viresh

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web