From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Mario Limonciello <mario.limonciello@amd.com>,
Huang Rui <ray.huang@amd.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: Perry Yuan <perry.yuan@amd.com>,
K Prateek Nayak <kprateek.nayak@amd.com>
Subject: [PATCH 1/6] cpufreq/amd-pstate: Grab "amd_pstate_driver_lock" when toggling dynamic_epp
Date: Fri, 8 May 2026 05:17:43 +0000 [thread overview]
Message-ID: <20260508051748.10484-2-kprateek.nayak@amd.com> (raw)
In-Reply-To: <20260508051748.10484-1-kprateek.nayak@amd.com>
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: e30ca6dd5345 ("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>
---
drivers/cpufreq/amd-pstate.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 453084c67327f..5e2d28c73294d 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1707,6 +1707,8 @@ static int amd_pstate_change_driver_mode(int mode)
{
int ret;
+ lockdep_assert_held(&amd_pstate_driver_lock);
+
ret = amd_pstate_unregister_driver(0);
if (ret)
return ret;
@@ -1821,6 +1823,13 @@ static ssize_t dynamic_epp_store(struct device *a, struct device_attribute *b,
if (ret)
return ret;
+ guard(mutex)(&amd_pstate_driver_lock);
+
+ if (cppc_state != AMD_PSTATE_ACTIVE) {
+ pr_debug("dynamic_epp can only be toggled in active mode\n");
+ return -EINVAL;
+ }
+
if (dynamic_epp == enabled)
return -EINVAL;
--
2.34.1
next prev parent reply other threads:[~2026-05-08 5:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 5:17 [PATCH 0/6] cpufreq/amd-pstate: Dynamic EPP fixes K Prateek Nayak
2026-05-08 5:17 ` K Prateek Nayak [this message]
2026-05-08 5:17 ` [PATCH 2/6] cpufreq/amd-pstate: Return -ENOMEM on failure to allocate profile_name K Prateek Nayak
2026-05-08 5:17 ` [PATCH 3/6] cpufreq/amd-pstate: Allow writes to dynamic_epp when state isn't modified K Prateek Nayak
2026-05-08 5:17 ` [PATCH 4/6] cpufreq/amd-pstate: Reorder notifier unregistration and floor perf reset K Prateek Nayak
2026-05-08 5:17 ` [PATCH 5/6] cpufreq/amd-pstate: Use "epp_default_dc" as default when dynamic_epp is disabled K Prateek Nayak
2026-05-08 5:17 ` [PATCH 6/6] cpufreq/amd-pstate-ut: Drop policy reference before driver switch K Prateek Nayak
2026-05-08 18:04 ` [PATCH 0/6] cpufreq/amd-pstate: Dynamic EPP fixes Mario Limonciello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260508051748.10484-2-kprateek.nayak@amd.com \
--to=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=perry.yuan@amd.com \
--cc=rafael@kernel.org \
--cc=ray.huang@amd.com \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox