Skip to content

Commit efb29fb

Browse files
oleg-nesterovKAGA-KOKO
authored andcommitted
kthread: Don't use to_live_kthread() in kthread_stop()
kthread_stop() had to use to_live_kthread() simply because it was not possible to access kthread->exited after the exiting task clears task_struct->vfork_done. Now that to_kthread() is always valid, wake_up_process() + wait_for_completion() can be done ununconditionally. It's not an issue anymore if the task has already issued complete_vfork_done() or died. The exiting task can get the spurious wakeup after mm_release() but this is possible without this change too and is fine; do_task_dead() ensures that this can't make any harm. As a further enhancement this could be converted to task_work_add() later, so ->vfork_done can be avoided completely. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Cc: Chunming Zhou <David1.Zhou@amd.com> Cc: Roman Pen <roman.penyaev@profitbricks.com> Cc: Petr Mladek <pmladek@suse.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Tejun Heo <tj@kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: Andrew Morton <akpm@linux-foundation.org> Link: http://lkml.kernel.org/r/20161129175103.GA5336@redhat.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent eff9662 commit efb29fb

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

‎kernel/kthread.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,11 @@ int kthread_stop(struct task_struct *k)
532532
trace_sched_kthread_stop(k);
533533

534534
get_task_struct(k);
535-
kthread = to_live_kthread(k);
536-
if (kthread) {
537-
set_bit(KTHREAD_SHOULD_STOP, &kthread->flags);
538-
__kthread_unpark(k, kthread);
539-
wake_up_process(k);
540-
wait_for_completion(&kthread->exited);
541-
}
535+
kthread = to_kthread(k);
536+
set_bit(KTHREAD_SHOULD_STOP, &kthread->flags);
537+
__kthread_unpark(k, kthread);
538+
wake_up_process(k);
539+
wait_for_completion(&kthread->exited);
542540
ret = k->exit_code;
543541
put_task_struct(k);
544542

0 commit comments

Comments
 (0)