lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5306DC49.4060603@zytor.com>
Date:	Thu, 20 Feb 2014 20:55:37 -0800
From:	"H. Peter Anvin" <hpa@...or.com>
To:	behanw@...verseincode.com, tglx@...utronix.de, mingo@...hat.com,
	x86@...nel.org, peterz@...radead.org, ak@...ux.intel.com,
	oleg@...hat.com
CC:	akpm@...ux-foundation.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] x86: LLVMLinux: Reimplement current_stack_pointer without
 register usage.

This seems like really deep magic when looking at it... at the very 
least, this needs to be very carefully commented, including why it works 
on the various platforms.

How much does this actually affect the output?  I only see three uses of 
current_stack_pointer:

/* how to get the thread information struct from C */
static inline struct thread_info *current_thread_info(void)
{
         return (struct thread_info *)
                 (current_stack_pointer & ~(THREAD_SIZE - 1));
}

... here we need the mov anyway, because we have to then AND it with a 
mask, which we obviously can't do inside the stack pointer.

kernel/irq_32.c:        irqctx->tinfo.previous_esp = current_stack_pointer;

(two times)

Here we are moving it into a memory variable anyway, which the "=g" 
constraint should allow.

So I see no evidence this is more efficient in any way.

	-hpa


On 02/20/2014 08:44 PM, behanw@...verseincode.com wrote:
> From: Behan Webster <behanw@...verseincode.com>
>
> Use asm to make the globally named register work again for gcc and clang.
> Much more efficient than copying the stack pointer to a variable and back again.
>
> Signed-off-by: Behan Webster <behanw@...verseincode.com>
> ---
>   arch/x86/include/asm/thread_info.h | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
> index e1940c0..e27ccc1 100644
> --- a/arch/x86/include/asm/thread_info.h
> +++ b/arch/x86/include/asm/thread_info.h
> @@ -163,10 +163,10 @@ struct thread_info {
>    */
>   #ifndef __ASSEMBLY__
>
> -#define current_stack_pointer ({		\
> -	unsigned long sp;			\
> -	asm("mov %%esp,%0" : "=g" (sp));	\
> -	sp;					\
> +#define current_stack_pointer ({			\
> +	register unsigned long sp asm("esp") __used;	\
> +	asm("" : "=r" (sp));				\
> +	sp;						\
>   })
>
>   /* how to get the thread information struct from C */
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