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=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 CC4C9C47082 for ; Wed, 26 May 2021 19:07:03 +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 98A88610A8 for ; Wed, 26 May 2021 19:07:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98A88610A8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.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=wnpoiIXnGuyYpF8bLHG10i09oDTm2q4piA4QmKpZQ6Y=; b=zQXIwCUUoayGHZ BmQ3gBwXR6y2NzXoA0HEMuIQdvvKgl6tDxusCkKrk5ms1mCAWY+BGJEUqDmuAJ9layDZZeZLAoLqX 63id3J6XyT5Vy7hFNAq13qZ8kyQDY3q/ztxEar7PtxWWhTexHvfCLFp0szoI2/zhLX6FWv5Oik0NT lYz3e3WuUBV0qQLcCYaG1ijig7ahzQNC/tS2HfsiLHdMmSORdwSJYvrYBSuIZ3eHTwq5HQi4SKghu Mnuf1ns2ffZWawil54aBeReIoT7mvFKmcAppMby6/JGmhBP8nsFStp9usQkFjzx3nCM1pKlYjue3E VpYXRlaOU4I/mpWnFIlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1llyp1-00GnZV-BG; Wed, 26 May 2021 19:04:05 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1llxm7-00GJ30-Cx for linux-arm-kernel@bombadil.infradead.org; Wed, 26 May 2021 17:56:59 +0000 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-Disposition: inline In-Reply-To: <20210526161249.GD19691@willie-the-truck> 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 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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel