Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751533AbdILU01 (ORCPT ); Tue, 12 Sep 2017 16:26:27 -0400 Received: from ppsw-33.csi.cam.ac.uk ([131.111.8.133]:40422 "EHLO ppsw-33.csi.cam.ac.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751105AbdILU0X (ORCPT ); Tue, 12 Sep 2017 16:26:23 -0400 X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://help.uis.cam.ac.uk/email-scanner-virus Subject: Re: [RFC 17/17] x86/traps: Use a new on_thread_stack() helper to clean up an assertion To: Josh Poimboeuf , Andy Lutomirski Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , Brian Gerst , Juergen Gross , Boris Ostrovsky , Kees Cook References: <20170912201140.gcnjxdpzxhg4nyi5@treble> From: Andrew Cooper Message-ID: <4b3d8ab1-6aaf-c5ff-0a66-e8a254fdfe45@citrix.com> Date: Tue, 12 Sep 2017 21:25:58 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170912201140.gcnjxdpzxhg4nyi5@treble> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1541 Lines: 42 On 12/09/2017 21:11, Josh Poimboeuf wrote: > On Wed, Sep 06, 2017 at 02:37:02PM -0700, Andy Lutomirski wrote: >> Signed-off-by: Andy Lutomirski >> --- >> arch/x86/include/asm/processor.h | 17 +++++++++++++++++ >> arch/x86/include/asm/thread_info.h | 11 ----------- >> arch/x86/kernel/traps.c | 3 +-- >> 3 files changed, 18 insertions(+), 13 deletions(-) >> >> diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h >> index 4c137472f530..b6f8dc11c222 100644 >> --- a/arch/x86/include/asm/processor.h >> +++ b/arch/x86/include/asm/processor.h >> @@ -534,6 +534,23 @@ static inline unsigned long current_top_of_stack(void) >> #endif >> } >> >> +static inline unsigned long current_stack_pointer(void) >> +{ >> + unsigned long sp; >> +#ifdef CONFIG_X86_64 >> + asm("mov %%rsp,%0" : "=g" (sp)); >> +#else >> + asm("mov %%esp,%0" : "=g" (sp)); >> +#endif >> + return sp; >> +} > I know you're just moving the function, but this function could also be > cleaned up by using _ASM_SP and getting rid of the ifdef. > For GCC, there is a rather more efficient way of doing this, which allows the compiler much more flexibility than forcing the use of a mov instruction. http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/include/asm-x86/current.h;h=89849929ebf98e9ba04659f59b5521982a718b2d;hb=HEAD#l47 I don't know how much you care in Linux, but in Xen it makes a massive code-volume difference, as that construct is the core of current (because we can't use %fs/%gs). ~Andrew