hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/arch/x86/include/asm/archrandom.h
....@@ -1,23 +1,10 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * This file is part of the Linux kernel.
34 *
45 * Copyright (c) 2011-2014, Intel Corporation
56 * Authors: Fenghua Yu <fenghua.yu@intel.com>,
67 * H. Peter Anvin <hpa@linux.intel.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify it
9
- * under the terms and conditions of the GNU General Public License,
10
- * version 2, as published by the Free Software Foundation.
11
- *
12
- * This program is distributed in the hope it will be useful, but WITHOUT
13
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
- * more details.
16
- *
17
- * You should have received a copy of the GNU General Public License along with
18
- * this program; if not, write to the Free Software Foundation, Inc.,
19
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20
- *
218 */
229
2310 #ifndef ASM_X86_ARCHRANDOM_H
....@@ -28,67 +15,53 @@
2815
2916 #define RDRAND_RETRY_LOOPS 10
3017
31
-#define RDRAND_INT ".byte 0x0f,0xc7,0xf0"
32
-#define RDSEED_INT ".byte 0x0f,0xc7,0xf8"
33
-#ifdef CONFIG_X86_64
34
-# define RDRAND_LONG ".byte 0x48,0x0f,0xc7,0xf0"
35
-# define RDSEED_LONG ".byte 0x48,0x0f,0xc7,0xf8"
36
-#else
37
-# define RDRAND_LONG RDRAND_INT
38
-# define RDSEED_LONG RDSEED_INT
39
-#endif
40
-
4118 /* Unconditional execution of RDRAND and RDSEED */
4219
43
-static inline bool rdrand_long(unsigned long *v)
20
+static inline bool __must_check rdrand_long(unsigned long *v)
4421 {
4522 bool ok;
4623 unsigned int retry = RDRAND_RETRY_LOOPS;
4724 do {
48
- asm volatile(RDRAND_LONG
25
+ asm volatile("rdrand %[out]"
4926 CC_SET(c)
50
- : CC_OUT(c) (ok), "=a" (*v));
27
+ : CC_OUT(c) (ok), [out] "=r" (*v));
5128 if (ok)
5229 return true;
5330 } while (--retry);
5431 return false;
5532 }
5633
57
-static inline bool rdrand_int(unsigned int *v)
34
+static inline bool __must_check rdrand_int(unsigned int *v)
5835 {
5936 bool ok;
6037 unsigned int retry = RDRAND_RETRY_LOOPS;
6138 do {
62
- asm volatile(RDRAND_INT
39
+ asm volatile("rdrand %[out]"
6340 CC_SET(c)
64
- : CC_OUT(c) (ok), "=a" (*v));
41
+ : CC_OUT(c) (ok), [out] "=r" (*v));
6542 if (ok)
6643 return true;
6744 } while (--retry);
6845 return false;
6946 }
7047
71
-static inline bool rdseed_long(unsigned long *v)
48
+static inline bool __must_check rdseed_long(unsigned long *v)
7249 {
7350 bool ok;
74
- asm volatile(RDSEED_LONG
51
+ asm volatile("rdseed %[out]"
7552 CC_SET(c)
76
- : CC_OUT(c) (ok), "=a" (*v));
53
+ : CC_OUT(c) (ok), [out] "=r" (*v));
7754 return ok;
7855 }
7956
80
-static inline bool rdseed_int(unsigned int *v)
57
+static inline bool __must_check rdseed_int(unsigned int *v)
8158 {
8259 bool ok;
83
- asm volatile(RDSEED_INT
60
+ asm volatile("rdseed %[out]"
8461 CC_SET(c)
85
- : CC_OUT(c) (ok), "=a" (*v));
62
+ : CC_OUT(c) (ok), [out] "=r" (*v));
8663 return ok;
8764 }
88
-
89
-/* Conditional execution based on CPU type */
90
-#define arch_has_random() static_cpu_has(X86_FEATURE_RDRAND)
91
-#define arch_has_random_seed() static_cpu_has(X86_FEATURE_RDSEED)
9265
9366 /*
9467 * These are the generic interfaces; they must not be declared if the
....@@ -97,24 +70,24 @@
9770 */
9871 #ifdef CONFIG_ARCH_RANDOM
9972
100
-static inline bool arch_get_random_long(unsigned long *v)
73
+static inline bool __must_check arch_get_random_long(unsigned long *v)
10174 {
102
- return arch_has_random() ? rdrand_long(v) : false;
75
+ return static_cpu_has(X86_FEATURE_RDRAND) ? rdrand_long(v) : false;
10376 }
10477
105
-static inline bool arch_get_random_int(unsigned int *v)
78
+static inline bool __must_check arch_get_random_int(unsigned int *v)
10679 {
107
- return arch_has_random() ? rdrand_int(v) : false;
80
+ return static_cpu_has(X86_FEATURE_RDRAND) ? rdrand_int(v) : false;
10881 }
10982
110
-static inline bool arch_get_random_seed_long(unsigned long *v)
83
+static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
11184 {
112
- return arch_has_random_seed() ? rdseed_long(v) : false;
85
+ return static_cpu_has(X86_FEATURE_RDSEED) ? rdseed_long(v) : false;
11386 }
11487
115
-static inline bool arch_get_random_seed_int(unsigned int *v)
88
+static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
11689 {
117
- return arch_has_random_seed() ? rdseed_int(v) : false;
90
+ return static_cpu_has(X86_FEATURE_RDSEED) ? rdseed_int(v) : false;
11891 }
11992
12093 extern void x86_init_rdrand(struct cpuinfo_x86 *c);