All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: Use RDRAND and RDSEED mnemonics in archrandom.h
@ 2020-05-08 10:58 Uros Bizjak
  2020-05-08 16:57 ` hpa
  2020-05-18 18:06 ` [tip: x86/cpu] x86/cpu: " tip-bot2 for Uros Bizjak
  0 siblings, 2 replies; 3+ messages in thread
From: Uros Bizjak @ 2020-05-08 10:58 UTC (permalink / raw)
  To: x86, linux-kernel
  Cc: Uros Bizjak, H. Peter Anvin, Ingo Molnar, Thomas Gleixner

Current minimum required version of binutils is 2.23,
which supports RDRAND and RDSEED instruction mnemonics.

Replace the byte-wise specification of RDRAND and
RDSEED with these proper mnemonics.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Ingo Molnar <mingo@redhat.com>
CC: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/include/asm/archrandom.h | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/archrandom.h b/arch/x86/include/asm/archrandom.h
index 7a4bb1bd4bdb..ebc248e49549 100644
--- a/arch/x86/include/asm/archrandom.h
+++ b/arch/x86/include/asm/archrandom.h
@@ -15,16 +15,6 @@
 
 #define RDRAND_RETRY_LOOPS	10
 
-#define RDRAND_INT	".byte 0x0f,0xc7,0xf0"
-#define RDSEED_INT	".byte 0x0f,0xc7,0xf8"
-#ifdef CONFIG_X86_64
-# define RDRAND_LONG	".byte 0x48,0x0f,0xc7,0xf0"
-# define RDSEED_LONG	".byte 0x48,0x0f,0xc7,0xf8"
-#else
-# define RDRAND_LONG	RDRAND_INT
-# define RDSEED_LONG	RDSEED_INT
-#endif
-
 /* Unconditional execution of RDRAND and RDSEED */
 
 static inline bool __must_check rdrand_long(unsigned long *v)
@@ -32,9 +22,9 @@ static inline bool __must_check rdrand_long(unsigned long *v)
 	bool ok;
 	unsigned int retry = RDRAND_RETRY_LOOPS;
 	do {
-		asm volatile(RDRAND_LONG
+		asm volatile("rdrand %[out]"
 			     CC_SET(c)
-			     : CC_OUT(c) (ok), "=a" (*v));
+			     : CC_OUT(c) (ok), [out] "=r" (*v));
 		if (ok)
 			return true;
 	} while (--retry);
@@ -46,9 +36,9 @@ static inline bool __must_check rdrand_int(unsigned int *v)
 	bool ok;
 	unsigned int retry = RDRAND_RETRY_LOOPS;
 	do {
-		asm volatile(RDRAND_INT
+		asm volatile("rdrand %[out]"
 			     CC_SET(c)
-			     : CC_OUT(c) (ok), "=a" (*v));
+			     : CC_OUT(c) (ok), [out] "=r" (*v));
 		if (ok)
 			return true;
 	} while (--retry);
@@ -58,18 +48,18 @@ static inline bool __must_check rdrand_int(unsigned int *v)
 static inline bool __must_check rdseed_long(unsigned long *v)
 {
 	bool ok;
-	asm volatile(RDSEED_LONG
+	asm volatile("rdseed %[out]"
 		     CC_SET(c)
-		     : CC_OUT(c) (ok), "=a" (*v));
+		     : CC_OUT(c) (ok), [out] "=r" (*v));
 	return ok;
 }
 
 static inline bool __must_check rdseed_int(unsigned int *v)
 {
 	bool ok;
-	asm volatile(RDSEED_INT
+	asm volatile("rdseed %[out]"
 		     CC_SET(c)
-		     : CC_OUT(c) (ok), "=a" (*v));
+		     : CC_OUT(c) (ok), [out] "=r" (*v));
 	return ok;
 }
 
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86: Use RDRAND and RDSEED mnemonics in archrandom.h
  2020-05-08 10:58 [PATCH] x86: Use RDRAND and RDSEED mnemonics in archrandom.h Uros Bizjak
@ 2020-05-08 16:57 ` hpa
  2020-05-18 18:06 ` [tip: x86/cpu] x86/cpu: " tip-bot2 for Uros Bizjak
  1 sibling, 0 replies; 3+ messages in thread
