Skip to contentSkip to conversation

mm/init: cpu_hotplug_init() must be initialized before SLAB

PATCH In review Benjamin Herrenschmidt 5 participants 8 messages Jun 23, 2009 CPU hotplug

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/init: cpu_hotplug_init() must be initialized before SLAB

SLAB uses get/put_online_cpus() which use a mutex which is itself only initialized when cpu_hotplug_init() is called. Currently we hang suring boot in SLAB due to doing that too late. This moves the call to cpu_hotplug_init() to before mm_init() (it should be safe to call that early).

This fixes boot with SLAB on some PowerPC machines.

---

Sachin, James, do that fix the boot failures you've been seeing ?

init/main.c +11 -1
Index: linux-work/init/main.c
===================================================================
@@ -608,7 +608,18 @@ asmlinkage void __init start_kernel(void
 	vfs_caches_init_early();
 	sort_main_extable();
 	trap_init();
+
+	/*
+	 * This initializes the mutex used by get/put_online_cpus()
+	 * which is used by SLAB
+	 */
+	cpu_hotplug_init();
+
+	/*
+	 * Initialize the page allocator, SL*B and vmalloc
+	 */
 	mm_init();
+
 	/*
 	 * Set up the scheduler prior starting any interrupts (such as the
 	 * timer interrupt). Full topology setup happens at smp_init()
@@ -678,7 +689,6 @@ asmlinkage void __init start_kernel(void
 #endif
 	page_cgroup_init();
 	enable_debug_pagealloc();
-	cpu_hotplug_init();
 	kmemtrace_init();
 	kmemleak_init();
 	debug_objects_mem_init();
#1 lore raw
Quoted 6 lines · Benjamin Herrenschmidt

SLAB uses get/put_online_cpus() which use a mutex which is itself only initialized when cpu_hotplug_init() is called. Currently we hang suring boot in SLAB due to doing that too late. This moves the call to cpu_hotplug_init() to before mm_init() (it should be safe to call that early).

Quoted 6 lines

This fixes boot with SLAB on some PowerPC machines.

---

Sachin, James, do that fix the boot failures you've been seeing ?

Yes, that seems to fix it for me.

James

#2 lore raw
In reply to Benjamin Herrenschmidt

Review

Quoted 5 lines · Benjamin Herrenschmidt
(quoted diff) +5 -0
+	/*
+	 * This initializes the mutex used by get/put_online_cpus()
+	 * which is used by SLAB
+	 */
+	cpu_hotplug_init();

Oh fudge it.

Why not get rid of that stupid thing, rather than have that subtle dependency and a comment for it.

IOW, does this simpler alternative also work?

When given the choice of simplifying and removing code, always do so.

Static initializers are much nicer than having to worry about when something gets initialized, no?

Linus

---
 include/linux/cpu.h |    5 -----
 init/main.c         |    1 -
 kernel/cpu.c        |   13 +++++--------
 3 files changed, 5 insertions(+), 14 deletions(-)
include/linux/cpu.h +0 -5
index 2643d84..4d668e0 100644
@@ -69,7 +69,6 @@ static inline void unregister_cpu_notifier(struct notifier_block *nb)
 
 int cpu_up(unsigned int cpu);
 void notify_cpu_starting(unsigned int cpu);
-extern void cpu_hotplug_init(void);
 extern void cpu_maps_update_begin(void);
 extern void cpu_maps_update_done(void);
 
@@ -84,10 +83,6 @@ static inline void unregister_cpu_notifier(struct notifier_block *nb)
 {
 }
 
-static inline void cpu_hotplug_init(void)
-{
-}
-
 static inline void cpu_maps_update_begin(void)
 {
 }
init/main.c +0 -1
index 09131ec..4870dfe 100644
@@ -678,7 +678,6 @@ asmlinkage void __init start_kernel(void)
 #endif
 	page_cgroup_init();
 	enable_debug_pagealloc();
-	cpu_hotplug_init();
 	kmemtrace_init();
 	kmemleak_init();
 	debug_objects_mem_init();
kernel/cpu.c +5 -8
index 395b697..8ce1004 100644
@@ -34,14 +34,11 @@ static struct {
 	 * an ongoing cpu hotplug operation.
 	 */
 	int refcount;
-} cpu_hotplug;
-
-void __init cpu_hotplug_init(void)
-{
-	cpu_hotplug.active_writer = NULL;
-	mutex_init(&cpu_hotplug.lock);
-	cpu_hotplug.refcount = 0;
-}
+} cpu_hotplug = {
+	.active_writer = NULL,
+	.lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
+	.refcount = 0,
+};
 
 #ifdef CONFIG_HOTPLUG_CPU
 
