Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3715454pxb; Mon, 24 Jan 2022 16:09:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjmXRvfOAhEs3PWJzZQ/G8sN6QLuYbKw+W+9YgSlfyz6nBLl6oMlRVTOQbbgmV06TMiAKW X-Received: by 2002:a17:902:ab89:b0:14a:1802:7c15 with SMTP id f9-20020a170902ab8900b0014a18027c15mr15931843plr.88.1643069351854; Mon, 24 Jan 2022 16:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069351; cv=none; d=google.com; s=arc-20160816; b=Z5E6ldorBbTJ/0afsPvfSXgDsDPLIXt0AhDSmmc+9w2Z7j8e9XD0a5EGWvSbJjsjHj ADtYAMn6itSc1yv+ZbWwOLyiGQQf3AIlvpg9OHsje/xlG4a4BEBVa78LciCzzh7XakL3 LV+jHl6uwzVoy0aSHa+VQrULsjOTdremt8XaxtGCd7m9yG3hsBY2DUlDMHY3nT/807fI 2HJNxQRuomJ7DnmO4D06VdzQs1Ag0fbujeFPtfyCUWcz1jeHwBS/pYlWOVjFr9BFK84j MaFTmGetncn0vofOD7RV8jksERbi6TFyVCxRF1lxzzs7P/93Tvi9pRbOg82aqM+c60hq Vppw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MaCZuqA3JR+hn1Dcbp45WSRHgRLCTArL+UmdzSoAKRM=; b=p1TmIUi51/AFpiu/wUTZitWySJLtuzSpNaO9vJDnAihNVzEvWxT4mQzAVmBfIN3imB b2PIjxdiob11cpVZTuc8MSYtwyOSAxF1+q0uhkFBQS0eD6jvf0NxX4ccD3ICjqCOnvmU MZL8EuQQM9EKe/ViyTgptwo0a+gC9QxtVR9O0SDpEt5G5PPpDruStkXya55z0eUd2e7K yiZH9vZoSMjy4VCOuWQl3ogzTW471mUO1+wI+LDUSKPxJhdElZ6wLOSjEIgIgAdyM7Lu 5O0If3NXaizgp0QZfJjCa2s26dSggm3N8SfRWP2HcOgYXQ7NQJaA2sY0P5IEpQHO2IQc PNSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="0F+c4s/v"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si1235450plg.8.2022.01.24.16.08.59; Mon, 24 Jan 2022 16:09:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="0F+c4s/v"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357214AbiAYAE4 (ORCPT + 99 others); Mon, 24 Jan 2022 19:04:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382903AbiAXWlx (ORCPT ); Mon, 24 Jan 2022 17:41:53 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80346C06B5A5; Mon, 24 Jan 2022 13:05:22 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1F14F61361; Mon, 24 Jan 2022 21:05:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE3F6C340E5; Mon, 24 Jan 2022 21:05:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058321; bh=0XhSti58rGg1bd0mP0ZghW2OZEV0aA4SSU2tDfHBNT0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0F+c4s/vGI8G2t5kEwm4cnjjC8Y5EVV+h7JblogqYCYiwt8xSHgFJgwHCZ7UgSMk1 L4iBVcKxkFJNufWPEotN5mkTiQ84JV4zHhwOAXQu9n3bQDQAdGZPT8Iis+l8xCrwln DqpWnQs2ozNgLpf+c8NWx0DGZ6+sfsGHuVDnV4gw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Li Hua , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.16 0251/1039] sched/rt: Try to restart rt period timer when rt runtime exceeded Date: Mon, 24 Jan 2022 19:34:00 +0100 Message-Id: <20220124184133.766926257@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Li Hua [ Upstream commit 9b58e976b3b391c0cf02e038d53dd0478ed3013c ] When rt_runtime is modified from -1 to a valid control value, it may cause the task to be throttled all the time. Operations like the following will trigger the bug. E.g: 1. echo -1 > /proc/sys/kernel/sched_rt_runtime_us 2. Run a FIFO task named A that executes while(1) 3. echo 950000 > /proc/sys/kernel/sched_rt_runtime_us When rt_runtime is -1, The rt period timer will not be activated when task A enqueued. And then the task will be throttled after setting rt_runtime to 950,000. The task will always be throttled because the rt period timer is not activated. Fixes: d0b27fa77854 ("sched: rt-group: synchonised bandwidth period") Reported-by: Hulk Robot Signed-off-by: Li Hua Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20211203033618.11895-1-hucool.lihua@huawei.com Signed-off-by: Sasha Levin --- kernel/sched/rt.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index b48baaba2fc2e..7b4f4fbbb4048 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -52,11 +52,8 @@ void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime) rt_b->rt_period_timer.function = sched_rt_period_timer; } -static void start_rt_bandwidth(struct rt_bandwidth *rt_b) +static inline void do_start_rt_bandwidth(struct rt_bandwidth *rt_b) { - if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF) - return; - raw_spin_lock(&rt_b->rt_runtime_lock); if (!rt_b->rt_period_active) { rt_b->rt_period_active = 1; @@ -75,6 +72,14 @@ static void start_rt_bandwidth(struct rt_bandwidth *rt_b) raw_spin_unlock(&rt_b->rt_runtime_lock); } +static void start_rt_bandwidth(struct rt_bandwidth *rt_b) +{ + if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF) + return; + + do_start_rt_bandwidth(rt_b); +} + void init_rt_rq(struct rt_rq *rt_rq) { struct rt_prio_array *array; @@ -1031,13 +1036,17 @@ static void update_curr_rt(struct rq *rq) for_each_sched_rt_entity(rt_se) { struct rt_rq *rt_rq = rt_rq_of_se(rt_se); + int exceeded; if (sched_rt_runtime(rt_rq) != RUNTIME_INF) { raw_spin_lock(&rt_rq->rt_runtime_lock); rt_rq->rt_time += delta_exec; - if (sched_rt_runtime_exceeded(rt_rq)) + exceeded = sched_rt_runtime_exceeded(rt_rq); + if (exceeded) resched_curr(rq); raw_spin_unlock(&rt_rq->rt_runtime_lock); + if (exceeded) + do_start_rt_bandwidth(sched_rt_bandwidth(rt_rq)); } } } @@ -2911,8 +2920,12 @@ static int sched_rt_global_validate(void) static void sched_rt_do_global(void) { + unsigned long flags; + + raw_spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags); def_rt_bandwidth.rt_runtime = global_rt_runtime(); def_rt_bandwidth.rt_period = ns_to_ktime(global_rt_period()); + raw_spin_unlock_irqrestore(&def_rt_bandwidth.rt_runtime_lock, flags); } int sched_rt_handler(struct ctl_table *table, int write, void *buffer, -- 2.34.1