From: hpa @ 2020-05-08 16:57 UTC (permalink / raw)
  To: Uros Bizjak, x86, linux-kernel; +Cc: Ingo Molnar, Thomas Gleixner

On May 8, 2020 3:58:17 AM PDT, Uros Bizjak <ubizjak@gmail.com> wrote:
>Current minimum required version of binutils is 2.23,
>which supports RDRAND and RDSEED instruction mnemonics.
>
>Replace the byte-wise specification of RDRAND and
>RDSEED with these proper mnemonics.
>
>Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
>CC: "H. Peter Anvin" <hpa@zytor.com>
>CC: Ingo Molnar <mingo@redhat.com>
>CC: Thomas Gleixner <tglx@linutronix.de>
>---
> arch/x86/include/asm/archrandom.h | 26 ++++++++------------------
> 1 file changed, 8 insertions(+), 18 deletions(-)
>
>diff --git a/arch/x86/include/asm/archrandom.h
>b/arch/x86/include/asm/archrandom.h
>index 7a4bb1bd4bdb..ebc248e49549 100644
>--- a/arch/x86/include/asm/archrandom.h
>+++ b/arch/x86/include/asm/archrandom.h
>@@ -15,16 +15,6 @@
> 
> #define RDRAND_RETRY_LOOPS	10
> 
>-#define RDRAND_INT	".byte 0x0f,0xc7,0xf0"
>-#define RDSEED_INT	".byte 0x0f,0xc7,0xf8"
>-#ifdef CONFIG_X86_64
>-# define RDRAND_LONG	".byte 0x48,0x0f,0xc7,0xf0"
>-# define RDSEED_LONG	".byte 0x48,0x0f,0xc7,0xf8"
>-#else
>-# define RDRAND_LONG	RDRAND_INT
>-# define RDSEED_LONG	RDSEED_INT
>-#endif
>-
> /* Unconditional execution of RDRAND and RDSEED */
> 
> static inline bool __must_check rdrand_long(unsigned long *v)
>@@ -32,9 +22,9 @@ static inline bool __must_check rdrand_long(unsigned
>long *v)
> 	bool ok;
> 	unsigned int retry = RDRAND_RETRY_LOOPS;
> 	do {
>-		asm volatile(RDRAND_LONG
>+		asm volatile("rdrand %[out]"
> 			     CC_SET(c)
>-			     : CC_OUT(c) (ok), "=a" (*v));
>+			     : CC_OUT(c) (ok), [out] "=r" (*v));
> 		if (ok)
> 			return true;
> 	} while (--retry);
>@@ -46,9 +36,9 @@ static inline bool __must_check rdrand_int(unsigned
>int *v)
> 	bool ok;
> 	unsigned int retry = RDRAND_RETRY_LOOPS;
> 	do {
>-		asm volatile(RDRAND_INT
>+		asm volatile("rdrand %[out]"
> 			     CC_SET(c)
>-			     : CC_OUT(c) (ok), "=a" (*v));
>+			     : CC_OUT(c) (ok), [out] "=r" (*v));
> 		if (ok)
> 			return true;
> 	} while (--retry);
>@@ -58,18 +48,18 @@ static inline bool __must_check rdrand_int(unsigned
>int *v)
> static inline bool __must_check rdseed_long(unsigned long *v)
> {
> 	bool ok;
>-	asm volatile(RDSEED_LONG
>+	asm volatile("rdseed %[out]"
> 		     CC_SET(c)
>-		     : CC_OUT(c) (ok), "=a" (*v));
>+		     : CC_OUT(c) (ok), [out] "=r" (*v));
> 	return ok;
> }
> 
> static inline bool __must_check rdseed_int(unsigned int *v)
> {
> 	bool ok;
>-	asm volatile(RDSEED_INT
>+	asm volatile("rdseed %[out]"
> 		     CC_SET(c)
>-		     : CC_OUT(c) (ok), "=a" (*v));
>+		     : CC_OUT(c) (ok), [out] "=r" (*v));
> 	return ok;
> }
> 

Reviewed-by: H. Peter Anvin (Intel) <hpa@zytor.com>
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: x86/cpu] x86/cpu: Use RDRAND and RDSEED mnemonics in archrandom.h
  2020-05-08 10:58 [PATCH] x86: Use RDRAND and RDSEED mnemonics in archrandom.h Uros Bizjak
  2020-05-08 16:57 ` hpa
@ 2020-05-18 18:06 ` tip-bot2 for Uros Bizjak
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2020-05-18 18:06 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Uros Bizjak, Borislav Petkov, H. Peter Anvin (Intel),
	Peter Zijlstra (Intel),
	x86, LKML

