From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758877AbcIPJSa (ORCPT ); Fri, 16 Sep 2016 05:18:30 -0400 Received: from terminus.zytor.com ([198.137.202.10]:37098 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755788AbcIPJSW (ORCPT ); Fri, 16 Sep 2016 05:18:22 -0400 Date: Fri, 16 Sep 2016 02:17:20 -0700 From: tip-bot for Oleg Nesterov Message-ID: Cc: torvalds@linux-foundation.org, tglx@linutronix.de, dvlasenk@redhat.com, bp@alien8.de, oleg@redhat.com, brgerst@gmail.com, mingo@kernel.org, linux-kernel@vger.kernel.org, jann@thejh.net, jpoimboe@redhat.com, luto@kernel.org, hpa@zytor.com, peterz@infradead.org Reply-To: brgerst@gmail.com, mingo@kernel.org, jpoimboe@redhat.com, jann@thejh.net, linux-kernel@vger.kernel.org, peterz@infradead.org, hpa@zytor.com, luto@kernel.org, torvalds@linux-foundation.org, tglx@linutronix.de, dvlasenk@redhat.com, oleg@redhat.com, bp@alien8.de In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] kthread: Pin the stack via try_get_task_stack()/put_task_stack() in to_live_kthread() function Git-Commit-ID: 23196f2e5f5d810578a772785807dcdc2b9fdce9 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: 23196f2e5f5d810578a772785807dcdc2b9fdce9 Gitweb: http://git.kernel.org/tip/23196f2e5f5d810578a772785807dcdc2b9fdce9 Author: Oleg Nesterov AuthorDate: Thu, 15 Sep 2016 22:45:44 -0700 Committer: Ingo Molnar CommitDate: Fri, 16 Sep 2016 09:18:53 +0200 kthread: Pin the stack via try_get_task_stack()/put_task_stack() in to_live_kthread() function get_task_struct(tsk) no longer pins tsk->stack so all users of to_live_kthread() should do try_get_task_stack/put_task_stack to protect "struct kthread" which lives on kthread's stack. TODO: Kill to_live_kthread(), perhaps we can even kill "struct kthread" too, and rework kthread_stop(), it can use task_work_add() to sync with the exiting kernel thread. Message-Id: <20160629180357.GA7178@redhat.com> Signed-off-by: Oleg Nesterov Signed-off-by: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Jann Horn Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/cb9b16bbc19d4aea4507ab0552e4644c1211d130.1474003868.git.luto@kernel.org Signed-off-by: Ingo Molnar --- kernel/kthread.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index 9ff173d..4ab4c37 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -64,7 +64,7 @@ static inline struct kthread *to_kthread(struct task_struct *k) static struct kthread *to_live_kthread(struct task_struct *k) { struct completion *vfork = ACCESS_ONCE(k->vfork_done); - if (likely(vfork)) + if (likely(vfork) && try_get_task_stack(k)) return __to_kthread(vfork); return NULL; } @@ -425,8 +425,10 @@ void kthread_unpark(struct task_struct *k) { struct kthread *kthread = to_live_kthread(k); - if (kthread) + if (kthread) { __kthread_unpark(k, kthread); + put_task_stack(k); + } } EXPORT_SYMBOL_GPL(kthread_unpark); @@ -455,6 +457,7 @@ int kthread_park(struct task_struct *k) wait_for_completion(&kthread->parked); } } + put_task_stack(k); ret = 0; } return ret; @@ -490,6 +493,7 @@ int kthread_stop(struct task_struct *k) __kthread_unpark(k, kthread); wake_up_process(k); wait_for_completion(&kthread->exited); + put_task_stack(k); } ret = k->exit_code; put_task_struct(k);