From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932299AbdEXRnH (ORCPT ); Wed, 24 May 2017 13:43:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50008 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932233AbdEXRmt (ORCPT ); Wed, 24 May 2017 13:42:49 -0400 Date: Wed, 24 May 2017 10:42:44 -0700 From: "Paul E. McKenney" To: Thomas Gleixner Cc: LKML , Peter Zijlstra , Ingo Molnar , Steven Rostedt , Sebastian Siewior Subject: Re: [patch V3 05/32] stop_machine: Provide stop_machine_cpuslocked() Reply-To: paulmck@linux.vnet.ibm.com References: <20170524081511.203800767@linutronix.de> <20170524081547.400700852@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170524081547.400700852@linutronix.de> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17052417-0044-0000-0000-00000337E103 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007111; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000212; SDB=6.00865054; UDB=6.00429494; IPR=6.00644834; BA=6.00005372; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015566; XFM=3.00000015; UTC=2017-05-24 17:42:45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052417-0045-0000-0000-00000765EEDC Message-Id: <20170524174244.GG3956@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-05-24_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705240083 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 24, 2017 at 10:15:16AM +0200, Thomas Gleixner wrote: > From: Sebastian Andrzej Siewior > > Some call sites of stop_machine() are within a get_online_cpus() protected > region. > > stop_machine() calls get_online_cpus() as well, which is possible in the > current implementation but prevents converting the hotplug locking to a > percpu rwsem. > > Provide stop_machine_cpuslocked() to avoid nested calls to get_online_cpus(). > > Signed-off-by: Sebastian Andrzej Siewior > Signed-off-by: Thomas Gleixner > Cc: Peter Zijlstra > Cc: Steven Rostedt Acked-by: Paul E. McKenney > --- > include/linux/stop_machine.h | 26 +++++++++++++++++++++++--- > kernel/stop_machine.c | 11 +++++++---- > 2 files changed, 30 insertions(+), 7 deletions(-) > > Index: b/include/linux/stop_machine.h > =================================================================== > --- a/include/linux/stop_machine.h > +++ b/include/linux/stop_machine.h > @@ -116,15 +116,29 @@ static inline int try_stop_cpus(const st > * @fn() runs. > * > * This can be thought of as a very heavy write lock, equivalent to > - * grabbing every spinlock in the kernel. */ > + * grabbing every spinlock in the kernel. > + * > + * Protects against CPU hotplug. > + */ > int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus); > > +/** > + * stop_machine_cpuslocked: freeze the machine on all CPUs and run this function > + * @fn: the function to run > + * @data: the data ptr for the @fn() > + * @cpus: the cpus to run the @fn() on (NULL = any online cpu) > + * > + * Same as above. Must be called from with in a cpus_read_lock() protected > + * region. Avoids nested calls to cpus_read_lock(). > + */ > +int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus); > + > int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data, > const struct cpumask *cpus); > #else /* CONFIG_SMP || CONFIG_HOTPLUG_CPU */ > > -static inline int stop_machine(cpu_stop_fn_t fn, void *data, > - const struct cpumask *cpus) > +static inline int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, > + const struct cpumask *cpus) > { > unsigned long flags; > int ret; > @@ -134,6 +148,12 @@ static inline int stop_machine(cpu_stop_ > return ret; > } > > +static inline int stop_machine(cpu_stop_fn_t fn, void *data, > + const struct cpumask *cpus) > +{ > + return stop_machine_cpuslocked(fn, data, cpus); > +} > + > static inline int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data, > const struct cpumask *cpus) > { > Index: b/kernel/stop_machine.c > =================================================================== > --- a/kernel/stop_machine.c > +++ b/kernel/stop_machine.c > @@ -552,7 +552,8 @@ static int __init cpu_stop_init(void) > } > early_initcall(cpu_stop_init); > > -static int __stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus) > +int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, > + const struct cpumask *cpus) > { > struct multi_stop_data msdata = { > .fn = fn, > @@ -561,6 +562,8 @@ static int __stop_machine(cpu_stop_fn_t > .active_cpus = cpus, > }; > > + lockdep_assert_cpus_held(); > + > if (!stop_machine_initialized) { > /* > * Handle the case where stop_machine() is called > @@ -590,9 +593,9 @@ int stop_machine(cpu_stop_fn_t fn, void > int ret; > > /* No CPUs can come up or down during this. */ > - get_online_cpus(); > - ret = __stop_machine(fn, data, cpus); > - put_online_cpus(); > + cpus_read_lock(); > + ret = stop_machine_cpuslocked(fn, data, cpus); > + cpus_read_unlock(); > return ret; > } > EXPORT_SYMBOL_GPL(stop_machine); > >