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=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 334D6C2D0E4 for ; Fri, 27 Nov 2020 13:19:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F99122245 for ; Fri, 27 Nov 2020 13:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730378AbgK0NTW (ORCPT ); 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; > } 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=-8.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 819D1C64E7A for ; Fri, 27 Nov 2020 13:20:44 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 A96AA22244 for ; Fri, 27 Nov 2020 13:20:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="0SFHVXHY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A96AA22244 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com 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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject: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=J6+IDSs2nD2Qc4rU6HdNLOrqgzwlwjVnRDEV4eFr4vA=; b=0SFHVXHYtFk8jrtTZO2qUWPGO NosjUfaNnnAY6S5VyWih1LGE2KXZcXlVBsW2eWdkftkNlX1sA+zFS7aZHwyqOMM0xUmEkMLTFRiUP +tHQW25P3PFAanYBbIMfawzCLoqkGG/LcdNZRFNHOiX7eL2Su/KgwJSvlROFxFhiBLDwX0jT8989F xapsJTRYcrJ2PqvKubKqkVwApqq/tl8+5Qigbi3cZd/8F0MSMDTMeWQvvItKQDlRuTNv7UgwVc35k Sx5KnTwr4OmNMTvOwacFExnZ7JZMA9xYtUxMRkLclw3AINnHZbXVpxDwe8cJRUjpEFDMxI8YdsOxa r3BRfhcFg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kideo-0000zV-FH; Fri, 27 Nov 2020 13:19:26 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidel-0000yq-SL for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2020 13:19:24 +0000 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 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-Disposition: inline In-Reply-To: <20201124155039.13804-8-will@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201127_081923_986353_9A4A40A9 X-CRM114-Status: GOOD ( 18.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Marc Zyngier , kernel-team@android.com, Vincent Guittot , Juri Lelli , Quentin Perret , Peter Zijlstra , Catalin Marinas , Johannes Weiner , linux-kernel@vger.kernel.org, Ingo Molnar , Li Zefan , Greg Kroah-Hartman , Tejun Heo , Suren Baghdasaryan , Morten Rasmussen , linux-arm-kernel@lists.infradead.org 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 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; > } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel