Skip to contentSkip to conversation

cpufreq: powernv: Fix frame-size-overflow in powernv_cpufreq_work_fn

PATCH Applied Pratik Rajesh Sampat 6 participants 7 messages Mar 16, 2020 – Mar 26, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: powernv: Fix frame-size-overflow in powernv_cpufreq_work_fn

The patch avoids allocating cpufreq_policy on stack hence fixing frame size overflow in 'powernv_cpufreq_work_fn'

Fixes 227942809b52 ("cpufreq: powernv: Restore cpu frequency to policy->cur on unthrottling")
---
 drivers/cpufreq/powernv-cpufreq.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/cpufreq/powernv-cpufreq.c +8 -5
index 56f4bc0d209e..20ee0661555a 100644
@@ -902,6 +902,7 @@ static struct notifier_block powernv_cpufreq_reboot_nb = {
 void powernv_cpufreq_work_fn(struct work_struct *work)
 {
 	struct chip *chip = container_of(work, struct chip, throttle);
+	struct cpufreq_policy *policy;
 	unsigned int cpu;
 	cpumask_t mask;
 
@@ -916,12 +917,14 @@ void powernv_cpufreq_work_fn(struct work_struct *work)
 	chip->restore = false;
 	for_each_cpu(cpu, &mask) {
 		int index;
-		struct cpufreq_policy policy;
 
-		cpufreq_get_policy(&policy, cpu);
-		index = cpufreq_table_find_index_c(&policy, policy.cur);
-		powernv_cpufreq_target_index(&policy, index);
-		cpumask_andnot(&mask, &mask, policy.cpus);
+		policy = cpufreq_cpu_get(cpu);
+		if (!policy)
+			continue;
+		index = cpufreq_table_find_index_c(policy, policy->cur);
+		powernv_cpufreq_target_index(policy, index);
+		cpumask_andnot(&mask, &mask, policy->cpus);
+		cpufreq_cpu_put(policy);
 	}
 out:
 	put_online_cpus();
Signature · 1 line
2.24.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Pratik,

Thanks.

I have checked:

- for matching puts/gets
- that all the '.' to '->' conversions, aud uses of '&' check out
- that the Snowpatch checks pass (https://patchwork.ozlabs.org/patch/1255580/)

On that basis:

Regards,
Daniel

Quoted 43 lines

The patch avoids allocating cpufreq_policy on stack hence fixing frame size overflow in 'powernv_cpufreq_work_fn'

Fixes 227942809b52 ("cpufreq: powernv: Restore cpu frequency to policy->cur on unthrottling")
---
 drivers/cpufreq/powernv-cpufreq.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/cpufreq/powernv-cpufreq.c +8 -5
index 56f4bc0d209e..20ee0661555a 100644
@@ -902,6 +902,7 @@ static struct notifier_block powernv_cpufreq_reboot_nb = {
 void powernv_cpufreq_work_fn(struct work_struct *work)
 {
 	struct chip *chip = container_of(work, struct chip, throttle);
+	struct cpufreq_policy *policy;
 	unsigned int cpu;
 	cpumask_t mask;
 
@@ -916,12 +917,14 @@ void powernv_cpufreq_work_fn(struct work_struct *work)
 	chip->restore = false;
 	for_each_cpu(cpu, &mask) {
 		int index;
-		struct cpufreq_policy policy;
 
-		cpufreq_get_policy(&policy, cpu);
-		index = cpufreq_table_find_index_c(&policy, policy.cur);
-		powernv_cpufreq_target_index(&policy, index);
-		cpumask_andnot(&mask, &mask, policy.cpus);
+		policy = cpufreq_cpu_get(cpu);
+		if (!policy)
+			continue;
+		index = cpufreq_table_find_index_c(policy, policy->cur);
+		powernv_cpufreq_target_index(policy, index);
+		cpumask_andnot(&mask, &mask, policy->cpus);
+		cpufreq_cpu_put(policy);
 	}
 out:
 	put_online_cpus();
Signature · 1 line
2.24.1
#2 lore raw
In reply to Pratik Rajesh Sampat
Quoted 5 lines · CET Pratik Rajesh Sampat

The patch avoids allocating cpufreq_policy on stack hence fixing frame size overflow in 'powernv_cpufreq_work_fn'

Fixes 227942809b52 ("cpufreq: powernv: Restore cpu frequency to policy->cur on unthrottling")

Any objections or concerns here?

If not, I'll queue it up.

Quoted 37 lines
---
 drivers/cpufreq/powernv-cpufreq.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/cpufreq/powernv-cpufreq.c +8 -5
index 56f4bc0d209e..20ee0661555a 100644
@@ -902,6 +902,7 @@ static struct notifier_block powernv_cpufreq_reboot_nb = {
 void powernv_cpufreq_work_fn(struct work_struct *work)
 {
 	struct chip *chip = container_of(work, struct chip, throttle);
+	struct cpufreq_policy *policy;
 	unsigned int cpu;
 	cpumask_t mask;
 
@@ -916,12 +917,14 @@ void powernv_cpufreq_work_fn(struct work_struct *work)
 	chip->restore = false;
 	for_each_cpu(cpu, &mask) {
 		int index;
-		struct cpufreq_policy policy;
 
-		cpufreq_get_policy(&policy, cpu);
-		index = cpufreq_table_find_index_c(&policy, policy.cur);
-		powernv_cpufreq_target_index(&policy, index);
-		cpumask_andnot(&mask, &mask, policy.cpus);
+		policy = cpufreq_cpu_get(cpu);
+		if (!policy)
+			continue;
+		index = cpufreq_table_find_index_c(policy, policy->cur);
+		powernv_cpufreq_target_index(policy, index);
+		cpumask_andnot(&mask, &mask, policy->cpus);
+		cpufreq_cpu_put(policy);
 	}
 out:
 	put_online_cpus();
#3 lore raw
Quoted 10 lines · Rafael J. Wysocki
Quoted 5 lines · CET Pratik Rajesh Sampat

The patch avoids allocating cpufreq_policy on stack hence fixing frame size overflow in 'powernv_cpufreq_work_fn'

Fixes 227942809b52 ("cpufreq: powernv: Restore cpu frequency to policy->cur on unthrottling")

Any objections or concerns here?

If not, I'll queue it up.

I have it in my testing branch, but if you pick it up I can drop it.

cheers

Quoted 33 lines
Quoted 33 lines
drivers/cpufreq/powernv-cpufreq.c +8 -5
index 56f4bc0d209e..20ee0661555a 100644
@@ -902,6 +902,7 @@ static struct notifier_block powernv_cpufreq_reboot_nb = {
 void powernv_cpufreq_work_fn(struct work_struct *work)
 {
 	struct chip *chip = container_of(work, struct chip, throttle);
+	struct cpufreq_policy *policy;
 	unsigned int cpu;
 	cpumask_t mask;
 
@@ -916,12 +917,14 @@ void powernv_cpufreq_work_fn(struct work_struct *work)
 	chip->restore = false;
 	for_each_cpu(cpu, &mask) {
 		int index;
-		struct cpufreq_policy policy;
 
-		cpufreq_get_policy(&policy, cpu);
-		index = cpufreq_table_find_index_c(&policy, policy.cur);
-		powernv_cpufreq_target_index(&policy, index);
-		cpumask_andnot(&mask, &mask, policy.cpus);
+		policy = cpufreq_cpu_get(cpu);
+		if (!policy)
+			continue;
+		index = cpufreq_table_find_index_c(policy, policy->cur);
+		powernv_cpufreq_target_index(policy, index);
+		cpumask_andnot(&mask, &mask, policy->cpus);
+		cpufreq_cpu_put(policy);
 	}
 out:
 	put_online_cpus();
#4 lore raw
Quoted 5 lines · CET Michael Ellerman
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · CET Pratik Rajesh Sampat

The patch avoids allocating cpufreq_policy on stack hence fixing frame size overflow in 'powernv_cpufreq_work_fn'

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Fixes 227942809b52 ("cpufreq: powernv: Restore cpu frequency to policy->cur on unthrottling")

Any objections or concerns here?

If not, I'll queue it up.

I have it in my testing branch,

Great!

Quoted 1 line

but if you pick it up I can drop it.

Let it go in through your tree.

Cheers!

Reviewed-by on v1 1/1
#5 lore raw
In reply to Pratik Rajesh Sampat
Quoted 3 lines · Pratik Rajesh Sampat

The patch avoids allocating cpufreq_policy on stack hence fixing frame size overflow in 'powernv_cpufreq_work_fn'

Thanks for fixing this.

Quoted 2 lines
Fixes 227942809b52 ("cpufreq: powernv: Restore cpu frequency to policy->cur on unthrottling")
Quoted 39 lines
---
 drivers/cpufreq/powernv-cpufreq.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/cpufreq/powernv-cpufreq.c +8 -5
index 56f4bc0d209e..20ee0661555a 100644
@@ -902,6 +902,7 @@ static struct notifier_block powernv_cpufreq_reboot_nb = {
 void powernv_cpufreq_work_fn(struct work_struct *work)
 {
 	struct chip *chip = container_of(work, struct chip, throttle);
+	struct cpufreq_policy *policy;
 	unsigned int cpu;
 	cpumask_t mask;
 
@@ -916,12 +917,14 @@ void powernv_cpufreq_work_fn(struct work_struct *work)
 	chip->restore = false;
 	for_each_cpu(cpu, &mask) {
 		int index;
-		struct cpufreq_policy policy;
 
-		cpufreq_get_policy(&policy, cpu);
-		index = cpufreq_table_find_index_c(&policy, policy.cur);
-		powernv_cpufreq_target_index(&policy, index);
-		cpumask_andnot(&mask, &mask, policy.cpus);
+		policy = cpufreq_cpu_get(cpu);
+		if (!policy)
+			continue;
+		index = cpufreq_table_find_index_c(policy, policy->cur);
+		powernv_cpufreq_target_index(policy, index);
+		cpumask_andnot(&mask, &mask, policy->cpus);
+		cpufreq_cpu_put(policy);
 	}
 out:
 	put_online_cpus();
Signature · 1 line
2.24.1
#6 lore raw
In reply to Pratik Rajesh Sampat
Quoted 5 lines · Pratik Rajesh Sampat

The patch avoids allocating cpufreq_policy on stack hence fixing frame size overflow in 'powernv_cpufreq_work_fn'

Fixes 227942809b52 ("cpufreq: powernv: Restore cpu frequency to policy->cur on unthrottling")

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/d95fe371ecd28901f11256c610b988ed44e36ee2

cheers