Bug 1119206

Summary: RFE: Multiple virtio-rng devices support
Product: Red Hat Enterprise Linux 7 Reporter: Peter Krempa <pkrempa>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: akong, bsarathy, dyuan, juzhang, juzhou, knoel, lhuang, mkenneth, mzhan, pkrempa, rbalakri, virt-bugs, virt-maint, xfu, xuhan
Target Milestone: rcKeywords: FutureFeature
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.7-1.el7 Doc Type: Enhancement
Doc Text:
Feature: Both kernel and qemu support multiple virtio-rng devices to be specified for a VM. Libvirt supported only one. Reason: Original implementation of the driver in the kernel was flawed and it was considered dropping the multiple rng support at first. Libvirt thus didn't implement support for more than one device. Result: Libvirt is now able to specify multiple virtio-rng devices to be used with a VM.
Story Points: ---
Clone Of: 915335 Environment:
Last Closed: 2015-03-05 07:41:02 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 915335, 917953    
Bug Blocks:    

Description Peter Krempa 2014-07-14 09:20:05 UTC
+++ This bug was initially created as a clone of Bug #915335 +++

Both qemu-kvm and the kernel support now multiple virtio-rng devices. Libvirt's support was crippled to support just one device as the original intent was not to support multiple RNGs.

This bug will track adding support for multiple RNGs in a domain.

There was already an attempt to add this:
http://www.redhat.com/archives/libvir-list/2013-February/msg01423.html

Kernel commits adding the support:

commit a17597d3b418ca5a394d14724ccfc295cb3186c8
Author: Sasha Levin <sasha.levin>
Date:   Fri May 16 11:42:43 2014 +0930

    virtio-rng: fixes for device registration/unregistration
    
    There are several fixes in this patch (mostly because it's hard
    splitting them up):
    
     - Revert the name field in struct hwrng back to 'const'. Also, don't
    do an extra kmalloc for the name - just wasteful.
     - Deal with allocation failures properly.
     - Use IDA to allocate device number instead of brute forcing one.
    
    Signed-off-by: Sasha Levin <sasha.levin>
    Signed-off-by: Rusty Russell <rusty.au>


commit e5d23a8cc38c555f9f3a40dcc5d14030105df9a8
Author: Sasha Levin <sasha.levin>
Date:   Fri May 16 11:41:57 2014 +0930

    virtio-rng: fix boot with virtio-rng device
    
    Commit "virtio-rng: support multiple virtio-rng devices" has broken
    boot with a virtio-rng device because the 'init' callback of the
    virtio-rng device was left unitialized to garbage, and got called
    by the hwrng infrastructure, killing the guest on boot.
    
    Signed-off-by: Sasha Levin <sasha.levin>
    Signed-off-by: Rusty Russell <rusty.au>
    Fixes: 08e53fbdb85c0f6f45c0f7c1ea3defc1752a95ce

commit 08e53fbdb85c0f6f45c0f7c1ea3defc1752a95ce
Author: Amos Kong <akong>
Date:   Wed May 14 10:33:46 2014 +0930

    virtio-rng: support multiple virtio-rng devices
    
    Current hwrng core supports to register multiple hwrng devices,
    and there is only one device really works in the same time.
    QEMU alsu supports to have multiple virtio-rng backends.
    
    This patch changes virtio-rng driver to support multiple
    virtio-rng devices.
    
    ]# cat /sys/class/misc/hw_random/rng_available
    virtio_rng.0 virtio_rng.1
    ]# cat /sys/class/misc/hw_random/rng_current
    virtio_rng.0
    ]# echo -n virtio_rng.1 > /sys/class/misc/hw_random/rng_current
    ]# dd if=/dev/hwrng of=/dev/null
    
    Signed-off-by: Amos Kong <akong>
    Signed-off-by: Rusty Russell <rusty.au>

Comment 1 Peter Krempa 2014-07-25 07:40:35 UTC
Libvirt added this feature in v1.2.6-261-g7214d5d:

commit 7214d5da28c90fcdb62345190e34c76a345f9f70
Author: Peter Krempa <pkrempa>
Date:   Thu Jul 24 15:15:20 2014 +0200

    test: qemu: Add tests for multiple virtio-rng devices

commit bbddbefa2f8a8ef72287077d7d4b7190f3bf2609
Author: Peter Krempa <pkrempa>
Date:   Mon Feb 25 23:31:11 2013 +0100

    virtio-rng: allow multiple RNG devices
    
    qemu supports adding multiple RNG devices. This patch allows libvirt to
    support this.

Comment 3 Luyao Huang 2014-12-08 01:49:23 UTC
Verify this bug with libvirt-1.2.8-10.el7.x86_64 :

1.Start a guest with multiple virtio-rng devices
# virsh list 
 Id    Name                           State
----------------------------------------------------
 42    r7                             running


# virsh dumpxml r7
    <rng model='virtio'>
      <backend model='random'>/dev/random</backend>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </rng>
    <rng model='virtio'>
      <backend model='random'>/dev/random</backend>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </rng>
    <rng model='virtio'>
      <backend model='egd' type='udp'>
        <source mode='connect' host='localhost' service='1234'/>
      </backend>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/>
    </rng>
  </devices>

2.check qemu cmd line:
# ps aux|grep qemu
-object rng-random,id=rng0,filename=/dev/random -device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x9 -object rng-random,id=rng1,filename=/dev/random -device virtio-rng-pci,rng=rng1,bus=pci.0,addr=0xa -chardev udp,id=charrng2,host=localhost,port=1234,localaddr=,localport=0 -object rng-egd,chardev=charrng2,id=rng2 -device virtio-rng-pci,rng=rng2,bus=pci.0,addr=0xb

 
2.login guest to check if virtio_rng work well

IN GUEST:
# time cat /sys/devices/virtual/misc/hw_random/rng_current
virtio_rng.0

real	0m39.333s
user	0m0.002s
sys	0m0.000s

# time cat /sys/devices/virtual/misc/hw_random/rng_available 
virtio_rng.0 virtio_rng.1 virtio_rng.2 

real	0m24.679s
user	0m0.000s
sys	0m0.002s

# echo -n virtio_rng.1 > /sys/class/misc/hw_random/rng_current
# dd if=/dev/hwrng of=/tmp/random
^C^C5+1 records in
5+0 records out
2560 bytes (2.6 kB) copied, 495.8 s, 0.0 kB/s

It is very slow and this issue seems because bug 1008860.

Comment 4 Luyao Huang 2014-12-08 02:08:05 UTC
Hi peter,

I found this bug depends on bug 917953, but bug 917953 is a bug tracker of qemu-kvm, can i verify this bug now?

Thanks in advance for your answer.

Comment 5 Peter Krempa 2014-12-08 10:19:28 UTC
(In reply to Luyao Huang from comment #4)
> Hi peter,
> 
> I found this bug depends on bug 917953, but bug 917953 is a bug tracker of
> qemu-kvm, can i verify this bug now?

That bug dependency is probably wrong. As you were able to checked that it works then it's okay to set it to VERIFIED.

Comment 6 Luyao Huang 2014-12-08 12:17:37 UTC
(In reply to Peter Krempa from comment #5)
> (In reply to Luyao Huang from comment #4)
> > Hi peter,
> > 
> > I found this bug depends on bug 917953, but bug 917953 is a bug tracker of
> > qemu-kvm, can i verify this bug now?
> 
> That bug dependency is probably wrong. As you were able to checked that it
> works then it's okay to set it to VERIFIED.

Thanks for your reply and verify this bug

Comment 8 errata-xmlrpc 2015-03-05 07:41:02 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2015-0323.html