virtio: Add virtio-rng driver
PATCH 1/1 virtio: Add virtio-rng driver
Hi folks,
This patch is a first cut at a driver for virtio-rng. Its not problem free, but it works.
Features:
* Raw and EGD protocol support
* Rate limiting (simple)
Known problems:
* provokes a bug in the kernels virtio-rng driver that results in data corruption.
* Does not reconnect to the host when using a socket to get data (qemu limitation?)
Todo:
* Add burst rate limiting
* Reconnection support
With a patch to the guest kernel to fix the virtio-rng driver, I see no FIPS-140-2 test failures.
Please review!
PATCH 1/1 virtio: Add virtio-rng driver
This patch adds support for virtio-rng. Data is read from a chardev and
can be either raw entropy or received via the EGD protocol.
--- Makefile.target | 2 +- hw/pci.h | 1 + hw/virtio-pci.c | 27 ++++++++ hw/virtio-rng.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-rng.h | 19 ++++++ hw/virtio.h | 2 + rng.h | 18 +++++ 7 files changed, 262 insertions(+), 1 deletions(-) create mode 100644 hw/virtio-rng.c create mode 100644 hw/virtio-rng.h create mode 100644 rng.h
Makefile.target +1 -1
@@ -159,7 +159,7 @@ ifdef CONFIG_SOFTMMU obj-y = vl.o async.o monitor.o pci.o pci_host.o pcie_host.o machine.o gdbstub.o # virtio has to be here due to weird dependency between PCI and virtio-net. # need to fix this properly -obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-pci.o +obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-pci.o virtio-rng.o obj-$(CONFIG_KVM) += kvm.o kvm-all.o obj-$(CONFIG_ISA_MMIO) += isa_mmio.o LIBS+=-lz
hw/pci.h +1 -0
@@ -70,6 +70,7 @@ extern target_phys_addr_t pci_mem_base;#define PCI_DEVICE_ID_VIRTIO_BLOCK 0x1001#define PCI_DEVICE_ID_VIRTIO_BALLOON 0x1002#define PCI_DEVICE_ID_VIRTIO_CONSOLE 0x1003 +#define PCI_DEVICE_ID_VIRTIO_RNG 0x1004typedef uint64_t pcibus_t ;#define FMT_PCIBUS PRIx64
hw/virtio-pci.c +27 -0
@@ -20,6 +20,7 @@#include "sysemu.h" #include "msix.h" #include "net.h" +#include "rng.h" #include "loader.h" /* from Linux's linux/virtio_pci.h */
@@ -92,6 +93,7 @@ typedef struct {uint32_t nvectors;DriveInfo *dinfo;NICConf nic; +RNGConf rng; } VirtIOPCIProxy;/* virtio device */
@@ -539,6 +541,21 @@ static int virtio_balloon_init_pci(PCIDevice *pci_dev)return 0 ; } +static int virtio_rng_init_pci (PCIDevice *pci_dev) +{ +VirtIOPCIProxy *proxy =DO_UPCAST (VirtIOPCIProxy, pci_dev, pci_dev); +VirtIODevice *vdev; + + vdev =virtio_rng_init (&pci_dev->qdev, &proxy->rng); +virtio_init_pci (proxy, vdev, +PCI_VENDOR_ID_REDHAT_QUMRANET , +PCI_DEVICE_ID_VIRTIO_RNG , +PCI_CLASS_OTHERS , +0x00 ); + +return 0 ; +} +static PCIDeviceInfo virtio_info[] = { { .qdev.name ="virtio-blk-pci" ,
@@ -580,6 +597,16 @@ static PCIDeviceInfo virtio_info[] = { .exit = virtio_exit_pci, .qdev.reset = virtio_pci_reset, },{ + .qdev.name = "virtio-rng-pci", + .qdev.size = sizeof(VirtIOPCIProxy), + .init = virtio_rng_init_pci, + .exit = virtio_exit_pci, + .qdev.props = (Property[]) { + DEFINE_RNG_PROPERTIES(VirtIOPCIProxy, rng), + DEFINE_PROP_END_OF_LIST(), + }, + .qdev.reset = virtio_pci_reset, + },{/* end of list */ } };
hw/virtio-rng.c new file +194 -0
194 lines not on this page · raw message
hw/virtio-rng.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* Virtio RNG Support +* +* Copyright Collabora 2009 +* +* Authors: +* Ian Molton <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ +#ifndef _QEMU_VIRTIO_RNG_H +#define _QEMU_VIRTIO_RNG_H + +/* The ID for virtio console */ +#define VIRTIO_ID_RNG 4 + +#endif
hw/virtio.h +2 -0
@@ -16,6 +16,7 @@#include "hw.h" #include "net.h" +#include "rng.h" #include "qdev.h" #include "sysemu.h"
@@ -167,6 +168,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo);VirtIODevice *virtio_net_init (DeviceState *dev,NICConf *conf);VirtIODevice *virtio_console_init (DeviceState *dev);VirtIODevice *virtio_balloon_init (DeviceState *dev); +VirtIODevice *virtio_rng_init (DeviceState *dev,RNGConf *rngdev);void virtio_net_exit (VirtIODevice *vdev);
rng.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef QEMU_RNG_H +#define QEMU_RNG_H + +#include "qemu-option.h" + +/* qdev rng properties */ + +typedef struct RNGConf { +CharDriverState *chrdev; +uint64_t rate; +char *proto; +}RNGConf ; + +#define DEFINE_RNG_PROPERTIES (_state, _conf) \ + DEFINE_PROP_CHR("chardev", _state, _conf.chrdev), \ + DEFINE_PROP_SIZE("rate", _state, _conf.rate, 0), \ + DEFINE_PROP_STRING("protocol", _state, _conf.proto) +#endif
Signature · 1 line
1.6.5
Quoted 2 lines · Ian Molton
This patch adds support for virtio-rng. Data is read from a chardev and
can be either raw entropy or received via the EGD protocol.
No comments?