Received: by 10.213.65.68 with SMTP id h4csp2113702imn; Sun, 8 Apr 2018 20:03:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+RgPk/oUfTV1UPnpy1Rcu4wRD/U68tIPLlk3NVikMiT9hXmdbGZ2dpQgN1MDwDcu1tDqjy X-Received: by 10.99.121.73 with SMTP id u70mr24448978pgc.232.1523243025833; Sun, 08 Apr 2018 20:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243025; cv=none; d=google.com; s=arc-20160816; b=ffYUVYFHU50zTifzZ5qXeOPrx3V0kqFHtL9+5MRFDlxkdCg21hWfGjGW3VaqcGeNpv 2QCrsDp5BJrmbCoGm4x5ddluIhuoAJTqYMPfpwROAuuQRZ4LdeeRkAv/An5Y0SK27DK0 nmYzOSgYAuHqpq2eiLMqlFvyFUwqWqwfLGL9wvQrR84Uuh6QrMXN2YXMnK8UZCBRnmGp EFUXMPYh8a0SQhj8Lecgi2wT0cAnnjW7+5vZxUQ4xzlWBbETW181e8zQ9tQyt914os0Z hEYZwc3u3d0O/jjp4/wdWIuNitXBqfmzN/c3ETxHO4Oknbytfxcx5dK2HxDPkypGeFCi r4tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=DAVesM2fa8nMxSxReFgHGbOpXpDFNXGzkLqRkSXIHhg=; b=0kb0/Vd7tPiamCg5PjUugKU+hO7xsgOeVZ4UJBE/8TWaY55lgbdjeb2lw8nCebyH5z MKRqhTnY01zOXQA8fufNQLP81lEQeqIK08HXzE0oEze8H2gJrESLzke9aYZYSmo6fXas LvsKWXWUXGUg/VULraL8QYx1iD5gfGl2Btr98AL4ErjgqqUMOjxI3APDCcmXIpc2jH8j okzXGmMMpcUjwMqqVAQ8YTS5peHqcYhK+qx9oy4r5HdJc2wL2Qo6yMfdTIGCYgsOxAdn STzjsYSNRajwTMm1C8BMN5R5vvscysUOjBCyG4nHwI9XOP/StQzDs1vMsNO581+rasZH aTLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=oDZbHFko; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4-v6si13617335plb.205.2018.04.08.20.03.08; Sun, 08 Apr 2018 20:03:45 -0700 (PDT) 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=pass header.i=@microsoft.com header.s=selector1 header.b=oDZbHFko; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756018AbeDIA3i (ORCPT + 99 others); Sun, 8 Apr 2018 20:29:38 -0400 Received: from mail-by2nam03on0107.outbound.protection.outlook.com ([104.47.42.107]:6816 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753028AbeDIA3b (ORCPT ); Sun, 8 Apr 2018 20:29:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DAVesM2fa8nMxSxReFgHGbOpXpDFNXGzkLqRkSXIHhg=; b=oDZbHFkog5qpxktuXd/bLGcQ6jIZsws7V2owniLQ44vKo0ZbwCpUzR4AwCsyC7ChPBBBJAhr7QexCEptXrePOhIreZo33/9z+EkieS/eaA8GRWFQez0Kfsk/+cZ3cbkbb1Fb/seHcTNmnFf6NdkyKNiUPNdmBtVcF3wZQmqklYg= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0967.namprd21.prod.outlook.com (52.132.133.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:29:24 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:29:24 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Daniel Axtens , Ben Segall , Konstantin Khlebnikov , Linus Torvalds , Mike Galbraith , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 102/293] sched/fair: WARN() and refuse to set buddy when !se->on_rq Thread-Topic: [PATCH AUTOSEL for 4.9 102/293] sched/fair: WARN() and refuse to set buddy when !se->on_rq Thread-Index: AQHTz5kWA3tPKz8zpUKSUZKgi90tGg== Date: Mon, 9 Apr 2018 00:24:13 +0000 Message-ID: <20180409002239.163177-102-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0967;7:CtdcDjb0K2xVnMTVYqXLIMpEDShQPOQc8NkVl1oaDzMiEB4cosl21oqwYPDZLH+T/5mVXcFawE4JZpGl8D1+8qJYuJMCKue1JTbwvDW+ocVan1fVT3l/BAWF6RiCLwM7qvbESLPzth2z9LJSucBFQhfstXw29HdO1q5A7bxWm7zlJ8405Ui4je/wWVWiS+pyAKcJVCWIZ+BgK0y0hyjDAjdT37MfqXuAl6vE7kUO06NLnpaBz0X5ISJ0tURgEtje;20:QdAr4vXo2GQpMDouopr4W0nyYv+MA9SJm1DPTd/1hTS9fkgdp7rV7PFOCBil2HQBLL3xZ7SkRBvLDf4I8QvRYsoPW7IjKcLCSIqvIgdIyBKdat+S3kb+Eh8Uxdt/yKOniQ3DWZPnGAZBXcc0+uvgdOVSGwMBx+8lepWGQVeNZG0= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 4358f96c-bed3-4ce0-4322-08d59db0f256 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0967; x-ms-traffictypediagnostic: DM5PR2101MB0967: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(26323138287068)(89211679590171)(211936372134217)(42068640409301)(153496737603132); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB0967;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0967; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(366004)(376002)(39380400002)(346002)(199004)(189003)(6506007)(486006)(86362001)(14454004)(59450400001)(68736007)(102836004)(99286004)(26005)(3846002)(6116002)(186003)(476003)(2616005)(1076002)(3280700002)(86612001)(72206003)(966005)(4326008)(446003)(54906003)(76176011)(11346002)(2906002)(22452003)(3660700001)(110136005)(97736004)(316002)(6666003)(5660300001)(478600001)(8676002)(6512007)(6306002)(8936002)(8666007)(107886003)(6486002)(53936002)(81166006)(36756003)(81156014)(10290500003)(6436002)(10090500001)(25786009)(66066001)(7416002)(4477795004)(106356001)(305945005)(7736002)(2501003)(5250100002)(105586002)(2900100001)(22906009)(217873001)(6606295002);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0967;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: ADZKBCZrH1s89ZlfzXV15g6ndJZ2cOTt/qk964S1ahgpB+IKfSRYzlTZ+/q5RnVFc7HyigUjVUn/V+fJnWWaDU1i3mWlZNw1+o41mhVSTgkR37hMOIKut4RFmCrsbg4bP7HUaXCk/LOcfrB5wWwnZK7E1Hv9JfzWIvf0Bcw4ltjTcc6Dit09QMkTZGkCMXyFMSIUGazI8H6ACEdt7NLYDQfxB3oYsxualIBn7g25VIR3P77ut6Y/NxEL6c0TPzgZF/dDnCEi72k9s5V/Yzx0Mk36TzhqtT4HLl2KN6RP17OKvfiGqagdp7AVZYapk5Woz3hQ2+4zLVrguk/4sZZ7L3v8rUxnFQMwSrXCMTMcDkIulEHGqNQnt7M7Rc1gqEFS3hATBdG1qr6vHfWgh35UBYhSTTB+QK0GKPB7w+1YyzE= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4358f96c-bed3-4ce0-4322-08d59db0f256 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:24:13.3468 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0967 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Axtens [ Upstream commit c5ae366e12b2bd56fc7d7e9d484836bec9ddc110 ] If we set a next or last buddy for a se that is not on_rq, we will end up taking a NULL pointer dereference in wakeup_preempt_entity via pick_next_task_fair. Detect when we would be about to do that, throw a warning and then refuse to actually set it. This has been suggested at least twice: https://marc.info/?l=3Dlinux-kernel&m=3D146651668921468&w=3D2 https://lkml.org/lkml/2016/6/16/663 I recently had to debug a problem with these (we hadn't backported Konstantin's patches in this area) and this would have saved a lot of time/pain. Just do it. Signed-off-by: Daniel Axtens Cc: Ben Segall Cc: Konstantin Khlebnikov Cc: Linus Torvalds Cc: Mike Galbraith Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20170510201139.16236-1-dja@axtens.net Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/sched/fair.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 3d862f5b0331..44f2dd56a88f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5774,8 +5774,11 @@ static void set_last_buddy(struct sched_entity *se) if (entity_is_task(se) && unlikely(task_of(se)->policy =3D=3D SCHED_IDLE)= ) return; =20 - for_each_sched_entity(se) + for_each_sched_entity(se) { + if (SCHED_WARN_ON(!se->on_rq)) + return; cfs_rq_of(se)->last =3D se; + } } =20 static void set_next_buddy(struct sched_entity *se) @@ -5783,8 +5786,11 @@ static void set_next_buddy(struct sched_entity *se) if (entity_is_task(se) && unlikely(task_of(se)->policy =3D=3D SCHED_IDLE)= ) return; =20 - for_each_sched_entity(se) + for_each_sched_entity(se) { + if (SCHED_WARN_ON(!se->on_rq)) + return; cfs_rq_of(se)->next =3D se; + } } =20 static void set_skip_buddy(struct sched_entity *se) --=20 2.15.1