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=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 AAD20C12002 for ; Wed, 14 Jul 2021 20:04:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8763D613D1 for ; Wed, 14 Jul 2021 20:04:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240229AbhGNUGv (ORCPT ); Wed, 14 Jul 2021 16:06:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:49318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241381AbhGNTw1 (ORCPT ); Wed, 14 Jul 2021 15:52:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 66143613F8; Wed, 14 Jul 2021 19:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626292128; bh=Csn/RnxPMPaL5qmyamdW+7ODVbUXiffXGy8X59WJJRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KmoI8gHGz4YtMC3gXZewFM6CfdphRQsn7Z+B3Fh5SfSmMxtJn29ll0IOM7vIP0nAT FT2LI/SVaQT0QFzoATdsWAC1EQ80XZCih7hGxFnq4chiS1sqqC/580Y0LNSdFMXh0U +kdR75qOeheD3Mw35RjtYC2fiYoC21IbNZr5SgqsYWsssI1OXZmM46IFYG90sly7z8 uLKSVnX8j+vMGyusddup8hg0Qgvqn7y+OWghAZP+9rvbUKSCqHHXgKPaCOW0WKhkgx +f00k2A2KWwEI4HQYzHalh7Z0BHNHmpWny2bfaMOqTh7qQnFr+BtCI5YsVOQUmitN6 ZI4isW3QYdw+A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Odin Ugedal , Peter Zijlstra , Ben Segall , Sasha Levin Subject: [PATCH AUTOSEL 4.4 10/10] sched/fair: Fix CFS bandwidth hrtimer expiry type Date: Wed, 14 Jul 2021 15:48:33 -0400 Message-Id: <20210714194833.56197-10-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210714194833.56197-1-sashal@kernel.org> References: <20210714194833.56197-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Odin Ugedal [ Upstream commit 72d0ad7cb5bad265adb2014dbe46c4ccb11afaba ] The time remaining until expiry of the refresh_timer can be negative. Casting the type to an unsigned 64-bit value will cause integer underflow, making the runtime_refresh_within return false instead of true. These situations are rare, but they do happen. This does not cause user-facing issues or errors; other than possibly unthrottling cfs_rq's using runtime from the previous period(s), making the CFS bandwidth enforcement less strict in those (special) situations. Signed-off-by: Odin Ugedal Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Ben Segall Link: https://lore.kernel.org/r/20210629121452.18429-1-odin@uged.al Signed-off-by: Sasha Levin --- kernel/sched/fair.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 15952d0e340b..e00f17070cb2 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3852,7 +3852,7 @@ static const u64 cfs_bandwidth_slack_period = 5 * NSEC_PER_MSEC; static int runtime_refresh_within(struct cfs_bandwidth *cfs_b, u64 min_expire) { struct hrtimer *refresh_timer = &cfs_b->period_timer; - u64 remaining; + s64 remaining; /* if the call-back is running a quota refresh is already occurring */ if (hrtimer_callback_running(refresh_timer)) @@ -3860,7 +3860,7 @@ static int runtime_refresh_within(struct cfs_bandwidth *cfs_b, u64 min_expire) /* is a quota refresh about to occur? */ remaining = ktime_to_ns(hrtimer_expires_remaining(refresh_timer)); - if (remaining < min_expire) + if (remaining < (s64)min_expire) return 1; return 0; -- 2.30.2