* [PATCH] cpufreq: Hold the policy write lock when changing boost state
@ 2026-11-03 18:19 Christian Loehle
2026-11-03 18:48 ` Rafael J. Wysocki (Intel)
0 siblings, 1 reply; 2+ messages in thread
From: Christian Loehle @ 2026-11-03 18:19 UTC (permalink / raw)
To: Rafael J. Wysocki, Viresh Kumar
Cc: Mario Limonciello, Sumit Gupta, Jie Zhan, linux-kernel, linux-pm
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] cpufreq: Hold the policy write lock when changing boost state
2026-11-03 18:19 [PATCH] cpufreq: Hold the policy write lock when changing boost state Christian Loehle
@ 2026-11-03 18:48 ` Rafael J. Wysocki (Intel)
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-03 18:48 UTC (permalink / raw)
To: Christian Loehle
Cc: Rafael J. Wysocki, Viresh Kumar, Mario Limonciello, Sumit Gupta,
Jie Zhan, linux-kernel, linux-pm
On Tue, Nov 3, 2026 at 7:19 PM Christian Loehle
<christian.loehle@arm.com> wrote:
>
> 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;
> --
Applied as 7.4-rc material, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-03 18:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 18:19 [PATCH] cpufreq: Hold the policy write lock when changing boost state Christian Loehle
2026-11-03 18:48 ` Rafael J. Wysocki (Intel)
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®