Skip to content

Commit 9228169

Browse files
kudureranganathsuperm1
authored andcommitted
cpufreq/amd-pstate: Grab "amd_pstate_driver_lock" when toggling dynamic_epp
Concurrently changing driver mode and dynamic_epp with: echo passive > /sys/devices/system/cpu/amd_pstate/status& echo disable > /sys/devices/system/cpu/amd_pstate/dynamic_epp& hits the WARN_ON_ONCE() in static_key_disable_cpuslocked() and hangs the system since both sysfs writes are trying to do amd_pstate_change_driver_mode() without any synchronization. Grab the "amd_pstate_driver_lock" mutex when modifying "dynamic_epp" to prevent the two paths from racing with each other. Add a lockdep assertion for "amd_pstate_driver_lock" in amd_pstate_change_driver_mode() to formalize the dependency. Since "cppc_mode" is stable under "amd_pstate_driver_lock", only reload the driver when in "AMD_PSTATE_ACTIVE" mode and reject all writes when in passive or guided mode, or if the driver is not loaded, since only active mode operates on EPP. Fixes: e30ca6d ("cpufreq/amd-pstate: Add dynamic energy performance preference") Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com> Link: https://lore.kernel.org/r/20260508051748.10484-2-kprateek.nayak@amd.com Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
1 parent 7fd2df2 commit 9228169

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/cpufreq/amd-pstate.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,8 @@ static int amd_pstate_change_driver_mode(int mode)
17071707
{
17081708
int ret;
17091709

1710+
lockdep_assert_held(&amd_pstate_driver_lock);
1711+
17101712
ret = amd_pstate_unregister_driver(0);
17111713
if (ret)
17121714
return ret;
@@ -1821,6 +1823,13 @@ static ssize_t dynamic_epp_store(struct device *a, struct device_attribute *b,
18211823
if (ret)
18221824
return ret;
18231825

1826+
guard(mutex)(&amd_pstate_driver_lock);
1827+
1828+
if (cppc_state != AMD_PSTATE_ACTIVE) {
1829+
pr_debug("dynamic_epp can only be toggled in active mode\n");
1830+
return -EINVAL;
1831+
}
1832+
18241833
if (dynamic_epp == enabled)
18251834
return -EINVAL;
18261835

0 commit comments

Comments
 (0)