forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/arch/x86/kernel/cpu/rdrand.c
....@@ -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, 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 #include <asm/processor.h>
....@@ -42,7 +29,8 @@
4229 #ifdef CONFIG_ARCH_RANDOM
4330 void x86_init_rdrand(struct cpuinfo_x86 *c)
4431 {
45
- unsigned long tmp;
32
+ unsigned int changed = 0;
33
+ unsigned long tmp, prev;
4634 int i;
4735
4836 if (!cpu_has(c, X86_FEATURE_RDRAND))
....@@ -55,5 +43,24 @@
5543 return;
5644 }
5745 }
46
+
47
+ /*
48
+ * Stupid sanity-check whether RDRAND does *actually* generate
49
+ * some at least random-looking data.
50
+ */
51
+ prev = tmp;
52
+ for (i = 0; i < SANITY_CHECK_LOOPS; i++) {
53
+ if (rdrand_long(&tmp)) {
54
+ if (prev != tmp)
55
+ changed++;
56
+
57
+ prev = tmp;
58
+ }
59
+ }
60
+
61
+ if (WARN_ON_ONCE(!changed))
62
+ pr_emerg(
63
+"RDRAND gives funky smelling output, might consider not using it by booting with \"nordrand\"");
64
+
5865 }
5966 #endif