diff options
| author | Michael Ellerman <michael@ellerman.id.au> | 2015-03-20 05:39:41 -0400 |
|---|---|---|
| committer | Alexander Graf <agraf@suse.de> | 2015-04-21 09:21:29 -0400 |
| commit | e928e9cb3601ce240189bfea05b67ebd391c85ae (patch) | |
| tree | d76d6501bea8ffe04a448e5a5660d8926f22b3b4 /arch/powerpc/include | |
| parent | 99342cf8044420eebdf9297ca03a14cb6a7085a1 (diff) | |
KVM: PPC: Book3S HV: Add fast real-mode H_RANDOM implementation.
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>
Diffstat (limited to 'arch/powerpc/include')
| -rw-r--r-- | arch/powerpc/include/asm/archrandom.h | 11 | ||||
| -rw-r--r-- | arch/powerpc/include/asm/kvm_ppc.h | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/arch/powerpc/include/asm/archrandom.h b/arch/powerpc/include/asm/archrandom.h index bde531103638..0cc6eedc4780 100644 --- a/arch/powerpc/include/asm/archrandom.h +++ b/arch/powerpc/include/asm/archrandom.h | |||
| @@ -30,8 +30,6 @@ static inline int arch_has_random(void) | |||
| 30 | return !!ppc_md.get_random_long; | 30 | return !!ppc_md.get_random_long; |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | int powernv_get_random_long(unsigned long *v); | ||
| 34 | |||
| 35 | static inline int arch_get_random_seed_long(unsigned long *v) | 33 | static inline int arch_get_random_seed_long(unsigned long *v) |
| 36 | { | 34 | { |
| 37 | return 0; | 35 | return 0; |
| @@ -47,4 +45,13 @@ static inline int arch_has_random_seed(void) | |||
| 47 | 45 | ||
| 48 | #endif /* CONFIG_ARCH_RANDOM */ | 46 | #endif /* CONFIG_ARCH_RANDOM */ |
| 49 | 47 | ||
| 48 | #ifdef CONFIG_PPC_POWERNV | ||
| 49 | int powernv_hwrng_present(void); | ||
| 50 | int powernv_get_random_long(unsigned long *v); | ||
| 51 | int powernv_get_random_real_mode(unsigned long *v); | ||
| 52 | #else | ||
| 53 | static inline int powernv_hwrng_present(void) { return 0; } | ||
| 54 | static inline int powernv_get_random_real_mode(unsigned long *v) { return 0; } | ||
| 55 | #endif | ||
| 56 | |||
| 50 | #endif /* _ASM_POWERPC_ARCHRANDOM_H */ | 57 | #endif /* _ASM_POWERPC_ARCHRANDOM_H */ |
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 46bf652c9169..b8475daad884 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h | |||
| @@ -302,6 +302,8 @@ static inline bool is_kvmppc_hv_enabled(struct kvm *kvm) | |||
| 302 | return kvm->arch.kvm_ops == kvmppc_hv_ops; | 302 | return kvm->arch.kvm_ops == kvmppc_hv_ops; |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | extern int kvmppc_hwrng_present(void); | ||
| 306 | |||
| 305 | /* | 307 | /* |
| 306 | * Cuts out inst bits with ordering according to spec. | 308 | * Cuts out inst bits with ordering according to spec. |
| 307 | * That means the leftmost bit is zero. All given bits are included. | 309 | * That means the leftmost bit is zero. All given bits are included. |
