Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1594194pxu; Fri, 27 Nov 2020 10:31:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOmIjGa8iB6icBLoT043WnERTpS16G7USo6Fj/IM7xuujKF0UrysQ2+CZ/Dl+eBzg5DV2O X-Received: by 2002:aa7:df89:: with SMTP id b9mr9158929edy.335.1606501889008; Fri, 27 Nov 2020 10:31:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606501889; cv=none; d=google.com; s=arc-20160816; b=TIL7fIJygirufA9TJJCi6HHItcDhzw2uFajtX1HAO7p+rDpDb7CxwfuDxZslaYw9N1 itxU8/8YT2akAkCtVdkVzgImb7HwNOMEPvajnD3O0+p6GpjHRfLJ8U8VAvZ1iP5T2Wf5 d8V0ntWZfLPOjkmpPZhGFVryFr7eNenzZu+3vxMQKBHG2hCVdl88OBJmkeErovlbE4Om yE0iM7tM3WYj09ZMKArm4MdNG6pwPKrBWsRmiJqKAeg+rspCQBfTLeNHjoxA9O8hPMP3 e1aTGBrzMxaG6gyzDqnqtDVnnd30bLw/aqfqWlHOp5IijH7peQF68Atmrp0E6AfdN8g8 eQzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=lfOQiYW2mysZkUrZatacjRFW31+9CI2SzWW2AHxkkwg=; b=d3QObvsUcbvZ/266IynsIl0PO+gA0omJTNA/viCs76sBUrcCmB5x4YKlEszZ7MQ5SX 4VEj2+jCTyKw49dzwwd17JZHjG2Q1DbqLtdJETlagOyJhICbORqgYFpMq6YLSY8hF3eb 5gtWYAwzQ0knbkEoayvl/SQZI/2S1CJg9u26VUTvItkEygqVa6PbLKCR7808tRH9jLjv JysaYzZkbADfMksVkvkSuXs0tD6RPUBW8rm8y8BBNWEp8hnsQjDCmpUvSYzz5jewjoGq GCk9sXTXShZ6BVcifXqOXGWBJFC14MlwAIHOLNBZWtG+oCDHcw12eZHzGtFPfuCRU36f cD7g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z7si6309213edp.295.2020.11.27.10.31.06; Fri, 27 Nov 2020 10:31:28 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730371AbgK0NTW (ORCPT + 99 others); Fri, 27 Nov 2020 08:19:22 -0500 Received: from foss.arm.com ([217.140.110.172]:41458 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730364AbgK0NTV (ORCPT ); Fri, 27 Nov 2020 08:19:21 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 341AC31B; Fri, 27 Nov 2020 05:19:21 -0800 (PST) Received: from e107158-lin.cambridge.arm.com (unknown [10.1.194.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 011DA3F70D; Fri, 27 Nov 2020 05:19:18 -0800 (PST) Date: Fri, 27 Nov 2020 13:19:16 +0000 From: Qais Yousef 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 , 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: <20201127131916.ncoqmg62dselezyl@e107158-lin.cambridge.arm.com> References: <20201124155039.13804-1-will@kernel.org> <20201124155039.13804-8-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201124155039.13804-8-will@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks -- Qais Yousef > */ > -static int __set_cpus_allowed_ptr(struct task_struct *p, > - const struct cpumask *new_mask, bool check) > +static int __set_cpus_allowed_ptr_locked(struct task_struct *p, > + const struct cpumask *new_mask, > + bool check, > + struct rq *rq, > + struct rq_flags *rf) > { > const struct cpumask *cpu_valid_mask = cpu_active_mask; > 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) { > @@ -1929,7 +1923,7 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, > if (task_running(rq, p) || p->state == TASK_WAKING) { > struct migration_arg arg = { p, dest_cpu }; > /* Need help from migration thread: drop lock and wait. */ > - task_rq_unlock(rq, p, &rf); > + task_rq_unlock(rq, p, rf); > stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg); > return 0; > } else if (task_on_rq_queued(p)) { > @@ -1937,20 +1931,69 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, > * OK, since we're going to drop the lock immediately > * afterwards anyway. > */ > - rq = move_queued_task(rq, &rf, p, dest_cpu); > + rq = move_queued_task(rq, rf, p, dest_cpu); > } > out: > - task_rq_unlock(rq, p, &rf); > + task_rq_unlock(rq, p, rf); > > return ret; > }