summaryrefslogtreecommitdiff
authorXie XiuQi <xiexiuqi@huawei.com>2019-04-20 08:34:16 (GMT)
committer Greg Kroah-Hartman <gregkh@linuxfoundation.org>2019-05-02 07:32:01 (GMT)
commitc9e5f60b6a6b679f27cb7d7ed8a26840ad56513c (patch)
tree4e7d1d46796b692f935b9a714e1198e0888d3cf6
parenta51d5ec23a013b5e2f5d1eac9e791160df632bc9 (diff)
downloadcommon-c9e5f60b6a6b679f27cb7d7ed8a26840ad56513c.zip
common-c9e5f60b6a6b679f27cb7d7ed8a26840ad56513c.tar.gz
common-c9e5f60b6a6b679f27cb7d7ed8a26840ad56513c.tar.bz2
sched/numa: Fix a possible divide-by-zero
commit a860fa7b96e1a1c974556327aa1aee852d434c21 upstream. sched_clock_cpu() may not be consistent between CPUs. If a task migrates to another CPU, then se.exec_start is set to that CPU's rq_clock_task() by update_stats_curr_start(). Specifically, the new value might be before the old value due to clock skew. So then if in numa_get_avg_runtime() the expression: 'now - p->last_task_numa_placement' ends up as -1, then the divider '*period + 1' in task_numa_placement() is 0 and things go bang. Similar to update_curr(), check if time goes backwards to avoid this. [ peterz: Wrote new changelog. ] [ mingo: Tweaked the code comment. ] Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: cj.chengjian@huawei.com Cc: <stable@vger.kernel.org> Link: http://lkml.kernel.org/r/20190425080016.GX11158@hirez.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat
-rw-r--r--kernel/sched/fair.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 4b1e066..f0c9b69 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1925,6 +1925,10 @@ static u64 numa_get_avg_runtime(struct task_struct *p, u64 *period)
if (p->last_task_numa_placement) {
delta = runtime - p->last_sum_exec_runtime;
*period = now - p->last_task_numa_placement;
+
+ /* Avoid time going backwards, prevent potential divide error: */
+ if (unlikely((s64)*period < 0))
+ *period = 0;
} else {
delta = p->se.avg.load_sum / p->se.load.weight;
*period = LOAD_AVG_MAX;