#3 lore raw
Quoted 11 lines · Linus Torvalds

Review

Quoted 5 lines · Benjamin Herrenschmidt
(quoted diff) +5 -0
+	/*
+	 * This initializes the mutex used by get/put_online_cpus()
+	 * which is used by SLAB
+	 */
+	cpu_hotplug_init();

Oh fudge it.

Quoted 4 lines

Why not get rid of that stupid thing, rather than have that subtle dependency and a comment for it.

IOW, does this simpler alternative also work?

You mean static init ? Sure, it should do.

Quoted 1 line

When given the choice of simplifying and removing code, always do so.

Yup. Agreed. Thought about it... got shy :-)

Quoted 2 lines

Static initializers are much nicer than having to worry about when something gets initialized, no?

I'll test that asap.

Quoted 67 lines

Linus

---
 include/linux/cpu.h |    5 -----
 init/main.c         |    1 -
 kernel/cpu.c        |   13 +++++--------
 3 files changed, 5 insertions(+), 14 deletions(-)
include/linux/cpu.h +0 -5
index 2643d84..4d668e0 100644
@@ -69,7 +69,6 @@ static inline void unregister_cpu_notifier(struct notifier_block *nb)
 
 int cpu_up(unsigned int cpu);
 void notify_cpu_starting(unsigned int cpu);
-extern void cpu_hotplug_init(void);
 extern void cpu_maps_update_begin(void);
 extern void cpu_maps_update_done(void);
 
@@ -84,10 +83,6 @@ static inline void unregister_cpu_notifier(struct notifier_block *nb)
 {
 }
 
-static inline void cpu_hotplug_init(void)
-{
-}
-
 static inline void cpu_maps_update_begin(void)
 {
 }
init/main.c +0 -1
index 09131ec..4870dfe 100644
@@ -678,7 +678,6 @@ asmlinkage void __init start_kernel(void)
 #endif
 	page_cgroup_init();
 	enable_debug_pagealloc();
-	cpu_hotplug_init();
 	kmemtrace_init();
 	kmemleak_init();
 	debug_objects_mem_init();
kernel/cpu.c +5 -8
index 395b697..8ce1004 100644
@@ -34,14 +34,11 @@ static struct {
 	 * an ongoing cpu hotplug operation.
 	 */
 	int refcount;
-} cpu_hotplug;
-
-void __init cpu_hotplug_init(void)
-{
-	cpu_hotplug.active_writer = NULL;
-	mutex_init(&cpu_hotplug.lock);
-	cpu_hotplug.refcount = 0;
-}
+} cpu_hotplug = {
+	.active_writer = NULL,
+	.lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
+	.refcount = 0,
+};
 
 #ifdef CONFIG_HOTPLUG_CPU
 
#4 lore raw
In reply to Linus Torvalds
Quoted 2 lines · Linus Torvalds

Static initializers are much nicer than having to worry about when something gets initialized, no?

Your patch works here and fixes the problem too.

Thanks !

Cheers,
Ben.

Quoted 72 lines

Linus

