Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4808629yba; Tue, 30 Apr 2019 04:51:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIKvekQ2+qCut3nER6Ym2qA/qnwyz3DkQqEbOskloezFpMf16iuf1eHsWTbi32jW10CkQR X-Received: by 2002:a17:902:7883:: with SMTP id q3mr68452838pll.60.1556625106445; Tue, 30 Apr 2019 04:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556625106; cv=none; d=google.com; s=arc-20160816; b=eJz/ammnSQyQdHHTOEXo1hoU3u2+DYQwXRnEfuS05LpSaUWaGCPNx4a2BEuSVy0O8u RR1luQNQKRpIOq0Yiu6vXrvRUP8rlvfmqtbxdG4cl5GGHXlgicPEulHjVq7+CkyEliL6 +wfK+knIpxsEIUAvxyGWoQGUwKQnonOaDggmr/IjbU2MimuMunywCb07+YTp/bMZwzVr ALUrroW32CI3PFAxyNkN5Gf7RUZC+qSxG4zKQX3YyHTXANhWJjUqGyRY84ChEA7N7pdO b39kZLVAb9qQ63Td8m+UHTVAJ04o1Mx2cWdaL7PRZPpZBPNYGEf7rcN9si+S68avBXh3 uROw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OwDdVthbo9z0CHywYiOqrzk7TVbVccNKnXhSPXiOR1s=; b=DSR5sLC0ALOcvn/rRUQDPXyVIr0o/AuGunhKZPVGgyMkf4q73R/oPSGNvrCdpRwXPa rXq9DGnvC2pxToQD92vf9duggRDH+SA8e9KxwJXPneBQrJ7WN894A2oDV9AinhTC54/z 9y99rmaCaq6/ATNLN2MSFkTbP0ZsUR9pNcvJ2e95/yuQFWpLPYrF8KV7Qkt+HjNeloxU rdBtwU917Wmzd7XnI4e1kPpJ7bQ/Iie5e6ZWvLA7S/H9Y3OX1NqkpYMkVRqYzKrhsFtQ fG7lNZTcteaqidAOgkFZ/6MNgQQMHIQNg6VtNdFhCk2HOy9rQ6vOc99x6WBkmbROd3qu UUNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aceNiob4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n17si12260247pgj.487.2019.04.30.04.51.31; Tue, 30 Apr 2019 04:51:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aceNiob4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730913AbfD3Lsv (ORCPT + 99 others); Tue, 30 Apr 2019 07:48:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:35082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730367AbfD3Lst (ORCPT ); Tue, 30 Apr 2019 07:48:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 76B1B2054F; Tue, 30 Apr 2019 11:48:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556624929; bh=PeyLxRrvPim8ODYBuucyUJC6RM4ioJ05WxbCoJag5Y8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aceNiob4ZH9Zt+ld19K6rW2vgLxSN5pm0HFThXR77i83ij4CLI+HCBxeqI3WVReo+ S29vNV0ItFTv8tLka4ToOYnDpUH8VT2gbLsSAFO7bwPdG1oGa0TOrsJyJAV72oEETe bT7cQaRFC+OiON+wzDvTD9WW6Ic0yTW+/kWtZlog= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xie XiuQi , "Peter Zijlstra (Intel)" , Linus Torvalds , Thomas Gleixner , cj.chengjian@huawei.com, Ingo Molnar Subject: [PATCH 5.0 26/89] sched/numa: Fix a possible divide-by-zero Date: Tue, 30 Apr 2019 13:38:17 +0200 Message-Id: <20190430113611.222275490@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113609.741196396@linuxfoundation.org> References: <20190430113609.741196396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xie XiuQi 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 Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: cj.chengjian@huawei.com Cc: Link: http://lkml.kernel.org/r/20190425080016.GX11158@hirez.programming.kicks-ass.net Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- kernel/sched/fair.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1994,6 +1994,10 @@ static u64 numa_get_avg_runtime(struct t 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; *period = LOAD_AVG_MAX;