Skip to content

Commit 3d81b3d

Browse files
ubizjaksuryasaimadhu
authored andcommitted
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 <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: H. Peter Anvin (Intel) <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 7e32a9d commit 3d81b3d

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

arch/x86/include/asm/archrandom.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,16 @@
1515

1616
#define RDRAND_RETRY_LOOPS 10
1717

18-
#define RDRAND_INT ".byte 0x0f,0xc7,0xf0"
19-
#define RDSEED_INT ".byte 0x0f,0xc7,0xf8"
20-
#ifdef CONFIG_X86_64
21-
# define RDRAND_LONG ".byte 0x48,0x0f,0xc7,0xf0"
22-
# define RDSEED_LONG ".byte 0x48,0x0f,0xc7,0xf8"
23-
#else
24-
# define RDRAND_LONG RDRAND_INT
25-
# define RDSEED_LONG RDSEED_INT
26-
#endif
27-
2818
/* Unconditional execution of RDRAND and RDSEED */
2919

3020
static inline bool __must_check rdrand_long(unsigned long *v)
3121
{
3222
bool ok;
3323
unsigned int retry = RDRAND_RETRY_LOOPS;
3424
do {
35-
asm volatile(RDRAND_LONG
25+
asm volatile("rdrand %[out]"
3626
CC_SET(c)
37-
: CC_OUT(c) (ok), "=a" (*v));
27+
: CC_OUT(c) (ok), [out] "=r" (*v));
3828
if (ok)
3929
return true;
4030
} while (--retry);
@@ -46,9 +36,9 @@ static inline bool __must_check rdrand_int(unsigned int *v)
4636
bool ok;
4737
unsigned int retry = RDRAND_RETRY_LOOPS;
4838
do {
49-
asm volatile(RDRAND_INT
39+
asm volatile("rdrand %[out]"
5040
CC_SET(c)
51-
: CC_OUT(c) (ok), "=a" (*v));
41+
: CC_OUT(c) (ok), [out] "=r" (*v));
5242
if (ok)
5343
return true;
5444
} while (--retry);
@@ -58,18 +48,18 @@ static inline bool __must_check rdrand_int(unsigned int *v)
5848
static inline bool __must_check rdseed_long(unsigned long *v)
5949
{
6050
bool ok;
61-
asm volatile(RDSEED_LONG
51+
asm volatile("rdseed %[out]"
6252
CC_SET(c)
63-
: CC_OUT(c) (ok), "=a" (*v));
53+
: CC_OUT(c) (ok), [out] "=r" (*v));
6454
return ok;
6555
}
6656

6757
static inline bool __must_check rdseed_int(unsigned int *v)
6858
{
6959
bool ok;
70-
asm volatile(RDSEED_INT
60+
asm volatile("rdseed %[out]"
7161
CC_SET(c)
72-
: CC_OUT(c) (ok), "=a" (*v));
62+
: CC_OUT(c) (ok), [out] "=r" (*v));
7363
return ok;
7464
}
7565

0 commit comments

Comments
 (0)