Skip to contentSkip to conversation

cpufreq: CPPC: Avoid overflow when calculating desired_perf

PATCH In review Hoan Tran 3 participants 4 messages Sep 14, 2016 – Sep 19, 2016

Subsystems (2)
lore
Share & tools
lore

Hoan Tran

author
#0 lore raw

PATCH 1/1 cpufreq: CPPC: Avoid overflow when calculating desired_perf

This patch fixes overflow issue when calculating the desired_perf.

---
 drivers/cpufreq/cppc_cpufreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +2 -1
index 894e465..3e0961e 100644
@@ -84,7 +84,8 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
 
 	cpu = all_cpu_data[policy->cpu];
 
-	cpu->perf_ctrls.desired_perf = target_freq * policy->max / cppc_dmi_max_khz;
+	cpu->perf_ctrls.desired_perf =
+		(u64)target_freq * policy->max / cppc_dmi_max_khz;
 	freqs.old = policy->cur;
 	freqs.new = target_freq;
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 12 lines · Hoan Tran

This patch fixes overflow issue when calculating the desired_perf.

---
 drivers/cpufreq/cppc_cpufreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +0 -0
index 894e465..3e0961e 100644

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, · line 90

Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c +2 -1
@@ -84,7 +84,8 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
 
 	cpu = all_cpu_data[policy->cpu];
 
-	cpu->perf_ctrls.desired_perf = target_freq * policy->max / cppc_dmi_max_khz;
+	cpu->perf_ctrls.desired_perf =
+		(u64)target_freq * policy->max / cppc_dmi_max_khz;
 	freqs.old = policy->cur;
 	freqs.new = target_freq;

That's on top of the CPPC material in linux-next I gather?

Which commit does it fix?

Thanks,
Rafael

author
#2 lore raw

Hi Rafael,

Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Hoan Tran

This patch fixes overflow issue when calculating the desired_perf.

---
 drivers/cpufreq/cppc_cpufreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +0 -0
index 894e465..3e0961e 100644
@@ -84,7 +84,8 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
 
      cpu = all_cpu_data[policy->cpu];
 
Quoted 7 lines

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, · line 90

Quoted 5 lines
drivers/cpufreq/cppc_cpufreq.c +2 -1
-     cpu->perf_ctrls.desired_perf = target_freq * policy->max / cppc_dmi_max_khz;
+     cpu->perf_ctrls.desired_perf =
+             (u64)target_freq * policy->max / cppc_dmi_max_khz;
      freqs.old = policy->cur;
      freqs.new = target_freq;

That's on top of the CPPC material in linux-next I gather?

Yes, it's on TOP of linux-next.

Quoted 2 lines

Which commit does it fix?

This is a fix for ad38677df44b67e0f5b6c4d31e9c2734abde8ed9 (cpufreq:
CPPC: Force reporting values in KHz to fix user space interface)
http://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/drivers/cpufreq/cppc_cpufreq.c?id=ad38677df44b67e0f5b6c4d31e9c2734abde8ed9

Thanks
Hoan

Quoted 4 lines

Thanks,
Rafael

#3 lore raw
Quoted 30 lines · Hoan Tran

Hi Rafael,

Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Hoan Tran

This patch fixes overflow issue when calculating the desired_perf.

---
 drivers/cpufreq/cppc_cpufreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpufreq/cppc_cpufreq.c +0 -0
index 894e465..3e0961e 100644
@@ -84,7 +84,8 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
 
      cpu = all_cpu_data[policy->cpu];
 
Quoted 7 lines

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, · line 90

Quoted 5 lines
drivers/cpufreq/cppc_cpufreq.c +2 -1
-     cpu->perf_ctrls.desired_perf = target_freq * policy->max / cppc_dmi_max_khz;
+     cpu->perf_ctrls.desired_perf =
+             (u64)target_freq * policy->max / cppc_dmi_max_khz;
      freqs.old = policy->cur;
      freqs.new = target_freq;

That's on top of the CPPC material in linux-next I gather?

Yes, it's on TOP of linux-next.

Quoted 1 line
Quoted 13 lines
Quoted 1 line

Which commit does it fix?

This is a fix for ad38677df44b67e0f5b6c4d31e9c2734abde8ed9 (cpufreq:
CPPC: Force reporting values in KHz to fix user space interface)
http://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/drivers/cpufreq/cppc_cpufreq.c?id=ad38677df44b67e0f5b6c4d31e9c2734abde8ed9

Thanks
Hoan

Quoted 4 lines

Thanks,
Rafael

Nice catch, Hoan. Thanks!

Signature · 8 lines
ciao,
al
-----------------------------------
Al Stone
Software Engineer
Red Hat, Inc.
[email protected]
-----------------------------------