Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2049393rdb; Sun, 19 Nov 2023 23:39:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKMZ9M+BmKMhRQKNQwpniGJ01FJLtkGxBRjZNgpPTLyDC71WYrnxeKvLcxnNEbFwWZlYEB X-Received: by 2002:a17:902:f541:b0:1ce:5bc8:4734 with SMTP id h1-20020a170902f54100b001ce5bc84734mr15423311plf.30.1700465953255; Sun, 19 Nov 2023 23:39:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700465953; cv=none; d=google.com; s=arc-20160816; b=XYMv4ZSlCnyOB1/z9zL0QlK8qNff6rpRwdDizmfHOEvJxIPLq/4TDj4EZt3JRu7wSu MkI0M9HSpDYVcweRwOs0oh5Y7RFQZ3nxM9AtncZAari9PuNgD80dCNEjOmeG0UwHWuHl zjmIa87VFdMZEx1rPmejIzckqCsmpSl61gRXjGF/3CvDDFY/GDo5fBx8+p3Wx9QKx6TT PUgVZMpbjkeJhm+7fBoYbSiFIPGE/AKokcoGeM53dzIssqo49B+tJfJQDiMKoyG8mVRQ g/ep76hWZ5Q82OJqkYIuroBdIiXON4xgeitvNqgb2YZnAVlWKm3RyBixH1esGjKRrzKp F6Uw== 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 :message-id:date:subject:cc:to:from; bh=vuNPrUzYj3AmMt8iZm8s+GWh8e8gQ6zo50kNF+NgpX8=; fh=e9zvVdHeyitYLyDUzBMQfpZ1AkxqJ4AjnzfROW/pTj4=; b=jmBJGusq3S+jbpdcLSvUpaPwHWXOuCg0OBp/hEpNZs32DNpoGxWDHV380YHN5BG8Qe fXrXK8kueBGQPJJ3XD+1+MgAmwyjVG0dRE1YvxTfkPuorOWWUswi+sf5yd9NLVK0Otch RprGFhDchYIfNyhf9TQlnfl30k3SGl4CpP9ILovfccmLPsvlCqODBy5Al0DZQ6yi76SV fII8peoSvZkkl0bVeHbto7ScGiA1qHDlD6EULe/7nhGHXY6xknXZbpHdoYEJps9CmQL3 gg5xAWcyFIY6Ufg8OwcEdEzbH7DALaXH0yRO7VyZA5lRhMkfR3+gvTxR+r/cGY+m0OU+ 2UxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id c4-20020a170903234400b001cf58065627si3523235plh.303.2023.11.19.23.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 23:39:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C1487806B9C0; Sun, 19 Nov 2023 23:39:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231948AbjKTHi6 (ORCPT + 99 others); Mon, 20 Nov 2023 02:38:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjKTHi4 (ORCPT ); Mon, 20 Nov 2023 02:38:56 -0500 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87A3EB4 for ; Sun, 19 Nov 2023 23:38:51 -0800 (PST) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 3AK7cQLe038238; Mon, 20 Nov 2023 15:38:26 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4SYfPK4SPKz2K7tXg; Mon, 20 Nov 2023 15:33:09 +0800 (CST) Received: from BJ10918NBW01.spreadtrum.com (10.0.73.73) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 20 Nov 2023 15:38:24 +0800 From: Xuewen Yan To: , , , , , , , , , CC: , , Subject: [PATCH] sched/eevdf: Avoid NULL in pick_eevdf Date: Mon, 20 Nov 2023 15:38:21 +0800 Message-ID: <20231120073821.1304-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.73.73] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 3AK7cQLe038238 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 19 Nov 2023 23:39:10 -0800 (PST) Now in pick_eevdf function, add the pick_first_entity to prevent picking null when using eevdf, however, the leftmost may be null. As a result, it would cause oops because the se is NULL. Fix this by compare the curr and left, if the left is null, set the se be curr. Fixes: 147f3efaa241 ("sched/fair: Implement an EEVDF-like scheduling policy") Signed-off-by: Xuewen Yan --- kernel/sched/fair.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d7a3c63a2171..10916f6778ac 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -951,12 +951,28 @@ static struct sched_entity *__pick_eevdf(struct cfs_rq *cfs_rq) return NULL; } +/* Just simply choose the se with the smallest vruntime */ +static struct sched_entity *__pick_cfs(struct cfs_rq *cfs_rq) +{ + struct sched_entity *curr = cfs_rq->curr; + struct sched_entity *left = __pick_first_entity(cfs_rq); + + /* + * If curr is set we have to see if its left of the leftmost entity + * still in the tree, provided there was anything in the tree at all. + */ + if (!left || (curr && entity_before(curr, left))) + left = curr; + + return left; +} + static struct sched_entity *pick_eevdf(struct cfs_rq *cfs_rq) { struct sched_entity *se = __pick_eevdf(cfs_rq); if (!se) { - struct sched_entity *left = __pick_first_entity(cfs_rq); + struct sched_entity *left = __pick_cfs(cfs_rq); if (left) { pr_err("EEVDF scheduling fail, picking leftmost\n"); return left; -- 2.25.1