[PATCH v6 2/2] cpufreq: acpi-cpufreq: report filtered-out P-states in extract_msr()
From: lirongqing
Date: Sat Nov 14 2026 - 09:08:05 EST
From: Li RongQing <lirongqing@xxxxxxxxx>
extract_msr() maps the status value read from the hardware to a
frequency by walking policy->freq_table. freq_table[] is built by
filtering out _PSS entries that are not lower in frequency than the
previous one, so firmware may autonomously switch the CPU to a P-state
that has no freq_table entry. The status of such a P-state cannot be
matched and extract_msr() falls back to freq_table[0].frequency.
get_cur_freq_on_cpu() is the ->get() callback for the
ACPI_ADR_SPACE_FIXED_HARDWARE case. When firmware has changed the
P-state behind the OS's back, it sets data->resume so that the next
->target() call rewrites the control register even if the requested
P-state equals perf->state. However, acpi_cpufreq_target() is reached
only if the cpufreq core sees a difference between the requested
frequency and policy->cur, because __cpufreq_driver_target() and
__target_index() return early when target_freq == policy->cur.
policy->cur is resynchronized from the ->get() value by
cpufreq_verify_current_freq(), so the frequency returned by ->get()
has to differ from policy->cur for data->resume to be acted upon in
the ->target_index() path.
If the OS is at the P-state corresponding to freq_table[0] and firmware
switches the CPU to a filtered-out P-state, the fallback makes ->get()
return the same frequency as policy->cur and cached_freq. data->resume
is left clear, policy->cur is not updated, and the CPU stays at the
firmware-selected P-state while the cpufreq core believes it is at
freq_table[0].
Look the status up in all of perf->states[] instead and return the
frequency of the matching ACPI P-state. For P-states retained in
freq_table[] this returns the same value as before, because the
frequency of each freq_table entry is perf->states[driver_data]
.core_frequency converted to kHz. For a filtered-out P-state whose
frequency differs from policy->cur, get_cur_freq_on_cpu() now sets
data->resume and the cpufreq core updates policy->cur through
cpufreq_out_of_sync(), so the next request for the expected P-state
reaches acpi_cpufreq_target() and rewrites the control register.
The fallback to freq_table[0].frequency is kept for a status that
matches no _PSS entry at all, since returning 0 from ->get() makes
cpufreq_online() fail and triggers a warning in cpufreq_update_policy().
A filtered-out P-state with the same frequency as policy->cur is still
not detected through the ->target_index() path, but in that case the
CPU runs at the frequency the cpufreq core expects.
extract_io() is not changed: for ACPI_ADR_SPACE_SYSTEM_IO no ->get()
callback is registered and extract_io() is only used by check_freqs().
Fixes: e56a727b023d ("[CPUFREQ] Make acpi-cpufreq more robust against BIOS freq changes behind our back.")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://sashiko.dev/#/patchset/20260910111329.2220-1-lirongqing%40baidu.com
Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
---
drivers/cpufreq/acpi-cpufreq.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 2d7d147..3dc7ee4 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -210,8 +210,8 @@ static unsigned extract_io(struct cpufreq_policy *policy, u32 value)
static unsigned extract_msr(struct cpufreq_policy *policy, u32 msr)
{
struct acpi_cpufreq_data *data = policy->driver_data;
- struct cpufreq_frequency_table *pos;
struct acpi_processor_performance *perf;
+ unsigned int i;
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
msr &= AMD_MSR_RANGE;
@@ -222,9 +222,9 @@ static unsigned extract_msr(struct cpufreq_policy *policy, u32 msr)
perf = to_perf_data(data);
- cpufreq_for_each_entry(pos, policy->freq_table)
- if (msr == perf->states[pos->driver_data].status)
- return pos->frequency;
+ for (i = 0; i < perf->state_count; i++)
+ if (msr == perf->states[i].status)
+ return perf->states[i].core_frequency * 1000;
return policy->freq_table[0].frequency;
}
--
2.9.4