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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 77741C47082 for ; Wed, 26 May 2021 17:57:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53B6B613D2 for ; Wed, 26 May 2021 17:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234620AbhEZR6o (ORCPT ); Wed, 26 May 2021 13:58:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232812AbhEZR6j (ORCPT ); Wed, 26 May 2021 13:58:39 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C9C1C061574; Wed, 26 May 2021 10:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=dSnlplH+138nPXTWJojZCFoizY/iYF/lvcDTHARd9FQ=; b=mrbjozp92fwTw28bf3Z18/EP1s n68GQr+GGZZwHHH3xRBVhBkuR6yJS/PSyEThFUCuVTf+AYVpoPITNfWkVN+8+efr02TxCTpcmM8Qq Fz/pIMeZDrKhSk3kKAB5jc8B+HKUHxbMYzgDWBQR3Q2nutcRPQpwtAtmIdigGV0BKIpXE14yxthMK QRBEdL7jcXtmLVa5LOZLOiY72DDfqcrUfh2C9KMTS9cnz8ISqVtYGpXj85HNaGscI5SJ4loNXtjVk N6bYcKKqfQI/pV7pPmCYv3+vMTzLKIgMoxPMlQnnJZGGqV38LZal1Gse786mkSoMRaOUqPTj2AZcq ADE4JmHA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1llxlw-000ivJ-Dd; Wed, 26 May 2021 17:56:55 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 0B9B130022C; Wed, 26 May 2021 19:56:52 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E0246201D301D; Wed, 26 May 2021 19:56:51 +0200 (CEST) Date: Wed, 26 May 2021 19:56:51 +0200 From: Peter Zijlstra To: Will Deacon 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: References: <20210525151432.16875-1-will@kernel.org> <20210525151432.16875-11-will@kernel.org> <20210526161249.GD19691@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210526161249.GD19691@willie-the-truck> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.