From patchwork Tue May 18 09:47:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 12264415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3786C433ED for ; Tue, 18 May 2021 09:56:38 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EF4E6024A for ; Tue, 18 May 2021 09:56:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EF4E6024A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=atrW2wmseOV4HvLT3JFnuGknE2oI062xjcc5s0+slJo=; b=Eb/ACntJDQDRGXMlCPqLs6aUz itRBPOy3e57wuxYt8PqFQuqMqiM+7TEtoVPz5QhZaz0jzKlrMJRs4EL3n7vZjurfeq5ghMBtu42kz YONH8P84g9o8tWoi7Nd7KwodO1Qmy0R52bR7vdjIQumX7rrXagi76RrBu/TkagLYz9J/B6NqZQF6F buIpqqT6Mt2eRh1Tph26mRbAKyJlfJ+AIxyPaeOzbEGAwvQqNmfp4GF75oZIMj43G3JEa0JMydU9t IqLskK0YHV1RleKoyEQSq8aoHOSuol/vv9NHbU4Dz1yAhUIRt2bWrv+RHvKiOOoyd6KEw4aznwazM WkCSNM6eg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1liwQq-000FFo-I6; Tue, 18 May 2021 09:54:32 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liwKY-000Dsf-6M for linux-arm-kernel@desiato.infradead.org; Tue, 18 May 2021 09:48:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=iVMYSKzq3hfG2og4eSIkeTuf05Jn8RhTmkKMBnY1U0c=; b=u6lyPoPFmjXEhguns3vO+VoGax zI1apoD4u8hiTMX6hh9bgwQ4pDTLCopMYMKXvYjg2D7sfd9aHiKsETAWDTmNjSGhglvBBuD3KzOvm er3X2U2H61ZLXOjfDPsye0iJA/23aWF4qaWNjbN3nnkorGXyBV8jyfdGI/Xua5VUXig5UTjoFXReM Y2fRmc2Xa/nvXs5Ap85qpcB2osbk5abUK19Dpppi17/k+n9bzRuhtrT8r+hMV4UwAD44ByuC5VAzE ah4DxGLbCIjYavUoUNA1ZgR7UgPQRHonF6XphUGMJ5jiU+uKUKnKKkpAgkrAgpkcj5acKQsDzG7oC +rXWS8aA==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liwKV-00EWeb-FU for linux-arm-kernel@lists.infradead.org; Tue, 18 May 2021 09:48:00 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0C391613CE; Tue, 18 May 2021 09:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621331279; bh=EV9JgCxKjLj4KVtD7cKw871l26IXkBBXbX6fJNN8AkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QqN0MSxlEWysNMl3QzC9VV1pquDbqXqjrrvGQioYU6YK/JDHtOJmFhEn4e6Yz9pPn krlxtnuEtmgB7W/xdaMVwHhPp2EFjsqVSWh9KzZJ7ixKZXtz7sprabF5LJuvT9aLqm zXlIbJNaSAqN05og4Uev+SmBGglmP6/ifaR/Z6/0mv41joOk+ZyJiyT7KJa5hUsNCh FHDpi7QSMs4GSKVLwtNkXznYWi/PAcTZ2KtJ3uIhrR+j/7yMp/3SZ/9Z7zAoJu+MBE fQ4YekLvZPq0FsLtAyGntl6Ci5qj3Dyw6dCOD1RltEn7LhmiK97uvujTMP6B98bhvf IXxQ9YVOktUPg== From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon , Catalin Marinas , Marc Zyngier , Greg Kroah-Hartman , Peter Zijlstra , Morten Rasmussen , Qais Yousef , Suren Baghdasaryan , Quentin Perret , Tejun Heo , Li Zefan , Johannes Weiner , Ingo Molnar , Juri Lelli , Vincent Guittot , "Rafael J. Wysocki" , kernel-team@android.com Subject: [PATCH v6 06/21] sched: Introduce task_cpu_possible_mask() to limit fallback rq selection Date: Tue, 18 May 2021 10:47:10 +0100 Message-Id: <20210518094725.7701-7-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210518094725.7701-1-will@kernel.org> References: <20210518094725.7701-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_024759_577770_BCA9BAA6 X-CRM114-Status: GOOD ( 16.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Asymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters. On such a system, we must take care not to migrate a task to an unsupported CPU when forcefully moving tasks in select_fallback_rq() in response to a CPU hot-unplug operation. Introduce a task_cpu_possible_mask() hook which, given a task argument, allows an architecture to return a cpumask of CPUs that are capable of executing that task. The default implementation returns the cpu_possible_mask, since sane machines do not suffer from per-cpu ISA limitations that affect scheduling. The new mask is used when selecting the fallback runqueue as a last resort before forcing a migration to the first active CPU. Reviewed-by: Quentin Perret Signed-off-by: Will Deacon --- include/linux/mmu_context.h | 8 ++++++++ kernel/sched/core.c | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/linux/mmu_context.h b/include/linux/mmu_context.h index 03dee12d2b61..bc4ac3c525e6 100644 --- a/include/linux/mmu_context.h +++ b/include/linux/mmu_context.h @@ -14,4 +14,12 @@ static inline void leave_mm(int cpu) { } #endif +/* + * CPUs that are capable of running task @p. By default, we assume a sane, + * homogeneous system. Must contain at least one active CPU. + */ +#ifndef task_cpu_possible_mask +# define task_cpu_possible_mask(p) cpu_possible_mask +#endif + #endif diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 5226cc26a095..482f7fdca0e8 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1813,8 +1813,11 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu) return cpu_online(cpu); /* Non kernel threads are not allowed during either online or offline. */ - if (!(p->flags & PF_KTHREAD)) - return cpu_active(cpu); + if (!(p->flags & PF_KTHREAD)) { + if (cpu_active(cpu)) + return cpumask_test_cpu(cpu, task_cpu_possible_mask(p)); + return false; + } /* KTHREAD_IS_PER_CPU is always allowed. */ if (kthread_is_per_cpu(p)) @@ -2792,10 +2795,9 @@ static int select_fallback_rq(int cpu, struct task_struct *p) * * More yuck to audit. */ - do_set_cpus_allowed(p, cpu_possible_mask); + do_set_cpus_allowed(p, task_cpu_possible_mask(p)); state = fail; break; - case fail: BUG(); break;