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


Groups > linux.kernel > #1306554 > unrolled thread

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

Started byJuri Lelli <juri.lelli@arm.com>
First post2016-01-11 18:40 +0100
Last post2016-01-14 19:00 +0100
Articles 3 — 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 12/19] cpufreq: fix locking of policy->rwsem in cpufreq_init_policy Juri Lelli <juri.lelli@arm.com> - 2016-01-11 18:40 +0100
    Re: [RFC PATCH 12/19] cpufreq: fix locking of policy->rwsem in  cpufreq_init_policy Viresh Kumar <viresh.kumar@linaro.org> - 2016-01-12 11:50 +0100
      Re: [RFC PATCH 12/19] cpufreq: fix locking of policy->rwsem in  cpufreq_init_policy Juri Lelli <juri.lelli@arm.com> - 2016-01-14 19:00 +0100

#1306554 — [RFC PATCH 12/19] cpufreq: fix locking of policy->rwsem in cpufreq_init_policy

FromJuri Lelli <juri.lelli@arm.com>
Date2016-01-11 18:40 +0100
Subject[RFC PATCH 12/19] cpufreq: fix locking of policy->rwsem in cpufreq_init_policy
Message-ID<qPOBK-5zs-47@gated-at.bofh.it>
There are paths in cpufreq_init_policy 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 | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index e7fc5c9..2c7cc6c73 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -998,21 +998,24 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp
 {
 	int ret = 0;
 
+	down_write(&policy->rwsem);
+
 	/* Has this CPU been taken care of already? */
-	if (cpumask_test_cpu(cpu, policy->cpus))
+	if (cpumask_test_cpu(cpu, policy->cpus)) {
+		up_write(&policy->rwsem);
 		return 0;
+	}
 
 	if (has_target()) {
 		ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
 		if (ret) {
+			up_write(&policy->rwsem);
 			pr_err("%s: Failed to stop governor\n", __func__);
 			return ret;
 		}
 	}
 
-	down_write(&policy->rwsem);
 	cpumask_set_cpu(cpu, policy->cpus);
-	up_write(&policy->rwsem);
 
 	if (has_target()) {
 		ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
@@ -1020,10 +1023,12 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp
 			ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
 
 		if (ret) {
+			up_write(&policy->rwsem);
 			pr_err("%s: Failed to start governor\n", __func__);
 			return ret;
 		}
 	}
+	up_write(&policy->rwsem);
 
 	return 0;
 }
-- 
2.2.2

[toc] | [next] | [standalone]


#1307246 — Re: [RFC PATCH 12/19] cpufreq: fix locking of policy->rwsem in cpufreq_init_policy

FromViresh Kumar <viresh.kumar@linaro.org>
Date2016-01-12 11:50 +0100
SubjectRe: [RFC PATCH 12/19] cpufreq: fix locking of policy->rwsem in cpufreq_init_policy
Message-ID<qQ4Gu-8a9-11@gated-at.bofh.it>
In reply to#1306554
On 11-01-16, 17:35, Juri Lelli wrote:
> There are paths in cpufreq_init_policy 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 | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index e7fc5c9..2c7cc6c73 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -998,21 +998,24 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp
>  {
>  	int ret = 0;
>  
> +	down_write(&policy->rwsem);
> +
>  	/* Has this CPU been taken care of already? */
> -	if (cpumask_test_cpu(cpu, policy->cpus))
> +	if (cpumask_test_cpu(cpu, policy->cpus)) {
> +		up_write(&policy->rwsem);

Perhaps create a label at the end to unlock the rwsem and jump to it?

-- 
viresh

[toc] | [prev] | [next] | [standalone]


#1309547 — Re: [RFC PATCH 12/19] cpufreq: fix locking of policy->rwsem in cpufreq_init_policy

FromJuri Lelli <juri.lelli@arm.com>
Date2016-01-14 19:00 +0100
SubjectRe: [RFC PATCH 12/19] cpufreq: fix locking of policy->rwsem in cpufreq_init_policy
Message-ID<qQUlI-1WT-11@gated-at.bofh.it>
In reply to#1307246
On 12/01/16 16:09, Viresh Kumar wrote:
> On 11-01-16, 17:35, Juri Lelli wrote:
> > There are paths in cpufreq_init_policy 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 | 11 ++++++++---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> > index e7fc5c9..2c7cc6c73 100644
> > --- a/drivers/cpufreq/cpufreq.c
> > +++ b/drivers/cpufreq/cpufreq.c
> > @@ -998,21 +998,24 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp
> >  {
> >  	int ret = 0;
> >  
> > +	down_write(&policy->rwsem);
> > +
> >  	/* Has this CPU been taken care of already? */
> > -	if (cpumask_test_cpu(cpu, policy->cpus))
> > +	if (cpumask_test_cpu(cpu, policy->cpus)) {
> > +		up_write(&policy->rwsem);
> 
> Perhaps create a label at the end to unlock the rwsem and jump to it?
> 

Yep, done.

Thanks,

- Juri

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web