public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] smpboot: calling smpboot_register_percpu_thread is unsafe during one CPU being down
  2012-12-11 14:17 [PATCH] smpboot: calling smpboot_register_percpu_thread is unsafe during one CPU being down Chuansheng Liu
@ 2012-12-11  6:30 ` Srivatsa S. Bhat
  0 siblings, 0 replies; 2+ messages in thread
From: Srivatsa S. Bhat @ 2012-12-11  6:30 UTC (permalink / raw)
  To: Chuansheng Liu; +Cc: tglx, paul.mckenney, linux-kernel

On 12/11/2012 07:47 PM, Chuansheng Liu wrote:
> 
> When one CPU is going down, and smpboot_register_percpu_thread is called,
> there is the race issue below:
> T1(CPUA):                                      T2(CPUB):
> _cpu_down()                                    smpboot_register_percpu_thread()
>   smpboot_park_threads()                       ...
>   __stop_machine()                               __smpboot_create_thread(CPU_Dying)
>                                                  [Currently, the being down CPU is online yet]
>     take_cpu_down()                              smpboot_unpark_thread(CPU_Dying)
>       __cpu_disable()                              ....
>         native_cpu_disable()
>    ....                                          Here the new kthread will get running
>                                                  based on the CPU_Dying
>         set_cpu_online(cpu, false)
>    ....
>    cpu_notify(CPU_DYING)
> 
> After notified the CPU_DYING, the new created kthead for dying CPU will
> be migrated to another CPU in migration_call().
> 
> Here we need use get_online_cpus()/put_online_cpus() when calling
> function smpboot_register_percpu_thread().
> 
> Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>

Reviewed-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>

Regards,
Srivatsa S. Bhat

> ---
>  kernel/smpboot.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/kernel/smpboot.c b/kernel/smpboot.c
> index d6c5fc0..3fe708a 100644
> --- a/kernel/smpboot.c
> +++ b/kernel/smpboot.c
> @@ -266,6 +266,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
>  	unsigned int cpu;
>  	int ret = 0;
> 
> +	get_online_cpus();
>  	mutex_lock(&smpboot_threads_lock);
>  	for_each_online_cpu(cpu) {
>  		ret = __smpboot_create_thread(plug_thread, cpu);
> @@ -278,6 +279,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
>  	list_add(&plug_thread->list, &hotplug_threads);
>  out:
>  	mutex_unlock(&smpboot_threads_lock);
> +	put_online_cpus();
>  	return ret;
>  }
>  EXPORT_SYMBOL_GPL(smpboot_register_percpu_thread);
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] smpboot: calling smpboot_register_percpu_thread is unsafe during one CPU being down
@ 2012-12-11 14:17 Chuansheng Liu
  2012-12-11  6:30 ` Srivatsa S. Bhat
  0 siblings, 1 reply; 2+ messages in thread
From: Chuansheng Liu @ 2012-12-11 14:17 UTC (permalink / raw)
  To: tglx, paul.mckenney, srivatsa.bhat; +Cc: linux-kernel, chuansheng.liu


When one CPU is going down, and smpboot_register_percpu_thread is called,
there is the race issue below:
T1(CPUA):                                      T2(CPUB):
_cpu_down()                                    smpboot_register_percpu_thread()
  smpboot_park_threads()                       ...
  __stop_machine()                               __smpboot_create_thread(CPU_Dying)
                                                 [Currently, the being down CPU is online yet]
    take_cpu_down()                              smpboot_unpark_thread(CPU_Dying)
      __cpu_disable()                              ....
        native_cpu_disable()
   ....                                          Here the new kthread will get running
                                                 based on the CPU_Dying
        set_cpu_online(cpu, false)
   ....
   cpu_notify(CPU_DYING)

After notified the CPU_DYING, the new created kthead for dying CPU will
be migrated to another CPU in migration_call().

Here we need use get_online_cpus()/put_online_cpus() when calling
function smpboot_register_percpu_thread().

Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
---
 kernel/smpboot.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/kernel/smpboot.c b/kernel/smpboot.c
index d6c5fc0..3fe708a 100644
--- a/kernel/smpboot.c
+++ b/kernel/smpboot.c
@@ -266,6 +266,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
 	unsigned int cpu;
 	int ret = 0;
 
+	get_online_cpus();
 	mutex_lock(&smpboot_threads_lock);
 	for_each_online_cpu(cpu) {
 		ret = __smpboot_create_thread(plug_thread, cpu);
@@ -278,6 +279,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
 	list_add(&plug_thread->list, &hotplug_threads);
 out:
 	mutex_unlock(&smpboot_threads_lock);
+	put_online_cpus();
 	return ret;
 }
 EXPORT_SYMBOL_GPL(smpboot_register_percpu_thread);
-- 
1.7.0.4




^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-11  6:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-11 14:17 [PATCH] smpboot: calling smpboot_register_percpu_thread is unsafe during one CPU being down Chuansheng Liu
2012-12-11  6:30 ` Srivatsa S. Bhat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox