mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-15 13:15:57 +00:00
Merge branch 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull scheduler fixes from Ingo Molnar: "Two fixes for autogroup scheduling, for races when turning the feature on/off via /proc/sys/kernel/sched_autogroup_enabled" * 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: sched/autogroup: Do not use autogroup->tg in zombie threads sched/autogroup: Fix autogroup_move_group() to never skip sched_move_task()
This commit is contained in:
commit
000b8949e9
@ -2567,6 +2567,7 @@ extern void sched_autogroup_create_attach(struct task_struct *p);
|
|||||||
extern void sched_autogroup_detach(struct task_struct *p);
|
extern void sched_autogroup_detach(struct task_struct *p);
|
||||||
extern void sched_autogroup_fork(struct signal_struct *sig);
|
extern void sched_autogroup_fork(struct signal_struct *sig);
|
||||||
extern void sched_autogroup_exit(struct signal_struct *sig);
|
extern void sched_autogroup_exit(struct signal_struct *sig);
|
||||||
|
extern void sched_autogroup_exit_task(struct task_struct *p);
|
||||||
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
||||||
extern void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m);
|
extern void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m);
|
||||||
extern int proc_sched_autogroup_set_nice(struct task_struct *p, int nice);
|
extern int proc_sched_autogroup_set_nice(struct task_struct *p, int nice);
|
||||||
@ -2576,6 +2577,7 @@ static inline void sched_autogroup_create_attach(struct task_struct *p) { }
|
|||||||
static inline void sched_autogroup_detach(struct task_struct *p) { }
|
static inline void sched_autogroup_detach(struct task_struct *p) { }
|
||||||
static inline void sched_autogroup_fork(struct signal_struct *sig) { }
|
static inline void sched_autogroup_fork(struct signal_struct *sig) { }
|
||||||
static inline void sched_autogroup_exit(struct signal_struct *sig) { }
|
static inline void sched_autogroup_exit(struct signal_struct *sig) { }
|
||||||
|
static inline void sched_autogroup_exit_task(struct task_struct *p) { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int yield_to(struct task_struct *p, bool preempt);
|
extern int yield_to(struct task_struct *p, bool preempt);
|
||||||
|
@ -836,6 +836,7 @@ void __noreturn do_exit(long code)
|
|||||||
*/
|
*/
|
||||||
perf_event_exit_task(tsk);
|
perf_event_exit_task(tsk);
|
||||||
|
|
||||||
|
sched_autogroup_exit_task(tsk);
|
||||||
cgroup_exit(tsk);
|
cgroup_exit(tsk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -111,10 +111,13 @@ bool task_wants_autogroup(struct task_struct *p, struct task_group *tg)
|
|||||||
{
|
{
|
||||||
if (tg != &root_task_group)
|
if (tg != &root_task_group)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We can only assume the task group can't go away on us if
|
* If we race with autogroup_move_group() the caller can use the old
|
||||||
* autogroup_move_group() can see us on ->thread_group list.
|
* value of signal->autogroup but in this case sched_move_task() will
|
||||||
|
* be called again before autogroup_kref_put().
|
||||||
|
*
|
||||||
|
* However, there is no way sched_autogroup_exit_task() could tell us
|
||||||
|
* to avoid autogroup->tg, so we abuse PF_EXITING flag for this case.
|
||||||
*/
|
*/
|
||||||
if (p->flags & PF_EXITING)
|
if (p->flags & PF_EXITING)
|
||||||
return false;
|
return false;
|
||||||
@ -122,6 +125,16 @@ bool task_wants_autogroup(struct task_struct *p, struct task_group *tg)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sched_autogroup_exit_task(struct task_struct *p)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* We are going to call exit_notify() and autogroup_move_group() can't
|
||||||
|
* see this thread after that: we can no longer use signal->autogroup.
|
||||||
|
* See the PF_EXITING check in task_wants_autogroup().
|
||||||
|
*/
|
||||||
|
sched_move_task(p);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
autogroup_move_group(struct task_struct *p, struct autogroup *ag)
|
autogroup_move_group(struct task_struct *p, struct autogroup *ag)
|
||||||
{
|
{
|
||||||
@ -138,13 +151,20 @@ autogroup_move_group(struct task_struct *p, struct autogroup *ag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p->signal->autogroup = autogroup_kref_get(ag);
|
p->signal->autogroup = autogroup_kref_get(ag);
|
||||||
|
/*
|
||||||
if (!READ_ONCE(sysctl_sched_autogroup_enabled))
|
* We can't avoid sched_move_task() after we changed signal->autogroup,
|
||||||
goto out;
|
* this process can already run with task_group() == prev->tg or we can
|
||||||
|
* race with cgroup code which can read autogroup = prev under rq->lock.
|
||||||
|
* In the latter case for_each_thread() can not miss a migrating thread,
|
||||||
|
* cpu_cgroup_attach() must not be possible after cgroup_exit() and it
|
||||||
|
* can't be removed from thread list, we hold ->siglock.
|
||||||
|
*
|
||||||
|
* If an exiting thread was already removed from thread list we rely on
|
||||||
|
* sched_autogroup_exit_task().
|
||||||
|
*/
|
||||||
for_each_thread(p, t)
|
for_each_thread(p, t)
|
||||||
sched_move_task(t);
|
sched_move_task(t);
|
||||||
out:
|
|
||||||
unlock_task_sighand(p, &flags);
|
unlock_task_sighand(p, &flags);
|
||||||
autogroup_kref_put(prev);
|
autogroup_kref_put(prev);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user