Skip to content

Commit 3afbbd9

Browse files
committed
qemu: Fall back to /dev/urandom if KVM RNG can't initialise
Initialising the KVM RNG can fail if KVM_CAP_PPC_HWRNG is not present, which happens on Power9 hosts prior to kernel commit: 7ef3d06f1bc4 ("powerpc/powernv/kvm: Use darn for H_RANDOM on Power9") Instead tell qemu to use the KVM RNG if present, but fallback to /dev/urandom if it is not available.
1 parent f351bcc commit 3afbbd9

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

lib/qemu.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ def qemu_main(qemu_machine, cpuinfo_platform, cpu, net, args):
175175

176176
extra_args = []
177177
if 'pseries' in qemu_machine:
178+
rng = '-object rng-random,filename=/dev/urandom,id=rng0 -device spapr-rng,rng=rng0'
178179
if accel == 'kvm':
179-
extra_args = ['-device spapr-rng,use-kvm=true']
180-
else:
181-
extra_args = ['-device spapr-rng,rng=rng0 -object rng-random,filename=/dev/urandom,id=rng0']
180+
rng += ',use-kvm=true'
181+
182+
extra_args += [rng]
182183

183184
host_mount = get_env_var('QEMU_HOST_MOUNT')
184185
if host_mount and not os.path.isdir(host_mount):

0 commit comments

Comments
 (0)