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.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 01E8BC71156 for ; Tue, 1 Dec 2020 16:57:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B500420758 for ; Tue, 1 Dec 2020 16:57:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="gB+zf/56" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392228AbgLAQ5o (ORCPT ); Tue, 1 Dec 2020 11:57:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:41940 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387876AbgLAQ5o (ORCPT ); Tue, 1 Dec 2020 11:57:44 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B17992151B; Tue, 1 Dec 2020 16:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606841823; bh=+4ZrlHG5vhlXWRw+9FvtNpOLKhlitTQsHmck6tUTTfc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gB+zf/56lvQEVYhYjfWTh9bKEpDsPjMrBPoFmBRNL61Xf71+qZcHZMyn8HQNFAa40 MYfNo69z4/mDIlvPx84lFQ5x0qs4WPQFZ8ELrTZySn53jsxlzG/j330EQMGK22Cr9s eMkKnw5P8gYhp1f7ja8k5z3nSpebLrqOgVcZmtFA= Date: Tue, 1 Dec 2020 16:56:57 +0000 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 , kernel-team@android.com Subject: Re: [PATCH v4 07/14] sched: Introduce restrict_cpus_allowed_ptr() to limit task CPU affinity Message-ID: <20201201165656.GE27783@willie-the-truck> References: <20201124155039.13804-1-will@kernel.org> <20201124155039.13804-8-will@kernel.org> <20201127131916.ncoqmg62dselezyl@e107158-lin.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201127131916.ncoqmg62dselezyl@e107158-lin.cambridge.arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 27, 2020 at 01:19:16PM +0000, Qais Yousef wrote: > On 11/24/20 15:50, Will Deacon wrote: > > [...] > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index d2003a7d5ab5..818c8f7bdf2a 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -1860,24 +1860,18 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask) > > } > > > > /* > > - * Change a given task's CPU affinity. Migrate the thread to a > > - * proper CPU and schedule it away if the CPU it's executing on > > - * is removed from the allowed bitmask. > > - * > > - * NOTE: the caller must have a valid reference to the task, the > > - * task must not exit() & deallocate itself prematurely. The > > - * call is not atomic; no spinlocks may be held. > > + * Called with both p->pi_lock and rq->lock held; drops both before returning. > > nit: wouldn't it be better for the caller to acquire and release the locks? > Not a big deal but it's always confusing when half of the work done outside the > function and the other half done inside. That came up in the last version of the patches iirc, but the problem is that __set_cpus_allowed_ptr_locked() can trigger migration, which can drop the lock and take another one for the new runqueue. Given that this function is internal to the scheduler, I think we can probably live with it. Will