Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1204572pxu; Mon, 23 Nov 2020 14:34:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJztUqvpMVf77SqQqcdMzoz2dytoOxW7m/HILzlSUt1PVCXNNzmURVSMU3Vp1HSBzVaY0bkS X-Received: by 2002:a17:906:4944:: with SMTP id f4mr1551779ejt.231.1606170874455; Mon, 23 Nov 2020 14:34:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606170874; cv=none; d=google.com; s=arc-20160816; b=Y2dnEDY6gPdOh4ijnicRt40t7et9cHzX4seJ9QSeSLEv6ROl2iTs8qbbMkyyLCzjO6 rKy2kOWXFtv9aE+6Q2fOOJsUtFry6ISKEQCkNTldD/AH5WtVL8X1S5mrrQUWIRM8zWqK qD+l+TUaIX3NqllExQ94MVCIXb7ng9tqaPQ7XfzJ86oPsls+/1f81cGMi1MwOkyFZWig WKP8vd1ySoca+49CSBM0ZiUJTaCdOMq2UQ3fpuz9P2t1YW+P65tzCPkmtPJwza+1mts2 Nj6W2b7EsNPCOnIgp4lchF4xfXWGp2xHFHbyrgDeSg9jUO+km6I+dpyIW69V4xqQxMsw pgtw== 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=cPnDLVKj+DPxr083osv3zXyPFQhs54KxYx09xwb42ic=; b=Vlqmx3VjO0JMR7elH/g4Udd526hDNJkK4tR062XSd9LtYd7jpGZ0kxYZkGiP++cW7t zYu1Oz6dxBMy5L/aZtOtd/vQ/FOx+J+0pfHJlbDu0CT48imiOJEofRYxVORz3AxMNE0S lbry6Wu9blmFcUmsSnP5FAnFokOgxALqnf0dLLChzFFx5LRQnOM6awV+//fC1tJWzOyb Tg9KbWewocw9VKPiUtK3wtWqNzyHPIhWC/4V8xrJ3vztMq/JftNuDnOGMOIkZjaMLFu1 5ePeY9bqj0fIEP25BtpbLCC/rKYYxnAR/KP4i6MxbdLosBhlXt62+2cbj6Btkfyo869p 0SQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Tefczu19; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p25si7859063edq.230.2020.11.23.14.34.11; Mon, 23 Nov 2020 14:34:34 -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=@gmail.com header.s=20161025 header.b=Tefczu19; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731590AbgKWWbJ (ORCPT + 99 others); Mon, 23 Nov 2020 17:31:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731220AbgKWWbI (ORCPT ); Mon, 23 Nov 2020 17:31:08 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A1D9C0613CF for ; Mon, 23 Nov 2020 14:31:08 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id m9so15603477pgb.4 for ; Mon, 23 Nov 2020 14:31:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cPnDLVKj+DPxr083osv3zXyPFQhs54KxYx09xwb42ic=; b=Tefczu192j63TB+7ma9/BNgcAY6j9leOp+37CRRI6fsbIk55o21Ow3NcCKAu4YC9rH BCrWf621SzFcBHdxIezBsjUq6+F/Ux9wCQjZPHEIiC30qkMBA08nbrvpqEJPzdD53CtA k3YLuHhV79QFhdqTSirKsFOpWQM/5Ciq6vxqIXm956hkiffWHyLvS53JTIfl/i/+2LE9 8sxTIkgtjy/xu9xBz0Q8uFpCV4/CXnlkVNl5VS+RJ5VTk+GoOEl8KnrGv2/YxM4VFkzf yzfPL8EBs8tja7OeVvZ2B/0YQs2+VrdJLlwOSAWay4+gVtQQdCjhdqLa2/XFVC+k7pFn +cAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cPnDLVKj+DPxr083osv3zXyPFQhs54KxYx09xwb42ic=; b=Ll/CThe2bQlfDhbUpSAYHNqWiF8IuAXWRvEkd58w033fiq3SufWaKj8Szw22bQH5u/ czNZlFBPHC/kWFireJAyiA8DOgy4uyi+vR/wYtPFkFgOjBtJZT8/LoaUw2WoBT5daMnF tigf+Iy2icwkTTwK89K7UDvaOnlS7Rn/YrtfwpO5qhC83Ap5vXiN84oJeZxs0wJ84qNy VAaAu1rqH9cLoHZZVBiId6K3HjOj+kHJa7PlXoyReEIzfecsk2y5oWzJBfvify9/dffG 8JE32FAWPnkS9jkkwuEiTdv/TrHM+cSpkgdYFeA8q6Uz6U/9d6G0Og8XU1JtKGBRb70e 8yQg== X-Gm-Message-State: AOAM531a49CiuP3TzRcY11GxmRDS8lRzcr0+JQLezrInNXxy96NnjElF XS3BEiJecTFUK9P9fKsVhzU= X-Received: by 2002:a63:ea04:: with SMTP id c4mr1320558pgi.412.1606170667676; Mon, 23 Nov 2020 14:31:07 -0800 (PST) Received: from localhost (61-68-227-232.tpgi.com.au. [61.68.227.232]) by smtp.gmail.com with ESMTPSA id j69sm4190739pfd.37.2020.11.23.14.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 14:31:05 -0800 (PST) Date: Tue, 24 Nov 2020 09:31:02 +1100 From: Balbir Singh To: Vineeth Pillai Cc: "Joel Fernandes (Google)" , Nishanth Aravamudan , Julien Desfossez , Peter Zijlstra , Tim Chen , 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: <20201123223102.GA8893@balbir-desktop> 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 01:11:06PM -0500, Vineeth Pillai wrote: > Hi Balbir, > > On 11/20/20 5:15 AM, 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? > A little more context on this crash in v8 is here: > https://lwn.net/ml/linux-kernel/8230ada7-839f-2335-9a55-b09f6a813e91@linux.microsoft.com/ > > The issue here arises from the fact that, we try to pick task for a > sibling while sibling is running a task. Running tasks are not in the > cfs_rq and pick_next_entity can return NULL if there is only one cfs > task in the cfs_rq. This would not happen normally because > put_prev_task is called before pick_task and put_prev_task adds the > task back to cfs_rq. But for coresched, pick_task is called on a > remote sibling's cfs_rq without calling put_prev_task and this can > lead to pick_next_entity returning NULL. > > The initial logic of passing NULL would work fine as long as we call > put_prev_task before calling pick_task_fair. But for coresched, we > call pick_task_fair on siblings while the task is running and would > not be able to call put_prev_task. So this refactor of the code fixes > the crash by explicitly passing curr. > > Hope this clarifies.. > Yes, it does! Thanks, Balbir Singh.