Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2410714ybx; Fri, 8 Nov 2019 04:02:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxuKNGO6ylTFIFEigEDH/TgIWrzcq4bQtyCUfiPvrsu7WUxRHigCxBQgtcn2I9P9P6UxckX X-Received: by 2002:a7b:c762:: with SMTP id x2mr7840859wmk.128.1573214524002; Fri, 08 Nov 2019 04:02:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573214523; cv=none; d=google.com; s=arc-20160816; b=TUOCC/VFdakV6hs7LZWrI0KOkcfi6WlF6BthZPjR+cHFuls5DV6/l5bcSG0QZTQkod e4Jpia8woIBLg4iaZ4M3yfMcDu2LwltLM3VHTvtQb47DjPHjRQ3tmmwAlS2k87yB3cIN 7hQ+7lcGgNSccALh+AXg6V0Eo6FSSBD4HKN72qDaCSPFv8+cF2N+jvnNHXQTZhXscJXO 6OXkp37DoU/UNikQyW9GNWfYWg/yO8DbDcJII5dUwPgtf63ZWUbiG9+CvwcMnxYCe5BK vdHSGzeFjXnadkWIEfCYo856ogUVjcv+lanh9MPx/ddJXwFe72gxmhRgAReWKd8mGmjb EPmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LzWFQdxb4LwLZQfLCTEGrcAMyzovJYdVyqlUvic3qgI=; b=LWtDIqD77YYAb4fvLqHyRqMeQN96+3gAzJKojIkkFCxa4iBLaN6hiQAk9Q1GStyJNO XafQyd+RdGG3faMMv+p30WD+otWOU5xH3oLVjxAI+VOGZMFB4hwEz21flwdAFF6n+WoW iSwHNtPrHxiR5y92iH2iPtUqzWgb7vXJ3GllfhETvaANPtwNZRPaK4CShKsf7NdfdNdE 13uuwj/KnwcF6VxLA++BKi03U7Z/q9mV5VNcVIYXmLMTBqAIpid8hkD+OOkX7q+RvOMK 4mISm11u/HmSuEgAuS55sTdDg42+Yu/jxrbgxbEvfyFXAVpE5wW5YaeCcfctLn7i93/T 4lIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=nDl0RKwL; 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 o3si4293546edi.374.2019.11.08.04.01.39; Fri, 08 Nov 2019 04:02:03 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=nDl0RKwL; 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 S2391362AbfKHMBL (ORCPT + 99 others); Fri, 8 Nov 2019 07:01:11 -0500 Received: from merlin.infradead.org ([205.233.59.134]:43250 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390977AbfKHMBI (ORCPT ); Fri, 8 Nov 2019 07:01:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LzWFQdxb4LwLZQfLCTEGrcAMyzovJYdVyqlUvic3qgI=; b=nDl0RKwL5GyOZJA56UhKYSZgD 8a0RbGKX4LEAkfSpM38JDQJ3Hz3Of/dtf9bDDsQhwAU5qb54nvJ7STnjA5o2Kn0002LLK3lsqNEHI uBaPoWPOhn1KICAYhsaGpS7uSOE380Xr7Jpv2jLaJ18OTcMTW3Mlp1xDiaIbDRjETkgsf8K3bGy4F ClMFX7Kx0z+d0C8PUlohQt7oNYXyCvjm4fjETEjn3rLu4JgL8L6VXd+CBPmnsMy55VsuF20lJNZL4 yaw5AmIZ6QAwN7kagYCFnxH7g+iUn5FZdSpfu9xlzTpgVJa8+pMkBCwbhXR7Ip7EmVOWCDH031MhG GZa9m6KNA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iT2wP-0001zg-In; Fri, 08 Nov 2019 12:00:37 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 141053075F0; Fri, 8 Nov 2019 12:59:30 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 0755B2025EDB2; Fri, 8 Nov 2019 13:00:35 +0100 (CET) Date: Fri, 8 Nov 2019 13:00:35 +0100 From: Peter Zijlstra To: Quentin Perret Cc: Kirill Tkhai , linux-kernel@vger.kernel.org, aaron.lwe@gmail.com, valentin.schneider@arm.com, mingo@kernel.org, pauld@redhat.com, jdesfossez@digitalocean.com, naravamudan@digitalocean.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, juri.lelli@redhat.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, kernel-team@android.com, john.stultz@linaro.org Subject: Re: NULL pointer dereference in pick_next_task_fair Message-ID: <20191108120034.GK4131@hirez.programming.kicks-ass.net> References: <20191106120525.GX4131@hirez.programming.kicks-ass.net> <33643a5b-1b83-8605-2347-acd1aea04f93@virtuozzo.com> <20191106165437.GX4114@hirez.programming.kicks-ass.net> <20191106172737.GM5671@hirez.programming.kicks-ass.net> <831c2cd4-40a4-31b2-c0aa-b5f579e770d6@virtuozzo.com> <20191107132628.GZ4114@hirez.programming.kicks-ass.net> <20191107153848.GA31774@google.com> <20191107184356.GF4114@hirez.programming.kicks-ass.net> <20191107192907.GA30258@worktop.programming.kicks-ass.net> <20191108110212.GA204618@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191108110212.GA204618@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 08, 2019 at 11:02:12AM +0000, Quentin Perret wrote: > On Thursday 07 Nov 2019 at 20:29:07 (+0100), Peter Zijlstra wrote: > > I still havne't had food, but this here compiles... > > And it seems to work, too :) Excellent! > > @@ -3929,13 +3929,17 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) > > } > > > > restart: > > - /* > > - * Ensure that we put DL/RT tasks before the pick loop, such that they > > - * can PULL higher prio tasks when we lower the RQ 'priority'. > > - */ > > - prev->sched_class->put_prev_task(rq, prev, rf); > > - if (!rq->nr_running) > > - newidle_balance(rq, rf); > > +#ifdef CONFIG_SMP > > + for (class = prev->sched_class; > > + class != &idle_sched_class; > > + class = class->next) { > > + > > + if (class->balance(rq, prev, rf)) > > + break; > > + } > > +#endif > > + > > + put_prev_task(rq, prev); > > Right, that looks much cleaner IMO. I'm thinking if we killed the > special case for CFS above we could do with a single loop to iterate the > classes, and you could fold ->balance() in ->pick_next_task() ... No, you can't, because then you're back to having to restart the pick when something happens when we drop the rq halfway down the pick. Which is something I really wanted to get rid of. > That would remove one call site to newidle_balance() too, which I think > is good. Hackbench probably won't like that, though. Yeah, that fast path really is important. I've got a few patches pending there, fixing a few things and that gets me 2% extra on a sched-yield benchmark. > > +static int balance_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) > > +{ > > + if (rq->cfs.nr_running) FWIW that must test rq->nr_running. > > + return 1; > > + > > + return newidle_balance(rq, rf) != 0; > > And you can ignore the RETRY_TASK case here under the assumption that > we must have tried to pull from RT/DL before ending up here ? Well, the balance callback can always return 0 and be correct. The point is mostly to avoid more work. In this case, since fair is the last class and we've already excluded idle for balancing, the win is minimal. But since we have the code, might as well dtrt.