Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1864018rwb; Fri, 19 Aug 2022 10:39:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR5DEXnq1jG/a7UsVWTbqiehynEc7dEOQE1heMdql0/+bPML0XfLXkeLrhp/man/KnyyK7F5 X-Received: by 2002:a17:903:110e:b0:171:3114:7112 with SMTP id n14-20020a170903110e00b0017131147112mr8567062plh.114.1660930740469; Fri, 19 Aug 2022 10:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930740; cv=none; d=google.com; s=arc-20160816; b=ccPnjWJ7iVAKee+fqGmykfG7dqPlLsschQCS5BG4Euyyms1B/v0H4afa0SFgHsubjN JuWF21zQWPx4xBaAT+DJU+uq1SF+tvaXTKxeVchEhOz04ls7nGwQg6cLJ64SFxyMJu29 orZIUDtsA6/qfE1aCJnxhlEyq+U/AizVlcv+LcLDhSXtXVjf85fd0FZ2vjmrSPcYQyFT YZpWqFeawKLrmp9dSTDiltzGi1gzwZMz9qp7maU3BqDqLhUmHmds5ptbrUfnCDVF3qYb yEzGwxpxp86grTjbgfAoSr3oKZzWARnVB30WNRBO2WFK3i+66h7wH/TJYSpsHgvcWu8r S8gQ== 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=I0u26mqZ7wwiJcXZ6hQJyGUHKng0VrQ4p8078KCYmZs=; b=d41DgHhMQcnNT4pfop4R2C5dJbDtCZvSKb44E0ckYvIo4EE52Kb1s1BzrLGok9Np+L UZ0SWxae2nFlvOF84QsbHkhr56a6C2nsaj+eusQvv+Fns7na2+Cnmm20odiGRo7nhSYa hUW9LpX1+LuNxrFj0Io+I6rRVYKYl8x4McmBqOq04s4vgMScdODhq2M/j367E9CMoh3r dg4XFIGTGDAdhJaoFqXMFe1pLif/+0MhdKpcRPmmAvC0A30irwUezrj6h6xRFbFOtnBO bu9FYgF8paaU+ITNlugXTXB2PK4y3JDktFW+6cHtL2fwniWQgezb4C0OwZMHXP3EswQx /XaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vK2kExhU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c29-20020a630d1d000000b0041cef931e70si2794676pgl.724.2022.08.19.10.38.49; Fri, 19 Aug 2022 10:39:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vK2kExhU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1351336AbiHSQFQ (ORCPT + 99 others); Fri, 19 Aug 2022 12:05:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351492AbiHSQBw (ORCPT ); Fri, 19 Aug 2022 12:01:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC380E085; Fri, 19 Aug 2022 08:53:28 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id D72BAB8280D; Fri, 19 Aug 2022 15:53:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16567C433D7; Fri, 19 Aug 2022 15:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924391; bh=RgsWbcE0RvmXnbB6B+pyTQLKK215UEHWm8koiGRdXLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vK2kExhU+6n8JqWLH+/dhBk1i6E8EsKXDlw5ybbZC2Y0/SjJXI2cOPAGs4FHoe6Ph d2sDR0ffHH3fGlPR60DH1HggPzDrrDWvDx3pE9h/vVtgclcoNterXrwg41RCH4blon 1t6W+tjfWmMeCyvbzAwrQDpJQU4cSWFbWQv2QSD0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Saenz Julienne , "Peter Zijlstra (Intel)" , Valentin Schneider , Phil Auld , Sasha Levin Subject: [PATCH 5.10 148/545] nohz/full, sched/rt: Fix missed tick-reenabling bug in dequeue_task_rt() Date: Fri, 19 Aug 2022 17:38:38 +0200 Message-Id: <20220819153835.957660978@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicolas Saenz Julienne [ Upstream commit 5c66d1b9b30f737fcef85a0b75bfe0590e16b62a ] dequeue_task_rt() only decrements 'rt_rq->rt_nr_running' after having called sched_update_tick_dependency() preventing it from re-enabling the tick on systems that no longer have pending SCHED_RT tasks but have multiple runnable SCHED_OTHER tasks: dequeue_task_rt() dequeue_rt_entity() dequeue_rt_stack() dequeue_top_rt_rq() sub_nr_running() // decrements rq->nr_running sched_update_tick_dependency() sched_can_stop_tick() // checks rq->rt.rt_nr_running, ... __dequeue_rt_entity() dec_rt_tasks() // decrements rq->rt.rt_nr_running ... Every other scheduler class performs the operation in the opposite order, and sched_update_tick_dependency() expects the values to be updated as such. So avoid the misbehaviour by inverting the order in which the above operations are performed in the RT scheduler. Fixes: 76d92ac305f2 ("sched: Migrate sched to use new tick dependency mask model") Signed-off-by: Nicolas Saenz Julienne Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Reviewed-by: Phil Auld Link: https://lore.kernel.org/r/20220628092259.330171-1-nsaenzju@redhat.com Signed-off-by: Sasha Levin --- kernel/sched/rt.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 41b14d924203..e6f22836c600 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -437,7 +437,7 @@ static inline void rt_queue_push_tasks(struct rq *rq) #endif /* CONFIG_SMP */ static void enqueue_top_rt_rq(struct rt_rq *rt_rq); -static void dequeue_top_rt_rq(struct rt_rq *rt_rq); +static void dequeue_top_rt_rq(struct rt_rq *rt_rq, unsigned int count); static inline int on_rt_rq(struct sched_rt_entity *rt_se) { @@ -558,7 +558,7 @@ static void sched_rt_rq_dequeue(struct rt_rq *rt_rq) rt_se = rt_rq->tg->rt_se[cpu]; if (!rt_se) { - dequeue_top_rt_rq(rt_rq); + dequeue_top_rt_rq(rt_rq, rt_rq->rt_nr_running); /* Kick cpufreq (see the comment in kernel/sched/sched.h). */ cpufreq_update_util(rq_of_rt_rq(rt_rq), 0); } @@ -644,7 +644,7 @@ static inline void sched_rt_rq_enqueue(struct rt_rq *rt_rq) static inline void sched_rt_rq_dequeue(struct rt_rq *rt_rq) { - dequeue_top_rt_rq(rt_rq); + dequeue_top_rt_rq(rt_rq, rt_rq->rt_nr_running); } static inline int rt_rq_throttled(struct rt_rq *rt_rq) @@ -1043,7 +1043,7 @@ static void update_curr_rt(struct rq *rq) } static void -dequeue_top_rt_rq(struct rt_rq *rt_rq) +dequeue_top_rt_rq(struct rt_rq *rt_rq, unsigned int count) { struct rq *rq = rq_of_rt_rq(rt_rq); @@ -1054,7 +1054,7 @@ dequeue_top_rt_rq(struct rt_rq *rt_rq) BUG_ON(!rq->nr_running); - sub_nr_running(rq, rt_rq->rt_nr_running); + sub_nr_running(rq, count); rt_rq->rt_queued = 0; } @@ -1333,18 +1333,21 @@ static void __dequeue_rt_entity(struct sched_rt_entity *rt_se, unsigned int flag static void dequeue_rt_stack(struct sched_rt_entity *rt_se, unsigned int flags) { struct sched_rt_entity *back = NULL; + unsigned int rt_nr_running; for_each_sched_rt_entity(rt_se) { rt_se->back = back; back = rt_se; } - dequeue_top_rt_rq(rt_rq_of_se(back)); + rt_nr_running = rt_rq_of_se(back)->rt_nr_running; for (rt_se = back; rt_se; rt_se = rt_se->back) { if (on_rt_rq(rt_se)) __dequeue_rt_entity(rt_se, flags); } + + dequeue_top_rt_rq(rt_rq_of_se(back), rt_nr_running); } static void enqueue_rt_entity(struct sched_rt_entity *rt_se, unsigned int flags) -- 2.35.1