Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757871AbcJXQmX (ORCPT ); Mon, 24 Oct 2016 12:42:23 -0400 Received: from merlin.infradead.org ([205.233.59.134]:56670 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753766AbcJXQmV (ORCPT ); Mon, 24 Oct 2016 12:42:21 -0400 Date: Mon, 24 Oct 2016 18:42:18 +0200 From: Peter Zijlstra To: Roman Pen Cc: Andy Lutomirski , Oleg Nesterov , Thomas Gleixner , Ingo Molnar , Tejun Heo , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] kthread: allocate kthread structure using kmalloc Message-ID: <20161024164218.GT3102@twins.programming.kicks-ass.net> References: <20161024160814.3126-1-roman.penyaev@profitbricks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161024160814.3126-1-roman.penyaev@profitbricks.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1192 Lines: 34 On Mon, Oct 24, 2016 at 06:08:13PM +0200, Roman Pen wrote: > This patch avoids allocation of kthread structure on a stack, and simply > uses kmalloc. Allocation on a stack became a huge problem (with memory > corruption and all other not nice consequences) after the commit 2deb4be28 2deb4be28077 ("x86/dumpstack: When OOPSing, rewind the stack before do_exit()") Is the normal quoting style. .gitconfig: [core] abbrev = 12 [alias] one = show -s --pretty='format:%h (\"%s\")' > by Andy Lutomirski, which rewinds the stack on oops, thus ooopsed kthread > steps on a garbage memory while completion of task->vfork_done structure > on the following path: > > oops_end() > rewind_stack_do_exit() > exit_mm() > mm_release() > complete_vfork_done() > > Also in this patch two structures 'struct kthread_create_info' and > 'struct kthread' are merged into one 'struct kthread' and its freeing > is controlled by a reference counter. > > The last reference on kthread is put from a task work, the callback, > which is invoked from do_exit(). The major thing is that the last > put is happens *after* completion_vfork_done() is invoked. >