Skip to content

Commit 3e25a8e

Browse files
rafaeljwgregkh
authored andcommitted
cpufreq: intel_pstate: Check turbo_is_disabled() in store_no_turbo()
[ Upstream commit 350cbb5 ] After recent changes in intel_pstate, global.turbo_disabled is only set at the initialization time and never changed. However, it turns out that on some systems the "turbo disabled" bit in MSR_IA32_MISC_ENABLE, the initial state of which is reflected by global.turbo_disabled, can be flipped later and there should be a way to take that into account (other than checking that MSR every time the driver runs which is costly and useless overhead on the vast majority of systems). For this purpose, notice that before the changes in question, store_no_turbo() contained a turbo_is_disabled() check that was used for updating global.turbo_disabled if the "turbo disabled" bit in MSR_IA32_MISC_ENABLE had been flipped and that functionality can be restored. Then, users will be able to reset global.turbo_disabled by writing 0 to no_turbo which used to work before on systems with flipping "turbo disabled" bit. This guarantees the driver state to remain in sync, but READ_ONCE() annotations need to be added in two places where global.turbo_disabled is accessed locklessly, so modify the driver to make that happen. Fixes: 0940f1a ("cpufreq: intel_pstate: Do not update global.turbo_disabled after initialization") Closes: https://lore.kernel.org/linux-pm/bf3ebf1571a4788e97daf861eb493c12d42639a3.camel@xry111.site Suggested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Reported-by: Xi Ruoyao <xry111@xry111.site> Tested-by: Xi Ruoyao <xry111@xry111.site> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f227c2f commit 3e25a8e

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

drivers/cpufreq/intel_pstate.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,12 +1255,17 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
12551255

12561256
no_turbo = !!clamp_t(int, input, 0, 1);
12571257

1258-
if (no_turbo == global.no_turbo)
1259-
goto unlock_driver;
1260-
1261-
if (global.turbo_disabled) {
1262-
pr_notice_once("Turbo disabled by BIOS or unavailable on processor\n");
1258+
WRITE_ONCE(global.turbo_disabled, turbo_is_disabled());
1259+
if (global.turbo_disabled && !no_turbo) {
1260+
pr_notice("Turbo disabled by BIOS or unavailable on processor\n");
12631261
count = -EPERM;
1262+
if (global.no_turbo)
1263+
goto unlock_driver;
1264+
else
1265+
no_turbo = 1;
1266+
}
1267+
1268+
if (no_turbo == global.no_turbo) {
12641269
goto unlock_driver;
12651270
}
12661271

@@ -1730,7 +1735,7 @@ static u64 atom_get_val(struct cpudata *cpudata, int pstate)
17301735
u32 vid;
17311736

17321737
val = (u64)pstate << 8;
1733-
if (READ_ONCE(global.no_turbo) && !global.turbo_disabled)
1738+
if (READ_ONCE(global.no_turbo) && !READ_ONCE(global.turbo_disabled))
17341739
val |= (u64)1 << 32;
17351740

17361741
vid_fp = cpudata->vid.min + mul_fp(
@@ -1900,7 +1905,7 @@ static u64 core_get_val(struct cpudata *cpudata, int pstate)
19001905
u64 val;
19011906

19021907
val = (u64)pstate << 8;
1903-
if (READ_ONCE(global.no_turbo) && !global.turbo_disabled)
1908+
if (READ_ONCE(global.no_turbo) && !READ_ONCE(global.turbo_disabled))
19041909
val |= (u64)1 << 32;
19051910

19061911
return val;

0 commit comments

Comments
 (0)