Skip to content

Commit b4a11fa

Browse files
wkarnyrafaeljw
authored andcommitted
cpufreq: Fail driver register if it has adjust_perf without fast_switch
If fast_switch_possible flag is set by the scaling driver, the governor is free to select fast_switch function even if adjust_perf is set. Some scaling drivers which use adjust_perf don't set fast_switch thinking that the governor would never fall back to fast_switch. But the governor can fall back to fast_switch even in runtime if frequency invariance is disabled due to some reason. This could crash the kernel if the driver didn't set the fast_switch function pointer. Therefore, fail driver registration if it has adjust_perf without fast_switch. Suggested-by: Rafael J. Wysocki <[email protected]> Suggested-by: Viresh Kumar <[email protected]> Signed-off-by: Wyes Karny <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 858fd16 commit b4a11fa

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2828,7 +2828,8 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
28282828
(driver_data->setpolicy && (driver_data->target_index ||
28292829
driver_data->target)) ||
28302830
(!driver_data->get_intermediate != !driver_data->target_intermediate) ||
2831-
(!driver_data->online != !driver_data->offline))
2831+
(!driver_data->online != !driver_data->offline) ||
2832+
(driver_data->adjust_perf && !driver_data->fast_switch))
28322833
return -EINVAL;
28332834

28342835
pr_debug("trying to register driver %s\n", driver_data->name);

include/linux/cpufreq.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,10 @@ struct cpufreq_driver {
340340
/*
341341
* ->fast_switch() replacement for drivers that use an internal
342342
* representation of performance levels and can pass hints other than
343-
* the target performance level to the hardware.
343+
* the target performance level to the hardware. This can only be set
344+
* if ->fast_switch is set too, because in those cases (under specific
345+
* conditions) scale invariance can be disabled, which causes the
346+
* schedutil governor to fall back to the latter.
344347
*/
345348
void (*adjust_perf)(unsigned int cpu,
346349
unsigned long min_perf,

0 commit comments

Comments
 (0)