From 4251f58faa8c81a0ec19ba2c0e951c709815a962 Mon Sep 17 00:00:00 2001 From: Joonwoo Park Date: Fri, 27 Mar 2015 10:03:59 -0700 Subject: [PATCH] sched: check HMP scheduler tunables validity Check tunables validity to take valid values only. CRs-fixed: 812443 Change-Id: Ibb9ec0d6946247068174ab7abe775a6389412d5b Signed-off-by: Joonwoo Park --- kernel/sched/fair.c | 32 ++++++++++++++++++++++++-------- kernel/sysctl.c | 13 +++++++++---- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e00e8613e126..0bb2c88e6d94 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2573,17 +2573,38 @@ void post_big_small_task_count_change(const struct cpumask *cpus) DEFINE_MUTEX(policy_mutex); +#ifdef CONFIG_SCHED_FREQ_INPUT +static inline int invalid_value_freq_input(unsigned int *data) +{ + if (data == &sysctl_sched_migration_fixup) + return !(*data == 0 || *data == 1); + + if (data == &sysctl_sched_freq_account_wait_time) + return !(*data == 0 || *data == 1); + + return 0; +} +#else +static inline int invalid_value_freq_input(unsigned int *data) +{ + return 0; +} +#endif + static inline int invalid_value(unsigned int *data) { - int val = *data; + unsigned int val = *data; if (data == &sysctl_sched_ravg_hist_size) return (val < 2 || val > RAVG_HIST_SIZE_MAX); if (data == &sysctl_sched_window_stats_policy) - return (val >= WINDOW_STATS_INVALID_POLICY); + return val >= WINDOW_STATS_INVALID_POLICY; - return 0; + if (data == &sysctl_sched_account_wait_time) + return !(val == 0 || val == 1); + + return invalid_value_freq_input(data); } /* @@ -2649,11 +2670,6 @@ int sched_hmp_proc_update_handler(struct ctl_table *table, int write, sched_min_runtime = ((u64) sysctl_sched_min_runtime) * 1000; return 0; } - if ((sysctl_sched_downmigrate_pct > sysctl_sched_upmigrate_pct) || - *data > 100) { - *data = old_val; - return -EINVAL; - } if (data == (unsigned int *)&sysctl_sched_upmigrate_min_nice) update_min_nice = 1; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 0196f6f025d9..3541ea8f0d32 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -309,14 +309,16 @@ static struct ctl_table kern_table[] = { .data = &sysctl_sched_freq_inc_notify, .maxlen = sizeof(unsigned int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, }, { .procname = "sched_freq_dec_notify", .data = &sysctl_sched_freq_dec_notify, .maxlen = sizeof(unsigned int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, }, { .procname = "sched_migration_fixup", @@ -395,7 +397,8 @@ static struct ctl_table kern_table[] = { .data = &sysctl_sched_spill_nr_run, .maxlen = sizeof(unsigned int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, }, { .procname = "sched_upmigrate", @@ -444,7 +447,9 @@ static struct ctl_table kern_table[] = { .data = &sysctl_sched_enable_power_aware, .maxlen = sizeof(unsigned int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, }, #endif /* CONFIG_SCHED_HMP */ #ifdef CONFIG_SCHED_DEBUG