From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932519AbcLHNpB (ORCPT ); Thu, 8 Dec 2016 08:45:01 -0500 Received: from terminus.zytor.com ([198.137.202.10]:59688 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932478AbcLHNo7 (ORCPT ); Thu, 8 Dec 2016 08:44:59 -0500 Date: Thu, 8 Dec 2016 05:44:10 -0800 From: tip-bot for Oleg Nesterov Message-ID: Cc: akpm@linux-foundation.org, tj@kernel.org, oleg@redhat.com, alexander.deucher@amd.com, luto@amacapital.net, roman.penyaev@profitbricks.com, linux-kernel@vger.kernel.org, hpa@zytor.com, tglx@linutronix.de, David1.Zhou@amd.com, pmladek@suse.com, luto@kernel.org, mingo@kernel.org, peterz@infradead.org Reply-To: oleg@redhat.com, alexander.deucher@amd.com, akpm@linux-foundation.org, tj@kernel.org, roman.penyaev@profitbricks.com, linux-kernel@vger.kernel.org, luto@amacapital.net, David1.Zhou@amd.com, pmladek@suse.com, tglx@linutronix.de, hpa@zytor.com, peterz@infradead.org, luto@kernel.org, mingo@kernel.org In-Reply-To: <20161129175103.GA5336@redhat.com> References: <20161129175103.GA5336@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/core] kthread: Don't use to_live_kthread() in kthread_stop() Git-Commit-ID: efb29fbfa50c490dac64a9418ebe553be82df781 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: efb29fbfa50c490dac64a9418ebe553be82df781 Gitweb: http://git.kernel.org/tip/efb29fbfa50c490dac64a9418ebe553be82df781 Author: Oleg Nesterov AuthorDate: Tue, 29 Nov 2016 18:51:03 +0100 Committer: Thomas Gleixner CommitDate: Thu, 8 Dec 2016 14:36:19 +0100 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 Acked-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner Cc: Chunming Zhou Cc: Roman Pen Cc: Petr Mladek Cc: Andy Lutomirski Cc: Tejun Heo Cc: Andy Lutomirski Cc: Alex Deucher Cc: Andrew Morton Link: http://lkml.kernel.org/r/20161129175103.GA5336@redhat.com Signed-off-by: Thomas Gleixner --- kernel/kthread.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index 7891a94..4dcbc8b 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -532,13 +532,11 @@ int kthread_stop(struct task_struct *k) trace_sched_kthread_stop(k); get_task_struct(k); - kthread = to_live_kthread(k); - if (kthread) { - set_bit(KTHREAD_SHOULD_STOP, &kthread->flags); - __kthread_unpark(k, kthread); - wake_up_process(k); - wait_for_completion(&kthread->exited); - } + kthread = to_kthread(k); + set_bit(KTHREAD_SHOULD_STOP, &kthread->flags); + __kthread_unpark(k, kthread); + wake_up_process(k); + wait_for_completion(&kthread->exited); ret = k->exit_code; put_task_struct(k);