Skip to content

Commit

Permalink
sched: Inherit task cookie on fork()
Browse files Browse the repository at this point in the history
Note that sched_core_fork() is called from under tasklist_lock, and
not from sched_fork() earlier. This avoids a few races later.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Don Hiatt <dhiatt@digitalocean.com>
Tested-by: Hongyu Ning <hongyu.ning@linux.intel.com>
Tested-by: Vincent Guittot <vincent.guittot@linaro.org>
Link: https://lkml.kernel.org/r/20210422123308.980003687@infradead.org
  • Loading branch information
Peter Zijlstra committed May 12, 2021
1 parent 6e33cad commit 85dd3f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -2181,8 +2181,10 @@ const struct cpumask *sched_trace_rd_span(struct root_domain *rd);

#ifdef CONFIG_SCHED_CORE
extern void sched_core_free(struct task_struct *tsk);
extern void sched_core_fork(struct task_struct *p);
#else
static inline void sched_core_free(struct task_struct *tsk) { }
static inline void sched_core_fork(struct task_struct *p) { }
#endif

#endif
3 changes: 3 additions & 0 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,8 @@ static __latent_entropy struct task_struct *copy_process(

klp_copy_process(p);

sched_core_fork(p);

spin_lock(&current->sighand->siglock);

/*
Expand Down Expand Up @@ -2338,6 +2340,7 @@ static __latent_entropy struct task_struct *copy_process(
return p;

bad_fork_cancel_cgroup:
sched_core_free(p);
spin_unlock(&current->sighand->siglock);
write_unlock_irq(&tasklist_lock);
cgroup_cancel_fork(p, args);
Expand Down
6 changes: 6 additions & 0 deletions kernel/sched/core_sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ static unsigned long sched_core_clone_cookie(struct task_struct *p)
return cookie;
}

void sched_core_fork(struct task_struct *p)
{
RB_CLEAR_NODE(&p->core_node);
p->core_cookie = sched_core_clone_cookie(current);
}

void sched_core_free(struct task_struct *p)
{
sched_core_put_cookie(p->core_cookie);
Expand Down

0 comments on commit 85dd3f6

Please sign in to comment.