The following commit has been merged into the x86/cpu branch of tip:

Commit-ID:     3d81b3d1e55a518837c3d1f722c6d93abe34aa85
Gitweb:        https://git.kernel.org/tip/3d81b3d1e55a518837c3d1f722c6d93abe34aa85
Author:        Uros Bizjak <ubizjak@gmail.com>
AuthorDate:    Fri, 08 May 2020 12:58:17 +02:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Mon, 18 May 2020 19:50:47 +02:00

x86/cpu: Use RDRAND and RDSEED mnemonics in archrandom.h

Current minimum required version of binutils is 2.23,
which supports RDRAND and RDSEED instruction mnemonics.

Replace the byte-wise specification of RDRAND and
RDSEED with these proper mnemonics.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200508105817.207887-1-ubizjak@gmail.com
---
 arch/x86/include/asm/archrandom.h | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/archrandom.h b/arch/x86/include/asm/archrandom.h
index 7a4bb1b..ebc248e 100644
--- a/arch/x86/include/asm/archrandom.h
+++ b/arch/x86/include/asm/archrandom.h
@@ -15,16 +15,6 @@
 
 #define RDRAND_RETRY_LOOPS	10
 
-#define RDRAND_INT	".byte 0x0f,0xc7,0xf0"
-#define RDSEED_INT	".byte 0x0f,0xc7,0xf8"
-#ifdef CONFIG_X86_64
-# define RDRAND_LONG	".byte 0x48,0x0f,0xc7,0xf0"
-# define RDSEED_LONG	".byte 0x48,0x0f,0xc7,0xf8"
-#else
-# define RDRAND_LONG	RDRAND_INT
-# define RDSEED_LONG	RDSEED_INT
-#endif
-
 /* Unconditional execution of RDRAND and RDSEED */
 
 static inline bool __must_check rdrand_long(unsigned long *v)
@@ -32,9 +22,9 @@ static inline bool __must_check rdrand_long(unsigned long *v)
 	bool ok;
 	unsigned int retry = RDRAND_RETRY_LOOPS;
 	do {
-		asm volatile(RDRAND_LONG
+		asm volatile("rdrand %[out]"
 			     CC_SET(c)
-			     : CC_OUT(c) (ok), "=a" (*v));
+			     : CC_OUT(c) (ok), [out] "=r" (*v));
 		if (ok)
 			return true;
 	} while (--retry);
@@ -46,9 +36,9 @@ static inline bool __must_check rdrand_int(unsigned int *v)
 	bool ok;
 	unsigned int retry = RDRAND_RETRY_LOOPS;
 	do {
-		asm volatile(RDRAND_INT
+		asm volatile("rdrand %[out]"
 			     CC_SET(c)
-			     : CC_OUT(c) (ok), "=a" (*v));
+			     : CC_OUT(c) (ok), [out] "=r" (*v));
 		if (ok)
 			return true;
 	} while (--retry);
@@ -58,18 +48,18 @@ static inline bool __must_check rdrand_int(unsigned int *v)
 static inline bool __must_check rdseed_long(unsigned long *v)
 {
 	bool ok;
-	asm volatile(RDSEED_LONG
+	asm volatile("rdseed %[out]"
 		     CC_SET(c)
-		     : CC_OUT(c) (ok), "=a" (*v));
+		     : CC_OUT(c) (ok), [out] "=r" (*v));
 	return ok;
 }
 
 static inline bool __must_check rdseed_int(unsigned int *v)
 {
 	bool ok;
-	asm volatile(RDSEED_INT
+	asm volatile("rdseed %[out]"
 		     CC_SET(c)
-		     : CC_OUT(c) (ok), "=a" (*v));
+		     : CC_OUT(c) (ok), [out] "=r" (*v));
 	return ok;
 }
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-18 18:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 10:58 [PATCH] x86: Use RDRAND and RDSEED mnemonics in archrandom.h Uros Bizjak
2020-05-08 16:57 ` hpa
2020-05-18 18:06 ` [tip: x86/cpu] x86/cpu: " tip-bot2 for Uros Bizjak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.