* [PATCH] cpufreq, powernow-k8: Initialize per-cpu data-structures properly
@ 2014-02-17 10:48 Srivatsa S. Bhat
2014-02-17 11:05 ` Viresh Kumar
2014-02-18 2:06 ` Viresh Kumar
0 siblings, 2 replies; 4+ messages in thread
From: Srivatsa S. Bhat @ 2014-02-17 10:48 UTC (permalink / raw)
To: pierre-list, rjw; +Cc: viresh.kumar, linux-pm, linux-kernel, Srivatsa S. Bhat
The powernow-k8 driver maintains a per-cpu data-structure called powernow_data
that is used to perform the frequency transitions. It initializes this data-
structure only for the policy->cpu. So, accesses to this data-structure by
other CPUs results in various problems because they would have been
uninitialized.
Specifically, if a cpu (!= policy->cpu) invokes the drivers' ->get() function,
it returns 0 as the KHz value, since its per-cpu memory doesn't point to
anything valid. This causes problems during suspend/resume since
cpufreq_update_policy() tries to enforce this (0 KHz) as the current frequency
of the CPU, and this madness gets propagated to adjust_jiffies() as well.
Eventually, lots of things start breaking down, including the r8169 ethernet
card, in one particularly interesting case reported by Pierre Ossman.
https://bugzilla.kernel.org/show_bug.cgi?id=70311
Fix this by initializing the per-cpu data-structures of _all_ the CPUs
in the policy appropriately.
Cc: stable@vger.kernel.org
Reported-by: Pierre Ossman <pierre@ossman.eu>
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
---
drivers/cpufreq/powernow-k8.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index e10b646..6684e03 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -1076,7 +1076,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
{
struct powernow_k8_data *data;
struct init_on_cpu init_on_cpu;
- int rc;
+ int rc, cpu;
smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1);
if (rc)
@@ -1140,7 +1140,9 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n",
data->currfid, data->currvid);
- per_cpu(powernow_data, pol->cpu) = data;
+ /* Point all the CPUs in this policy to the same data */
+ for_each_cpu(cpu, pol->cpus)
+ per_cpu(powernow_data, cpu) = data;
return 0;
@@ -1155,6 +1157,7 @@ err_out:
static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
{
struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
+ int cpu;
if (!data)
return -EINVAL;
@@ -1165,7 +1168,8 @@ static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
kfree(data->powernow_table);
kfree(data);
- per_cpu(powernow_data, pol->cpu) = NULL;
+ for_each_cpu(cpu, pol->cpus)
+ per_cpu(powernow_data, cpu) = NULL;
return 0;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cpufreq, powernow-k8: Initialize per-cpu data-structures properly
2014-02-17 10:48 [PATCH] cpufreq, powernow-k8: Initialize per-cpu data-structures properly Srivatsa S. Bhat
@ 2014-02-17 11:05 ` Viresh Kumar
2014-02-17 22:02 ` Rafael J. Wysocki
2014-02-18 2:06 ` Viresh Kumar
1 sibling, 1 reply; 4+ messages in thread
From: Viresh Kumar @ 2014-02-17 11:05 UTC (permalink / raw)
To: Srivatsa S. Bhat
Cc: Pierre Ossman, Rafael J. Wysocki, linux-pm, Linux Kernel Mailing List
On 17 February 2014 16:18, Srivatsa S. Bhat
<srivatsa.bhat@linux.vnet.ibm.com> wrote:
> The powernow-k8 driver maintains a per-cpu data-structure called powernow_data
> that is used to perform the frequency transitions. It initializes this data-
> structure only for the policy->cpu. So, accesses to this data-structure by
> other CPUs results in various problems because they would have been
> uninitialized.
>
> Specifically, if a cpu (!= policy->cpu) invokes the drivers' ->get() function,
> it returns 0 as the KHz value, since its per-cpu memory doesn't point to
> anything valid. This causes problems during suspend/resume since
> cpufreq_update_policy() tries to enforce this (0 KHz) as the current frequency
> of the CPU, and this madness gets propagated to adjust_jiffies() as well.
> Eventually, lots of things start breaking down, including the r8169 ethernet
> card, in one particularly interesting case reported by Pierre Ossman.
>
> https://bugzilla.kernel.org/show_bug.cgi?id=70311
>
> Fix this by initializing the per-cpu data-structures of _all_ the CPUs
> in the policy appropriately.
>
> Cc: stable@vger.kernel.org
> Reported-by: Pierre Ossman <pierre@ossman.eu>
> Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
> ---
>
> drivers/cpufreq/powernow-k8.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
> index e10b646..6684e03 100644
> --- a/drivers/cpufreq/powernow-k8.c
> +++ b/drivers/cpufreq/powernow-k8.c
> @@ -1076,7 +1076,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
> {
> struct powernow_k8_data *data;
> struct init_on_cpu init_on_cpu;
> - int rc;
> + int rc, cpu;
>
> smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1);
> if (rc)
> @@ -1140,7 +1140,9 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
> pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n",
> data->currfid, data->currvid);
>
> - per_cpu(powernow_data, pol->cpu) = data;
> + /* Point all the CPUs in this policy to the same data */
> + for_each_cpu(cpu, pol->cpus)
> + per_cpu(powernow_data, cpu) = data;
>
> return 0;
>
> @@ -1155,6 +1157,7 @@ err_out:
> static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
> {
> struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
> + int cpu;
>
> if (!data)
> return -EINVAL;
> @@ -1165,7 +1168,8 @@ static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
>
> kfree(data->powernow_table);
> kfree(data);
> - per_cpu(powernow_data, pol->cpu) = NULL;
> + for_each_cpu(cpu, pol->cpus)
> + per_cpu(powernow_data, cpu) = NULL;
>
> return 0;
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cpufreq, powernow-k8: Initialize per-cpu data-structures properly
2014-02-17 11:05 ` Viresh Kumar
@ 2014-02-17 22:02 ` Rafael J. Wysocki
0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2014-02-17 22:02 UTC (permalink / raw)
To: Viresh Kumar
Cc: Srivatsa S. Bhat, Pierre Ossman, linux-pm, Linux Kernel Mailing List
On Monday, February 17, 2014 04:35:08 PM Viresh Kumar wrote:
> On 17 February 2014 16:18, Srivatsa S. Bhat
> <srivatsa.bhat@linux.vnet.ibm.com> wrote:
> > The powernow-k8 driver maintains a per-cpu data-structure called powernow_data
> > that is used to perform the frequency transitions. It initializes this data-
> > structure only for the policy->cpu. So, accesses to this data-structure by
> > other CPUs results in various problems because they would have been
> > uninitialized.
> >
> > Specifically, if a cpu (!= policy->cpu) invokes the drivers' ->get() function,
> > it returns 0 as the KHz value, since its per-cpu memory doesn't point to
> > anything valid. This causes problems during suspend/resume since
> > cpufreq_update_policy() tries to enforce this (0 KHz) as the current frequency
> > of the CPU, and this madness gets propagated to adjust_jiffies() as well.
> > Eventually, lots of things start breaking down, including the r8169 ethernet
> > card, in one particularly interesting case reported by Pierre Ossman.
> >
> > https://bugzilla.kernel.org/show_bug.cgi?id=70311
> >
> > Fix this by initializing the per-cpu data-structures of _all_ the CPUs
> > in the policy appropriately.
> >
> > Cc: stable@vger.kernel.org
> > Reported-by: Pierre Ossman <pierre@ossman.eu>
> > Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
> > ---
> >
> > drivers/cpufreq/powernow-k8.c | 10 +++++++---
> > 1 file changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
> > index e10b646..6684e03 100644
> > --- a/drivers/cpufreq/powernow-k8.c
> > +++ b/drivers/cpufreq/powernow-k8.c
> > @@ -1076,7 +1076,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
> > {
> > struct powernow_k8_data *data;
> > struct init_on_cpu init_on_cpu;
> > - int rc;
> > + int rc, cpu;
> >
> > smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1);
> > if (rc)
> > @@ -1140,7 +1140,9 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
> > pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n",
> > data->currfid, data->currvid);
> >
> > - per_cpu(powernow_data, pol->cpu) = data;
> > + /* Point all the CPUs in this policy to the same data */
> > + for_each_cpu(cpu, pol->cpus)
> > + per_cpu(powernow_data, cpu) = data;
> >
> > return 0;
> >
> > @@ -1155,6 +1157,7 @@ err_out:
> > static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
> > {
> > struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
> > + int cpu;
> >
> > if (!data)
> > return -EINVAL;
> > @@ -1165,7 +1168,8 @@ static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
> >
> > kfree(data->powernow_table);
> > kfree(data);
> > - per_cpu(powernow_data, pol->cpu) = NULL;
> > + for_each_cpu(cpu, pol->cpus)
> > + per_cpu(powernow_data, cpu) = NULL;
> >
> > return 0;
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Queued up as a fix for 3.14, thanks!
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cpufreq, powernow-k8: Initialize per-cpu data-structures properly
2014-02-17 10:48 [PATCH] cpufreq, powernow-k8: Initialize per-cpu data-structures properly Srivatsa S. Bhat
2014-02-17 11:05 ` Viresh Kumar
@ 2014-02-18 2:06 ` Viresh Kumar
1 sibling, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2014-02-18 2:06 UTC (permalink / raw)
To: Srivatsa S. Bhat, stable
Cc: Pierre Ossman, Rafael J. Wysocki, linux-pm, Linux Kernel Mailing List
cc'ing stable for getting this in 3.12 and 3.13 as well..
On 17 February 2014 16:18, Srivatsa S. Bhat
<srivatsa.bhat@linux.vnet.ibm.com> wrote:
> The powernow-k8 driver maintains a per-cpu data-structure called powernow_data
> that is used to perform the frequency transitions. It initializes this data-
> structure only for the policy->cpu. So, accesses to this data-structure by
> other CPUs results in various problems because they would have been
> uninitialized.
>
> Specifically, if a cpu (!= policy->cpu) invokes the drivers' ->get() function,
> it returns 0 as the KHz value, since its per-cpu memory doesn't point to
> anything valid. This causes problems during suspend/resume since
> cpufreq_update_policy() tries to enforce this (0 KHz) as the current frequency
> of the CPU, and this madness gets propagated to adjust_jiffies() as well.
> Eventually, lots of things start breaking down, including the r8169 ethernet
> card, in one particularly interesting case reported by Pierre Ossman.
>
> https://bugzilla.kernel.org/show_bug.cgi?id=70311
>
> Fix this by initializing the per-cpu data-structures of _all_ the CPUs
> in the policy appropriately.
>
> Cc: stable@vger.kernel.org
> Reported-by: Pierre Ossman <pierre@ossman.eu>
> Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
> ---
>
> drivers/cpufreq/powernow-k8.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
> index e10b646..6684e03 100644
> --- a/drivers/cpufreq/powernow-k8.c
> +++ b/drivers/cpufreq/powernow-k8.c
> @@ -1076,7 +1076,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
> {
> struct powernow_k8_data *data;
> struct init_on_cpu init_on_cpu;
> - int rc;
> + int rc, cpu;
>
> smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1);
> if (rc)
> @@ -1140,7 +1140,9 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
> pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n",
> data->currfid, data->currvid);
>
> - per_cpu(powernow_data, pol->cpu) = data;
> + /* Point all the CPUs in this policy to the same data */
> + for_each_cpu(cpu, pol->cpus)
> + per_cpu(powernow_data, cpu) = data;
>
> return 0;
>
> @@ -1155,6 +1157,7 @@ err_out:
> static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
> {
> struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
> + int cpu;
>
> if (!data)
> return -EINVAL;
> @@ -1165,7 +1168,8 @@ static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
>
> kfree(data->powernow_table);
> kfree(data);
> - per_cpu(powernow_data, pol->cpu) = NULL;
> + for_each_cpu(cpu, pol->cpus)
> + per_cpu(powernow_data, cpu) = NULL;
>
> return 0;
> }
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-02-18 2:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-17 10:48 [PATCH] cpufreq, powernow-k8: Initialize per-cpu data-structures properly Srivatsa S. Bhat
2014-02-17 11:05 ` Viresh Kumar
2014-02-17 22:02 ` Rafael J. Wysocki
2014-02-18 2:06 ` Viresh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®