mirror of
https://github.com/torvalds/linux.git
synced 2024-12-18 17:12:55 +00:00
e928e9cb36
Some PowerNV systems include a hardware random-number generator. This HWRNG is present on POWER7+ and POWER8 chips and is capable of generating one 64-bit random number every microsecond. The random numbers are produced by sampling a set of 64 unstable high-frequency oscillators and are almost completely entropic. PAPR defines an H_RANDOM hypercall which guests can use to obtain one 64-bit random sample from the HWRNG. This adds a real-mode implementation of the H_RANDOM hypercall. This hypercall was implemented in real mode because the latency of reading the HWRNG is generally small compared to the latency of a guest exit and entry for all the threads in the same virtual core. Userspace can detect the presence of the HWRNG and the H_RANDOM implementation by querying the KVM_CAP_PPC_HWRNG capability. The H_RANDOM hypercall implementation will only be invoked when the guest does an H_RANDOM hypercall if userspace first enables the in-kernel H_RANDOM implementation using the KVM_CAP_PPC_ENABLE_HCALL capability. Signed-off-by: Michael Ellerman <michael@ellerman.id.au> Signed-off-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Alexander Graf <agraf@suse.de>
58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
#ifndef _ASM_POWERPC_ARCHRANDOM_H
|
|
#define _ASM_POWERPC_ARCHRANDOM_H
|
|
|
|
#ifdef CONFIG_ARCH_RANDOM
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
static inline int arch_get_random_long(unsigned long *v)
|
|
{
|
|
if (ppc_md.get_random_long)
|
|
return ppc_md.get_random_long(v);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static inline int arch_get_random_int(unsigned int *v)
|
|
{
|
|
unsigned long val;
|
|
int rc;
|
|
|
|
rc = arch_get_random_long(&val);
|
|
if (rc)
|
|
*v = val;
|
|
|
|
return rc;
|
|
}
|
|
|
|
static inline int arch_has_random(void)
|
|
{
|
|
return !!ppc_md.get_random_long;
|
|
}
|
|
|
|
static inline int arch_get_random_seed_long(unsigned long *v)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline int arch_get_random_seed_int(unsigned int *v)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline int arch_has_random_seed(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
#endif /* CONFIG_ARCH_RANDOM */
|
|
|
|
#ifdef CONFIG_PPC_POWERNV
|
|
int powernv_hwrng_present(void);
|
|
int powernv_get_random_long(unsigned long *v);
|
|
int powernv_get_random_real_mode(unsigned long *v);
|
|
#else
|
|
static inline int powernv_hwrng_present(void) { return 0; }
|
|
static inline int powernv_get_random_real_mode(unsigned long *v) { return 0; }
|
|
#endif
|
|
|
|
#endif /* _ASM_POWERPC_ARCHRANDOM_H */
|