---
 include/linux/cpu.h |    5 -----
 init/main.c         |    1 -
 kernel/cpu.c        |   13 +++++--------
 3 files changed, 5 insertions(+), 14 deletions(-)
include/linux/cpu.h +0 -5
index 2643d84..4d668e0 100644
@@ -69,7 +69,6 @@ static inline void unregister_cpu_notifier(struct notifier_block *nb)
 
 int cpu_up(unsigned int cpu);
 void notify_cpu_starting(unsigned int cpu);
-extern void cpu_hotplug_init(void);
 extern void cpu_maps_update_begin(void);
 extern void cpu_maps_update_done(void);
 
@@ -84,10 +83,6 @@ static inline void unregister_cpu_notifier(struct notifier_block *nb)
 {
 }
 
-static inline void cpu_hotplug_init(void)
-{
-}
-
 static inline void cpu_maps_update_begin(void)
 {
 }
init/main.c +0 -1
index 09131ec..4870dfe 100644
@@ -678,7 +678,6 @@ asmlinkage void __init start_kernel(void)
 #endif
 	page_cgroup_init();
 	enable_debug_pagealloc();
-	cpu_hotplug_init();
 	kmemtrace_init();
 	kmemleak_init();
 	debug_objects_mem_init();
kernel/cpu.c +5 -9
index 395b697..8ce1004 100644
@@ -34,14 +34,11 @@ static struct {
 	 * an ongoing cpu hotplug operation.
 	 */
 	int refcount;
-} cpu_hotplug;
-
-void __init cpu_hotplug_init(void)
-{
-	cpu_hotplug.active_writer = NULL;
-	mutex_init(&cpu_hotplug.lock);
-	cpu_hotplug.refcount = 0;
-}
+} cpu_hotplug = {
+	.active_writer = NULL,
+	.lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
+	.refcount = 0,
+};
 
 #ifdef CONFIG_HOTPLUG_CPU
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#5 lore raw
In reply to Linus Torvalds
Quoted 12 lines · Linus Torvalds

Review

Quoted 6 lines · Benjamin Herrenschmidt
(quoted diff) +5 -0
+	/*
+	 * This initializes the mutex used by get/put_online_cpus()
+	 * which is used by SLAB
+	 */
+	cpu_hotplug_init();

Oh fudge it.

Quoted 3 lines

Why not get rid of that stupid thing, rather than have that subtle dependency and a comment for it.

IOW, does this simpler alternative also work?

This fixes the problem for me.

Thanks
-Sachin

Signature · 6 lines
---------------------------------
Sachin Sant
IBM Linux Technology Center
India Systems and Technology Labs
Bangalore, India
---------------------------------
#6 lore raw
In reply to Linus Torvalds
Quoted 11 lines · Linus Torvalds

Review

Quoted 5 lines · Benjamin Herrenschmidt
(quoted diff) +5 -0
+	/*
+	 * This initializes the mutex used by get/put_online_cpus()
+	 * which is used by SLAB
+	 */
+	cpu_hotplug_init();

Oh fudge it.

Quoted 4 lines

Why not get rid of that stupid thing, rather than have that subtle dependency and a comment for it.

IOW, does this simpler alternative also work?

Yes, works for me.

James

#7 lore raw
In reply to Linus Torvalds
Quoted 5 lines · Benjamin Herrenschmidt
Quoted 5 lines
(quoted diff) +5 -0
+	/*
+	 * This initializes the mutex used by get/put_online_cpus()
+	 * which is used by SLAB
+	 */
+	cpu_hotplug_init();
Quoted 11 lines · Linus Torvalds

Oh fudge it.

Why not get rid of that stupid thing, rather than have that subtle dependency and a comment for it.

IOW, does this simpler alternative also work?

When given the choice of simplifying and removing code, always do so.

Static initializers are much nicer than having to worry about when something gets initialized, no?

Looks good to me. Thanks for fixing it up, Linus!

Pekka