Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1470897pxu; Tue, 24 Nov 2020 00:36:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxt2IENYu/VXK5D+FBvWV8CEswnJDKpdi/h+eEdoIJp3v3lSIqGnO72SuTZZuYmG00kSmxR X-Received: by 2002:a17:906:4e90:: with SMTP id v16mr3227747eju.477.1606206972376; Tue, 24 Nov 2020 00:36:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606206972; cv=none; d=google.com; s=arc-20160816; b=AeeFt3xSSueJeu0KjEWAKXm1apjgoJN3qZB8PA2xPVz7dlU2jgeUP4+iPUX/WRuqM0 iI0+R86UPv+3a6gqcoPnt/ohYvEqChOy/fA0m/LGaz/jMukghFcxd7tAxGEk7s4ZnwPT JnWfp/S0IqNMNwDQmTm9mz5pMJqtEBTnK51kOzXjGK9GWYliTV60twb+abvDDfEB3BjO 4cQLFqaCVYvDaDb8DpSqxnj5/TfIlkUyiCtea+Q1WNpziqoF0dvApxvD96seLct8H5B1 X4j2AO/Lj/vCTj8DlkeSf/jbNvBF2+xhok4nkUD3ismxhsWQh0/p+5Zwc2Aq6pMLTgEh XwgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1z5cl4E+1Kt5ZTJVS7bSlXS5dAz5x84o0QFQGPW0MwI=; b=mWXjWTmI8VE0rMd52yn6Y4zZ4FXYfg6ItxUDphNsXf964CwcFgUQlJM7GsZMAB9uaU okZVbrtV8qfgt0YCllDQzyCukPnJ0VI4YQnBsSOxB8YgEoBLFu2NcKIzIEU4gsXgWk/W F9jPclm7ZJ8WZ+3DHtXSO+d2u3lZ7VeYxwsInajV4r6WyKpFwTDDa2579wuTC0uZDm8K aOTpCHd9w+Z9iQ7nBqrptg1Rs0U7GhyiGBw/XI7FJCKu6q4Nsp0BF71PZJ/gRN7BdIBc 1DdVg7/9uwGZianE7h6Got5S5i6v/Y41Mu1N7HLkFQzTjJKR7Qf3kAoDkE1FDH5yUcrZ UNJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=TUOxQiaj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mc9si8291110ejb.616.2020.11.24.00.35.50; Tue, 24 Nov 2020 00:36:12 -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=@infradead.org header.s=merlin.20170209 header.b=TUOxQiaj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730683AbgKXIdH (ORCPT + 99 others); Tue, 24 Nov 2020 03:33:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730476AbgKXIdH (ORCPT ); Tue, 24 Nov 2020 03:33:07 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC047C0613CF for ; Tue, 24 Nov 2020 00:33:06 -0800 (PST) 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; bh=1z5cl4E+1Kt5ZTJVS7bSlXS5dAz5x84o0QFQGPW0MwI=; b=TUOxQiajN4MT/SrV3n5T0XJHNs ibPQSsgjFWHHfNC5igX2BOc3Z0l0Kei3PjbMXAmYx3v7QUjbfibKH6sDzGfuA6mGdwMS8JHCsa6Sy eo4Z/QwO9HQ/sTWR5yaiO48WyVmW4lUuNC1UrY1ktB8SD9Y2+Q51Dsq4+9RCmORBP1x0fpYacjlxa FRPbkkmzGadNf4GcflgnxN8nfwaubGPgr34iUUgY64tKaxZEsMhOsbJpkLs8YRZ1jt6eftqrsqqoF ZuSYfI65olro/Hxc5qrl/4EcXYrAd1ymfTsVjEWdWSylSSsCUMru6dUpuZ0Qgsb3HBrrQdpNFvqRx LdRQFF0Q==; 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 1khTjz-0003zd-Pz; Tue, 24 Nov 2020 08:32:00 +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 EBE563012DF; Tue, 24 Nov 2020 09:31:56 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A103024C2AFD3; Tue, 24 Nov 2020 09:31:56 +0100 (CET) Date: Tue, 24 Nov 2020 09:31:56 +0100 From: Peter Zijlstra To: "Singh, Balbir" Cc: "Joel Fernandes (Google)" , Nishanth Aravamudan , Julien Desfossez , Tim Chen , Vineeth Pillai , Aaron Lu , Aubrey Li , tglx@linutronix.de, linux-kernel@vger.kernel.org, mingo@kernel.org, torvalds@linux-foundation.org, fweisbec@gmail.com, keescook@chromium.org, kerrnel@google.com, Phil Auld , Valentin Schneider , Mel Gorman , Pawan Gupta , Paolo Bonzini , vineeth@bitbyteword.org, Chen Yu , Christian Brauner , Agata Gruza , Antonio Gomez Iglesias , graf@amazon.com, konrad.wilk@oracle.com, dfaggioli@suse.com, pjt@google.com, rostedt@goodmis.org, derkling@google.com, benbjiang@tencent.com, Alexandre Chartre , James.Bottomley@hansenpartnership.com, OWeisse@umich.edu, Dhaval Giani , Junaid Shahid , jsbarnes@google.com, chris.hyser@oracle.com, Ben Segall , Josh Don , Hao Luo , Tom Lendacky , Aubrey Li , "Paul E. McKenney" , Tim Chen Subject: Re: [PATCH -tip 03/32] sched/fair: Fix pick_task_fair crashes due to empty rbtree Message-ID: <20201124083156.GU3021@hirez.programming.kicks-ass.net> References: <20201117232003.3580179-1-joel@joelfernandes.org> <20201117232003.3580179-4-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 20, 2020 at 09:15:28PM +1100, Singh, Balbir wrote: > On 18/11/20 10:19 am, Joel Fernandes (Google) wrote: > > From: Peter Zijlstra > > > > pick_next_entity() is passed curr == NULL during core-scheduling. Due to > > this, if the rbtree is empty, the 'left' variable is set to NULL within > > the function. This can cause crashes within the function. > > > > This is not an issue if put_prev_task() is invoked on the currently > > running task before calling pick_next_entity(). However, in core > > scheduling, it is possible that a sibling CPU picks for another RQ in > > the core, via pick_task_fair(). This remote sibling would not get any > > opportunities to do a put_prev_task(). > > > > Fix it by refactoring pick_task_fair() such that pick_next_entity() is > > called with the cfs_rq->curr. This will prevent pick_next_entity() from > > crashing if its rbtree is empty. > > > > Also this fixes another possible bug where update_curr() would not be > > called on the cfs_rq hierarchy if the rbtree is empty. This could effect > > cross-cpu comparison of vruntime. > > > > It is not clear from the changelog as to what does put_prev_task() do to prevent > the crash from occuring? Why did we pass NULL as curr in the first place to > pick_next_entity? > > The patch looks functionally correct as in, it passes curr as the reference > to pick_next_entity() for left and entity_before comparisons. This patch should not exist; it should be smashed into the previous patch. There is no point in preserving a crash.