Skip to contentSkip to conversation

pi-futex: missing pi_waiters plist initialization

PATCH In review Heiko Carstens 2 participants 2 messages Jul 24, 2006 – Aug 22, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pi-futex: missing pi_waiters plist initialization

From: Heiko Carstens <[email protected]>

Initialize init task's pi_waiters plist. Otherwise cpu hotplug of cpu 0 might crash, since rt_mutex_getprio() accesses an uninitialized list head.

call chain which led to crash:

take_cpu_down
sched_idle_next
__setscheduler
rt_mutex_getprio

Using PLIST_HEAD_INIT in the INIT_TASK macro doesn't work unfortunately, since the pi_waiters member is only conditionally present.

Cc Arjan van de Ven <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>

---

 kernel/sched.c |    5 +++++
 1 file changed, 5 insertions(+)
kernel/sched.c +5 -0
index b44b9a4..db1014d 100644
@@ -6761,6 +6761,11 @@ #endif
 	}
 
 	set_load_weight(&init_task);
+
+#ifdef CONFIG_RT_MUTEXES
+	plist_head_init(&init_task.pi_waiters, &init_task.pi_lock);
+#endif
+
 	/*
 	 * The boot idle thread does lazy MMU switching as well:
 	 */
#1 lore raw
Quoted 7 lines · Heiko Carstens

From: Heiko Carstens <[email protected]>

Initialize init task's pi_waiters plist. Otherwise cpu hotplug of cpu 0 might crash, since rt_mutex_getprio() accesses an uninitialized list head.

call chain which led to crash:

Quoted 7 lines

take_cpu_down
sched_idle_next
__setscheduler
rt_mutex_getprio

Using PLIST_HEAD_INIT in the INIT_TASK macro doesn't work unfortunately, since the pi_waiters member is only conditionally present.

Hi
I felt it would be more appropriate to put initialization of
pi_waiters in fork_init function rather than in sched_init function as other init_task related initialization or happening in fork_init(). As well we have rt_mutex_init_task() function in fork.c which can be reused for initializing pi_waiters field of init_task.
Please go through the patch and let me know of your opinion.
Thanks
Sharyathi Nagesh

Signed-off-by <[email protected]>

----

kernel/fork.c +11 -9
Index: linux-2.6.18-rc4/kernel/fork.c
===================================================================
@@ -122,6 +122,16 @@
 		free_task(tsk);
 }
 
+
+static inline void rt_mutex_init_task(struct task_struct *p)
+{
+#ifdef CONFIG_RT_MUTEXES
+	spin_lock_init(&p->pi_lock);
+	plist_head_init(&p->pi_waiters, &p->pi_lock);
+	p->pi_blocked_on = NULL;
+#endif
+}
+
 void __init fork_init(unsigned long mempages)
 {
 #ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
@@ -151,6 +161,7 @@
 	init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
 	init_task.signal->rlim[RLIMIT_SIGPENDING] =
 		init_task.signal->rlim[RLIMIT_NPROC];
+	rt_mutex_init_task(&init_task);
 }
 
 static struct task_struct *dup_task_struct(struct task_struct *orig)
@@ -919,15 +930,6 @@
 	return current->pid;
 }
 
-static inline void rt_mutex_init_task(struct task_struct *p)
-{
-#ifdef CONFIG_RT_MUTEXES
-	spin_lock_init(&p->pi_lock);
-	plist_head_init(&p->pi_waiters, &p->pi_lock);
-	p->pi_blocked_on = NULL;
-#endif
-}
-
 /*
  * This creates a new process as a copy of the old one,
  * but does not actually start it yet.