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


Groups > linux.kernel > #1306542 > unrolled thread

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

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

#1306542 — [RFC PATCH 14/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_finish

FromJuri Lelli <juri.lelli@arm.com>
Date2016-01-11 18:40 +0100
Subject[RFC PATCH 14/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_finish
Message-ID<qPOBI-5zs-19@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, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 91158b0..ba452c3 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1381,9 +1381,13 @@ static void cpufreq_offline_finish(unsigned int cpu)
 		return;
 	}
 
+	down_write(&policy->rwsem);
+
 	/* Only proceed for inactive policies */
-	if (!policy_is_inactive(policy))
+	if (!policy_is_inactive(policy)) {
+		up_write(&policy->rwsem);
 		return;
+	}
 
 	/* If cpu is last user of policy, free policy */
 	if (has_target()) {
@@ -1392,6 +1396,8 @@ static void cpufreq_offline_finish(unsigned int cpu)
 			pr_err("%s: Failed to exit governor\n", __func__);
 	}
 
+	up_write(&policy->rwsem);
+
 	/*
 	 * Perform the ->exit() even during light-weight tear-down,
 	 * since this is a core component, and is essential for the
-- 
2.2.2

[toc] | [next] | [standalone]


#1307269 — Re: [RFC PATCH 14/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_finish

FromViresh Kumar <viresh.kumar@linaro.org>
Date2016-01-12 12:10 +0100
SubjectRe: [RFC PATCH 14/19] cpufreq: fix locking of policy->rwsem in cpufreq_offline_finish
Message-ID<qQ4ZP-5t-7@gated-at.bofh.it>
In reply to#1306542
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, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 91158b0..ba452c3 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1381,9 +1381,13 @@ static void cpufreq_offline_finish(unsigned int cpu)
>  		return;
>  	}
>  
> +	down_write(&policy->rwsem);
> +
>  	/* Only proceed for inactive policies */
> -	if (!policy_is_inactive(policy))
> +	if (!policy_is_inactive(policy)) {
> +		up_write(&policy->rwsem);
>  		return;
> +	}
>  
>  	/* If cpu is last user of policy, free policy */
>  	if (has_target()) {
> @@ -1392,6 +1396,8 @@ static void cpufreq_offline_finish(unsigned int cpu)
>  			pr_err("%s: Failed to exit governor\n", __func__);
>  	}
>  
> +	up_write(&policy->rwsem);
> +
>  	/*
>  	 * Perform the ->exit() even during light-weight tear-down,
>  	 * since this is a core component, and is essential for the

I think we need to nail down the purpose of the lock first and discuss
the races we are trying to fix. For example, policy is used by all
cpufreq drivers, etc and no one is stopping them to use it without
taking the lock..

FWIW, I have also tried to do some cleanups earlier, but was never
able to send them upstream due to busy schedule.

ssh://git@git.linaro.org/people/viresh.kumar/linux.git
cpufreq/core/locking

You might find some interesting bits there.

-- 
viresh

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web