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=-9.4 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 A3077C4338F for ; Tue, 17 Aug 2021 15:13:10 +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 2EF8D60FA0 for ; Tue, 17 Aug 2021 15:13:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2EF8D60FA0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=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=g1PCtv+NEF8mhNywN2flUNyjmfUq1oQSoGKY3qjbo1A=; b=STFeBCd0y6M9uM v1xBuvJsEnnNfDHZNq6+VHTDs342mhyqynLTXRCMfBrcCtQeUGDgEyi7LnrfsH2pAZ/C7mZUarTh3 1QifImzVono9wIjurmpWF69GBU2+dUY1oNkvp4eMCtlyeXBjIgpCUBHTbwMkq5OL/dd4Zk5zYC72W ZBfnG5shVkFqKPJtobNZKTdT4koLAXb/FozyQ23+E0q1d0qO6hZu+/o51BhHTqyB9JJX5ihS0jwO4 C9cndY36VLPe1Ru8DDLcvGY7SO89YBkFJ5/xZufvx4+FUGVx1yMW3TpGp1BHGIVO8a0lQ7ejG+9o7 pSsLsozo47d4g6WhBC8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mG0kC-002lsZ-Cj; Tue, 17 Aug 2021 15:11:12 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mG0k0-002lpx-Nx for linux-arm-kernel@bombadil.infradead.org; Tue, 17 Aug 2021 15:11:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=EuJByfvQk0EBkTrYkEfND0mLwG08uWKKtyupgcpfEi8=; b=NVftCgQ+xjBGnrwNBx5ruvegqJ FAVc3sV285AjsRH0KssPlRljyVsgHrS49ryXkCZfdr2OrWxuEXOVQ7eL00e+dHX/2qH91U01wLlyA pnH1Nf0cLhUZxT/b4LoclXcLvQlyTJJTe/YQhn53JkCaw00IVv1UVwoGZ+Ts2e9o1gGyhYGh3y/Eq cfHUYVRU06fBib/zrz7QgfqcJsvcRyeKVH74Km2N9LyD2uLj491uQfgaUR4mOCYoYM2DfoDHFRlvn zQ4yEGGHd06hD13wDz0jQCtRPh3ug8n3kHhU2yMX40H6No2wzmRzBrnpTe6WJNZwv/GFjWHzaSKLC 9t53/qBA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mG0jv-00AUjl-Vy; Tue, 17 Aug 2021 15:10:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 006F530009A; Tue, 17 Aug 2021 17:10:53 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id ADFC42C8F5E0B; Tue, 17 Aug 2021 17:10:53 +0200 (CEST) Date: Tue, 17 Aug 2021 17:10:53 +0200 From: Peter Zijlstra 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 , Morten Rasmussen , Qais Yousef , Suren Baghdasaryan , Quentin Perret , Tejun Heo , Johannes Weiner , Ingo Molnar , Juri Lelli , Vincent Guittot , "Rafael J. Wysocki" , Dietmar Eggemann , Daniel Bristot de Oliveira , Valentin Schneider , Mark Rutland , kernel-team@android.com Subject: Re: [PATCH v11 08/16] sched: Allow task CPU affinity to be restricted on asymmetric systems Message-ID: References: <20210730112443.23245-1-will@kernel.org> <20210730112443.23245-9-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210730112443.23245-9-will@kernel.org> 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, Jul 30, 2021 at 12:24:35PM +0100, Will Deacon wrote: > @@ -2783,20 +2778,173 @@ 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); > + > + return affine_move_task(rq, p, rf, dest_cpu, flags); > > out: > - task_rq_unlock(rq, p, &rf); > + task_rq_unlock(rq, p, rf); > > return ret; > } > +void relax_compatible_cpus_allowed_ptr(struct task_struct *p) > +{ > + unsigned long flags; > + struct cpumask *mask = p->user_cpus_ptr; > + > + /* > + * Try to restore the old affinity mask. If this fails, then > + * we free the mask explicitly to avoid it being inherited across > + * a subsequent fork(). > + */ > + if (!mask || !__sched_setaffinity(p, mask)) > + return; > + > + raw_spin_lock_irqsave(&p->pi_lock, flags); > + release_user_cpus_ptr(p); > + raw_spin_unlock_irqrestore(&p->pi_lock, flags); > +} Both these are a problem on RT. The easiest recourse is simply never freeing the CPU mask (except on exit). The alternative is something like the below I suppose.. I'm leaning towards the former option, wdyt? --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2733,6 +2733,7 @@ static int __set_cpus_allowed_ptr_locked const struct cpumask *cpu_allowed_mask = task_cpu_possible_mask(p); const struct cpumask *cpu_valid_mask = cpu_active_mask; bool kthread = p->flags & PF_KTHREAD; + struct cpumask *user_mask = NULL; unsigned int dest_cpu; int ret = 0; @@ -2792,9 +2793,13 @@ static int __set_cpus_allowed_ptr_locked __do_set_cpus_allowed(p, new_mask, flags); if (flags & SCA_USER) - release_user_cpus_ptr(p); + swap(user_mask, p->user_cpus_ptr); + + ret = affine_move_task(rq, p, rf, dest_cpu, flags); + + kfree(user_mask); - return affine_move_task(rq, p, rf, dest_cpu, flags); + return ret; out: task_rq_unlock(rq, p, rf); @@ -2954,8 +2959,10 @@ void relax_compatible_cpus_allowed_ptr(s return; raw_spin_lock_irqsave(&p->pi_lock, flags); - release_user_cpus_ptr(p); + p->user_cpus_ptr = NULL; raw_spin_unlock_irqrestore(&p->pi_lock, flags); + + kfree(mask); } void set_task_cpu(struct task_struct *p, unsigned int new_cpu) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel