Skip to content

Commit 9ef0ad4

Browse files
Liao Changrafaeljw
authored andcommitted
cpufreq: userspace: Move is_managed indicator into per-policy structure
The userspace governor uses the 'cpu' field of cpufreq_policy structure to track if it is allowed to set the speed of the policy. However, there is a window where the 'cpu' field is equal to the value of nr_cpus_id when all affected CPUs of policy are offline, which is an illegal value to get the per-CPU variable. To avoid this issue, modify the governor to use a per-policy indicator to track if the policy is managed. Signed-off-by: Liao Chang <[email protected]> Acked-by: Viresh Kumar <[email protected]> [ rjw: Changelog edits ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 285189c commit 9ef0ad4

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/cpufreq/cpufreq_userspace.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
#include <linux/mutex.h>
1616
#include <linux/slab.h>
1717

18-
static DEFINE_PER_CPU(unsigned int, cpu_is_managed);
19-
2018
struct userspace_policy {
19+
unsigned int is_managed;
2120
unsigned int setspeed;
2221
struct mutex mutex;
2322
};
@@ -37,7 +36,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
3736
pr_debug("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq);
3837

3938
mutex_lock(&userspace->mutex);
40-
if (!per_cpu(cpu_is_managed, policy->cpu))
39+
if (!userspace->is_managed)
4140
goto err;
4241

4342
userspace->setspeed = freq;
@@ -85,7 +84,7 @@ static int cpufreq_userspace_policy_start(struct cpufreq_policy *policy)
8584
pr_debug("started managing cpu %u\n", policy->cpu);
8685

8786
mutex_lock(&userspace->mutex);
88-
per_cpu(cpu_is_managed, policy->cpu) = 1;
87+
userspace->is_managed = 1;
8988
userspace->setspeed = policy->cur;
9089
mutex_unlock(&userspace->mutex);
9190
return 0;
@@ -98,7 +97,7 @@ static void cpufreq_userspace_policy_stop(struct cpufreq_policy *policy)
9897
pr_debug("managing cpu %u stopped\n", policy->cpu);
9998

10099
mutex_lock(&userspace->mutex);
101-
per_cpu(cpu_is_managed, policy->cpu) = 0;
100+
userspace->is_managed = 0;
102101
userspace->setspeed = 0;
103102
mutex_unlock(&userspace->mutex);
104103
}

0 commit comments

Comments
 (0)