Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp868053yba; Wed, 24 Apr 2019 10:54:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMYshliTdGLdopbDKtWd3rV37oFmf+4T1OsN3MkPaCDP+daBYqxtPLuGY2z9r/tiKbShmI X-Received: by 2002:a65:6107:: with SMTP id z7mr31670390pgu.313.1556128480229; Wed, 24 Apr 2019 10:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556128480; cv=none; d=google.com; s=arc-20160816; b=rC/hz3650CTBPAiqJ+mvEu6llRxf70oWFczhFxkOq/Cn6efF/E1MOzZnIRll8CYeV2 VStsZTBXnP9YZsRJq9i1l77tyiWM/ciRdox9Xl3Ynd0weAjQhVAhETdz89TI71rNfpYU VV8Z8rl0gDrCZC6LnSkMLFV/C/NWdDtaBfa8Yqo8/yqgGCh2FfGsQNLKq+CRFD+UyIsd HnPNaNLW13fa7UfF1CZQuoYegq3XmdH01wemwmdLy996rHrhO2jXU5e4lJrDg5sHJMMl 9ieT4SOcqv5NTaVlplBClYhtU+WbMmziX41mcXpwAYi8w99hJrPiX8fQBqm22iEumkjp 8kzA== 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=az1Fw/Da834SPbamuHQiwNvcNDCkYhgD9UVIjBTm0eE=; b=nqX2MrP3rg88cKbcGrbMOCpz1P4euIXp7+UKKGBN1OOU5QUz4JfnCT50dfc6tpSQ4t uvMdX2tAMr7snMLxBvBIyp0rK1e7CWe6Mw9Q6HEJIvdMDo/bwW4ahxau+bgcNo63fMKT IbELycTdX7UQXfC/yNgvz6x9726K+zbg/lw7EPZ/1a+tSdfQtmza/Pr0+4fB6UNAthTG 9+v5iLLbKa+JA3o2Smd0abKCaHDk4uHsNcTvty39OBqj1tvVGiCFneKOaS2KyEAWTt02 Q2ZBHWQ2JScSEST4T/DVbzYJGgJ9uWctWasO5R+sgzDQ5WnXgAwX/evUcA4/30zi0fgd lQ6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="uhEri4/4"; 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 k9si19779013pfb.251.2019.04.24.10.54.25; Wed, 24 Apr 2019 10:54:40 -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="uhEri4/4"; 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 S2390723AbfDXR2g (ORCPT + 99 others); Wed, 24 Apr 2019 13:28:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:54838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390719AbfDXR2e (ORCPT ); Wed, 24 Apr 2019 13:28:34 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (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 5EB0D21906; Wed, 24 Apr 2019 17:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126913; bh=zuHTLaHRDPZ2TDoYUdtOjpSuwluLsMs/x22ZQSuIj9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uhEri4/45d6f4qv89nIk1PFfLNhZvZONmqKyhRI2x29MZ1XrLswZbeV440vX6ihsC Ho/rN4fWQ9FALQRilAZTZeZbr8MCqG+/R6yTtQSFisNFZlE25W4Ld7mMtV+Pha4cD9 fpmnV/rsp6tPVXYBYKdp1wZtVQlQ5jMnyemGbrEU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phil Auld , "Peter Zijlstra (Intel)" , Anton Blanchard , Ben Segall , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 61/70] sched/fair: Limit sched_cfs_period_timer() loop to avoid hard lockup Date: Wed, 24 Apr 2019 19:10:21 +0200 Message-Id: <20190424170918.628916746@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170906.751869122@linuxfoundation.org> References: <20190424170906.751869122@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 [ Upstream commit 2e8e19226398db8265a8e675fcc0118b9e80c9e8 ] With extremely short cfs_period_us setting on a parent task group with a large number of children the for loop in sched_cfs_period_timer() can run until the watchdog fires. There is no guarantee that the call to hrtimer_forward_now() will ever return 0. The large number of children can make do_sched_cfs_period_timer() take longer than the period. NMI watchdog: Watchdog detected hard LOCKUP on cpu 24 RIP: 0010:tg_nop+0x0/0x10 walk_tg_tree_from+0x29/0xb0 unthrottle_cfs_rq+0xe0/0x1a0 distribute_cfs_runtime+0xd3/0xf0 sched_cfs_period_timer+0xcb/0x160 ? sched_cfs_slack_timer+0xd0/0xd0 __hrtimer_run_queues+0xfb/0x270 hrtimer_interrupt+0x122/0x270 smp_apic_timer_interrupt+0x6a/0x140 apic_timer_interrupt+0xf/0x20 To prevent this we add protection to the loop that detects when the loop has run too many times and scales the period and quota up, proportionally, so that the timer can complete before then next period expires. This preserves the relative runtime quota while preventing the hard lockup. A warning is issued reporting this state and the new values. Signed-off-by: Phil Auld Signed-off-by: Peter Zijlstra (Intel) Cc: Cc: Anton Blanchard Cc: Ben Segall Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: https://lkml.kernel.org/r/20190319130005.25492-1-pauld@redhat.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/sched/fair.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9829ede00498..a5d163903835 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4672,12 +4672,15 @@ static enum hrtimer_restart sched_cfs_slack_timer(struct hrtimer *timer) return HRTIMER_NORESTART; } +extern const u64 max_cfs_quota_period; + static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer) { struct cfs_bandwidth *cfs_b = container_of(timer, struct cfs_bandwidth, period_timer); int overrun; int idle = 0; + int count = 0; raw_spin_lock(&cfs_b->lock); for (;;) { @@ -4685,6 +4688,28 @@ static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer) if (!overrun) break; + if (++count > 3) { + u64 new, old = ktime_to_ns(cfs_b->period); + + new = (old * 147) / 128; /* ~115% */ + new = min(new, max_cfs_quota_period); + + cfs_b->period = ns_to_ktime(new); + + /* since max is 1s, this is limited to 1e9^2, which fits in u64 */ + cfs_b->quota *= new; + cfs_b->quota = div64_u64(cfs_b->quota, old); + + pr_warn_ratelimited( + "cfs_period_timer[cpu%d]: period too short, scaling up (new cfs_period_us %lld, cfs_quota_us = %lld)\n", + smp_processor_id(), + div_u64(new, NSEC_PER_USEC), + div_u64(cfs_b->quota, NSEC_PER_USEC)); + + /* reset count so we don't come right back in here */ + count = 0; + } + idle = do_sched_cfs_period_timer(cfs_b, overrun); } if (idle) -- 2.19.1