sched: Fix TASK_WAKING vs fork deadlock
Commit-ID: 0017d735092844118bef006696a750a0e4ef6ebd Gitweb: http://git.kernel.org/tip/0017d735092844118bef006696a750a0e4ef6ebd Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 24 Mar 2010 18:34:10 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 2 Apr 2010 20:12:03 +0200
sched: Fix TASK_WAKING vs fork deadlock
Oleg noticed a few races with the TASK_WAKING usage on fork.
- since TASK_WAKING is basically a spinlock, it should be IRQ safe
- since we set TASK_WAKING (*) without holding rq->lock it could be there still is a rq->lock holder, thereby not actually providing full serialization.
(*) in fact we clear PF_STARTING, which in effect enables TASK_WAKING.
Cure the second issue by not setting TASK_WAKING in sched_fork(), but only temporarily in wake_up_new_task() while calling select_task_rq().
Cure the first by holding rq->lock around the select_task_rq() call, this will disable IRQs, this however requires that we push down the rq->lock release into select_task_rq_fair()'s cgroup stuff.
Because select_task_rq_fair() still needs to drop the rq->lock we cannot fully get rid of TASK_WAKING.
LKML-Reference: <new-submission>
--- include/linux/sched.h | 3 +- kernel/sched.c | 65 +++++++++++++++++----------------------------- kernel/sched_fair.c | 8 ++++- kernel/sched_idletask.c | 3 +- kernel/sched_rt.c | 5 +-- 5 files changed, 36 insertions(+), 48 deletions(-)
include/linux/sched.h +2 -1
@@ -1046,7 +1046,8 @@ struct sched_class {void (*put_prev_task) (struct rq *rq,struct task_struct *p);#ifdef CONFIG_SMP -int (*select_task_rq)(struct task_struct *p,int sd_flag,int flags); +int (*select_task_rq)(struct rq *rq,struct task_struct *p, +int sd_flag,int flags);void (*pre_schedule) (struct rq *this_rq,struct task_struct *task);void (*post_schedule) (struct rq *this_rq);
kernel/sched.c +24 -41
128 lines not on this page · raw message
kernel/sched_fair.c +6 -2
@@ -1423,7 +1423,8 @@ select_idle_sibling(struct task_struct *p, struct sched_domain *sd, int target)* * preempt must be disabled. */ -static int select_task_rq_fair (struct task_struct *p,int sd_flag,int wake_flags) +static int +select_task_rq_fair (struct rq *rq,struct task_struct *p,int sd_flag,int wake_flags) {struct sched_domain *tmp, *affine_sd =NULL , *sd =NULL ;int cpu =smp_processor_id ();
@@ -1521,8 +1522,11 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag cpumask_weight(sched_domain_span(sd)))) tmp = affine_sd; -if (tmp) +if (tmp) { +raw_spin_unlock (&rq->lock);update_shares (tmp); +raw_spin_lock (&rq->lock); + } }#endif
kernel/sched_idletask.c +2 -1
@@ -6,7 +6,8 @@*/ #ifdef CONFIG_SMP -static int select_task_rq_idle (struct task_struct *p,int sd_flag,int flags) +static int +select_task_rq_idle (struct rq *rq,struct task_struct *p,int sd_flag,int flags) {return task_cpu (p);/* IDLE tasks as never migrated */ }
kernel/sched_rt.c +2 -3
@@ -948,10 +948,9 @@ static void yield_task_rt(struct rq *rq)#ifdef CONFIG_SMP static int find_lowest_rq (struct task_struct *task); -static int select_task_rq_rt (struct task_struct *p,int sd_flag,int flags) +static int +select_task_rq_rt (struct rq *rq,struct task_struct *p,int sd_flag,int flags) { -struct rq *rq =task_rq (p); -if (sd_flag !=SD_BALANCE_WAKE )return smp_processor_id ();