hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/s390/include/asm/archrandom.h
....@@ -2,7 +2,7 @@
22 /*
33 * Kernel interface for the s390 arch_random_* functions
44 *
5
- * Copyright IBM Corp. 2017
5
+ * Copyright IBM Corp. 2017, 2022
66 *
77 * Author: Harald Freudenberger <freude@de.ibm.com>
88 *
....@@ -14,47 +14,41 @@
1414 #ifdef CONFIG_ARCH_RANDOM
1515
1616 #include <linux/static_key.h>
17
+#include <linux/preempt.h>
1718 #include <linux/atomic.h>
19
+#include <asm/cpacf.h>
1820
1921 DECLARE_STATIC_KEY_FALSE(s390_arch_random_available);
2022 extern atomic64_t s390_arch_random_counter;
2123
22
-bool s390_arch_random_generate(u8 *buf, unsigned int nbytes);
23
-
24
-static inline bool arch_has_random(void)
24
+static inline bool __must_check arch_get_random_long(unsigned long *v)
2525 {
2626 return false;
2727 }
2828
29
-static inline bool arch_has_random_seed(void)
29
+static inline bool __must_check arch_get_random_int(unsigned int *v)
3030 {
31
- if (static_branch_likely(&s390_arch_random_available))
31
+ return false;
32
+}
33
+
34
+static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
35
+{
36
+ if (static_branch_likely(&s390_arch_random_available) &&
37
+ in_task()) {
38
+ cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v));
39
+ atomic64_add(sizeof(*v), &s390_arch_random_counter);
3240 return true;
33
- return false;
34
-}
35
-
36
-static inline bool arch_get_random_long(unsigned long *v)
37
-{
38
- return false;
39
-}
40
-
41
-static inline bool arch_get_random_int(unsigned int *v)
42
-{
43
- return false;
44
-}
45
-
46
-static inline bool arch_get_random_seed_long(unsigned long *v)
47
-{
48
- if (static_branch_likely(&s390_arch_random_available)) {
49
- return s390_arch_random_generate((u8 *)v, sizeof(*v));
5041 }
5142 return false;
5243 }
5344
54
-static inline bool arch_get_random_seed_int(unsigned int *v)
45
+static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
5546 {
56
- if (static_branch_likely(&s390_arch_random_available)) {
57
- return s390_arch_random_generate((u8 *)v, sizeof(*v));
47
+ if (static_branch_likely(&s390_arch_random_available) &&
48
+ in_task()) {
49
+ cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v));
50
+ atomic64_add(sizeof(*v), &s390_arch_random_counter);
51
+ return true;
5852 }
5953 return false;
6054 }