RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 915335 - RFE: Multiple virtio-rng devices support
Summary: RFE: Multiple virtio-rng devices support
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: kernel
Version: 7.0
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Amos Kong
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks: VirtIORNG 1119206 1119299
TreeView+ depends on / blocked
 
Reported: 2013-02-25 14:37 UTC by Peter Krempa
Modified: 2015-05-25 00:07 UTC (History)
15 users (show)

Fixed In Version: kernel-3.10.0-146.el7
Doc Type: Enhancement
Doc Text:
Clone Of:
: 1119206 (view as bug list)
Environment:
Last Closed: 2015-03-05 11:29:48 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2015:0290 0 normal SHIPPED_LIVE Important: kernel security, bug fix, and enhancement update 2015-03-05 16:13:58 UTC

Description Peter Krempa 2013-02-25 14:37:58 UTC
Description of problem:
the kernel panics on virtual machines that have 2 virtio-rng devices presented to the system


Version-Release number of selected component (if applicable):
kernel 2.6.32-358-el6-x86_64


How reproducible:
100%

Steps to Reproduce:
1. start a RHEL 6.4 guest in virtio-rng capable qemu (release 1.4) with the following command line arguments: -object rng-random,id=rng0,filename=/dev/zero -device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x7 -object rng-random,id=rng1,filename=/dev/zero -device virtio-rng-pci,rng=rng1,bus=pci.0,addr=0x8

2. boot the guest and verify that virtio-rng driver is inserted and /dev/hwrng exists

3. run dd if=/dev/hwrng of=/dev/null bs=1 count=1000

4. observe the crash
  
Actual results:
Kernel panics in the register_buffer function of the virtio-rng module.

Comment 2 Amit Shah 2013-02-26 05:32:34 UTC
A log of the crash would've been helpful.

Comment 3 Amit Shah 2013-02-26 05:34:43 UTC
The kernel driver is written with the assumption that there's only one virtio-rng device.

That does make sense as well: why have two rng devices of the same kind anyway?  If the host has multiple sources to feed from, the host can multiplex them and send the entropy the guest's way.

This one virtio-rng device limit should be enforced in qemu and libvirt.

Switching component to qemu-kvm, where we'll do this.

Comment 4 Peter Krempa 2013-02-26 11:13:05 UTC
I agree with forbidding to use multiple virtio-rng devices as I can't think of a useful use-case. 

