From patchwork Mon Nov 20 07:38:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuewen Yan X-Patchwork-Id: 166966 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2034813vqn; Sun, 19 Nov 2023 23:39:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGY5UQkoDmlZqqw0fUHd3rpmllRz9p2RQ24DzMh1gZePO9T8pY1DZWExlEPsA+m6nKet+DM X-Received: by 2002:a05:6a20:7d91:b0:161:aef5:6395 with SMTP id v17-20020a056a207d9100b00161aef56395mr8408530pzj.24.1700465949086; Sun, 19 Nov 2023 23:39:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700465949; cv=none; d=google.com; s=arc-20160816; b=1DRniQisetPWFwYbg+cJep+m8j3bfwWh0EO/t3Opsfp9uAUMtIgd4enifSEUcE768e nHI4WkqjPllSC2mk6NSS/dXL4I813ocSHGiGMX+uF2Nwj6kdZSJVZjahpmqwY2O37goH QmynpARxSoMoV5Fx44ABJ+pF+RdQPgju2iVTCI69OYmCvz3UguGvKcOYuKU2BI1Umze8 lKgpDzLy/EM8VyigU69hT2FDg/gbY866GEbWVkfvu1kAx+TfsOCyaN4ePX4Ic8xFDD/e j26PlsV5MnkrXgRbgjWUR5iDXJTTrrbNLoWyynlXZJLy0DIcqy1Q+80qCqkvu2YntcNp VOCw== 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:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u36-20020a631424000000b005b56de1fd82si7187843pgl.272.2023.11.19.23.39.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 23:39:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 2D259805A58F; Sun, 19 Nov 2023 23:39:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231982AbjKTHi6 (ORCPT + 27 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 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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Sun, 19 Nov 2023 23:39:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783067782773423785 X-GMAIL-MSGID: 1783067782773423785 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;