From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754361AbdDOOYM (ORCPT ); Sat, 15 Apr 2017 10:24:12 -0400 Received: from terminus.zytor.com ([65.50.211.136]:51219 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751711AbdDOOYK (ORCPT ); Sat, 15 Apr 2017 10:24:10 -0400 Date: Sat, 15 Apr 2017 07:16:30 -0700 From: tip-bot for Thomas Gleixner Message-ID: Cc: benh@kernel.crashing.org, davem@davemloft.net, lenb@kernel.org, tj@kernel.org, peterz@infradead.org, hpa@zytor.com, mpe@ellerman.id.au, bigeasy@linutronix.de, tglx@linutronix.de, fenghua.yu@intel.com, linux-kernel@vger.kernel.org, rjw@rjwysocki.net, tony.luck@intel.com, herbert@gondor.apana.org.au, mingo@kernel.org, jiangshanlai@gmail.com, viresh.kumar@linaro.org Reply-To: mingo@kernel.org, jiangshanlai@gmail.com, rjw@rjwysocki.net, herbert@gondor.apana.org.au, tony.luck@intel.com, viresh.kumar@linaro.org, tj@kernel.org, lenb@kernel.org, benh@kernel.crashing.org, davem@davemloft.net, tglx@linutronix.de, bigeasy@linutronix.de, linux-kernel@vger.kernel.org, fenghua.yu@intel.com, peterz@infradead.org, hpa@zytor.com, mpe@ellerman.id.au In-Reply-To: <20170412201042.262610721@linutronix.de> References: <20170412201042.262610721@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/core] workqueue: Provide work_on_cpu_safe() Git-Commit-ID: 0e8d6a9336b487a1dd6f1991ff376e669d4c87c6 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: 0e8d6a9336b487a1dd6f1991ff376e669d4c87c6 Gitweb: http://git.kernel.org/tip/0e8d6a9336b487a1dd6f1991ff376e669d4c87c6 Author: Thomas Gleixner AuthorDate: Wed, 12 Apr 2017 22:07:28 +0200 Committer: Thomas Gleixner CommitDate: Sat, 15 Apr 2017 12:20:53 +0200 workqueue: Provide work_on_cpu_safe() work_on_cpu() is not protected against CPU hotplug. For code which requires to be either executed on an online CPU or to fail if the CPU is not available the callsite would have to protect against CPU hotplug. Provide a function which does get/put_online_cpus() around the call to work_on_cpu() and fails the call with -ENODEV if the target CPU is not online. Preparatory patch to convert several racy task affinity manipulations. Signed-off-by: Thomas Gleixner Acked-by: Tejun Heo 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: Michael Ellerman Cc: "David S. Miller" Cc: Len Brown Link: http://lkml.kernel.org/r/20170412201042.262610721@linutronix.de Signed-off-by: Thomas Gleixner --- include/linux/workqueue.h | 5 +++++ kernel/workqueue.c | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index bde063c..c102ef6 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -608,8 +608,13 @@ static inline long work_on_cpu(int cpu, long (*fn)(void *), void *arg) { return fn(arg); } +static inline long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg) +{ + return fn(arg); +} #else long work_on_cpu(int cpu, long (*fn)(void *), void *arg); +long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg); #endif /* CONFIG_SMP */ #ifdef CONFIG_FREEZER diff --git a/kernel/workqueue.c b/kernel/workqueue.c index c0168b7..5bf1be0 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4735,6 +4735,29 @@ long work_on_cpu(int cpu, long (*fn)(void *), void *arg) return wfc.ret; } EXPORT_SYMBOL_GPL(work_on_cpu); + +/** + * work_on_cpu_safe - run a function in thread context on a particular cpu + * @cpu: the cpu to run on + * @fn: the function to run + * @arg: the function argument + * + * Disables CPU hotplug and calls work_on_cpu(). The caller must not hold + * any locks which would prevent @fn from completing. + * + * Return: The value @fn returns. + */ +long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg) +{ + long ret = -ENODEV; + + get_online_cpus(); + if (cpu_online(cpu)) + ret = work_on_cpu(cpu, fn, arg); + put_online_cpus(); + return ret; +} +EXPORT_SYMBOL_GPL(work_on_cpu_safe); #endif /* CONFIG_SMP */ #ifdef CONFIG_FREEZER