From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758744AbcH3WCR (ORCPT ); Tue, 30 Aug 2016 18:02:17 -0400 Received: from mail-ua0-f172.google.com ([209.85.217.172]:35219 "EHLO mail-ua0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758393AbcH3WCN (ORCPT ); Tue, 30 Aug 2016 18:02:13 -0400 MIME-Version: 1.0 In-Reply-To: <20160824165102.GB22613@jcartwri.amer.corp.natinst.com> References: <14c07d4fd173a5b117f51e8b939f9f4323e39899.1470907718.git.luto@kernel.org> <20160824165102.GB22613@jcartwri.amer.corp.natinst.com> From: Andy Lutomirski Date: Tue, 30 Aug 2016 15:01:51 -0700 Message-ID: Subject: Re: [PATCH v6 1/3] fork: Add generic vmalloced stack support To: Josh Cartwright Cc: Andy Lutomirski , X86 ML , Borislav Petkov , "linux-kernel@vger.kernel.org" , Brian Gerst , Oleg Nesterov Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 24, 2016 at 9:51 AM, Josh Cartwright wrote: > Hey Andy- > > Small non-critical/potential future optimization comment below: > > On Thu, Aug 11, 2016 at 02:35:21AM -0700, Andy Lutomirski wrote: >> If CONFIG_VMAP_STACK is selected, kernel stacks are allocated with >> vmalloc_node. >> >> grsecurity has had a similar feature (called >> GRKERNSEC_KSTACKOVERFLOW) for a long time. >> >> Cc: Oleg Nesterov >> Signed-off-by: Andy Lutomirski >> --- > [..] >> diff --git a/kernel/fork.c b/kernel/fork.c >> index 52e725d4a866..05f7ef796fb4 100644 >> --- a/kernel/fork.c >> +++ b/kernel/fork.c >> @@ -158,19 +158,39 @@ void __weak arch_release_thread_stack(unsigned long *stack) >> * Allocate pages if THREAD_SIZE is >= PAGE_SIZE, otherwise use a >> * kmemcache based allocator. >> */ >> -# if THREAD_SIZE >= PAGE_SIZE >> -static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, >> - int node) >> +# if THREAD_SIZE >= PAGE_SIZE || defined(CONFIG_VMAP_STACK) >> +static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) >> { >> +#ifdef CONFIG_VMAP_STACK >> + void *stack = __vmalloc_node_range(THREAD_SIZE, THREAD_SIZE, >> + VMALLOC_START, VMALLOC_END, >> + THREADINFO_GFP | __GFP_HIGHMEM, >> + PAGE_KERNEL, >> + 0, node, >> + __builtin_return_address(0)); >> + >> + /* >> + * We can't call find_vm_area() in interrupt context, and >> + * free_thread_stack can be called in interrupt context, so cache >> + * the vm_struct. >> + */ >> + if (stack) >> + tsk->stack_vm_area = find_vm_area(stack); > > This is annoying, we end up having to walk the vm_area tree twice (once > for the allocation, then here to get a handle on area). > > Perhaps it's time the vmalloc code learned an allocation API that > returned the vm_area handle as well. > Agreed. I may do this once everything else lands.