Received: by 10.223.185.116 with SMTP id b49csp72233wrg; Thu, 15 Feb 2018 16:50:19 -0800 (PST) X-Google-Smtp-Source: AH8x227k7SiSKD0s6AarZmrjCpK1dp9PDVEjFiB/rjrCmYGoJ6fU95wWbisXU/622m7MHZun3g+H X-Received: by 10.99.54.196 with SMTP id d187mr1622347pga.154.1518742218939; Thu, 15 Feb 2018 16:50:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518742218; cv=none; d=google.com; s=arc-20160816; b=eFoEcEK45EAYMLEuBm0Xan67GsW742gEtXkZGjBIOCdVY6LKzOhafT9832creFtL4y X2kt52dw9UD29p62yKrWo73rRjRGWsjBSQfAb/dDha4KJnZFq2O798+1xhKfdel4qVee NBqIVBGMUO05tcoQvldHQqJmE5e0GbwkuKKAsd22FVqtHoY5mj+jvUxjeSgsZF/gdncQ GZLeGiDvIMuALAJr7SO2LuSKfLltccTZjyuB7en32iPOjPTHbEZuYhEEXpz2pdyOUTUk zDAbN72dKR0L2vvOJ48R/LhEa7nPosE3FFCvebrAvzlgK2GvGcfvZkGxhtHHZD98JbVn JfFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Q3QfnalpPOYF6yrLhbmkXvZoDpnuvrfynpdgS44Q7tE=; b=umXoGL+deoVJE9xbDk4Q6guyMjYeXFoCcPjAM464+H9gFfHLM1CcM4CTtOqTIgmArN ucV+ko/N4mx41d11GII2UfnjNLQohbcxR8ON96knZ/awNPv2qNJbtwZMxq1Gj5OW9DVJ H2Mv59GseyN253tE8xBIarVlYjaDTM3oRbHaQ9OYxCNLfcqFpLbhML/C/gAnwt4voCes 449/Qe7LQAPqV6eRoBszkV0qYH+YJw8uA2CwAYKoWro/hw/q/IzotzUWoelYd9R+BFth BcchckGhi7m5PiQhHl//o1VH/HZK6ujHmQZEI/plQHldpepJUK9GC+/9/up1seEz6DPe SEiw== ARC-Authentication-Results: i=1; mx.google.com; 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 x1-v6si706005pln.571.2018.02.15.16.50.04; Thu, 15 Feb 2018 16:50:18 -0800 (PST) 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; 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 S1423815AbeBOPkw (ORCPT + 99 others); Thu, 15 Feb 2018 10:40:52 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60200 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423777AbeBOPkm (ORCPT ); Thu, 15 Feb 2018 10:40:42 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7A31E1162; Thu, 15 Feb 2018 15:40:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavan Kondeti , "Steven Rostedt (VMware)" , "Peter Zijlstra (Intel)" , Andrew Morton , Linus Torvalds , Mike Galbraith , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.15 011/202] sched/rt: Up the root domain ref count when passing it around via IPIs Date: Thu, 15 Feb 2018 16:15:11 +0100 Message-Id: <20180215151713.412410384@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steven Rostedt (VMware) commit 364f56653708ba8bcdefd4f0da2a42904baa8eeb upstream. When issuing an IPI RT push, where an IPI is sent to each CPU that has more than one RT task scheduled on it, it references the root domain's rto_mask, that contains all the CPUs within the root domain that has more than one RT task in the runable state. The problem is, after the IPIs are initiated, the rq->lock is released. This means that the root domain that is associated to the run queue could be freed while the IPIs are going around. Add a sched_get_rd() and a sched_put_rd() that will increment and decrement the root domain's ref count respectively. This way when initiating the IPIs, the scheduler will up the root domain's ref count before releasing the rq->lock, ensuring that the root domain does not go away until the IPI round is complete. Reported-by: Pavan Kondeti Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Peter Zijlstra (Intel) Cc: Andrew Morton Cc: Linus Torvalds Cc: Mike Galbraith Cc: Peter Zijlstra Cc: Thomas Gleixner Fixes: 4bdced5c9a292 ("sched/rt: Simplify the IPI based RT balancing logic") Link: http://lkml.kernel.org/r/CAEU1=PkiHO35Dzna8EQqNSKW1fr1y1zRQ5y66X117MG06sQtNA@mail.gmail.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- kernel/sched/rt.c | 9 +++++++-- kernel/sched/sched.h | 2 ++ kernel/sched/topology.c | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1990,8 +1990,11 @@ static void tell_cpu_to_push(struct rq * rto_start_unlock(&rq->rd->rto_loop_start); - if (cpu >= 0) + if (cpu >= 0) { + /* Make sure the rd does not get freed while pushing */ + sched_get_rd(rq->rd); irq_work_queue_on(&rq->rd->rto_push_work, cpu); + } } /* Called from hardirq context */ @@ -2021,8 +2024,10 @@ void rto_push_irq_work_func(struct irq_w raw_spin_unlock(&rd->rto_lock); - if (cpu < 0) + if (cpu < 0) { + sched_put_rd(rd); return; + } /* Try the next RT overloaded CPU */ irq_work_queue_on(&rd->rto_push_work, cpu); --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -665,6 +665,8 @@ extern struct mutex sched_domains_mutex; extern void init_defrootdomain(void); extern int sched_init_domains(const struct cpumask *cpu_map); extern void rq_attach_root(struct rq *rq, struct root_domain *rd); +extern void sched_get_rd(struct root_domain *rd); +extern void sched_put_rd(struct root_domain *rd); #ifdef HAVE_RT_PUSH_IPI extern void rto_push_irq_work_func(struct irq_work *work); --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -259,6 +259,19 @@ void rq_attach_root(struct rq *rq, struc call_rcu_sched(&old_rd->rcu, free_rootdomain); } +void sched_get_rd(struct root_domain *rd) +{ + atomic_inc(&rd->refcount); +} + +void sched_put_rd(struct root_domain *rd) +{ + if (!atomic_dec_and_test(&rd->refcount)) + return; + + call_rcu_sched(&rd->rcu, free_rootdomain); +} + static int init_rootdomain(struct root_domain *rd) { if (!zalloc_cpumask_var(&rd->span, GFP_KERNEL))