Libvirt isn't currently allowing multiple RNG's and I will not push the patch adding the support ( http://www.redhat.com/archives/libvir-list/2013-February/msg01423.html ).

Comment 6 Amit Shah 2013-04-23 05:48:32 UTC
Adjusting summary.

A brief chat with Anthony on IRC indicated he's not fine restricting qemu, and that it is a valid use-case to have multiple devices.  If indeed we do that, we'll flip this bug back to the kernel component to modify the hwrng layer in the kernel to use > 1 virtio-rng device and > 1 rng devices at the same time.

Comment 8 Amos Kong 2014-04-25 02:32:52 UTC
Additional info:

In bug 953097, we already fixed the kernel crash by rejecting to register multiple virtio-rng devices.

I tested with RHEL6.5 guest & upstream qemu, no crash, and the data comes from first rng-random backend.

Comment 9 Amos Kong 2014-04-25 16:17:47 UTC
Hi Amit

I found that kernel(drivers/char/hw_random/core.c) supports to register multiple hwrng devices, I just posted a patch to kernel driver to support multiple virtio-rng device.

https://lists.linux-foundation.org/pipermail/virtualization/2014-April/026535.html

Comment 10 Amit Shah 2014-05-02 10:49:25 UTC
(In reply to Amos Kong from comment #9)
> Hi Amit
> 
> I found that kernel(drivers/char/hw_random/core.c) supports to register
> multiple hwrng devices, I just posted a patch to kernel driver to support
> multiple virtio-rng device.
> 
> https://lists.linux-foundation.org/pipermail/virtualization/2014-April/
> 026535.html

Hi Amos,

I saw the patch, and as I observed above, and Rusty the reply in that thread, I don't see much value in the virtio-rng driver itself supporting multiple devices.

If the kernel's hwrng core could itself support multiplexing from multiple devices, that would be great.

So, with the current kernel-core design, only one hwrng can be active.  For the virtio-rng case, that means only one virtio-rng can be active.  We could easily switch the device side by using hotplug instead of the patch you propsed.

However, as Rusty says: 'why not' :-)

Comment 12 Amos Kong 2014-07-14 09:01:10 UTC
Upstream exists in Upstream (with some fixes), backport is needed.


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 14 Amos Kong 2014-08-04 05:34:59 UTC
  Tried to backported 4 patches to rhel7 kernel
  Last patch relies on new interface(eg: ida_simple_get()),
  some dependence backporting is needed.

  [PATCH 1/4]virtio-rng: don't crash if virtqueue is broken.
  [PATCH 2/4]virtio-rng: support multiple virtio-rng devices
  [PATCH 3/4]virtio-rng: fix boot with virtio-rng device
  [PATCH 4/4]virtio-rng: fixes for device registration/unregistration

  Upstream Virtio-rng driver still has some new issues, I will post
  this backport when all the issues are resolved. Some additional
  fixes will be backported in another bugs.

   Bug 1121540 - Hot-unplugging a busy virtio-rng device from Linux
     guest causes rng device stuck
   Bug 1081431 - virtio-rng module does not increment its reference
     count when /dev/hwrng in the guest is open, making it appear to
     be unused when it is in use

Comment 16 Jarod Wilson 2014-08-27 20:38:42 UTC
Patch(es) available on kernel-3.10.0-146.el7

Comment 18 Qian Guo 2014-09-01 09:42:04 UTC
Reproduced this bug with kernel-3.10.0-123.el7.x86_64
Steps:
1.Boot RHEL7 guest with 2 virtio-rng deivces:
#  /usr/libexec/qemu-kvm -cpu SandyBridge -enable-kvm -m 4G -smp 4,sockets=1,cores=4,threads=1 -name test -rtc base=localtime,clock=host,driftfix=slew  -k en-us  -boot menu=on -vnc :3 -vga cirrus -usb -device usb-tablet -monitor stdio -drive file=/home/rhel7/rhel7basecp1.qcow2,if=none,id=drive-system-disk,media=disk,format=qcow2,aio=native,werror=stop,rerror=stop -device virtio-blk-pci,drive=drive-system-disk,id=system-disk,addr=0x3 -qmp unix:/tmp/q1,server,nowait -net none -object rng-random,id=rng0,filename=/dev/urandom -device virtio-rng-pci,rng=rng0 -object rng-random,id=rng1,filename=/dev/urandom -device virtio-rng-pci,rng=rng1 -netdev tap,id=hostnet0,vhost=on,script=/etc/qemu-ifup -device virtio-net-pci,netdev=hostnet0,id=vnet0,mac=52:54:00:1a:2b:02

2.In guest, from dmesg:
# dmesg |grep rng
[    0.540247] alg: No test for stdrng (krng)
[    3.207351] virtio_rng: probe of virtio2 failed with error -16

3.And only 1 virtio-rng found in guest:
# cat /sys/class/misc/hw_random/rng_available 
virtio 
# cat /sys/class/misc/hw_random/rng_current 
virtio

4.In guest, use the rng device.
# dd if=/dev/hwrng of=test bs=512 count=10

Result: 
1.Did not crash (the reporter crash since its guest is rhel6 and bug 917505  has been fixed )
2.Only can get virtio from /sys/class/misc/hw_random/xx

So according to above, this bug is reproduced.

Verify this bug with kernel-3.10.0-148.el7.x86_64 (guest and host both installed)
Steps:
1.Boot rhel7 guest with kernel-3.10.0-148.el7.x86_64, and cli is same as above.

2.In guest, from dmesg, no error prints about rng:
# dmesg |grep rng
[    0.534911] alg: No test for stdrng (krng)

3.Check rng_available rng_current
# cat /sys/class/misc/hw_random/rng_current 
virtio_rng.0
# cat /sys/class/misc/hw_random/rng_available 
virtio_rng.0 virtio_rng.1 

4.Check if it works
# dd if=/dev/hwrng of=/dev/null bs=512 count=100
100+0 records in
100+0 records out
51200 bytes (51 kB) copied,0.0851136 s,602 kB/s

5.Change current rng device
# echo -n virtio_rng.1 > /sys/class/misc/hw_random/rng_current

6.Recheck if it works
# dd if=/dev/hwrng of=/dev/null bs=512 count=100
100+0 records in
100+0 records out
51200 bytes (51 kB) copied,0.0672739 s,761 kB/s

So according to above, this bug is fixed.

Comment 20 errata-xmlrpc 2015-03-05 11:29:48 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-0290.html


Note You need to log in before you can comment on or make changes to this bug.