Bug 8816

Summary: Add support for paravirtualized hardware random number generator for qemu machines
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Cristian Iorga <cristian.iorga>
Component: virtual machinesAssignee: Saul Wold <sgw>
Status: RESOLVED FIXED QA Contact: Costin <costin.c.constantin>
Severity: enhancement    
Priority: Medium+ CC: alexandru.c.georgescu
Version: 2.1   
Target Milestone: 2.1 M3   
Hardware: Other   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know
Bug Depends on:    
Bug Blocks: 8681    

Description Cristian Iorga 2015-12-16 11:33:32 UTC
Add support for paravirtualized hardware random number generator for qemu machines

Qemu BSPs might end up not having enough entropy for normal OS/apps operation.

This might help fix the issue.
Comment 1 Cristian Iorga 2015-12-16 11:36:21 UTC
References:

1. About Random Numbers and Virtual Machines
http://log.amitshah.net/2013/01/about-random-numbers-and-virtual-machines/

2. QEMU Features-Done/VirtIORNG
http://wiki.qemu.org/Features-Done/VirtIORNG

3. QEMU/Devices/Virtio
https://en.wikibooks.org/wiki/QEMU/Devices/Virtio
Comment 2 Cristian Iorga 2015-12-18 16:38:18 UTC
Design started.
Comment 3 Cristian Iorga 2016-01-12 16:34:12 UTC
Implementation is dependent on Linux features that will be active in 4.4, so implementation is postponed until poky master switches to Linux 4.4.
Comment 4 Cristian Iorga 2016-01-29 18:11:18 UTC
Kernel config fragments:
CONFIG_HW_RANDOM=y
CONFIG_HW_RANDOM_VIRTIO=y

runqemu params:
runqemu qemux86-64 core-image-sato kvm qemuparams="-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"

Check paravirtualization:

cat /sys/devices/virtual/misc/hw_random/rng_available
cat /sys/devices/virtual/misc/hw_random/rng_current
cat /dev/hwrng

rng-tools are needed:

Link /dev/hwrng to /dev/random

rngd -r /dev/hwrng

RNG-tools

Source: http://sourceforge.net/projects/gkernel/files/rng-tools/
Other possible sources: https://qa.debian.org/cgi-bin/vcswatch?package=rng-tools

# rngd -r /dev/urandom
Takes from /dev/urandom (non-blocking) to generate entropy for /dev/random (blocking)

Links that might help:
https://wiki.archlinux.org/index.php/Rng-tools
http://security.stackexchange.com/questions/39992/is-it-safe-to-use-rng-tools-on-a-virtual-machine
Comment 5 Cristian Iorga 2016-01-29 18:12:01 UTC
#Next Steps#
1. Add rng-tools to core-image-sato image
2. How it can be added only for qemu machines?
3. Create link
4. Update runqemu for the inclusion of paravirtualized random number generator
5. Update the kernel config fragments
6. Move rng-tools from meta-oe to oe-core (??)
Comment 6 Saul Wold 2016-02-10 16:58:12 UTC
Pushing to M3 due to change of resources
Comment 7 Saul Wold 2016-02-15 17:02:21 UTC
These two patches add rng-tools to the qemu images and increase the availablity 
of entropy bits

http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=6740dd55798641a47744b891aa1d8fa5e04c2cdc
http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=ce3df21122d7fc4ede6fe36009afb297004672ef

The Kernel configs have been updated to include the HW_RANDOM_VIRTIO and 
HW_RANDOM in virtio.cfg of the yocto-kernel-cache.