Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1355189 > unrolled thread
| Started by | Richard Cochran <rcochran@linutronix.de> |
|---|---|
| First post | 2016-03-10 16:20 +0100 |
| Last post | 2016-03-12 01:00 +0100 |
| Articles | 5 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH] cpufreq: Make cpufreq_quick_get() safe to call. Richard Cochran <rcochran@linutronix.de> - 2016-03-10 16:20 +0100
Re: [PATCH] cpufreq: Make cpufreq_quick_get() safe to call. "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2016-03-10 23:20 +0100
Re: [PATCH] cpufreq: Make cpufreq_quick_get() safe to call. "Rafael J. Wysocki" <rafael@kernel.org> - 2016-03-11 03:30 +0100
[PATCH v2] cpufreq: Make cpufreq_quick_get() safe to call. Richard Cochran <rcochran@linutronix.de> - 2016-03-11 09:50 +0100
Re: [PATCH v2] cpufreq: Make cpufreq_quick_get() safe to call. Viresh Kumar <viresh.kumar@linaro.org> - 2016-03-12 01:00 +0100
| From | Richard Cochran <rcochran@linutronix.de> |
|---|---|
| Date | 2016-03-10 16:20 +0100 |
| Subject | [PATCH] cpufreq: Make cpufreq_quick_get() safe to call. |
| Message-ID | <rbaxz-jy-3@gated-at.bofh.it> |
The function, cpufreq_quick_get, accesses the global 'cpufreq_driver' and
its fields without taking the associated lock, cpufreq_driver_lock.
Without the locking, nothing guarantees that 'cpufreq_driver' remains
consistent during the call. This patch fixes the issue by taking the lock
before accessing the data structure.
Cc: Dirk Brandewie <dirk.brandewie@gmail.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
---
drivers/cpufreq/cpufreq.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index e979ec7..ce02b2b 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1457,9 +1457,17 @@ unsigned int cpufreq_quick_get(unsigned int cpu)
{
struct cpufreq_policy *policy;
unsigned int ret_freq = 0;
+ unsigned long flags;
+
+ read_lock_irqsave(&cpufreq_driver_lock, flags);
if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get)
- return cpufreq_driver->get(cpu);
+ ret_freq = cpufreq_driver->get(cpu);
+
+ read_unlock_irqrestore(&cpufreq_driver_lock, flags);
+
+ if (ret_freq)
+ return ret_freq;
policy = cpufreq_cpu_get(cpu);
if (policy) {
--
2.1.4
[toc] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rjw@rjwysocki.net> |
|---|---|
| Date | 2016-03-10 23:20 +0100 |
| Message-ID | <rbh62-4Y2-5@gated-at.bofh.it> |
| In reply to | #1355189 |
On Thursday, March 10, 2016 04:10:36 PM Richard Cochran wrote:
> The function, cpufreq_quick_get, accesses the global 'cpufreq_driver' and
> its fields without taking the associated lock, cpufreq_driver_lock.
>
> Without the locking, nothing guarantees that 'cpufreq_driver' remains
> consistent during the call. This patch fixes the issue by taking the lock
> before accessing the data structure.
>
> Cc: Dirk Brandewie <dirk.brandewie@gmail.com>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Signed-off-by: Richard Cochran <rcochran@linutronix.de>
Can you please CC PM-related patches to linux-pm@vger.kernel.org? They
are much easier to handle for me then.
> ---
> drivers/cpufreq/cpufreq.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index e979ec7..ce02b2b 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1457,9 +1457,17 @@ unsigned int cpufreq_quick_get(unsigned int cpu)
> {
> struct cpufreq_policy *policy;
> unsigned int ret_freq = 0;
> + unsigned long flags;
> +
> + read_lock_irqsave(&cpufreq_driver_lock, flags);
>
> if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get)
> - return cpufreq_driver->get(cpu);
> + ret_freq = cpufreq_driver->get(cpu);
> +
> + read_unlock_irqrestore(&cpufreq_driver_lock, flags);
> +
> + if (ret_freq)
> + return ret_freq;
>
> policy = cpufreq_cpu_get(cpu);
> if (policy) {
>
I would prefer something like this:
read_lock_irqsave(&cpufreq_driver_lock, flags);
if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) {
unsigned int ret_freq = cpufreq_driver->get(cpu);
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
return ret_freq;
}
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
Thanks,
Rafael
[toc] | [prev] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rafael@kernel.org> |
|---|---|
| Date | 2016-03-11 03:30 +0100 |
| Message-ID | <rbkZX-7ID-1@gated-at.bofh.it> |
| In reply to | #1355425 |
On Thu, Mar 10, 2016 at 11:20 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Thursday, March 10, 2016 04:10:36 PM Richard Cochran wrote:
>> The function, cpufreq_quick_get, accesses the global 'cpufreq_driver' and
>> its fields without taking the associated lock, cpufreq_driver_lock.
>>
>> Without the locking, nothing guarantees that 'cpufreq_driver' remains
>> consistent during the call. This patch fixes the issue by taking the lock
>> before accessing the data structure.
>>
>> Cc: Dirk Brandewie <dirk.brandewie@gmail.com>
>> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>> Cc: Viresh Kumar <viresh.kumar@linaro.org>
>> Signed-off-by: Richard Cochran <rcochran@linutronix.de>
>
> Can you please CC PM-related patches to linux-pm@vger.kernel.org? They
> are much easier to handle for me then.
>
>> ---
>> drivers/cpufreq/cpufreq.c | 10 +++++++++-
>> 1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index e979ec7..ce02b2b 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -1457,9 +1457,17 @@ unsigned int cpufreq_quick_get(unsigned int cpu)
>> {
>> struct cpufreq_policy *policy;
>> unsigned int ret_freq = 0;
>> + unsigned long flags;
>> +
>> + read_lock_irqsave(&cpufreq_driver_lock, flags);
>>
>> if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get)
>> - return cpufreq_driver->get(cpu);
>> + ret_freq = cpufreq_driver->get(cpu);
>> +
>> + read_unlock_irqrestore(&cpufreq_driver_lock, flags);
>> +
>> + if (ret_freq)
>> + return ret_freq;
>>
>> policy = cpufreq_cpu_get(cpu);
>> if (policy) {
>>
>
> I would prefer something like this:
>
> read_lock_irqsave(&cpufreq_driver_lock, flags);
>
> if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) {
> unsigned int ret_freq = cpufreq_driver->get(cpu);
Sorry, ret_freq is needed outside of this block anyway, so that would be
ret_freq = cpufreq_driver->get(cpu);
>
> read_unlock_irqrestore(&cpufreq_driver_lock, flags);
> return ret_freq;
> }
>
> read_unlock_irqrestore(&cpufreq_driver_lock, flags);
[toc] | [prev] | [next] | [standalone]
| From | Richard Cochran <rcochran@linutronix.de> |
|---|---|
| Date | 2016-03-11 09:50 +0100 |
| Subject | [PATCH v2] cpufreq: Make cpufreq_quick_get() safe to call. |
| Message-ID | <rbqVK-3vt-37@gated-at.bofh.it> |
| In reply to | #1355547 |
The function, cpufreq_quick_get, accesses the global 'cpufreq_driver' and
its fields without taking the associated lock, cpufreq_driver_lock.
Without the locking, nothing guarantees that 'cpufreq_driver' remains
consistent during the call. This patch fixes the issue by taking the lock
before accessing the data structure.
Cc: Dirk Brandewie <dirk.brandewie@gmail.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: linux-pm@vger.kernel.org
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
---
drivers/cpufreq/cpufreq.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index e979ec7..053aa1f 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1457,9 +1457,17 @@ unsigned int cpufreq_quick_get(unsigned int cpu)
{
struct cpufreq_policy *policy;
unsigned int ret_freq = 0;
+ unsigned long flags;
- if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get)
- return cpufreq_driver->get(cpu);
+ read_lock_irqsave(&cpufreq_driver_lock, flags);
+
+ if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) {
+ ret_freq = cpufreq_driver->get(cpu);
+ read_unlock_irqrestore(&cpufreq_driver_lock, flags);
+ return ret_freq;
+ }
+
+ read_unlock_irqrestore(&cpufreq_driver_lock, flags);
policy = cpufreq_cpu_get(cpu);
if (policy) {
--
2.1.4
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-03-12 01:00 +0100 |
| Subject | Re: [PATCH v2] cpufreq: Make cpufreq_quick_get() safe to call. |
| Message-ID | <rbF8m-5sL-5@gated-at.bofh.it> |
| In reply to | #1355707 |
On 11-03-16, 09:43, Richard Cochran wrote: > The function, cpufreq_quick_get, accesses the global 'cpufreq_driver' and > its fields without taking the associated lock, cpufreq_driver_lock. > > Without the locking, nothing guarantees that 'cpufreq_driver' remains > consistent during the call. This patch fixes the issue by taking the lock > before accessing the data structure. > > Cc: Dirk Brandewie <dirk.brandewie@gmail.com> > Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > Cc: Viresh Kumar <viresh.kumar@linaro.org> > Cc: linux-pm@vger.kernel.org > Signed-off-by: Richard Cochran <rcochran@linutronix.de> > --- > drivers/cpufreq/cpufreq.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) Acked-by: Viresh Kumar <viresh.kumar@linaro.org> -- viresh
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web