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: <20090429062222.GA22188@Krystal>
Date:	Wed, 29 Apr 2009 02:22:22 -0400
From:	Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca>
To:	mingo@...hat.com
Cc:	linux-kernel@...r.kernel.org, hpa@...or.com, tglx@...utronix.de,
	mingo@...e.hu, linux-tip-commits@...r.kernel.org
Subject: Re: [tip:x86/asm] x86: clean up alternative.h

* tip-bot for Mathieu Desnoyers (mathieu.desnoyers@...ymtl.ca) wrote:
> Commit-ID:  edc953fa4ebc0265ef3b1754fe116a9fd4264e15
> Gitweb:     http://git.kernel.org/tip/edc953fa4ebc0265ef3b1754fe116a9fd4264e15
> Author:     Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca>
> AuthorDate: Tue, 28 Apr 2009 11:13:46 -0400
> Committer:  Ingo Molnar <mingo@...e.hu>
> CommitDate: Tue, 28 Apr 2009 17:42:08 +0200
> 
> x86: clean up alternative.h
> 
> Alternative header duplicates assembly that could be merged in
> one single macro.  Merging this into this macro also allows to
> directly declare ALTERNATIVE() statements within assembly code.
> 
> Uses a __stringify() of the feature bits rather than passing a
> "i" operand.  Leave the old %0 operand as-is (set to 0), unused
> to stay compatible with API.
> 
> (v2: tab alignment fixes)
> 
> [ Impact: cleanup ]
> 
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca>
> LKML-Reference: <20090428151346.GA31212@...stal>
> Signed-off-by: Ingo Molnar <mingo@...e.hu>
> 
> 
> ---
>  arch/x86/include/asm/alternative.h |   59 ++++++++++++++----------------------
>  1 files changed, 23 insertions(+), 36 deletions(-)
> 
> diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
> index f6aa18e..1a37bcd 100644
> --- a/arch/x86/include/asm/alternative.h
> +++ b/arch/x86/include/asm/alternative.h
> @@ -3,6 +3,7 @@
>  
>  #include <linux/types.h>
>  #include <linux/stddef.h>
> +#include <linux/stringify.h>
>  #include <asm/asm.h>
>  
>  /*
> @@ -74,6 +75,22 @@ static inline void alternatives_smp_switch(int smp) {}
>  
>  const unsigned char *const *find_nop_table(void);
>  
> +/* alternative assembly primitive: */
> +#define ALTERNATIVE(oldinstr, newinstr, feature)			\
> +									\
> +      "661:\n\t" oldinstr "\n662:\n"					\
> +      ".section .altinstructions,\"a\"\n"				\
> +      _ASM_ALIGN "\n"							\
> +      _ASM_PTR "661b\n"				/* label           */	\
> +      _ASM_PTR "663f\n"				/* new instruction */	\
> +      "	 .byte " __stringify(feature) "\n"	/* feature bit     */	\
> +      "	 .byte 662b-661b\n"			/* sourcelen       */	\
> +      "	 .byte 664f-663f\n"			/* replacementlen  */	\

I posted an updated v3 this morning which removes the "tab" before each
of these .byte, as requested by Peter.

Mathieu

> +      ".previous\n"							\
> +      ".section .altinstr_replacement, \"ax\"\n"			\
> +      "663:\n\t" newinstr "\n664:\n"		/* replacement     */	\
> +      ".previous"
> +
>  /*
>   * Alternative instructions for different CPU types or capabilities.
>   *
> @@ -87,18 +104,7 @@ const unsigned char *const *find_nop_table(void);
>   * without volatile and memory clobber.
>   */
>  #define alternative(oldinstr, newinstr, feature)			\
> -	asm volatile ("661:\n\t" oldinstr "\n662:\n"			\
> -		      ".section .altinstructions,\"a\"\n"		\
> -		      _ASM_ALIGN "\n"					\
> -		      _ASM_PTR "661b\n"		/* label */		\
> -		      _ASM_PTR "663f\n"		/* new instruction */	\
> -		      "	 .byte %c0\n"		/* feature bit */	\
> -		      "	 .byte 662b-661b\n"	/* sourcelen */		\
> -		      "	 .byte 664f-663f\n"	/* replacementlen */	\
> -		      ".previous\n"					\
> -		      ".section .altinstr_replacement,\"ax\"\n"		\
> -		      "663:\n\t" newinstr "\n664:\n"  /* replacement */	\
> -		      ".previous" :: "i" (feature) : "memory")
> +	asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) : : : "memory")
>  
>  /*
>   * Alternative inline assembly with input.
> @@ -109,35 +115,16 @@ const unsigned char *const *find_nop_table(void);
>   * Best is to use constraints that are fixed size (like (%1) ... "r")
>   * If you use variable sized constraints like "m" or "g" in the
>   * replacement make sure to pad to the worst case length.
> + * Leaving an unused argument 0 to keep API compatibility.
>   */
>  #define alternative_input(oldinstr, newinstr, feature, input...)	\
> -	asm volatile ("661:\n\t" oldinstr "\n662:\n"			\
> -		      ".section .altinstructions,\"a\"\n"		\
> -		      _ASM_ALIGN "\n"					\
> -		      _ASM_PTR "661b\n"		/* label */		\
> -		      _ASM_PTR "663f\n"		/* new instruction */	\
> -		      "	 .byte %c0\n"		/* feature bit */	\
> -		      "	 .byte 662b-661b\n"	/* sourcelen */		\
> -		      "	 .byte 664f-663f\n"	/* replacementlen */	\
> -		      ".previous\n"					\
> -		      ".section .altinstr_replacement,\"ax\"\n"		\
> -		      "663:\n\t" newinstr "\n664:\n"  /* replacement */	\
> -		      ".previous" :: "i" (feature), ##input)
> +	asm volatile (ALTERNATIVE(oldinstr, newinstr, feature)		\
> +		: : "i" (0), ## input)
>  
>  /* Like alternative_input, but with a single output argument */
>  #define alternative_io(oldinstr, newinstr, feature, output, input...)	\
> -	asm volatile ("661:\n\t" oldinstr "\n662:\n"			\
> -		      ".section .altinstructions,\"a\"\n"		\
> -		      _ASM_ALIGN "\n"					\
> -		      _ASM_PTR "661b\n"		/* label */		\
> -		      _ASM_PTR "663f\n"		/* new instruction */	\
> -		      "	 .byte %c[feat]\n"	/* feature bit */	\
> -		      "	 .byte 662b-661b\n"	/* sourcelen */		\
> -		      "	 .byte 664f-663f\n"	/* replacementlen */	\
> -		      ".previous\n"					\
> -		      ".section .altinstr_replacement,\"ax\"\n"		\
> -		      "663:\n\t" newinstr "\n664:\n"  /* replacement */ \
> -		      ".previous" : output : [feat] "i" (feature), ##input)
> +	asm volatile (ALTERNATIVE(oldinstr, newinstr, feature)		\
> +		: output : "i" (0), ## input)
>  
>  /*
>   * use this macro(s) if you need more than one output parameter

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
--
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