From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751953AbcF2SE2 (ORCPT ); Wed, 29 Jun 2016 14:04:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44537 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751525AbcF2SE1 (ORCPT ); Wed, 29 Jun 2016 14:04:27 -0400 Date: Wed, 29 Jun 2016 20:03:58 +0200 From: Oleg Nesterov To: Andy Lutomirski Cc: Andy Lutomirski , Linus Torvalds , Peter Zijlstra , Tejun Heo , LKP , LKML , kernel test robot Subject: [PATCH] kthread: to_live_kthread() needs try_get_task_stack() Message-ID: <20160629180357.GA7178@redhat.com> References: <20160627145443.GA17145@redhat.com> <20160627170010.GA21628@redhat.com> <20160628185853.GA3998@redhat.com> <20160628201249.GA12471@redhat.com> <20160628225929.GB8591@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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.25]); Wed, 29 Jun 2016 18:04:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/29, Andy Lutomirski wrote: > > I pushed that change to my tree (seems to work well enough to boot > without warnings as long as I don't unmount XFS, but not particularly > well tested). Want to refresh your patch on top? Please see the trivial fix below. Compile tested, but looks obvious. Btw, why free_thread_stack() calls vfree() with irqs disabled? Doesn't look good and perhaps even wrong; at least vmap_debug_free_range() does flush_tlb_kernel_range() and smp_call_function() can deadlock? ------------------------------------------------------------------------------- Subject: [PATCH] kthread: to_live_kthread() needs try_get_task_stack() 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. Signed-off-by: Oleg Nesterov --- 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); -- 2.5.0