virtio,vhost: fixes, features, cleanups.
FLR support. Misc fixes, cleanups. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> -----BEGIN PGP SIGNATURE----- iQEcBAABAgAGBQJdb6W/AAoJECgfDbjSjVRpRlEIAKvo9Sbq9bOtZ8nhbfJvLBWV nyOk5kgwv+XE+VhYGTsU7poYDPdRQn8uohBzXDb1zzCHd9corHriUXnUQ8TkDdz9 V9v8buK7qRPZa4OddPRVHDPZEn7OBbvNanhbo/Nw8iRcE/XdW+Ezw33A/aR8rSY7 KOxHYHeR2uBzVVDWKxp2yfBd+Zm9gbO27Y1thb9fyi4o7mHZ+gbrFl2p7z3wilNK KuGi0jCmS4I+4h2wmrZXnzSrozg9vJhXxkkdfI7QBze1XiVqC8w/bCcjXGVVGfhe SOvJH9A+yVyWpfjJpgmof4UISah+4zTi9G2SanZ4UERULD/NsiGfLQTVilUijAk= =K61t -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging virtio,vhost: fixes, features, cleanups. FLR support. Misc fixes, cleanups. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # gpg: Signature made Wed 04 Sep 2019 12:53:35 BST # gpg: using RSA key 281F0DB8D28D5469 # gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" [full] # gpg: aka "Michael S. Tsirkin <mst@redhat.com>" [full] # Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67 # Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469 * remotes/mst/tags/for_upstream: libvhost-user: introduce and use vu_has_protocol_feature() libvhost-user: fix SLAVE_SEND_FD handling virtio-pci: Add Function Level Reset support virtio-rng: change default backend to rng-builtin virtio-rng: Keep the default backend out of VirtIORNGConf rng-builtin: add an RNG backend that uses qemu_guest_getrandom() Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
a8b5ad8e1f
@ -1,4 +1,4 @@
|
|||||||
common-obj-y += rng.o rng-egd.o
|
common-obj-y += rng.o rng-egd.o rng-builtin.o
|
||||||
common-obj-$(CONFIG_POSIX) += rng-random.o
|
common-obj-$(CONFIG_POSIX) += rng-random.o
|
||||||
|
|
||||||
common-obj-$(CONFIG_TPM) += tpm.o
|
common-obj-$(CONFIG_TPM) += tpm.o
|
||||||
|
77
backends/rng-builtin.c
Normal file
77
backends/rng-builtin.c
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* QEMU Builtin Random Number Generator Backend
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||||
|
* See the COPYING file in the top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
#include "sysemu/rng.h"
|
||||||
|
#include "qemu/main-loop.h"
|
||||||
|
#include "qemu/guest-random.h"
|
||||||
|
|
||||||
|
#define RNG_BUILTIN(obj) OBJECT_CHECK(RngBuiltin, (obj), TYPE_RNG_BUILTIN)
|
||||||
|
|
||||||
|
typedef struct RngBuiltin {
|
||||||
|
RngBackend parent;
|
||||||
|
QEMUBH *bh;
|
||||||
|
} RngBuiltin;
|
||||||
|
|
||||||
|
static void rng_builtin_receive_entropy_bh(void *opaque)
|
||||||
|
{
|
||||||
|
RngBuiltin *s = opaque;
|
||||||
|
|
||||||
|
while (!QSIMPLEQ_EMPTY(&s->parent.requests)) {
|
||||||
|
RngRequest *req = QSIMPLEQ_FIRST(&s->parent.requests);
|
||||||
|
|
||||||
|
qemu_guest_getrandom_nofail(req->data, req->size);
|
||||||
|
|
||||||
|
req->receive_entropy(req->opaque, req->data, req->size);
|
||||||
|
|
||||||
|
rng_backend_finalize_request(&s->parent, req);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rng_builtin_request_entropy(RngBackend *b, RngRequest *req)
|
||||||
|
{
|
||||||
|
RngBuiltin *s = RNG_BUILTIN(b);
|
||||||
|
|
||||||
|
qemu_bh_schedule(s->bh);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rng_builtin_init(Object *obj)
|
||||||
|
{
|
||||||
|
RngBuiltin *s = RNG_BUILTIN(obj);
|
||||||
|
|
||||||
|
s->bh = qemu_bh_new(rng_builtin_receive_entropy_bh, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rng_builtin_finalize(Object *obj)
|
||||||
|
{
|
||||||
|
RngBuiltin *s = RNG_BUILTIN(obj);
|
||||||
|
|
||||||
|
qemu_bh_delete(s->bh);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rng_builtin_class_init(ObjectClass *klass, void *data)
|
||||||
|
{
|
||||||
|
RngBackendClass *rbc = RNG_BACKEND_CLASS(klass);
|
||||||
|
|
||||||
|
rbc->request_entropy = rng_builtin_request_entropy;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const TypeInfo rng_builtin_info = {
|
||||||
|
.name = TYPE_RNG_BUILTIN,
|
||||||
|
.parent = TYPE_RNG_BACKEND,
|
||||||
|
.instance_size = sizeof(RngBuiltin),
|
||||||
|
.instance_init = rng_builtin_init,
|
||||||
|
.instance_finalize = rng_builtin_finalize,
|
||||||
|
.class_init = rng_builtin_class_init,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void register_types(void)
|
||||||
|
{
|
||||||
|
type_register_static(&rng_builtin_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
type_init(register_types);
|
@ -94,6 +94,11 @@ bool vu_has_feature(VuDev *dev,
|
|||||||
return has_feature(dev->features, fbit);
|
return has_feature(dev->features, fbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool vu_has_protocol_feature(VuDev *dev, unsigned int fbit)
|
||||||
|
{
|
||||||
|
return has_feature(dev->protocol_features, fbit);
|
||||||
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vu_request_to_string(unsigned int req)
|
vu_request_to_string(unsigned int req)
|
||||||
{
|
{
|
||||||
@ -951,8 +956,7 @@ vu_check_queue_inflights(VuDev *dev, VuVirtq *vq)
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!has_feature(dev->protocol_features,
|
if (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
||||||
VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1097,7 +1101,7 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd,
|
|||||||
|
|
||||||
vmsg.fd_num = fd_num;
|
vmsg.fd_num = fd_num;
|
||||||
|
|
||||||
if ((dev->protocol_features & VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) == 0) {
|
if (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2190,8 +2194,7 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz)
|
|||||||
static int
|
static int
|
||||||
vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
|
vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
|
||||||
{
|
{
|
||||||
if (!has_feature(dev->protocol_features,
|
if (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
||||||
VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2208,8 +2211,7 @@ vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx)
|
|||||||
static int
|
static int
|
||||||
vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
|
vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
|
||||||
{
|
{
|
||||||
if (!has_feature(dev->protocol_features,
|
if (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
||||||
VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2225,8 +2227,7 @@ vu_queue_inflight_pre_put(VuDev *dev, VuVirtq *vq, int desc_idx)
|
|||||||
static int
|
static int
|
||||||
vu_queue_inflight_post_put(VuDev *dev, VuVirtq *vq, int desc_idx)
|
vu_queue_inflight_post_put(VuDev *dev, VuVirtq *vq, int desc_idx)
|
||||||
{
|
{
|
||||||
if (!has_feature(dev->protocol_features,
|
if (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
||||||
VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@
|
|||||||
#include "hw/pci/pci.h"
|
#include "hw/pci/pci.h"
|
||||||
#include "hw/mem/nvdimm.h"
|
#include "hw/mem/nvdimm.h"
|
||||||
|
|
||||||
GlobalProperty hw_compat_4_1[] = {};
|
GlobalProperty hw_compat_4_1[] = {
|
||||||
|
{ "virtio-pci", "x-pcie-flr-init", "off" },
|
||||||
|
};
|
||||||
const size_t hw_compat_4_1_len = G_N_ELEMENTS(hw_compat_4_1);
|
const size_t hw_compat_4_1_len = G_N_ELEMENTS(hw_compat_4_1);
|
||||||
|
|
||||||
GlobalProperty hw_compat_4_0[] = {
|
GlobalProperty hw_compat_4_0[] = {
|
||||||
|
@ -604,6 +604,10 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
|
|||||||
|
|
||||||
pci_default_write_config(pci_dev, address, val, len);
|
pci_default_write_config(pci_dev, address, val, len);
|
||||||
|
|
||||||
|
if (proxy->flags & VIRTIO_PCI_FLAG_INIT_FLR) {
|
||||||
|
pcie_cap_flr_write_config(pci_dev, address, val, len);
|
||||||
|
}
|
||||||
|
|
||||||
if (range_covers_byte(address, len, PCI_COMMAND) &&
|
if (range_covers_byte(address, len, PCI_COMMAND) &&
|
||||||
!(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
|
!(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
|
||||||
virtio_pci_stop_ioeventfd(proxy);
|
virtio_pci_stop_ioeventfd(proxy);
|
||||||
@ -1780,6 +1784,10 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
|
|||||||
pcie_ats_init(pci_dev, 256);
|
pcie_ats_init(pci_dev, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (proxy->flags & VIRTIO_PCI_FLAG_INIT_FLR) {
|
||||||
|
/* Set Function Level Reset capability bit */
|
||||||
|
pcie_cap_flr_init(pci_dev);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* make future invocations of pci_is_express() return false
|
* make future invocations of pci_is_express() return false
|
||||||
@ -1847,6 +1855,8 @@ static Property virtio_pci_properties[] = {
|
|||||||
VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT, true),
|
VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT, true),
|
||||||
DEFINE_PROP_BIT("x-pcie-pm-init", VirtIOPCIProxy, flags,
|
DEFINE_PROP_BIT("x-pcie-pm-init", VirtIOPCIProxy, flags,
|
||||||
VIRTIO_PCI_FLAG_INIT_PM_BIT, true),
|
VIRTIO_PCI_FLAG_INIT_PM_BIT, true),
|
||||||
|
DEFINE_PROP_BIT("x-pcie-flr-init", VirtIOPCIProxy, flags,
|
||||||
|
VIRTIO_PCI_FLAG_INIT_FLR_BIT, true),
|
||||||
DEFINE_PROP_END_OF_LIST(),
|
DEFINE_PROP_END_OF_LIST(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ enum {
|
|||||||
VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
|
VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
|
||||||
VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
|
VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
|
||||||
VIRTIO_PCI_FLAG_INIT_PM_BIT,
|
VIRTIO_PCI_FLAG_INIT_PM_BIT,
|
||||||
|
VIRTIO_PCI_FLAG_INIT_FLR_BIT,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Need to activate work-arounds for buggy guests at vmstate load. */
|
/* Need to activate work-arounds for buggy guests at vmstate load. */
|
||||||
@ -80,6 +81,9 @@ enum {
|
|||||||
/* Init Power Management */
|
/* Init Power Management */
|
||||||
#define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
|
#define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
|
||||||
|
|
||||||
|
/* Init Function Level Reset capability */
|
||||||
|
#define VIRTIO_PCI_FLAG_INIT_FLR (1 << VIRTIO_PCI_FLAG_INIT_FLR_BIT)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MSIMessage msg;
|
MSIMessage msg;
|
||||||
int virq;
|
int virq;
|
||||||
|
@ -192,27 +192,24 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vrng->conf.rng == NULL) {
|
if (vrng->conf.rng == NULL) {
|
||||||
vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
|
Object *default_backend = object_new(TYPE_RNG_BUILTIN);
|
||||||
|
|
||||||
user_creatable_complete(USER_CREATABLE(vrng->conf.default_backend),
|
user_creatable_complete(USER_CREATABLE(default_backend),
|
||||||
&local_err);
|
&local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
object_unref(OBJECT(vrng->conf.default_backend));
|
object_unref(default_backend);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
object_property_add_child(OBJECT(dev),
|
object_property_add_child(OBJECT(dev), "default-backend",
|
||||||
"default-backend",
|
default_backend, &error_abort);
|
||||||
OBJECT(vrng->conf.default_backend),
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* The child property took a reference, we can safely drop ours now */
|
/* The child property took a reference, we can safely drop ours now */
|
||||||
object_unref(OBJECT(vrng->conf.default_backend));
|
object_unref(default_backend);
|
||||||
|
|
||||||
object_property_set_link(OBJECT(dev),
|
object_property_set_link(OBJECT(dev), default_backend,
|
||||||
OBJECT(vrng->conf.default_backend),
|
"rng", &error_abort);
|
||||||
"rng", NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vrng->rng = vrng->conf.rng;
|
vrng->rng = vrng->conf.rng;
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
#include "hw/virtio/virtio.h"
|
#include "hw/virtio/virtio.h"
|
||||||
#include "sysemu/rng.h"
|
#include "sysemu/rng.h"
|
||||||
#include "sysemu/rng-random.h"
|
|
||||||
#include "standard-headers/linux/virtio_rng.h"
|
#include "standard-headers/linux/virtio_rng.h"
|
||||||
|
|
||||||
#define TYPE_VIRTIO_RNG "virtio-rng-device"
|
#define TYPE_VIRTIO_RNG "virtio-rng-device"
|
||||||
@ -27,7 +26,6 @@ struct VirtIORNGConf {
|
|||||||
RngBackend *rng;
|
RngBackend *rng;
|
||||||
uint64_t max_bytes;
|
uint64_t max_bytes;
|
||||||
uint32_t period_ms;
|
uint32_t period_ms;
|
||||||
RngRandom *default_backend;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct VirtIORNG {
|
typedef struct VirtIORNG {
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#define RNG_BACKEND_CLASS(klass) \
|
#define RNG_BACKEND_CLASS(klass) \
|
||||||
OBJECT_CLASS_CHECK(RngBackendClass, (klass), TYPE_RNG_BACKEND)
|
OBJECT_CLASS_CHECK(RngBackendClass, (klass), TYPE_RNG_BACKEND)
|
||||||
|
|
||||||
|
#define TYPE_RNG_BUILTIN "rng-builtin"
|
||||||
|
|
||||||
typedef struct RngRequest RngRequest;
|
typedef struct RngRequest RngRequest;
|
||||||
typedef struct RngBackendClass RngBackendClass;
|
typedef struct RngBackendClass RngBackendClass;
|
||||||
typedef struct RngBackend RngBackend;
|
typedef struct RngBackend RngBackend;
|
||||||
|
@ -4332,6 +4332,13 @@ other options.
|
|||||||
|
|
||||||
The @option{share} boolean option is @var{on} by default with memfd.
|
The @option{share} boolean option is @var{on} by default with memfd.
|
||||||
|
|
||||||
|
@item -object rng-builtin,id=@var{id}
|
||||||
|
|
||||||
|
Creates a random number generator backend which obtains entropy from
|
||||||
|
QEMU builtin functions. The @option{id} parameter is a unique ID that
|
||||||
|
will be used to reference this entropy backend from the @option{virtio-rng}
|
||||||
|
device. By default, the @option{virtio-rng} device uses this RNG backend.
|
||||||
|
|
||||||
@item -object rng-random,id=@var{id},filename=@var{/dev/random}
|
@item -object rng-random,id=@var{id},filename=@var{/dev/random}
|
||||||
|
|
||||||
Creates a random number generator backend which obtains entropy from
|
Creates a random number generator backend which obtains entropy from
|
||||||
|
Loading…
Reference in New Issue
Block a user