From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754484AbdDOO2H (ORCPT ); Sat, 15 Apr 2017 10:28:07 -0400 Received: from terminus.zytor.com ([65.50.211.136]:52575 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753773AbdDOO2F (ORCPT ); Sat, 15 Apr 2017 10:28:05 -0400 Date: Sat, 15 Apr 2017 07:18:04 -0700 From: tip-bot for Thomas Gleixner Message-ID: Cc: fenghua.yu@intel.com, hpa@zytor.com, tj@kernel.org, mpe@ellerman.id.au, bigeasy@linutronix.de, herbert@gondor.apana.org.au, viresh.kumar@linaro.org, lenb@kernel.org, jiangshanlai@gmail.com, tony.luck@intel.com, rjw@rjwysocki.net, mingo@kernel.org, davem@davemloft.net, benh@kernel.crashing.org, peterz@infradead.org, tglx@linutronix.de, paulus@samba.org, linux-kernel@vger.kernel.org Reply-To: fenghua.yu@intel.com, hpa@zytor.com, tj@kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, bigeasy@linutronix.de, lenb@kernel.org, viresh.kumar@linaro.org, jiangshanlai@gmail.com, rjw@rjwysocki.net, tony.luck@intel.com, mingo@kernel.org, benh@kernel.crashing.org, davem@davemloft.net, tglx@linutronix.de, peterz@infradead.org, paulus@samba.org, linux-kernel@vger.kernel.org In-Reply-To: <20170412201042.518053336@linutronix.de> References: <20170412201042.518053336@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/core] powerpc/smp: Replace open coded task affinity logic Git-Commit-ID: 6d11b87d55eb75007a3721c2de5938f5bbf607fb X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 6d11b87d55eb75007a3721c2de5938f5bbf607fb Gitweb: http://git.kernel.org/tip/6d11b87d55eb75007a3721c2de5938f5bbf607fb Author: Thomas Gleixner AuthorDate: Wed, 12 Apr 2017 22:07:31 +0200 Committer: Thomas Gleixner CommitDate: Sat, 15 Apr 2017 12:20:54 +0200 powerpc/smp: Replace open coded task affinity logic Init task invokes smp_ops->setup_cpu() from smp_cpus_done(). Init task can run on any online CPU at this point, but the setup_cpu() callback requires to be invoked on the boot CPU. This is achieved by temporarily setting the affinity of the calling user space thread to the requested CPU and reset it to the original affinity afterwards. That's racy vs. CPU hotplug and concurrent affinity settings for that thread resulting in code executing on the wrong CPU and overwriting the new affinity setting. That's actually not a problem in this context as neither CPU hotplug nor affinity settings can happen, but the access to task_struct::cpus_allowed is about to restricted. Replace it with a call to work_on_cpu_safe() which achieves the same result. Signed-off-by: Thomas Gleixner Acked-by: Michael Ellerman Cc: Fenghua Yu Cc: Tony Luck Cc: Herbert Xu Cc: "Rafael J. Wysocki" Cc: Peter Zijlstra Cc: Benjamin Herrenschmidt Cc: Sebastian Siewior Cc: Lai Jiangshan Cc: Viresh Kumar Cc: Tejun Heo Cc: Paul Mackerras Cc: linuxppc-dev@lists.ozlabs.org Cc: "David S. Miller" Cc: Len Brown Link: http://lkml.kernel.org/r/20170412201042.518053336@linutronix.de Signed-off-by: Thomas Gleixner --- arch/powerpc/kernel/smp.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index 46f89e6..d68ed1f 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -787,24 +787,21 @@ static struct sched_domain_topology_level powerpc_topology[] = { { NULL, }, }; -void __init smp_cpus_done(unsigned int max_cpus) +static __init long smp_setup_cpu_workfn(void *data __always_unused) { - cpumask_var_t old_mask; + smp_ops->setup_cpu(boot_cpuid); + return 0; +} - /* We want the setup_cpu() here to be called from CPU 0, but our - * init thread may have been "borrowed" by another CPU in the meantime - * se we pin us down to CPU 0 for a short while +void __init smp_cpus_done(unsigned int max_cpus) +{ + /* + * We want the setup_cpu() here to be called on the boot CPU, but + * init might run on any CPU, so make sure it's invoked on the boot + * CPU. */ - alloc_cpumask_var(&old_mask, GFP_NOWAIT); - cpumask_copy(old_mask, ¤t->cpus_allowed); - set_cpus_allowed_ptr(current, cpumask_of(boot_cpuid)); - if (smp_ops && smp_ops->setup_cpu) - smp_ops->setup_cpu(boot_cpuid); - - set_cpus_allowed_ptr(current, old_mask); - - free_cpumask_var(old_mask); + work_on_cpu_safe(boot_cpuid, smp_setup_cpu_workfn, NULL); if (smp_ops && smp_ops->bringup_done) smp_ops->bringup_done(); @@ -812,7 +809,6 @@ void __init smp_cpus_done(unsigned int max_cpus) dump_numa_cpu_topology(); set_sched_topology(powerpc_topology); - } #ifdef CONFIG_HOTPLUG_CPU