From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.9 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_SANE_1 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 82493C47088 for ; Wed, 26 May 2021 20:04:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 3E6A661440 for ; Wed, 26 May 2021 20:04:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E6A661440 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=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=auXAdEBA/JRdWj8EjTD9Ak3Y4mZ3129Gk4nJMTztGqA=; b=RsoS2uzdRwEE3K PSk9Q0WfZ66WCpCU5ITtEEfG7gVLjTjE5Hr5f1kZLtH5wRqrINybSo9Lc7jBFVdQCsl2RBBVcxuir N8u9Sx8iCUID7jm2v+3U4lQ8tm9IpQK0TKw2QuVv6kat4V7uEDc6YFJbGcm3gGjdUhJTaSUfM4NVp 8cTfsscDe7/F6Q6PDfvQ8FWufbyfbhVkXFyez8P1pZxTN+dygBAUn4+dX8G/MiRizYzanWY0KvwR+ 5JMOGXqw8/w8HR6VV/6P5z+CBmGDL3VWzUM6K5WHrlGAKqRD7ndDoi6x+BF2QWHWQRV27Sw4osJj+ OIsplGnYCq5zrZVkoVZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1llzjL-00HDUI-CH; Wed, 26 May 2021 20:02:17 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1llyl2-00GltR-Sp for linux-arm-kernel@lists.infradead.org; Wed, 26 May 2021 18:59:58 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0CA9C613B5; Wed, 26 May 2021 18:59:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622055596; bh=RiifrWwNlnMm/PqO08AH6OqcdaPzZ5RiPjMFx7iMOoc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LgFD6l1ln24ZA1lamq0yqLCsrrLgHzOYKnjjxIuMAA/nP1vjQ88iftvavYAbjgKrE nB1cNEOg0WYAxRi7ifQfNIkPVQU/E96hn3ivL5DkSZpQh+YYWAfas9eme7Y6PAezVx x6NRiTHC0A6nZfoD6mF36jUP0i8PtVD6ROwSIZH3SIvhDBNJCUBX8jzrHm7n2h91xb W4kIUuS1U2+3EtBX+ZoGJdZzMj0W7RHYX7KBES25rVR0V3aS3L0tboO3KXXXV/wmAa E8t0P6STfh1zwDv7WYd351PC00X8qzuGSbjsV8hqD1GnYQvZm+uKK5mAiKA6ThdkCF YJ+20YpCgjeqw== Date: Wed, 26 May 2021 19:59:49 +0100 From: Will Deacon To: Peter Zijlstra Cc: linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Catalin Marinas , Marc Zyngier , Greg Kroah-Hartman , Morten Rasmussen , Qais Yousef , Suren Baghdasaryan , Quentin Perret , Tejun Heo , Johannes Weiner , Ingo Molnar , Juri Lelli , Vincent Guittot , "Rafael J. Wysocki" , Dietmar Eggemann , Daniel Bristot de Oliveira , kernel-team@android.com Subject: Re: [PATCH v7 10/22] sched: Reject CPU affinity changes based on task_cpu_possible_mask() Message-ID: <20210526185949.GC20055@willie-the-truck> References: <20210525151432.16875-1-will@kernel.org> <20210525151432.16875-11-will@kernel.org> <20210526161249.GD19691@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210526_115957_030780_96FA2041 X-CRM114-Status: GOOD ( 34.16 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, May 26, 2021 at 07:56:51PM +0200, Peter Zijlstra wrote: > On Wed, May 26, 2021 at 05:12:49PM +0100, Will Deacon wrote: > > On Wed, May 26, 2021 at 05:15:51PM +0200, Peter Zijlstra wrote: > > > On Tue, May 25, 2021 at 04:14:20PM +0100, Will Deacon wrote: > > > > Reject explicit requests to change the affinity mask of a task via > > > > set_cpus_allowed_ptr() if the requested mask is not a subset of the > > > > mask returned by task_cpu_possible_mask(). This ensures that the > > > > 'cpus_mask' for a given task cannot contain CPUs which are incapable of > > > > executing it, except in cases where the affinity is forced. > > > > > > > > Reviewed-by: Quentin Perret > > > > Signed-off-by: Will Deacon > > > > --- > > > > kernel/sched/core.c | 4 ++++ > > > > 1 file changed, 4 insertions(+) > > > > > > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > > > index 00ed51528c70..8ca7854747f1 100644 > > > > --- a/kernel/sched/core.c > > > > +++ b/kernel/sched/core.c > > > > @@ -2346,6 +2346,7 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, > > > > u32 flags) > > > > { > > > > const struct cpumask *cpu_valid_mask = cpu_active_mask; > > > > + const struct cpumask *cpu_allowed_mask = task_cpu_possible_mask(p); > > > > unsigned int dest_cpu; > > > > struct rq_flags rf; > > > > struct rq *rq; > > > > @@ -2366,6 +2367,9 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, > > > > * set_cpus_allowed_common() and actually reset p->cpus_ptr. > > > > */ > > > > cpu_valid_mask = cpu_online_mask; > > > > + } else if (!cpumask_subset(new_mask, cpu_allowed_mask)) { > > > > + ret = -EINVAL; > > > > + goto out; > > > > } > > > > > > So what about the case where the 32bit task is in-kernel and in > > > migrate-disable ? surely we ought to still validate the new mask against > > > task_cpu_possible_mask. > > > > That's a good question. > > > > Given that 32-bit tasks in the kernel are running in 64-bit mode, we can > > actually tolerate them moving around arbitrarily as long as they _never_ try > > to return to userspace on a 64-bit-only CPU. I think this should be the case > > as long as we don't try to return to userspace with migration disabled, no? > > Consider: > > 8 CPUs, lower 4 have 32bit, higher 4 do not > > A - a 32 bit task B > > sys_foo() > migrate_disable() > sys_sched_setaffinity(A, 0xf0) > if (.. | migration_disabled(A)) > // not checking nothing > > __do_set_cpus_allowed(); > > migrate_enable() > __set_cpus_allowed(SCA_MIGRATE_ENABLE) > // frob outselves somewhere in 0xf0 > sysret > *BOOM* > > > That is, I'm thinking we ought to disallow that sched_setaffinity() with > -EINVAL for 0xf0 has no intersection with 0x0f. I *think* the cpuset_cpus_allowed() check in sys_sched_setaffinity() will save us here by reducing the 0xf0 mask to 0x0 early on. However, after seeing this example I'd be much happier checking this in SCA anyway so I'll add that for the next version! Thanks, Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel