From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756234AbcK2RvU (ORCPT ); Tue, 29 Nov 2016 12:51:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33230 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755801AbcK2RvH (ORCPT ); Tue, 29 Nov 2016 12:51:07 -0500 Date: Tue, 29 Nov 2016 18:51:03 +0100 From: Oleg Nesterov To: Andrew Morton , Ingo Molnar Cc: Alex Deucher , Andy Lutomirski , Andy Lutomirski , Chunming Zhou , Peter Zijlstra , Petr Mladek , Roman Pen , Tejun Heo , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] kthread: don't use to_live_kthread() in kthread_stop() Message-ID: <20161129175103.GA5336@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161129175037.GA5319@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 29 Nov 2016 17:51:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kthread_stop() had to use to_live_kthread() simply because it was not possible to access kthread->exited after the exiting kthread clears task_struct->vfork_done. Now that to_kthread() is always valid we can do wake_up_process() + wait_for_completion() unconditionally, we don't care if it has already passed complete_vfork_done() or even dead. The exiting kthread can get the spurious wakeup after mm_release() but this is possible without this change too and this is fine, do_task_dead() ensures that this can't make any harm. Note: we can even change this function to use task_work_add() and avoid ->vfork_done altogether, probably we will do this later. Signed-off-by: Oleg Nesterov Reviewed-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); -- 2.5.0