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=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 6DE07C2B9F7 for ; Tue, 25 May 2021 02:19:59 +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 3C4A26141D for ; Tue, 25 May 2021 02:19:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C4A26141D 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=ehwgWdBUB8N3kzSZWufth+txj71bQMh9Svdlw0YEc8g=; b=BZkxJS2oBIB/Dt SmKsG6JJ2Zkc8T4AN8+8FS7YV+24JZZcIrZ1Yl6uijVwBntb6fac4MhYFiv4aZ+KY4WNM05YjDs7M Q7ClRCFz/1jrFExj1FRSbfiJCFElSdOn7GOcPV4cPxdAiFr3rzr+ntVgHWPnBNtn7/jQawx+mtaoK swxtSeyGN3jV4oteRK/86+Dd9DNQIfXcAQQlDmtMssocKEhvkAlKFXQ1Ea26qt9gfV1uuhh8pSoIj Ob6XjfjTwVth4WmdsuZya0+PdPY4qDCl3FvGEp44Iau4UwSBQIb42L6Tz+dv4ScQeB02H29vu0K4q QCou+bocT2C1kilkMtzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1llMdq-002t7X-1h; Tue, 25 May 2021 02:17:58 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1llIMd-001z2Y-KP for linux-arm-kernel@lists.infradead.org; Mon, 24 May 2021 21:43:57 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 34A98613F5; Mon, 24 May 2021 21:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621892635; bh=TbSZnvGZwQBH/lRda1abNy4XGQftqlBj3TmjR9lTeVA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TfNrW0WwMMoZd1Oy+m7yRNOWd35YC+C7tzraf73B8ba7aZBnyQwVe6IYvsCUZ6AZT 4Brl2TDeqHsrF3Jy+RZv76N2BwX/zzUZB9IKkZ47F6Mlp5ceuGMrRz5Wk1UDXH1k81 vSagh7VHHtoSRM02VBng0GVnYZWVpva5nQojVnlu5UpSFE+0QtZDtT/E3vozsr7KZL fnjyknHhd61amw6Z4Ll7h4fxngnsTie1D3fUo/olVn2GLiQdzhTucqO+Qk9OUHcCHY bjpXJc6DhFEIZo2zED+6j7P3W0x9LCsB3k+JWo0Am9/vZYN4K5ORK10pBb0aFP6CnY NqyHCbcU5gxcg== Date: Mon, 24 May 2021 22:43:49 +0100 From: Will Deacon To: Qais Yousef Cc: linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Catalin Marinas , Marc Zyngier , Greg Kroah-Hartman , Peter Zijlstra , Morten Rasmussen , Suren Baghdasaryan , Quentin Perret , Tejun Heo , Li Zefan , Johannes Weiner , Ingo Molnar , Juri Lelli , Vincent Guittot , "Rafael J. Wysocki" , kernel-team@android.com Subject: Re: [PATCH v6 12/21] sched: Allow task CPU affinity to be restricted on asymmetric systems Message-ID: <20210524214348.GH15545@willie-the-truck> References: <20210518094725.7701-1-will@kernel.org> <20210518094725.7701-13-will@kernel.org> <20210521171132.ev56j4isuxtf2zqa@e107158-lin.cambridge.arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210521171132.ev56j4isuxtf2zqa@e107158-lin.cambridge.arm.com> 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-20210524_144355_761422_ED20AA8D X-CRM114-Status: GOOD ( 27.45 ) 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 Fri, May 21, 2021 at 06:11:32PM +0100, Qais Yousef wrote: > On 05/18/21 10:47, Will Deacon wrote: > > +static int __set_cpus_allowed_ptr_locked(struct task_struct *p, > > + const struct cpumask *new_mask, > > + u32 flags, > > + struct rq *rq, > > + struct rq_flags *rf) > > + __releases(rq->lock) > > + __releases(p->pi_lock) > > { > > 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; > > int ret = 0; > > > > - rq = task_rq_lock(p, &rf); > > update_rq_clock(rq); > > > > if (p->flags & PF_KTHREAD || is_migration_disabled(p)) { > > @@ -2430,20 +2425,158 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, > > > > __do_set_cpus_allowed(p, new_mask, flags); > > > > - return affine_move_task(rq, p, &rf, dest_cpu, flags); > > + if (flags & SCA_USER) > > + release_user_cpus_ptr(p); > > Why do we need to release the pointer here? > > Doesn't this mean if a 32bit task requests to change its affinity, then we'll > lose this info and a subsequent execve() to a 64bit application means we won't > be able to restore the original mask? > > ie: > > p0-64bit > execve(32bit_app) > // p1-32bit created > p1-32bit.change_affinity() > relase_user_cpus_ptr() > execve(64bit_app) // lost info about p0 affinity? > > Hmm I think this helped me to get the answer. p1 changed its affinity, then > there's nothing to be inherited by a new execve(), so yes we no longer need > this info. Yup, you got it. > > +static int restrict_cpus_allowed_ptr(struct task_struct *p, > > + struct cpumask *new_mask, > > + const struct cpumask *subset_mask) > > +{ > > + struct rq_flags rf; > > + struct rq *rq; > > + int err; > > + struct cpumask *user_mask = NULL; > > + > > + if (!p->user_cpus_ptr) > > + user_mask = kmalloc(cpumask_size(), GFP_KERNEL); > > + > > + rq = task_rq_lock(p, &rf); > > + > > + /* > > + * We're about to butcher the task affinity, so keep track of what > > + * the user asked for in case we're able to restore it later on. > > + */ > > + if (user_mask) { > > + cpumask_copy(user_mask, p->cpus_ptr); > > + p->user_cpus_ptr = user_mask; > > + } > > + > > + /* > > + * Forcefully restricting the affinity of a deadline task is > > + * likely to cause problems, so fail and noisily override the > > + * mask entirely. > > + */ > > + if (task_has_dl_policy(p) && dl_bandwidth_enabled()) { > > + err = -EPERM; > > + goto err_unlock; > > free(user_mark) first? > > > + } > > + > > + if (!cpumask_and(new_mask, &p->cpus_mask, subset_mask)) { > > + err = -EINVAL; > > + goto err_unlock; > > ditto We free the mask when the task exits so we don't actually need to clean up here. I left it like this on the assumption that failing here means that it's very likely that either the task will exit or retry very soon. However I agree that it would be clearer to free the thing anyway, so I'll rejig the code to do that. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel