From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752015AbbCSPr0 (ORCPT ); Thu, 19 Mar 2015 11:47:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40343 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751128AbbCSPrY (ORCPT ); Thu, 19 Mar 2015 11:47:24 -0400 Message-ID: <550AEF88.7020209@redhat.com> Date: Thu, 19 Mar 2015 16:47:20 +0100 From: Denys Vlasenko User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Andy Lutomirski CC: Linus Torvalds , Steven Rostedt , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Oleg Nesterov , Frederic Weisbecker , Alexei Starovoitov , Will Drewry , Kees Cook , X86 ML , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 1/3] x86: get rid of KERNEL_STACK_OFFSET References: <1426708056-2785-1-git-send-email-dvlasenk@redhat.com> <550AEB03.6010701@redhat.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/19/2015 04:43 PM, Andy Lutomirski wrote: > On Thu, Mar 19, 2015 at 8:28 AM, Denys Vlasenko wrote: >> On 03/18/2015 09:54 PM, Andy Lutomirski wrote: >>> On Wed, Mar 18, 2015 at 12:47 PM, Denys Vlasenko wrote: >>>> PER_CPU_VAR(kernel_stack) was set up in a way where it points >>>> five stack slots below the top of stack. >>>> >>>> Presumably, it was done to avoid one "sub $5*8,%rsp" >>>> in syscall/sysenter code paths, where iret frame needs to be >>>> created by hand. >>>> >>>> Ironically, none of them benefits from this optimization, >>>> since all of them need to allocate additional data on stack >>>> (struct pt_regs), so they still have to perform subtraction. >>>> >>>> This patch eliminates KERNEL_STACK_OFFSET. >>>> >>>> PER_CPU_VAR(kernel_stack) now points directly to top of stack. >>>> pt_regs allocations are adjusted to allocate iret frame as well. >>>> Hopefully we can merge it later with 32-bit specific >>>> PER_CPU_VAR(cpu_current_top_of_stack) variable... >>>> >>>> Semi-mysterious expressions THREAD_INFO(%rsp,RIP) - "why RIP??" >>>> are now replaced by more logical THREAD_INFO(%rsp,SIZEOF_PTREGS) - >>>> "calculate thread_info's address using information that >>>> rsp is SIZEOF_PTREGS bytes below the stack top". >>>> >>>> Net result in generated code is that constants in several insns >>>> are changed. >>>> >>>> This change is necessary for changing struct pt_regs creation >>>> in SYSCALL64 code path from MOV to PUSH instructions. >>>> >>> >>> Would it be reasonable to break this up into two pieces: first, remove >>> KERNEL_STACK_OFFSET from THREAD_INFO and related macros (i.e. make >>> them relative to current_top_of_stack instead) >> >> PER_CPU(cpu_current_top_of_stack) exists only in 32 bits. >> Can't use it in 64-bit code. >> >> PER_CPU(cpu_current_top_of_stack) becomes equal >> to PER_CPU(kernel_stack) only after this patch. > > You could have a #define that gives the top of the stack from asm, though. > >> >> I plan to clean up PER_CPU(cpu_current_top_of_stack)/ >> PER_CPU(kernel_stack)/PER_CPU(tss->sp0) mess >> on top of my patches. >> >> First: this seems to be the easier way. > > It's probably easier, but it's harder to review since you're making > two change at once (changing the rsp loaded during syscall and > changing the way that GET_THREAD_INFO works). I will split off the THREAD_INFO() change.