* [PATCH] cpufreq: unlock when failing cpufreq_update_policy()
@ 2014-06-18 0:12 ` Aaron Plattner
0 siblings, 0 replies; 8+ messages in thread
From: Aaron Plattner @ 2014-06-18 0:12 UTC (permalink / raw)
To: linux-pm; +Cc: Aaron Plattner, linux-kernel, Viresh Kumar, Rafael J. Wysocki
Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if
cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy'
label, which exits without unlocking any of the locks the function acquired
earlier. This causes later calls into cpufreq to hang.
Fix this by creating a new 'unlock' label and jumping to that instead.
Fixes: bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
Link: https://devtalk.nvidia.com/default/topic/751903/kernel-3-15-and-nv-drivers-337-340-failed-to-initialize-the-nvidia-kernel-module-gtx-550-ti-/
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
---
I haven't reproduced this problem so I couldn't test it, but the bug and its
solution seem obvious enough.
drivers/cpufreq/cpufreq.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index aed2b0cb83dc..5b6d04f3b9ea 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2264,7 +2264,7 @@ int cpufreq_update_policy(unsigned int cpu)
new_policy.cur = cpufreq_driver->get(cpu);
if (WARN_ON(!new_policy.cur)) {
ret = -EIO;
- goto no_policy;
+ goto unlock;
}
if (!policy->cur) {
@@ -2279,6 +2279,7 @@ int cpufreq_update_policy(unsigned int cpu)
ret = cpufreq_set_policy(policy, &new_policy);
+unlock:
up_write(&policy->rwsem);
cpufreq_cpu_put(policy);
--
2.0.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] cpufreq: unlock when failing cpufreq_update_policy()
@ 2014-06-18 0:12 ` Aaron Plattner
0 siblings, 0 replies; 8+ messages in thread
From: Aaron Plattner @ 2014-06-18 0:12 UTC (permalink / raw)
To: linux-pm; +Cc: Aaron Plattner, linux-kernel, Viresh Kumar, Rafael J. Wysocki
Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if
cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy'
label, which exits without unlocking any of the locks the function acquired
earlier. This causes later calls into cpufreq to hang.
Fix this by creating a new 'unlock' label and jumping to that instead.
Fixes: bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
Link: https://devtalk.nvidia.com/default/topic/751903/kernel-3-15-and-nv-drivers-337-340-failed-to-initialize-the-nvidia-kernel-module-gtx-550-ti-/
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
---
I haven't reproduced this problem so I couldn't test it, but the bug and its
solution seem obvious enough.
drivers/cpufreq/cpufreq.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index aed2b0cb83dc..5b6d04f3b9ea 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2264,7 +2264,7 @@ int cpufreq_update_policy(unsigned int cpu)
new_policy.cur = cpufreq_driver->get(cpu);
if (WARN_ON(!new_policy.cur)) {
ret = -EIO;
- goto no_policy;
+ goto unlock;
}
if (!policy->cur) {
@@ -2279,6 +2279,7 @@ int cpufreq_update_policy(unsigned int cpu)
ret = cpufreq_set_policy(policy, &new_policy);
+unlock:
up_write(&policy->rwsem);
cpufreq_cpu_put(policy);
--
2.0.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] cpufreq: unlock when failing cpufreq_update_policy()
2014-06-18 0:12 ` Aaron Plattner
(?)
@ 2014-06-18 7:40 ` Viresh Kumar
2014-06-18 14:39 ` Aaron Plattner
-1 siblings, 1 reply; 8+ messages in thread
From: Viresh Kumar @ 2014-06-18 7:40 UTC (permalink / raw)
To: Aaron Plattner; +Cc: linux-pm, Linux Kernel Mailing List, Rafael J. Wysocki
On 18 June 2014 05:42, Aaron Plattner <aplattner@nvidia.com> wrote:
> Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if
> cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy'
> label, which exits without unlocking any of the locks the function acquired
> earlier. This causes later calls into cpufreq to hang.
>
> Fix this by creating a new 'unlock' label and jumping to that instead.
>
> Fixes: bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
> Link: https://devtalk.nvidia.com/default/topic/751903/kernel-3-15-and-nv-drivers-337-340-failed-to-initialize-the-nvidia-kernel-module-gtx-550-ti-/
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
> ---
> I haven't reproduced this problem so I couldn't test it, but the bug and its
> solution seem obvious enough.
>
> drivers/cpufreq/cpufreq.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index aed2b0cb83dc..5b6d04f3b9ea 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2264,7 +2264,7 @@ int cpufreq_update_policy(unsigned int cpu)
> new_policy.cur = cpufreq_driver->get(cpu);
> if (WARN_ON(!new_policy.cur)) {
> ret = -EIO;
> - goto no_policy;
> + goto unlock;
> }
>
> if (!policy->cur) {
> @@ -2279,6 +2279,7 @@ int cpufreq_update_policy(unsigned int cpu)
>
> ret = cpufreq_set_policy(policy, &new_policy);
>
> +unlock:
> up_write(&policy->rwsem);
>
> cpufreq_cpu_put(policy);
Hmm, yes we do have a problem here but the code became a bit ugly
now.. Can you please consider this diff instead?
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index aed2b0c..6caced5 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
struct cpufreq_policy new_policy;
int ret;
- if (!policy) {
- ret = -ENODEV;
- goto no_policy;
- }
+ if (!policy)
+ return = -ENODEV;
down_write(&policy->rwsem);
@@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
ret = cpufreq_set_policy(policy, &new_policy);
+no_policy:
up_write(&policy->rwsem);
cpufreq_cpu_put(policy);
-no_policy:
return ret;
}
EXPORT_SYMBOL(cpufreq_update_policy);
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] cpufreq: unlock when failing cpufreq_update_policy()
2014-06-18 7:40 ` Viresh Kumar
@ 2014-06-18 14:39 ` Aaron Plattner
2014-06-18 14:41 ` Viresh Kumar
0 siblings, 1 reply; 8+ messages in thread
From: Aaron Plattner @ 2014-06-18 14:39 UTC (permalink / raw)
To: Viresh Kumar; +Cc: linux-pm, Linux Kernel Mailing List, Rafael J. Wysocki
On 06/18/2014 12:40 AM, Viresh Kumar wrote:
> On 18 June 2014 05:42, Aaron Plattner <aplattner@nvidia.com> wrote:
>> Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if
>> cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy'
>> label, which exits without unlocking any of the locks the function acquired
>> earlier. This causes later calls into cpufreq to hang.
>>
>> Fix this by creating a new 'unlock' label and jumping to that instead.
>>
>> Fixes: bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
>> Link: https://devtalk.nvidia.com/default/topic/751903/kernel-3-15-and-nv-drivers-337-340-failed-to-initialize-the-nvidia-kernel-module-gtx-550-ti-/
>> Cc: Viresh Kumar <viresh.kumar@linaro.org>
>> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>> Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
>> ---
>> I haven't reproduced this problem so I couldn't test it, but the bug and its
>> solution seem obvious enough.
>>
>> drivers/cpufreq/cpufreq.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index aed2b0cb83dc..5b6d04f3b9ea 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -2264,7 +2264,7 @@ int cpufreq_update_policy(unsigned int cpu)
>> new_policy.cur = cpufreq_driver->get(cpu);
>> if (WARN_ON(!new_policy.cur)) {
>> ret = -EIO;
>> - goto no_policy;
>> + goto unlock;
>> }
>>
>> if (!policy->cur) {
>> @@ -2279,6 +2279,7 @@ int cpufreq_update_policy(unsigned int cpu)
>>
>> ret = cpufreq_set_policy(policy, &new_policy);
>>
>> +unlock:
>> up_write(&policy->rwsem);
>>
>> cpufreq_cpu_put(policy);
>
> Hmm, yes we do have a problem here but the code became a bit ugly
> now.. Can you please consider this diff instead?
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index aed2b0c..6caced5 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
> struct cpufreq_policy new_policy;
> int ret;
>
> - if (!policy) {
> - ret = -ENODEV;
> - goto no_policy;
> - }
> + if (!policy)
> + return = -ENODEV;
I assume you meant "return -ENODEV"?
> down_write(&policy->rwsem);
>
> @@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
>
> ret = cpufreq_set_policy(policy, &new_policy);
>
> +no_policy:
'no_policy' implied to me that policy was NULL, so this label should
still be renamed to 'unlock'. I'll send out a v2 that does this.
> up_write(&policy->rwsem);
>
> cpufreq_cpu_put(policy);
> -no_policy:
> return ret;
> }
> EXPORT_SYMBOL(cpufreq_update_policy);
>
--
Aaron
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cpufreq: unlock when failing cpufreq_update_policy()
2014-06-18 14:39 ` Aaron Plattner
@ 2014-06-18 14:41 ` Viresh Kumar
0 siblings, 0 replies; 8+ messages in thread
From: Viresh Kumar @ 2014-06-18 14:41 UTC (permalink / raw)
To: Aaron Plattner; +Cc: linux-pm, Linux Kernel Mailing List, Rafael J. Wysocki
On 18 June 2014 20:09, Aaron Plattner <aplattner@nvidia.com> wrote:
> I assume you meant "return -ENODEV"?
Yeah, sorry :)
>> down_write(&policy->rwsem);
>>
>> @@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
>>
>> ret = cpufreq_set_policy(policy, &new_policy);
>>
>> +no_policy:
>
>
> 'no_policy' implied to me that policy was NULL, so this label should still
> be renamed to 'unlock'. I'll send out a v2 that does this.
Yeah.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] cpufreq: unlock when failing cpufreq_update_policy()
2014-06-18 0:12 ` Aaron Plattner
@ 2014-06-18 18:27 ` Aaron Plattner
-1 siblings, 0 replies; 8+ messages in thread
From: Aaron Plattner @ 2014-06-18 18:27 UTC (permalink / raw)
To: linux-pm; +Cc: Aaron Plattner, linux-kernel, Viresh Kumar, Rafael J. Wysocki
Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if
cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy'
label, which exits without unlocking any of the locks the function acquired
earlier. This causes later calls into cpufreq to hang.
Fix this by creating a new 'unlock' label and jumping to that instead.
v2: Delete the no_policy label and just return early if policy is NULL.
Fixes: bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
Link: https://devtalk.nvidia.com/default/topic/751903/kernel-3-15-and-nv-drivers-337-340-failed-to-initialize-the-nvidia-kernel-module-gtx-550-ti-/
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
---
v1 of this was tested by the user affected by the problem, but I don't have his
email address so I can't add it as a Tested-by line.
drivers/cpufreq/cpufreq.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index aed2b0cb83dc..62259d27f03e 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
struct cpufreq_policy new_policy;
int ret;
- if (!policy) {
- ret = -ENODEV;
- goto no_policy;
- }
+ if (!policy)
+ return -ENODEV;
down_write(&policy->rwsem);
@@ -2264,7 +2262,7 @@ int cpufreq_update_policy(unsigned int cpu)
new_policy.cur = cpufreq_driver->get(cpu);
if (WARN_ON(!new_policy.cur)) {
ret = -EIO;
- goto no_policy;
+ goto unlock;
}
if (!policy->cur) {
@@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
ret = cpufreq_set_policy(policy, &new_policy);
+unlock:
up_write(&policy->rwsem);
cpufreq_cpu_put(policy);
-no_policy:
return ret;
}
EXPORT_SYMBOL(cpufreq_update_policy);
--
2.0.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2] cpufreq: unlock when failing cpufreq_update_policy()
@ 2014-06-18 18:27 ` Aaron Plattner
0 siblings, 0 replies; 8+ messages in thread
From: Aaron Plattner @ 2014-06-18 18:27 UTC (permalink / raw)
To: linux-pm; +Cc: Aaron Plattner, linux-kernel, Viresh Kumar, Rafael J. Wysocki
Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if
cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy'
label, which exits without unlocking any of the locks the function acquired
earlier. This causes later calls into cpufreq to hang.
Fix this by creating a new 'unlock' label and jumping to that instead.
v2: Delete the no_policy label and just return early if policy is NULL.
Fixes: bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
Link: https://devtalk.nvidia.com/default/topic/751903/kernel-3-15-and-nv-drivers-337-340-failed-to-initialize-the-nvidia-kernel-module-gtx-550-ti-/
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
---
v1 of this was tested by the user affected by the problem, but I don't have his
email address so I can't add it as a Tested-by line.
drivers/cpufreq/cpufreq.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index aed2b0cb83dc..62259d27f03e 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
struct cpufreq_policy new_policy;
int ret;
- if (!policy) {
- ret = -ENODEV;
- goto no_policy;
- }
+ if (!policy)
+ return -ENODEV;
down_write(&policy->rwsem);
@@ -2264,7 +2262,7 @@ int cpufreq_update_policy(unsigned int cpu)
new_policy.cur = cpufreq_driver->get(cpu);
if (WARN_ON(!new_policy.cur)) {
ret = -EIO;
- goto no_policy;
+ goto unlock;
}
if (!policy->cur) {
@@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
ret = cpufreq_set_policy(policy, &new_policy);
+unlock:
up_write(&policy->rwsem);
cpufreq_cpu_put(policy);
-no_policy:
return ret;
}
EXPORT_SYMBOL(cpufreq_update_policy);
--
2.0.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] cpufreq: unlock when failing cpufreq_update_policy()
2014-06-18 18:27 ` Aaron Plattner
(?)
@ 2014-06-18 23:57 ` Rafael J. Wysocki
-1 siblings, 0 replies; 8+ messages in thread
From: Rafael J. Wysocki @ 2014-06-18 23:57 UTC (permalink / raw)
To: Aaron Plattner; +Cc: linux-pm, linux-kernel, Viresh Kumar, Rafael J. Wysocki
On Wednesday, June 18, 2014 11:27:32 AM Aaron Plattner wrote:
> Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if
> cpufreq_driver->get(cpu) returns NULL. However, it jumps to the 'no_policy'
> label, which exits without unlocking any of the locks the function acquired
> earlier. This causes later calls into cpufreq to hang.
>
> Fix this by creating a new 'unlock' label and jumping to that instead.
>
> v2: Delete the no_policy label and just return early if policy is NULL.
>
> Fixes: bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
> Link: https://devtalk.nvidia.com/default/topic/751903/kernel-3-15-and-nv-drivers-337-340-failed-to-initialize-the-nvidia-kernel-module-gtx-550-ti-/
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
Applied, thanks!
> ---
> v1 of this was tested by the user affected by the problem, but I don't have his
> email address so I can't add it as a Tested-by line.
>
> drivers/cpufreq/cpufreq.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index aed2b0cb83dc..62259d27f03e 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
> struct cpufreq_policy new_policy;
> int ret;
>
> - if (!policy) {
> - ret = -ENODEV;
> - goto no_policy;
> - }
> + if (!policy)
> + return -ENODEV;
>
> down_write(&policy->rwsem);
>
> @@ -2264,7 +2262,7 @@ int cpufreq_update_policy(unsigned int cpu)
> new_policy.cur = cpufreq_driver->get(cpu);
> if (WARN_ON(!new_policy.cur)) {
> ret = -EIO;
> - goto no_policy;
> + goto unlock;
> }
>
> if (!policy->cur) {
> @@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
>
> ret = cpufreq_set_policy(policy, &new_policy);
>
> +unlock:
> up_write(&policy->rwsem);
>
> cpufreq_cpu_put(policy);
> -no_policy:
> return ret;
> }
> EXPORT_SYMBOL(cpufreq_update_policy);
>
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-06-18 23:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-18 0:12 [PATCH] cpufreq: unlock when failing cpufreq_update_policy() Aaron Plattner
2014-06-18 0:12 ` Aaron Plattner
2014-06-18 7:40 ` Viresh Kumar
2014-06-18 14:39 ` Aaron Plattner
2014-06-18 14:41 ` Viresh Kumar
2014-06-18 18:27 ` [PATCH v2] " Aaron Plattner
2014-06-18 18:27 ` Aaron Plattner
2014-06-18 23:57 ` Rafael J. Wysocki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.