Skip to content

Commit 7d85dfd

Browse files
Liao Changgregkh
Liao Chang
authored andcommitted
cpufreq: Fix the race condition while updating the transition_task of policy
[ Upstream commit 61bfbf7 ] The field 'transition_task' of policy structure is used to track the task which is performing the frequency transition. Using this field to print a warning once detect a case where the same task is calling _begin() again before completing the preivous frequency transition via the _end(). However, there is a potential race condition in _end() and _begin() APIs while updating the field 'transition_task' of policy, the scenario is depicted below: Task A Task B /* 1st freq transition */ Invoke _begin() { ... ... } /* 2nd freq transition */ Invoke _begin() { ... //waiting for A to ... //clear ... //transition_ongoing ... //in _end() for ... //the 1st transition | Change the frequency | | Invoke _end() { | ... | ... | transition_ongoing = false; V transition_ongoing = true; transition_task = current; transition_task = NULL; ... //A overwrites the task ... //performing the transition ... //result in error warning. } To fix this race condition, the transition_lock of policy structure is now acquired before updating policy structure in _end() API. Which ensure that only one task can update the 'transition_task' field at a time. Link: https://lore.kernel.org/all/[email protected]/ Fixes: ca654dc ("cpufreq: Catch double invocations of cpufreq_freq_transition_begin/end") Signed-off-by: Liao Chang <[email protected]> Acked-by: Viresh Kumar <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent bb31371 commit 7d85dfd

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/cpufreq/cpufreq.c

+2
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,10 @@ void cpufreq_freq_transition_end(struct cpufreq_policy *policy,
455455
policy->cur,
456456
policy->cpuinfo.max_freq);
457457

458+
spin_lock(&policy->transition_lock);
458459
policy->transition_ongoing = false;
459460
policy->transition_task = NULL;
461+
spin_unlock(&policy->transition_lock);
460462

461463
wake_up(&policy->transition_wait);
462464
}

0 commit comments

Comments
 (0)