Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp191294pxu; Tue, 1 Dec 2020 09:00:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7n3ELprre0AFjxn9t0t62WIMZ4VllmrgJq+LH9H2SbzlukeTPvJw1UH8WA/esyl0c/kxp X-Received: by 2002:a2e:b4d8:: with SMTP id r24mr1722959ljm.318.1606842034042; Tue, 01 Dec 2020 09:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606842034; cv=none; d=google.com; s=arc-20160816; b=k+wmQ2Cr9BI3z+UTeb/lH8ySynrplE1jsyT8lpLVt/4Suk1dbfIABNlUSlbjJyh2xK XiAboqLPsP8UcuT7886FMS6PngIybMPVc8ZrbmGjEYthdplyep4O5gZHLyGY0DpZuqhe x2mOS/S1WSnEHIzKJ1IMLdidn4z/Cir/oFTDWQ5t9/NTaimFnUaDYtuN4rviB+S64jhL qDjCk1sq9ViJHEplwLY9TTZvN8j7MNbC7wfDXU8vmtXm/Nd+DnValdwd/xw+MyCrGcHc j6/Ka5luW194AQSYUSH5ThEwLHj00Iu/9E6QIEuNGXfyBF2MIvx162NKA+6Bgcy/6/4L e0bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=iGMdMpAXQYJuZBGpwHUavxL2YRNQfKppea6W7jfRfXQ=; b=BqagDPdPygxCPFhhGo4hhuIHeyed0jHP0YroFOfFl+ij6eq9aMj3RpNIB5dcvH0Jfp tsowTfezFgo4sQ6LRij0LZnP2yDDkZ5GCThfU4QmfvgMujw8QkSttuk5YByU0jL9+0Fi bZHvCzgq300rUR9ElH2JaMJA5pa8dxayPYZwqbDPqIzmARMhJwBU5IYmqrBPuv9JbdoZ 9exG5O+oeeOOA8Wt4eYaTh6hTxkj3j/flBpfB0j1lade7/rB3oY1myKzVO59/N+rakSb EyCSel7CaRCZncKdhehDnlVOJQXQ9dWMTUPcKvoZGAgKqWwiL/VAPzCfNl5VanmVHXg9 QHQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="gB+zf/56"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v5si304977edi.183.2020.12.01.09.00.09; Tue, 01 Dec 2020 09:00:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="gB+zf/56"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392224AbgLAQ5o (ORCPT + 99 others); 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