From 89a180556f3c74572a27a8bca9392db99011de6d Mon Sep 17 00:00:00 2001 From: Pavankumar Kondeti Date: Thu, 28 Jan 2021 12:44:52 +0530 Subject: [PATCH] sched/walt: Synchronize per-task sysctl and sysctl_task_read_pid sysctl_task_read_pid sysctl needs to be set to the desired task's pid before reading any of the per-task sysctl. So use the same mutex for both of these sysctl handlers to prevent data tearing. While at it, fix an incorrect goto in sched_task_handler() function and restrict the range of sysctl_task_read_pid. Change-Id: I544010f51a28ff6e5c4f117d68816de147ef3d0f Signed-off-by: Pavankumar Kondeti --- kernel/sched/walt/sysctl.c | 35 ++++++++++++++++++++++++----------- kernel/sched/walt/walt.h | 1 - 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/kernel/sched/walt/sysctl.c b/kernel/sched/walt/sysctl.c index ded371ed3702..83ad94ca4536 100644 --- a/kernel/sched/walt/sysctl.c +++ b/kernel/sched/walt/sysctl.c @@ -53,13 +53,15 @@ unsigned int sysctl_sched_walt_rotate_big_tasks; unsigned int sysctl_sched_task_unfilter_period; unsigned int __read_mostly sysctl_sched_asym_cap_sibling_freq_match_pct; unsigned int sysctl_walt_low_latency_task_threshold; /* disabled by default */ -unsigned int sysctl_task_read_pid; unsigned int sysctl_sched_conservative_pl; unsigned int sysctl_sched_min_task_util_for_boost = 51; unsigned int sysctl_sched_min_task_util_for_colocation = 35; unsigned int sysctl_sched_many_wakeup_threshold = WALT_MANY_WAKEUP_DEFAULT; const int sched_user_hint_max = 1000; +/* range is [1 .. INT_MAX] */ +static int sysctl_task_read_pid = 1; + static void init_tg_pointers(void) { struct cgroup_subsys_state *css = &root_task_group.css; @@ -200,6 +202,20 @@ static int sched_ravg_window_handler(struct ctl_table *table, return ret; } +static DEFINE_MUTEX(sysctl_pid_mutex); +static int sched_task_read_pid_handler(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, + loff_t *ppos) +{ + int ret; + + mutex_lock(&sysctl_pid_mutex); + ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); + mutex_unlock(&sysctl_pid_mutex); + + return ret; +} + enum { TASK_BEGIN = 0, WAKE_UP_IDLE, @@ -225,20 +241,15 @@ static int sched_task_handler(struct ctl_table *table, int write, .maxlen = sizeof(pid_and_val), .mode = table->mode, }; - static DEFINE_MUTEX(mutex); - mutex_lock(&mutex); + mutex_lock(&sysctl_pid_mutex); if (!write) { - if (sysctl_task_read_pid <= 0) { - ret = -ENOENT; - goto unlock_mutex; - } task = get_pid_task(find_vpid(sysctl_task_read_pid), PIDTYPE_PID); if (!task) { ret = -ENOENT; - goto put_task; + goto unlock_mutex; } wts = (struct walt_task_struct *) task->android_vendor_data1; pid_and_val[0] = sysctl_task_read_pid; @@ -336,7 +347,7 @@ static int sched_task_handler(struct ctl_table *table, int write, put_task: put_task_struct(task); unlock_mutex: - mutex_unlock(&mutex); + mutex_unlock(&sysctl_pid_mutex); return ret; } @@ -832,9 +843,11 @@ struct ctl_table walt_table[] = { { .procname = "sched_task_read_pid", .data = &sysctl_task_read_pid, - .maxlen = sizeof(unsigned int), + .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = sched_task_read_pid_handler, + .extra1 = SYSCTL_ONE, + .extra2 = SYSCTL_INT_MAX, }, { .procname = "sched_load_boost", diff --git a/kernel/sched/walt/walt.h b/kernel/sched/walt/walt.h index f551ef30083b..d85ede69a67f 100644 --- a/kernel/sched/walt/walt.h +++ b/kernel/sched/walt/walt.h @@ -388,7 +388,6 @@ extern unsigned int sysctl_sched_walt_rotate_big_tasks; extern unsigned int sysctl_sched_task_unfilter_period; extern unsigned int __read_mostly sysctl_sched_asym_cap_sibling_freq_match_pct; extern unsigned int sysctl_walt_low_latency_task_threshold; /* disabled by default */ -extern unsigned int sysctl_task_read_pid; extern struct ctl_table walt_table[]; extern struct ctl_table walt_base_table[]; extern void walt_tunables(void);