From: Christian Loehle <christian.loehle@arm.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>
Cc: Mario Limonciello <superm1@kernel.org>,
Sumit Gupta <sumitg@nvidia.com>,
Jie Zhan <zhanjie9@hisilicon.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
linux-pm <linux-pm@vger.kernel.org>
Subject: [PATCH] cpufreq: Hold the policy write lock when changing boost state
Date: Tue, 3 Nov 2026 18:19:03 +0000 [thread overview]
Message-ID: <be3739f8-e668-4711-912c-91459d77ed35@arm.com> (raw)
The per-policy boost sysfs handler calls policy_set_boost() under
policy->rwsem, but the global boost handler and cpufreq_online() do not.
Consequently, global and per-policy boost changes can concurrently
update policy->boost_enabled, invoke the driver callback and update the
boost frequency QoS request. The driver callbacks also access policy
state, e.g. CPPC updates cpuinfo.max_freq that assumes policy->rw_sem
held.
Take policy->rwsem around policy_set_boost() in both unlocked
callers. Keep locking at the call sites because the per-policy sysfs
handler already holds the lock.
Fixes: 218a06a79d9a ("cpufreq: Support per-policy performance boost")
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
---
drivers/cpufreq/cpufreq.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 54dde8419bdc..015962e6c1fe 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -576,6 +576,8 @@ static int policy_set_boost(struct cpufreq_policy *policy, bool enable)
{
int ret;
+ lockdep_assert_held_write(&policy->rwsem);
+
if (policy->boost_enabled == enable)
return 0;
@@ -1629,6 +1631,8 @@ static int cpufreq_online(unsigned int cpu)
*/
if (cpufreq_driver->set_boost && policy->boost_supported &&
(new_policy || !cpufreq_boost_enabled())) {
+ guard(cpufreq_policy_write)(policy);
+
ret = policy_set_boost(policy, cpufreq_boost_enabled());
if (ret) {
/* If the set_boost fails, the online operation is not affected */
@@ -2830,6 +2834,8 @@ static int cpufreq_boost_trigger_state(int state)
if (!policy->boost_supported)
continue;
+ guard(cpufreq_policy_write)(policy);
+
ret = policy_set_boost(policy, state);
if (unlikely(ret))
break;
--
2.34.1
next reply other threads:[~2026-11-03 18:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 18:19 Christian Loehle [this message]
2026-11-03 18:48 ` Rafael J. Wysocki (Intel)
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=be3739f8-e668-4711-912c-91459d77ed35@arm.com \
--to=christian.loehle@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sumitg@nvidia.com \
--cc=superm1@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=zhanjie9@hisilicon.com \
/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
all inboxes | Powered by JetHome®