Skip to content

Commit 6e9d121

Browse files
wkarnyrafaeljw
authored andcommitted
cpufreq: amd-pstate: Fix invalid write to MSR_AMD_CPPC_REQ
`amd_pstate_set_epp` function uses `cppc_req_cached` and `epp` variable to update the MSR_AMD_CPPC_REQ register for AMD MSR systems. The recent commit 7cca9a9 ("cpufreq: amd-pstate: avoid uninitialized variable use") changed the sequence of updating cppc_req_cached and writing the MSR_AMD_CPPC_REQ. Therefore while switching from powersave to performance governor and vice-versa in active mode MSR_AMD_CPPC_REQ is set with the previous cached value. To fix this: first update the `cppc_req_cached` variable and then call `amd_pstate_set_epp` function. - Before commit 7cca9a9 ("cpufreq: amd-pstate: avoid uninitialized variable use"): With powersave governor: [ 1.652743] amd_pstate_epp_init: writing to cppc_req_cached = 0x1eff [ 1.652744] amd_pstate_set_epp: writing cppc_req_cached = 0x1eff [ 1.652746] amd_pstate_set_epp: writing min_perf = 30, des_perf = 0, max_perf = 255, epp = 0 Changing to performance governor: [ 300.493842] amd_pstate_epp_init: writing to cppc_req_cached = 0xffff [ 300.493846] amd_pstate_set_epp: writing cppc_req_cached = 0xffff [ 300.493847] amd_pstate_set_epp: writing min_perf = 255, des_perf = 0, max_perf = 255, epp = 0 - After commit 7cca9a9 ("cpufreq: amd-pstate: avoid uninitialized variable use"): With powersave governor: [ 1.646037] amd_pstate_set_epp: writing cppc_req_cached = 0xffff [ 1.646038] amd_pstate_set_epp: writing min_perf = 255, des_perf = 0, max_perf = 255, epp = 0 [ 1.646042] amd_pstate_epp_init: writing to cppc_req_cached = 0x1eff Changing to performance governor: [ 687.117401] amd_pstate_set_epp: writing cppc_req_cached = 0x1eff [ 687.117405] amd_pstate_set_epp: writing min_perf = 30, des_perf = 0, max_perf = 255, epp = 0 [ 687.117419] amd_pstate_epp_init: writing to cppc_req_cached = 0xffff - After this fix: With powersave governor: [ 2.525717] amd_pstate_epp_init: writing to cppc_req_cached = 0x1eff [ 2.525720] amd_pstate_set_epp: writing cppc_req_cached = 0x1eff [ 2.525722] amd_pstate_set_epp: writing min_perf = 30, des_perf = 0, max_perf = 255, epp = 0 Changing to performance governor: [ 3440.152468] amd_pstate_epp_init: writing to cppc_req_cached = 0xffff [ 3440.152473] amd_pstate_set_epp: writing cppc_req_cached = 0xffff [ 3440.152474] amd_pstate_set_epp: writing min_perf = 255, des_perf = 0, max_perf = 255, epp = 0 Fixes: 7cca9a9 ("cpufreq: amd-pstate: avoid uninitialized variable use") Signed-off-by: Wyes Karny <[email protected]> Acked-by: Huang Rui <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent f0f8e9e commit 6e9d121

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,27 +1057,28 @@ static void amd_pstate_epp_init(unsigned int cpu)
10571057

10581058
cpudata->epp_policy = cpudata->policy;
10591059

1060-
if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) {
1061-
epp = amd_pstate_get_epp(cpudata, value);
1062-
if (epp < 0)
1063-
goto skip_epp;
1064-
/* force the epp value to be zero for performance policy */
1065-
epp = 0;
1066-
} else {
1067-
/* Get BIOS pre-defined epp value */
1068-
epp = amd_pstate_get_epp(cpudata, value);
1069-
if (epp)
1070-
goto skip_epp;
1060+
/* Get BIOS pre-defined epp value */
1061+
epp = amd_pstate_get_epp(cpudata, value);
1062+
if (epp < 0) {
1063+
/**
1064+
* This return value can only be negative for shared_memory
1065+
* systems where EPP register read/write not supported.
1066+
*/
1067+
goto skip_epp;
10711068
}
1069+
1070+
if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)
1071+
epp = 0;
1072+
10721073
/* Set initial EPP value */
10731074
if (boot_cpu_has(X86_FEATURE_CPPC)) {
10741075
value &= ~GENMASK_ULL(31, 24);
10751076
value |= (u64)epp << 24;
10761077
}
10771078

1079+
WRITE_ONCE(cpudata->cppc_req_cached, value);
10781080
amd_pstate_set_epp(cpudata, epp);
10791081
skip_epp:
1080-
WRITE_ONCE(cpudata->cppc_req_cached, value);
10811082
cpufreq_cpu_put(policy);
10821083
}
10831084

0 commit comments

Comments
 (0)