virtio: Add vhost-user based RNG
v2 cover virtio: Add vhost-user based RNG
This sets adds a vhost-user based random number generator (RNG), similar to what has been done for i2c and virtiofsd, with the implementation following the patterns already set forth in those.
Applies cleanly to git://git.qemu.org/qemu.git master(1ea06abceec6).
Thanks,
Mathieu
-----
New for V2:
- Replaced "antropy" for "entropy" (Joakim).
Mathieu Poirier (5):
vhost-user-rng: Add vhost-user-rng implementation
vhost-user-rng-pci: Add vhost-user-rng-pci implementation
vhost-user-rng: backend: Add RNG vhost-user daemon implementation
docs: Add documentation for vhost based RNG implementation
MAINTAINERS: Add maintainer for vhost-user RNG implementation
MAINTAINERS | 9 + docs/tools/vhost-user-rng.rst | 74 +++++ hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 2 + hw/virtio/vhost-user-rng-pci.c | 79 +++++ hw/virtio/vhost-user-rng.c | 294 +++++++++++++++++ include/hw/virtio/vhost-user-rng.h | 33 ++ tools/meson.build | 8 + tools/vhost-user-rng/50-qemu-rng.json.in | 5 + tools/vhost-user-rng/main.c | 403 +++++++++++++++++++++++ tools/vhost-user-rng/meson.build | 10 + 11 files changed, 922 insertions(+) create mode 100644 docs/tools/vhost-user-rng.rst create mode 100644 hw/virtio/vhost-user-rng-pci.c create mode 100644 hw/virtio/vhost-user-rng.c create mode 100644 include/hw/virtio/vhost-user-rng.h create mode 100644 tools/vhost-user-rng/50-qemu-rng.json.in create mode 100644 tools/vhost-user-rng/main.c create mode 100644 tools/vhost-user-rng/meson.build
Signature · 1 line
2.25.1
PATCH v2 1/5 vhost-user-rng: Add vhost-user-rng implementation
Following in the footsteps of what whas done for vhost-user-i2c and virtiofsd, introduce a random number generator (RNG) backend that communicates with a vhost-user server to retrieve entropy. That way another VMM could be using the same vhost-user daemon and avoid having to write yet another RNG driver.
--- hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + hw/virtio/vhost-user-rng.c | 294 +++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-rng.h | 33 ++++ 4 files changed, 333 insertions(+) create mode 100644 hw/virtio/vhost-user-rng.c create mode 100644 include/hw/virtio/vhost-user-rng.h
hw/virtio/Kconfig +5 -0
@@ -58,3 +58,8 @@ config VIRTIO_MEM depends on LINUX depends on VIRTIO_MEM_SUPPORTED select MEM_DEVICE + +config VHOST_USER_RNG + bool + default y + depends on VIRTIO && VHOST_USER
hw/virtio/meson.build +1 -0
@@ -25,6 +25,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock. virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) +virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
hw/virtio/vhost-user-rng.c new file +294 -0
294 lines not on this page · raw message
include/hw/virtio/vhost-user-rng.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Vhost-user RNG virtio device +* +* Copyright (c) 2021 Mathieu Poirier <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef _QEMU_VHOST_USER_RNG_H +#define _QEMU_VHOST_USER_RNG_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "chardev/char-fe.h" + +#define TYPE_VHOST_USER_RNG "vhost-user-rng" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserRNG, VHOST_USER_RNG) + +struct VHostUserRNG { +/*< private >*/ +VirtIODevice parent; +CharBackend chardev; +struct vhost_virtqueue *vhost_vq; +struct vhost_dev vhost_dev; +VhostUserState vhost_user; +VirtQueue *req_vq; +bool connected; + +/*< public >*/ +}; + +#endif /* _QEMU_VHOST_USER_RNG_H */
Signature · 1 line
2.25.1
PATCH v2 2/5 vhost-user-rng-pci: Add vhost-user-rng-pci implementation
In reply to Mathieu PoirierThis patch provides a PCI bus interface to the vhost-user-rng backed. The implentation is similar to what was done for vhost-user-i2c-pci and vhost-user-fs-pci.
--- hw/virtio/meson.build | 1 + hw/virtio/vhost-user-rng-pci.c | 79 ++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 hw/virtio/vhost-user-rng-pci.c
hw/virtio/meson.build +1 -0
@@ -26,6 +26,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) +virtio_ss.add(when: ['CONFIG_VHOST_USER_RNG', 'CONFIG_VIRTIO_PCI'], if_true: files('vhost-user-rng-pci.c')) virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
hw/virtio/vhost-user-rng-pci.c new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 3/5 vhost-user-rng: backend: Add RNG vhost-user daemon implementation
In reply to Mathieu PoirierThis patch provides the vhost-user backend implementation to work in tandem with the vhost-user-rng implementation of the QEMU VMM.
It uses the vhost-user API so that other VMM can re-use the interface without having to write the driver again.
--- tools/meson.build | 8 + tools/vhost-user-rng/50-qemu-rng.json.in | 5 + tools/vhost-user-rng/main.c | 403 +++++++++++++++++++++++ tools/vhost-user-rng/meson.build | 10 + 4 files changed, 426 insertions(+) create mode 100644 tools/vhost-user-rng/50-qemu-rng.json.in create mode 100644 tools/vhost-user-rng/main.c create mode 100644 tools/vhost-user-rng/meson.build
tools/meson.build +8 -0
@@ -24,3 +24,11 @@ endif if have_virtiofsd subdir('virtiofsd') endif + +have_virtiorng = (have_system and + have_tools and + 'CONFIG_LINUX' in config_host) + +if have_virtiorng + subdir('vhost-user-rng') +endif
tools/vhost-user-rng/50-qemu-rng.json.in new file +5 -0
@@ -0,0 +1,5 @@ +{ + "description": "QEMU vhost-user-rng", + "type": "bridge", + "binary": "@libexecdir@/vhost-user-rng" +}
tools/vhost-user-rng/main.c new file +403 -0
403 lines not on this page · raw message
tools/vhost-user-rng/meson.build new file +10 -0
@@ -0,0 +1,10 @@ +executable('vhost-user-rng', files( + 'main.c'), + dependencies: [qemuutil, glib, gio, rt], + install: true, + install_dir: get_option('libexecdir')) + +configure_file(input: '50-qemu-rng.json.in', + output: '50-qemu-rng.json', + configuration: config_host, + install_dir: qemu_datadir / 'vhost-user')
Signature · 1 line
2.25.1
PATCH v2 4/5 docs: Add documentation for vhost based RNG implementation
In reply to Mathieu PoirierAdd description and example for the vhost-user based RNG implementation. Tailored on Viresh Kumar's vhost-user-i2c documentation.
--- docs/tools/vhost-user-rng.rst | 74 +++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 docs/tools/vhost-user-rng.rst
docs/tools/vhost-user-rng.rst new file +74 -0
@@ -0,0 +1,74 @@ +QEMU vhost-user-rng - RNG emulation backend +=========================================== + +Synopsis +-------- + +**vhost-user-rng** [*OPTIONS*] + +Description +----------- + +This program is a vhost-user backend that emulates a VirtIO random number +generator (RNG). It uses the host's random number generator pool, +/dev/urandom by default but configurable at will, to satisfy requests from +guests. + +This program is designed to work with QEMU's ``-device +vhost-user-rng-pci`` but should work with any virtual machine monitor +(VMM) that supports vhost-user. See the Examples section below. + +Options +------- + +.. program:: vhost-user-rng + +.. option:: -h, --help + + Print help. + +.. option:: -v, --verbose + + Increase verbosity of output + +.. option:: -s, --socket-path=PATH + + Listen on vhost-user UNIX domain socket at PATH. Incompatible with --fd. + +.. option:: -f, --fd=FDNUM + + Accept connections from vhost-user UNIX domain socket file descriptor FDNUM. + The file descriptor must already be listening for connections. + Incompatible with --socket-path. + +.. option:: -p, --period + + Rate, in milliseconds, at which the RNG hardware can generate random data. + Used in conjunction with the --max-bytes option. + +.. option:: -m, --max-bytes + + In conjuction with the --period parameter, provides the maximum number of byte + per milliseconds a RNG device can generate. + +Examples +-------- + +The daemon should be started first: + +:: + + host# vhost-user-rng --socket-path=rng.sock --period=1000 --max-bytes=4096 + +The QEMU invocation needs to create a chardev socket the device can +use to communicate as well as share the guests memory over a memfd. + +:: + + host# qemu-system \ + -chardev socket,path=$(PATH)/rng.sock,id=rng0 \ + -device vhost-user-rng-pci,chardev=rng0 \ + -m 4096 \ + -object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \ + -numa node,memdev=mem \ + ...
Signature · 1 line
2.25.1
PATCH v2 5/5 MAINTAINERS: Add maintainer for vhost-user RNG implementation
In reply to Mathieu PoirierThis patch adds entry for the vhost-user-rng related files.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -1951,6 +1951,15 @@ F: include/sysemu/rng*.h F: backends/rng*.c F: tests/qtest/virtio-rng-test.c +vhost-user-rng +M: Mathieu Poirier <[email protected]> +S: Supported +F: docs/tools/vhost-user-rng.rst +F: hw/virtio/vhost-user-rng.c +F: hw/virtio/vhost-user-rng-pci.c +F: include/hw/virtio/vhost-user-rng.h +F: tools/vhost-user-rng/* + virtio-crypto M: Gonglei <[email protected]> S: Supported
Signature · 1 line
2.25.1
Quoted 5 lines · Mathieu Poirier
This sets adds a vhost-user based random number generator (RNG), similar to what has been done for i2c and virtiofsd, with the implementation following the patterns already set forth in those.
Applies cleanly to
git://git.qemu.org/qemu.gitmaster(1ea06abceec6).
I get
/scm/qemu/docs/tools/vhost-user-rng.rst:document isn't included in any toctree
any idea?
Quoted 36 lines
Thanks,
Mathieu-----
New for V2:
- Replaced "antropy" for "entropy" (Joakim).Mathieu Poirier (5):
vhost-user-rng: Add vhost-user-rng implementation
vhost-user-rng-pci: Add vhost-user-rng-pci implementation
vhost-user-rng: backend: Add RNG vhost-user daemon implementation
docs: Add documentation for vhost based RNG implementation
MAINTAINERS: Add maintainer for vhost-user RNG implementationMAINTAINERS | 9 + docs/tools/vhost-user-rng.rst | 74 +++++ hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 2 + hw/virtio/vhost-user-rng-pci.c | 79 +++++ hw/virtio/vhost-user-rng.c | 294 +++++++++++++++++ include/hw/virtio/vhost-user-rng.h | 33 ++ tools/meson.build | 8 + tools/vhost-user-rng/50-qemu-rng.json.in | 5 + tools/vhost-user-rng/main.c | 403 +++++++++++++++++++++++ tools/vhost-user-rng/meson.build | 10 + 11 files changed, 922 insertions(+) create mode 100644 docs/tools/vhost-user-rng.rst create mode 100644 hw/virtio/vhost-user-rng-pci.c create mode 100644 hw/virtio/vhost-user-rng.c create mode 100644 include/hw/virtio/vhost-user-rng.h create mode 100644 tools/vhost-user-rng/50-qemu-rng.json.in create mode 100644 tools/vhost-user-rng/main.c create mode 100644 tools/vhost-user-rng/meson.buildSignature · 1 line
2.25.1
Good day Michael,
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Mathieu Poirier
This sets adds a vhost-user based random number generator (RNG), similar to what has been done for i2c and virtiofsd, with the implementation following the patterns already set forth in those.
Quoted 7 lines
Quoted 1 line
Applies cleanly to
git://git.qemu.org/qemu.gitmaster(1ea06abceec6).I get
/scm/qemu/docs/tools/vhost-user-rng.rst:document isn't included in any toctree
I assume this is because vhost-user-rng isn't listed in docs/tools/index.rst but I would like to test my theory before sending another revision. What build command did you use to generate this? I tried "make html" and "make man" as shown in the Documenation section of "make help" but those targets don't seem to be valid anymore.
Thanks,
Mathieu
Quoted 39 lines
any idea?
Quoted 36 lines
Thanks,
Mathieu-----
New for V2:
- Replaced "antropy" for "entropy" (Joakim).Mathieu Poirier (5):
vhost-user-rng: Add vhost-user-rng implementation
vhost-user-rng-pci: Add vhost-user-rng-pci implementation
vhost-user-rng: backend: Add RNG vhost-user daemon implementation
docs: Add documentation for vhost based RNG implementation
MAINTAINERS: Add maintainer for vhost-user RNG implementationMAINTAINERS | 9 + docs/tools/vhost-user-rng.rst | 74 +++++ hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 2 + hw/virtio/vhost-user-rng-pci.c | 79 +++++ hw/virtio/vhost-user-rng.c | 294 +++++++++++++++++ include/hw/virtio/vhost-user-rng.h | 33 ++ tools/meson.build | 8 + tools/vhost-user-rng/50-qemu-rng.json.in | 5 + tools/vhost-user-rng/main.c | 403 +++++++++++++++++++++++ tools/vhost-user-rng/meson.build | 10 + 11 files changed, 922 insertions(+) create mode 100644 docs/tools/vhost-user-rng.rst create mode 100644 hw/virtio/vhost-user-rng-pci.c create mode 100644 hw/virtio/vhost-user-rng.c create mode 100644 include/hw/virtio/vhost-user-rng.h create mode 100644 tools/vhost-user-rng/50-qemu-rng.json.in create mode 100644 tools/vhost-user-rng/main.c create mode 100644 tools/vhost-user-rng/meson.buildSignature · 1 line
2.25.1
Quoted 16 lines · Mathieu Poirier
Good day Michael,
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Mathieu Poirier
This sets adds a vhost-user based random number generator (RNG), similar to what has been done for i2c and virtiofsd, with the implementation following the patterns already set forth in those.
Quoted 7 lines
Quoted 1 line
Applies cleanly to
git://git.qemu.org/qemu.gitmaster(1ea06abceec6).I get
/scm/qemu/docs/tools/vhost-user-rng.rst:document isn't included in any toctree
Quoted 8 lines
I assume this is because vhost-user-rng isn't listed in
docs/tools/index.rstbut I would like to test my theory before sending another revision. What build command did you use to generate this? I tried "make html" and "make man" as shown in the Documenation section of "make help" but those targets don't seem to be valid anymore.Thanks,
Mathieu
I just used configure then make.
So this is why the patches got dropped from the pull request. I remember now.
Quoted 39 lines
Quoted 39 lines
any idea?
Quoted 36 lines
Thanks,
Mathieu-----
New for V2:
- Replaced "antropy" for "entropy" (Joakim).Mathieu Poirier (5):
vhost-user-rng: Add vhost-user-rng implementation
vhost-user-rng-pci: Add vhost-user-rng-pci implementation
vhost-user-rng: backend: Add RNG vhost-user daemon implementation
docs: Add documentation for vhost based RNG implementation
MAINTAINERS: Add maintainer for vhost-user RNG implementationMAINTAINERS | 9 + docs/tools/vhost-user-rng.rst | 74 +++++ hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 2 + hw/virtio/vhost-user-rng-pci.c | 79 +++++ hw/virtio/vhost-user-rng.c | 294 +++++++++++++++++ include/hw/virtio/vhost-user-rng.h | 33 ++ tools/meson.build | 8 + tools/vhost-user-rng/50-qemu-rng.json.in | 5 + tools/vhost-user-rng/main.c | 403 +++++++++++++++++++++++ tools/vhost-user-rng/meson.build | 10 + 11 files changed, 922 insertions(+) create mode 100644 docs/tools/vhost-user-rng.rst create mode 100644 hw/virtio/vhost-user-rng-pci.c create mode 100644 hw/virtio/vhost-user-rng.c create mode 100644 include/hw/virtio/vhost-user-rng.h create mode 100644 tools/vhost-user-rng/50-qemu-rng.json.in create mode 100644 tools/vhost-user-rng/main.c create mode 100644 tools/vhost-user-rng/meson.buildSignature · 1 line
2.25.1