forked from armbian/linux-rockchip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
s390/archrandom: simplify back to earlier design and initialize earlier
commit e4f7440 upstream. s390x appears to present two RNG interfaces: - a "TRNG" that gathers entropy using some hardware function; and - a "DRBG" that takes in a seed and expands it. Previously, the TRNG was wired up to arch_get_random_{long,int}(), but it was observed that this was being called really frequently, resulting in high overhead. So it was changed to be wired up to arch_get_random_ seed_{long,int}(), which was a reasonable decision. Later on, the DRBG was then wired up to arch_get_random_{long,int}(), with a complicated buffer filling thread, to control overhead and rate. Fortunately, none of the performance issues matter much now. The RNG always attempts to use arch_get_random_seed_{long,int}() first, which means a complicated implementation of arch_get_random_{long,int}() isn't really valuable or useful to have around. And it's only used when reseeding, which means it won't hit the high throughput complications that were faced before. So this commit returns to an earlier design of just calling the TRNG in arch_get_random_seed_{long,int}(), and returning false in arch_get_ random_{long,int}(). Part of what makes the simplification possible is that the RNG now seeds itself using the TRNG at bootup. But this only works if the TRNG is detected early in boot, before random_init() is called. So this commit also causes that check to happen in setup_arch(). Cc: [email protected] Cc: Harald Freudenberger <[email protected]> Cc: Ingo Franzki <[email protected]> Cc: Juergen Christ <[email protected]> Cc: Heiko Carstens <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Harald Freudenberger <[email protected]> Acked-by: Heiko Carstens <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
- Loading branch information
Showing
3 changed files
with
14 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/* | ||
* Kernel interface for the s390 arch_random_* functions | ||
* | ||
* Copyright IBM Corp. 2017 | ||
* Copyright IBM Corp. 2017, 2020 | ||
* | ||
* Author: Harald Freudenberger <[email protected]> | ||
* | ||
|
@@ -15,12 +15,11 @@ | |
|
||
#include <linux/static_key.h> | ||
#include <linux/atomic.h> | ||
#include <asm/cpacf.h> | ||
|
||
DECLARE_STATIC_KEY_FALSE(s390_arch_random_available); | ||
extern atomic64_t s390_arch_random_counter; | ||
|
||
bool s390_arch_random_generate(u8 *buf, unsigned int nbytes); | ||
|
||
static inline bool __must_check arch_get_random_long(unsigned long *v) | ||
{ | ||
return false; | ||
|
@@ -34,15 +33,19 @@ static inline bool __must_check arch_get_random_int(unsigned int *v) | |
static inline bool __must_check arch_get_random_seed_long(unsigned long *v) | ||
{ | ||
if (static_branch_likely(&s390_arch_random_available)) { | ||
return s390_arch_random_generate((u8 *)v, sizeof(*v)); | ||
cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v)); | ||
atomic64_add(sizeof(*v), &s390_arch_random_counter); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
static inline bool __must_check arch_get_random_seed_int(unsigned int *v) | ||
{ | ||
if (static_branch_likely(&s390_arch_random_available)) { | ||
return s390_arch_random_generate((u8 *)v, sizeof(*v)); | ||
cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v)); | ||
atomic64_add(sizeof(*v), &s390_arch_random_counter); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters