Skip to content

Commit dbea75f

Browse files
committed
cpufreq: intel_pstate: Clear HWP desired on suspend/shutdown and offline
Commit a365ab6 ("cpufreq: intel_pstate: Implement the ->adjust_perf() callback") caused intel_pstate to use nonzero HWP desired values in certain usage scenarios, but it did not prevent them from being leaked into the confugirations in which HWP desired is expected to be 0. The failing scenarios are switching the driver from the passive mode to the active mode and starting a new kernel via kexec() while intel_pstate is running in the passive mode. To address this issue, ensure that HWP desired will be cleared on offline and suspend/shutdown. Fixes: a365ab6 ("cpufreq: intel_pstate: Implement the ->adjust_perf() callback") Reported-by: Julia Lawall <[email protected]> Tested-by: Julia Lawall <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 833db72 commit dbea75f

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

drivers/cpufreq/intel_pstate.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,9 +1006,16 @@ static void intel_pstate_hwp_offline(struct cpudata *cpu)
10061006
*/
10071007
value &= ~GENMASK_ULL(31, 24);
10081008
value |= HWP_ENERGY_PERF_PREFERENCE(cpu->epp_cached);
1009-
WRITE_ONCE(cpu->hwp_req_cached, value);
10101009
}
10111010

1011+
/*
1012+
* Clear the desired perf field in the cached HWP request value to
1013+
* prevent nonzero desired values from being leaked into the active
1014+
* mode.
1015+
*/
1016+
value &= ~HWP_DESIRED_PERF(~0L);
1017+
WRITE_ONCE(cpu->hwp_req_cached, value);
1018+
10121019
value &= ~GENMASK_ULL(31, 0);
10131020
min_perf = HWP_LOWEST_PERF(READ_ONCE(cpu->hwp_cap_cached));
10141021

@@ -3003,6 +3010,27 @@ static int intel_cpufreq_cpu_exit(struct cpufreq_policy *policy)
30033010
return intel_pstate_cpu_exit(policy);
30043011
}
30053012

3013+
static int intel_cpufreq_suspend(struct cpufreq_policy *policy)
3014+
{
3015+
intel_pstate_suspend(policy);
3016+
3017+
if (hwp_active) {
3018+
struct cpudata *cpu = all_cpu_data[policy->cpu];
3019+
u64 value = READ_ONCE(cpu->hwp_req_cached);
3020+
3021+
/*
3022+
* Clear the desired perf field in MSR_HWP_REQUEST in case
3023+
* intel_cpufreq_adjust_perf() is in use and the last value
3024+
* written by it may not be suitable.
3025+
*/
3026+
value &= ~HWP_DESIRED_PERF(~0L);
3027+
wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value);
3028+
WRITE_ONCE(cpu->hwp_req_cached, value);
3029+
}
3030+
3031+
return 0;
3032+
}
3033+
30063034
static struct cpufreq_driver intel_cpufreq = {
30073035
.flags = CPUFREQ_CONST_LOOPS,
30083036
.verify = intel_cpufreq_verify_policy,
@@ -3012,7 +3040,7 @@ static struct cpufreq_driver intel_cpufreq = {
30123040
.exit = intel_cpufreq_cpu_exit,
30133041
.offline = intel_cpufreq_cpu_offline,
30143042
.online = intel_pstate_cpu_online,
3015-
.suspend = intel_pstate_suspend,
3043+
.suspend = intel_cpufreq_suspend,
30163044
.resume = intel_pstate_resume,
30173045
.update_limits = intel_pstate_update_limits,
30183046
.name = "intel_cpufreq",

0 commit comments

Comments
 (0)