Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp792621ybe; Fri, 13 Sep 2019 06:28:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjwCu+roKNPokxnAei5AjZChO/iuX72yDAQtN1mX89UnpoGN5jyXfdkAdyOoZSx5xV55pN X-Received: by 2002:a17:906:ce48:: with SMTP id se8mr38045617ejb.98.1568381315644; Fri, 13 Sep 2019 06:28:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568381315; cv=none; d=google.com; s=arc-20160816; b=eSUUwoywjPBzovFf+nnGAgkJhw1mKYYPbImkW6bLMvaBA7VWHmtDc6frHnetEpRrTL mLBphwG3Wd+gvwXoUUXbXhTf9Mmjgyovd5ngg0zICt3yVUYCO7BHbEgifwLvdkKyQMCT m25osia3dqHoZYyBW9UNU9TZDOedMqMhR2NEwz6U5inHJzpN3raD58D1AgugSNEGZLIp q39oaffpm9qcGsVQ9Jkl3dQ5EULXhLnSwp4Tj3UsNJuu1RBVVB85wpQRKA4l5pxvAsUo eCCS7JulgsNklQ470AGUx1sw9U/zJuNZ0bRVoIzkyqlqb4CC0+7LG9lzXqxHHjJjRMKV 3CTw== 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=lXWpAOJRYCRu+KQbDA88x9Upsu5kG5TU3NDNxDhY+WE=; b=jyYalMjbRI+sh8G9E6TpGlXGbaojdHrg9vyysVY34re8S+kAIGY7QyYnE4DVYq6hEr Y6lTmuEQSTYeYXrzD8JstwICxpTgoV2sc3tgJXhdXuA5bEOoJ8gSSYq/AGZOpPcLTTg6 hkcz4TRK6qkFi8Un2L4KxkCFjgdGHFNV1OvDxQq4yDcG3zjZMzEF6CjC618CorvQu6WF 6SB4WYdoFedev1Mdtk+1ldr5Gt7F+lDwo6A8Kj/hPuzS8+PW+gcm+taAFqTghrmJoTkF JehQWD53+z0SkL/hny7eLGe2yyrs1mwe3NAy3blNHT+AkdXHQox0SFS+cCVcgoEQ3AYp ItTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=okc85UCw; 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 c51si17622366edc.317.2019.09.13.06.28.12; Fri, 13 Sep 2019 06:28:35 -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=okc85UCw; 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 S2391083AbfIMNXW (ORCPT + 99 others); Fri, 13 Sep 2019 09:23:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:50980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390808AbfIMNVY (ORCPT ); Fri, 13 Sep 2019 09:21:24 -0400 Received: from localhost (unknown [104.132.45.99]) (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 E4B03206BB; Fri, 13 Sep 2019 13:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380883; bh=1KYHGBqfweu0I1NPQIQ0A4U12D3zB+VEp+7ZzFnXOwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=okc85UCwLXL2tuwj1SKLUME/nE9LosYJqZOt1xxaOwPhn/32qgfDNCkmVgZ946YtO Oa6SXU6GgyAKGqr7B6PZT1xGORidUHWFQJDzMFvVXy/44K124M+f1PrdLUxkl2I6hX TkFIhq/aS69/B6929ZPD4wOzmtOQNkCFz2IT/+SM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liangyan , "Peter Zijlstra (Intel)" , Valentin Schneider , Ben Segall , Linus Torvalds , Thomas Gleixner , shanpeic@linux.alibaba.com, xlpang@linux.alibaba.com, Ingo Molnar Subject: [PATCH 5.2 08/37] sched/fair: Dont assign runtime for throttled cfs_rq Date: Fri, 13 Sep 2019 14:07:13 +0100 Message-Id: <20190913130513.061588463@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130510.727515099@linuxfoundation.org> References: <20190913130510.727515099@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: Liangyan commit 5e2d2cc2588bd3307ce3937acbc2ed03c830a861 upstream. do_sched_cfs_period_timer() will refill cfs_b runtime and call distribute_cfs_runtime to unthrottle cfs_rq, sometimes cfs_b->runtime will allocate all quota to one cfs_rq incorrectly, then other cfs_rqs attached to this cfs_b can't get runtime and will be throttled. We find that one throttled cfs_rq has non-negative cfs_rq->runtime_remaining and cause an unexpetced cast from s64 to u64 in snippet: distribute_cfs_runtime() { runtime = -cfs_rq->runtime_remaining + 1; } The runtime here will change to a large number and consume all cfs_b->runtime in this cfs_b period. According to Ben Segall, the throttled cfs_rq can have account_cfs_rq_runtime called on it because it is throttled before idle_balance, and the idle_balance calls update_rq_clock to add time that is accounted to the task. This commit prevents cfs_rq to be assgined new runtime if it has been throttled until that distribute_cfs_runtime is called. Signed-off-by: Liangyan Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Reviewed-by: Ben Segall Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: shanpeic@linux.alibaba.com Cc: stable@vger.kernel.org Cc: xlpang@linux.alibaba.com Fixes: d3d9dc330236 ("sched: Throttle entities exceeding their allowed bandwidth") Link: https://lkml.kernel.org/r/20190826121633.6538-1-liangyan.peng@linux.alibaba.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- kernel/sched/fair.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4449,6 +4449,8 @@ static void __account_cfs_rq_runtime(str if (likely(cfs_rq->runtime_remaining > 0)) return; + if (cfs_rq->throttled) + return; /* * if we're unable to extend our runtime we resched so that the active * hierarchy can be throttled @@ -4652,6 +4654,9 @@ static u64 distribute_cfs_runtime(struct if (!cfs_rq_throttled(cfs_rq)) goto next; + /* By the above check, this should never be true */ + SCHED_WARN_ON(cfs_rq->runtime_remaining > 0); + runtime = -cfs_rq->runtime_remaining + 1; if (runtime > remaining) runtime = remaining;