From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69BD8C49ED7 for ; Fri, 13 Sep 2019 13:10:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DE82208C0 for ; Fri, 13 Sep 2019 13:10:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380249; bh=/Wpb0hxs3yi+xIrKEWTmOB1Ju6+6Mqm/GKsYh6CsmYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=eKGrzLw+3AFCw4isHa9XRgfHwOpoGk+DXJu+Hd7eBsonjGDtjsEfdkBEwbyPx7Ciz ksHWkreBvDCV19X9/SXdhnPzxwwcuW0R2DSl0hhH39TSNu5FvZDzm22J+OXJvqOWAM 3y+weZHwNyY/0DSma993kIgJBKEWaT0PO8X0HWg0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388824AbfIMNKs (ORCPT ); Fri, 13 Sep 2019 09:10:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:35586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388810AbfIMNKp (ORCPT ); Fri, 13 Sep 2019 09:10:45 -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 52B572089F; Fri, 13 Sep 2019 13:10:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380243; bh=/Wpb0hxs3yi+xIrKEWTmOB1Ju6+6Mqm/GKsYh6CsmYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gN24dd2PNWaDzp+lMdq+Ri6ymYjA+pSbYa2kqyyhPHmXYmDKXF3DLcLrQ05Ou7yq5 Sk4Qit8quhzVTuyE5A2mZDPWdAVlfAem04mbUzwoQaOqtxZRUuTlnBZYVi6bvljcL4 UARDkSSzAtf7pn6RR0HxAxMoczmKyUwCQIy7LSgE= 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 4.14 04/21] sched/fair: Dont assign runtime for throttled cfs_rq Date: Fri, 13 Sep 2019 14:06:57 +0100 Message-Id: <20190913130503.218272986@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130501.285837292@linuxfoundation.org> References: <20190913130501.285837292@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 @@ -4206,6 +4206,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 @@ -4402,6 +4404,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;