Skip to content

Commit 4badf2e

Browse files
gautshenrafaeljw
authored andcommitted
cpufreq: amd-pstate: Add ->fast_switch() callback
Schedutil normally calls the adjust_perf callback for drivers with adjust_perf callback available and fast_switch_possible flag set. However, when frequency invariance is disabled and schedutil tries to invoke fast_switch. So, there is a chance of kernel crash if this function pointer is not set. To protect against this scenario add fast_switch callback to amd_pstate driver. Fixes: 1d215f0 ("cpufreq: amd-pstate: Add fast switch function for AMD P-State") Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com> Signed-off-by: Wyes Karny <wyes.karny@amd.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 44c026a commit 4badf2e

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,8 @@ static int amd_pstate_verify(struct cpufreq_policy_data *policy)
444444
return 0;
445445
}
446446

447-
static int amd_pstate_target(struct cpufreq_policy *policy,
448-
unsigned int target_freq,
449-
unsigned int relation)
447+
static int amd_pstate_update_freq(struct cpufreq_policy *policy,
448+
unsigned int target_freq, bool fast_switch)
450449
{
451450
struct cpufreq_freqs freqs;
452451
struct amd_cpudata *cpudata = policy->driver_data;
@@ -465,14 +464,37 @@ static int amd_pstate_target(struct cpufreq_policy *policy,
465464
des_perf = DIV_ROUND_CLOSEST(target_freq * cap_perf,
466465
cpudata->max_freq);
467466

468-
cpufreq_freq_transition_begin(policy, &freqs);
467+
WARN_ON(fast_switch && !policy->fast_switch_enabled);
468+
/*
469+
* If fast_switch is desired, then there aren't any registered
470+
* transition notifiers. See comment for
471+
* cpufreq_enable_fast_switch().
472+
*/
473+
if (!fast_switch)
474+
cpufreq_freq_transition_begin(policy, &freqs);
475+
469476
amd_pstate_update(cpudata, min_perf, des_perf,
470-
max_perf, false, policy->governor->flags);
471-
cpufreq_freq_transition_end(policy, &freqs, false);
477+
max_perf, fast_switch, policy->governor->flags);
478+
479+
if (!fast_switch)
480+
cpufreq_freq_transition_end(policy, &freqs, false);
472481

473482
return 0;
474483
}
475484

485+
static int amd_pstate_target(struct cpufreq_policy *policy,
486+
unsigned int target_freq,
487+
unsigned int relation)
488+
{
489+
return amd_pstate_update_freq(policy, target_freq, false);
490+
}
491+
492+
static unsigned int amd_pstate_fast_switch(struct cpufreq_policy *policy,
493+
unsigned int target_freq)
494+
{
495+
return amd_pstate_update_freq(policy, target_freq, true);
496+
}
497+
476498
static void amd_pstate_adjust_perf(unsigned int cpu,
477499
unsigned long _min_perf,
478500
unsigned long target_perf,
@@ -715,6 +737,7 @@ static int amd_pstate_cpu_exit(struct cpufreq_policy *policy)
715737

716738
freq_qos_remove_request(&cpudata->req[1]);
717739
freq_qos_remove_request(&cpudata->req[0]);
740+
policy->fast_switch_possible = false;
718741
kfree(cpudata);
719742

720743
return 0;
@@ -1309,6 +1332,7 @@ static struct cpufreq_driver amd_pstate_driver = {
13091332
.flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_UPDATE_LIMITS,
13101333
.verify = amd_pstate_verify,
13111334
.target = amd_pstate_target,
1335+
.fast_switch = amd_pstate_fast_switch,
13121336
.init = amd_pstate_cpu_init,
13131337
.exit = amd_pstate_cpu_exit,
13141338
.suspend = amd_pstate_cpu_suspend,

0 commit comments

Comments
 (0)