lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 11 Mar 2022 16:11:11 +0800
From:   z00314508 <zhengzucheng@...wei.com>
To:     <rafael@...nel.org>, <viresh.kumar@...aro.org>,
        <tglx@...utronix.de>, <len.brown@...el.com>
CC:     <zhengzucheng@...wei.com>, <linux-pm@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>, <stable@...r.kernel.org>
Subject: [PATCH] cpufreq: fix cpufreq_get() can't get correct CPU frequency

From: Zucheng Zheng <zhengzucheng@...wei.com>

On some specific platforms, the cpufreq driver does not define
cpufreq_driver.get() routine (eg:x86 intel_pstate driver), as a
result, the cpufreq_get() can't get the correct CPU frequency.

Modern x86 processors include the hardware needed to accurately
calculate frequency over an interval -- APERF, MPERF and the TSC.
Here we use arch_freq_get_on_cpu() in preference to any driver
driver-specific cpufreq_driver.get() routine to get CPU frequency.

Fixes: f8475cef9008 ("x86: use common aperfmperf_khz_on_cpu() to calculate KHz using APERF/MPERF")
Signed-off-by: Zucheng Zheng <zhengzucheng@...wei.com>
---
 drivers/cpufreq/cpufreq.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 80f535cc8a75..d777257b4454 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1806,10 +1806,14 @@ unsigned int cpufreq_get(unsigned int cpu)
 {
 	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
 	unsigned int ret_freq = 0;
+	unsigned int freq;
 
 	if (policy) {
 		down_read(&policy->rwsem);
-		if (cpufreq_driver->get)
+		freq = arch_freq_get_on_cpu(policy->cpu);
+		if (freq)
+			ret_freq = freq;
+		else if (cpufreq_driver->get)
 			ret_freq = __cpufreq_get(policy);
 		up_read(&policy->rwsem);
 
-- 
2.18.0.huawei.25

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