From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbcF0Q7f (ORCPT ); Mon, 27 Jun 2016 12:59:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34004 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751601AbcF0Q7e (ORCPT ); Mon, 27 Jun 2016 12:59:34 -0400 Date: Mon, 27 Jun 2016 19:00:10 +0200 From: Oleg Nesterov To: Andy Lutomirski Cc: Andy Lutomirski , Linus Torvalds , Peter Zijlstra , Tejun Heo , LKP , LKML , kernel test robot Subject: Re: kthread_stop insanity (Re: [[DEBUG] force] 2642458962: BUG: unable to handle kernel paging request at ffffc90000997f18) Message-ID: <20160627170010.GA21628@redhat.com> References: <20160627145443.GA17145@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 27 Jun 2016 16:59:33 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/27, Andy Lutomirski wrote: > > On Mon, Jun 27, 2016 at 7:54 AM, Oleg Nesterov wrote: > > > >> Is there seriously no way to directly wait for a struct task_struct to > >> exit? Could we, say, kmalloc the completion (or maybe even the whole > >> struct kthread) and (ick!) hang it off ->vfork_done? > > > > Sure we can... And yes, I think we need to alloc the whole struct kthread. > > Just another (unfortunate) complication, the current code is simple. > > > > And probably kthread/kthread_stop should switch to task_work_exit(). > > Want to send a patch? I could do it, but you understand this code > much better than I do. Well, I'll try to do this tomorrow unless you do it. The problem is not the wait_for_completion(vfork_done) in kthread_stop(), we can avoid this immediately if we change it to use task_work_add(). The problem is to_live_kthread(). And damn, it seems to me that in the long term we can simpy kill "struct kthread" altogether. All we need is kthread_data() and this is just a pointer. flags,cpu,parked should go into smp_hotplug_thread. But this needs changes, so meanwhile we will have to kmalloc() it and free in free_task(). Or perhaps you can simply move "struct kthread" into task_struct as as temporary/ugly but trivial fix, then we can think more. Oleg.