virtio,vhost,pc: fixes and updates
balloon fixes wrt migration virtio-vsock device support Signed-off-by: Michael S. Tsirkin <mst@redhat.com> -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABAgAGBQJX0ytNAAoJECgfDbjSjVRp7GYH/0eRSoQhStOIa8LA8AmNTl6O +qf1oTXKIIVgnTqcs/YR/ELLiS2ncSVyMqsXD9Cm87RtqBKRgdfVR8lJ/2LfGXMD bRiyUdvceJ83Jz9F6UQJddpAAigQaUOzef+wKGofl3nCveSl/PdpJxektOlS2RCu nJvRRQza9m2XIGK2rKzY9vXNpubpcrwHoG7m74VtirAdg/s5p51e2UJ9KQuwr9nG zleZTs3RBrwh5W+iUOZFk3aQFGX2fnlw7P6F16QmfuQ7N/OMaaQ6WAmdz4uzzWic s3s9VZzZ4tIaZBZjUVgsDUubUKW4Gy5yFEUE3796VFCpiF6y7bI2gVGRT+0Qo7o= =/X+O -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging virtio,vhost,pc: fixes and updates balloon fixes wrt migration virtio-vsock device support Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # gpg: Signature made Fri 09 Sep 2016 22:36:13 BST # gpg: using RSA key 0x281F0DB8D28D5469 # gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" # gpg: aka "Michael S. Tsirkin <mst@redhat.com>" # 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: vhost-vsock: add virtio sockets device tests/acpi: speedup acpi tests virtio-pci: minor refactoring vhost: don't set vring call if no vector virtio-pci: error out when both legacy and modern modes are disabled virtio-balloon: fix stats vq migration virtio: add virtqueue_rewind() virtio-balloon: discard virtqueue element on reset virtio: zero vq->inuse in virtio_reset() virtio-pci: reduce modern_mem_bar size target-i386: present virtual L3 cache info for vcpus pc: Add 2.8 machine virtio-pci: use size from correct structure virtio: Tell the user what went wrong when event_notifier_init failed Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
c569c537e5
10
configure
vendored
10
configure
vendored
|
@ -229,6 +229,7 @@ xfs=""
|
|||
|
||||
vhost_net="no"
|
||||
vhost_scsi="no"
|
||||
vhost_vsock="no"
|
||||
kvm="no"
|
||||
rdma=""
|
||||
gprof="no"
|
||||
|
@ -674,6 +675,7 @@ Haiku)
|
|||
kvm="yes"
|
||||
vhost_net="yes"
|
||||
vhost_scsi="yes"
|
||||
vhost_vsock="yes"
|
||||
QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES"
|
||||
;;
|
||||
esac
|
||||
|
@ -1017,6 +1019,10 @@ for opt do
|
|||
;;
|
||||
--enable-vhost-scsi) vhost_scsi="yes"
|
||||
;;
|
||||
--disable-vhost-vsock) vhost_vsock="no"
|
||||
;;
|
||||
--enable-vhost-vsock) vhost_vsock="yes"
|
||||
;;
|
||||
--disable-opengl) opengl="no"
|
||||
;;
|
||||
--enable-opengl) opengl="yes"
|
||||
|
@ -4883,6 +4889,7 @@ echo "uuid support $uuid"
|
|||
echo "libcap-ng support $cap_ng"
|
||||
echo "vhost-net support $vhost_net"
|
||||
echo "vhost-scsi support $vhost_scsi"
|
||||
echo "vhost-vsock support $vhost_vsock"
|
||||
echo "Trace backends $trace_backends"
|
||||
if have_backend "simple"; then
|
||||
echo "Trace output file $trace_file-<pid>"
|
||||
|
@ -5264,6 +5271,9 @@ fi
|
|||
if test "$vhost_net" = "yes" ; then
|
||||
echo "CONFIG_VHOST_NET_USED=y" >> $config_host_mak
|
||||
fi
|
||||
if test "$vhost_vsock" = "yes" ; then
|
||||
echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
|
||||
fi
|
||||
if test "$blobs" = "yes" ; then
|
||||
echo "INSTALL_BLOBS=yes" >> $config_host_mak
|
||||
fi
|
||||
|
|
|
@ -437,13 +437,25 @@ static void pc_i440fx_machine_options(MachineClass *m)
|
|||
m->default_display = "std";
|
||||
}
|
||||
|
||||
static void pc_i440fx_2_7_machine_options(MachineClass *m)
|
||||
static void pc_i440fx_2_8_machine_options(MachineClass *m)
|
||||
{
|
||||
pc_i440fx_machine_options(m);
|
||||
m->alias = "pc";
|
||||
m->is_default = 1;
|
||||
}
|
||||
|
||||
DEFINE_I440FX_MACHINE(v2_8, "pc-i440fx-2.8", NULL,
|
||||
pc_i440fx_2_8_machine_options);
|
||||
|
||||
|
||||
static void pc_i440fx_2_7_machine_options(MachineClass *m)
|
||||
{
|
||||
pc_i440fx_2_8_machine_options(m);
|
||||
m->is_default = 0;
|
||||
m->alias = NULL;
|
||||
SET_MACHINE_COMPAT(m, PC_COMPAT_2_7);
|
||||
}
|
||||
|
||||
DEFINE_I440FX_MACHINE(v2_7, "pc-i440fx-2.7", NULL,
|
||||
pc_i440fx_2_7_machine_options);
|
||||
|
||||
|
@ -452,8 +464,6 @@ static void pc_i440fx_2_6_machine_options(MachineClass *m)
|
|||
{
|
||||
PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
|
||||
pc_i440fx_2_7_machine_options(m);
|
||||
m->is_default = 0;
|
||||
m->alias = NULL;
|
||||
pcmc->legacy_cpu_hotplug = true;
|
||||
SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
|
||||
}
|
||||
|
|
|
@ -293,12 +293,22 @@ static void pc_q35_machine_options(MachineClass *m)
|
|||
m->has_dynamic_sysbus = true;
|
||||
}
|
||||
|
||||
static void pc_q35_2_7_machine_options(MachineClass *m)
|
||||
static void pc_q35_2_8_machine_options(MachineClass *m)
|
||||
{
|
||||
pc_q35_machine_options(m);
|
||||
m->alias = "q35";
|
||||
}
|
||||
|
||||
DEFINE_Q35_MACHINE(v2_8, "pc-q35-2.8", NULL,
|
||||
pc_q35_2_8_machine_options);
|
||||
|
||||
static void pc_q35_2_7_machine_options(MachineClass *m)
|
||||
{
|
||||
pc_q35_2_8_machine_options(m);
|
||||
m->alias = NULL;
|
||||
SET_MACHINE_COMPAT(m, PC_COMPAT_2_7);
|
||||
}
|
||||
|
||||
DEFINE_Q35_MACHINE(v2_7, "pc-q35-2.7", NULL,
|
||||
pc_q35_2_7_machine_options);
|
||||
|
||||
|
@ -306,7 +316,6 @@ static void pc_q35_2_6_machine_options(MachineClass *m)
|
|||
{
|
||||
PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
|
||||
pc_q35_2_7_machine_options(m);
|
||||
m->alias = NULL;
|
||||
pcmc->legacy_cpu_hotplug = true;
|
||||
SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
|
||||
}
|
||||
|
|
|
@ -1658,6 +1658,57 @@ static const TypeInfo virtio_ccw_9p_info = {
|
|||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
|
||||
static Property vhost_vsock_ccw_properties[] = {
|
||||
DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id),
|
||||
DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
|
||||
VIRTIO_CCW_MAX_REV),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
|
||||
static void vhost_vsock_ccw_realize(VirtioCcwDevice *ccw_dev, Error **errp)
|
||||
{
|
||||
VHostVSockCCWState *dev = VHOST_VSOCK_CCW(ccw_dev);
|
||||
DeviceState *vdev = DEVICE(&dev->vdev);
|
||||
Error *err = NULL;
|
||||
|
||||
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
|
||||
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
}
|
||||
}
|
||||
|
||||
static void vhost_vsock_ccw_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
|
||||
|
||||
k->realize = vhost_vsock_ccw_realize;
|
||||
k->exit = virtio_ccw_exit;
|
||||
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
||||
dc->props = vhost_vsock_ccw_properties;
|
||||
dc->reset = virtio_ccw_reset;
|
||||
}
|
||||
|
||||
static void vhost_vsock_ccw_instance_init(Object *obj)
|
||||
{
|
||||
VHostVSockCCWState *dev = VHOST_VSOCK_CCW(obj);
|
||||
|
||||
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
||||
TYPE_VHOST_VSOCK);
|
||||
}
|
||||
|
||||
static const TypeInfo vhost_vsock_ccw_info = {
|
||||
.name = TYPE_VHOST_VSOCK_CCW,
|
||||
.parent = TYPE_VIRTIO_CCW_DEVICE,
|
||||
.instance_size = sizeof(VHostVSockCCWState),
|
||||
.instance_init = vhost_vsock_ccw_instance_init,
|
||||
.class_init = vhost_vsock_ccw_class_init,
|
||||
};
|
||||
#endif
|
||||
|
||||
static void virtio_ccw_register(void)
|
||||
{
|
||||
type_register_static(&virtio_ccw_bus_info);
|
||||
|
@ -1674,6 +1725,9 @@ static void virtio_ccw_register(void)
|
|||
#ifdef CONFIG_VIRTFS
|
||||
type_register_static(&virtio_ccw_9p_info);
|
||||
#endif
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
type_register_static(&vhost_vsock_ccw_info);
|
||||
#endif
|
||||
}
|
||||
|
||||
type_init(virtio_ccw_register)
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include "hw/virtio/virtio-balloon.h"
|
||||
#include "hw/virtio/virtio-rng.h"
|
||||
#include "hw/virtio/virtio-bus.h"
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
#include "hw/virtio/vhost-vsock.h"
|
||||
#endif /* CONFIG_VHOST_VSOCK */
|
||||
|
||||
#include "hw/s390x/s390_flic.h"
|
||||
#include "hw/s390x/css.h"
|
||||
|
@ -197,4 +200,16 @@ typedef struct V9fsCCWState {
|
|||
|
||||
#endif /* CONFIG_VIRTFS */
|
||||
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
#define TYPE_VHOST_VSOCK_CCW "vhost-vsock-ccw"
|
||||
#define VHOST_VSOCK_CCW(obj) \
|
||||
OBJECT_CHECK(VHostVSockCCWState, (obj), TYPE_VHOST_VSOCK_CCW)
|
||||
|
||||
typedef struct VHostVSockCCWState {
|
||||
VirtioCcwDevice parent_obj;
|
||||
VHostVSock vdev;
|
||||
} VHostVSockCCWState;
|
||||
|
||||
#endif /* CONFIG_VHOST_VSOCK */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,3 +5,5 @@ common-obj-y += virtio-mmio.o
|
|||
|
||||
obj-y += virtio.o virtio-balloon.o
|
||||
obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
|
||||
|
||||
obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
|
||||
|
|
|
@ -172,6 +172,19 @@ static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx)
|
|||
return idx - dev->vq_index;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
static int vhost_kernel_vsock_set_guest_cid(struct vhost_dev *dev,
|
||||
uint64_t guest_cid)
|
||||
{
|
||||
return vhost_kernel_call(dev, VHOST_VSOCK_SET_GUEST_CID, &guest_cid);
|
||||
}
|
||||
|
||||
static int vhost_kernel_vsock_set_running(struct vhost_dev *dev, int start)
|
||||
{
|
||||
return vhost_kernel_call(dev, VHOST_VSOCK_SET_RUNNING, &start);
|
||||
}
|
||||
#endif /* CONFIG_VHOST_VSOCK */
|
||||
|
||||
static const VhostOps kernel_ops = {
|
||||
.backend_type = VHOST_BACKEND_TYPE_KERNEL,
|
||||
.vhost_backend_init = vhost_kernel_init,
|
||||
|
@ -197,6 +210,10 @@ static const VhostOps kernel_ops = {
|
|||
.vhost_set_owner = vhost_kernel_set_owner,
|
||||
.vhost_reset_device = vhost_kernel_reset_device,
|
||||
.vhost_get_vq_index = vhost_kernel_get_vq_index,
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
.vhost_vsock_set_guest_cid = vhost_kernel_vsock_set_guest_cid,
|
||||
.vhost_vsock_set_running = vhost_kernel_vsock_set_running,
|
||||
#endif /* CONFIG_VHOST_VSOCK */
|
||||
};
|
||||
|
||||
int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type)
|
||||
|
|
417
hw/virtio/vhost-vsock.c
Normal file
417
hw/virtio/vhost-vsock.c
Normal file
|
@ -0,0 +1,417 @@
|
|||
/*
|
||||
* Virtio vsock device
|
||||
*
|
||||
* Copyright 2015 Red Hat, Inc.
|
||||
*
|
||||
* Authors:
|
||||
* Stefan Hajnoczi <stefanha@redhat.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or
|
||||
* (at your option) any later version. See the COPYING file in the
|
||||
* top-level directory.
|
||||
*/
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include "qemu/osdep.h"
|
||||
#include "standard-headers/linux/virtio_vsock.h"
|
||||
#include "qapi/error.h"
|
||||
#include "hw/virtio/virtio-bus.h"
|
||||
#include "hw/virtio/virtio-access.h"
|
||||
#include "migration/migration.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "hw/virtio/vhost-vsock.h"
|
||||
#include "qemu/iov.h"
|
||||
#include "monitor/monitor.h"
|
||||
|
||||
enum {
|
||||
VHOST_VSOCK_SAVEVM_VERSION = 0,
|
||||
|
||||
VHOST_VSOCK_QUEUE_SIZE = 128,
|
||||
};
|
||||
|
||||
static void vhost_vsock_get_config(VirtIODevice *vdev, uint8_t *config)
|
||||
{
|
||||
VHostVSock *vsock = VHOST_VSOCK(vdev);
|
||||
struct virtio_vsock_config vsockcfg = {};
|
||||
|
||||
virtio_stq_p(vdev, &vsockcfg.guest_cid, vsock->conf.guest_cid);
|
||||
memcpy(config, &vsockcfg, sizeof(vsockcfg));
|
||||
}
|
||||
|
||||
static int vhost_vsock_set_guest_cid(VHostVSock *vsock)
|
||||
{
|
||||
const VhostOps *vhost_ops = vsock->vhost_dev.vhost_ops;
|
||||
int ret;
|
||||
|
||||
if (!vhost_ops->vhost_vsock_set_guest_cid) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
ret = vhost_ops->vhost_vsock_set_guest_cid(&vsock->vhost_dev,
|
||||
vsock->conf.guest_cid);
|
||||
if (ret < 0) {
|
||||
return -errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vhost_vsock_set_running(VHostVSock *vsock, int start)
|
||||
{
|
||||
const VhostOps *vhost_ops = vsock->vhost_dev.vhost_ops;
|
||||
int ret;
|
||||
|
||||
if (!vhost_ops->vhost_vsock_set_running) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
ret = vhost_ops->vhost_vsock_set_running(&vsock->vhost_dev, start);
|
||||
if (ret < 0) {
|
||||
return -errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vhost_vsock_start(VirtIODevice *vdev)
|
||||
{
|
||||
VHostVSock *vsock = VHOST_VSOCK(vdev);
|
||||
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
|
||||
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
if (!k->set_guest_notifiers) {
|
||||
error_report("binding does not support guest notifiers");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = vhost_dev_enable_notifiers(&vsock->vhost_dev, vdev);
|
||||
if (ret < 0) {
|
||||
error_report("Error enabling host notifiers: %d", -ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = k->set_guest_notifiers(qbus->parent, vsock->vhost_dev.nvqs, true);
|
||||
if (ret < 0) {
|
||||
error_report("Error binding guest notifier: %d", -ret);
|
||||
goto err_host_notifiers;
|
||||
}
|
||||
|
||||
vsock->vhost_dev.acked_features = vdev->guest_features;
|
||||
ret = vhost_dev_start(&vsock->vhost_dev, vdev);
|
||||
if (ret < 0) {
|
||||
error_report("Error starting vhost: %d", -ret);
|
||||
goto err_guest_notifiers;
|
||||
}
|
||||
|
||||
ret = vhost_vsock_set_running(vsock, 1);
|
||||
if (ret < 0) {
|
||||
error_report("Error starting vhost vsock: %d", -ret);
|
||||
goto err_dev_start;
|
||||
}
|
||||
|
||||
/* guest_notifier_mask/pending not used yet, so just unmask
|
||||
* everything here. virtio-pci will do the right thing by
|
||||
* enabling/disabling irqfd.
|
||||
*/
|
||||
for (i = 0; i < vsock->vhost_dev.nvqs; i++) {
|
||||
vhost_virtqueue_mask(&vsock->vhost_dev, vdev, i, false);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
err_dev_start:
|
||||
vhost_dev_stop(&vsock->vhost_dev, vdev);
|
||||
err_guest_notifiers:
|
||||
k->set_guest_notifiers(qbus->parent, vsock->vhost_dev.nvqs, false);
|
||||
err_host_notifiers:
|
||||
vhost_dev_disable_notifiers(&vsock->vhost_dev, vdev);
|
||||
}
|
||||
|
||||
static void vhost_vsock_stop(VirtIODevice *vdev)
|
||||
{
|
||||
VHostVSock *vsock = VHOST_VSOCK(vdev);
|
||||
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
|
||||
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
|
||||
int ret;
|
||||
|
||||
if (!k->set_guest_notifiers) {
|
||||
return;
|
||||
}
|
||||
|
||||
ret = vhost_vsock_set_running(vsock, 0);
|
||||
if (ret < 0) {
|
||||
error_report("vhost vsock set running failed: %d", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
vhost_dev_stop(&vsock->vhost_dev, vdev);
|
||||
|
||||
ret = k->set_guest_notifiers(qbus->parent, vsock->vhost_dev.nvqs, false);
|
||||
if (ret < 0) {
|
||||
error_report("vhost guest notifier cleanup failed: %d", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
vhost_dev_disable_notifiers(&vsock->vhost_dev, vdev);
|
||||
}
|
||||
|
||||
static void vhost_vsock_set_status(VirtIODevice *vdev, uint8_t status)
|
||||
{
|
||||
VHostVSock *vsock = VHOST_VSOCK(vdev);
|
||||
bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
|
||||
|
||||
if (!vdev->vm_running) {
|
||||
should_start = false;
|
||||
}
|
||||
|
||||
if (vsock->vhost_dev.started == should_start) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (should_start) {
|
||||
vhost_vsock_start(vdev);
|
||||
} else {
|
||||
vhost_vsock_stop(vdev);
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t vhost_vsock_get_features(VirtIODevice *vdev,
|
||||
uint64_t requested_features,
|
||||
Error **errp)
|
||||
{
|
||||
/* No feature bits used yet */
|
||||
return requested_features;
|
||||
}
|
||||
|
||||
static void vhost_vsock_handle_output(VirtIODevice *vdev, VirtQueue *vq)
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
static void vhost_vsock_guest_notifier_mask(VirtIODevice *vdev, int idx,
|
||||
bool mask)
|
||||
{
|
||||
VHostVSock *vsock = VHOST_VSOCK(vdev);
|
||||
|
||||
vhost_virtqueue_mask(&vsock->vhost_dev, vdev, idx, mask);
|
||||
}
|
||||
|
||||
static bool vhost_vsock_guest_notifier_pending(VirtIODevice *vdev, int idx)
|
||||
{
|
||||
VHostVSock *vsock = VHOST_VSOCK(vdev);
|
||||
|
||||
return vhost_virtqueue_pending(&vsock->vhost_dev, idx);
|
||||
}
|
||||
|
||||
static void vhost_vsock_send_transport_reset(VHostVSock *vsock)
|
||||
{
|
||||
VirtQueueElement *elem;
|
||||
VirtQueue *vq = vsock->event_vq;
|
||||
struct virtio_vsock_event event = {
|
||||
.id = cpu_to_le32(VIRTIO_VSOCK_EVENT_TRANSPORT_RESET),
|
||||
};
|
||||
|
||||
elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
|
||||
if (!elem) {
|
||||
error_report("vhost-vsock missed transport reset event");
|
||||
return;
|
||||
}
|
||||
|
||||
if (elem->out_num) {
|
||||
error_report("invalid vhost-vsock event virtqueue element with "
|
||||
"out buffers");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (iov_from_buf(elem->in_sg, elem->in_num, 0,
|
||||
&event, sizeof(event)) != sizeof(event)) {
|
||||
error_report("vhost-vsock event virtqueue element is too short");
|
||||
goto out;
|
||||
}
|
||||
|
||||
virtqueue_push(vq, elem, sizeof(event));
|
||||
virtio_notify(VIRTIO_DEVICE(vsock), vq);
|
||||
|
||||
out:
|
||||
g_free(elem);
|
||||
}
|
||||
|
||||
static void vhost_vsock_save(QEMUFile *f, void *opaque, size_t size)
|
||||
{
|
||||
VHostVSock *vsock = opaque;
|
||||
VirtIODevice *vdev = VIRTIO_DEVICE(vsock);
|
||||
|
||||
/* At this point, backend must be stopped, otherwise
|
||||
* it might keep writing to memory. */
|
||||
assert(!vsock->vhost_dev.started);
|
||||
virtio_save(vdev, f);
|
||||
}
|
||||
|
||||
static void vhost_vsock_post_load_timer_cleanup(VHostVSock *vsock)
|
||||
{
|
||||
if (!vsock->post_load_timer) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_del(vsock->post_load_timer);
|
||||
timer_free(vsock->post_load_timer);
|
||||
vsock->post_load_timer = NULL;
|
||||
}
|
||||
|
||||
static void vhost_vsock_post_load_timer_cb(void *opaque)
|
||||
{
|
||||
VHostVSock *vsock = opaque;
|
||||
|
||||
vhost_vsock_post_load_timer_cleanup(vsock);
|
||||
vhost_vsock_send_transport_reset(vsock);
|
||||
}
|
||||
|
||||
static int vhost_vsock_load(QEMUFile *f, void *opaque, size_t size)
|
||||
{
|
||||
VHostVSock *vsock = opaque;
|
||||
VirtIODevice *vdev = VIRTIO_DEVICE(vsock);
|
||||
int ret;
|
||||
|
||||
ret = virtio_load(vdev, f, VHOST_VSOCK_SAVEVM_VERSION);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (virtio_queue_get_addr(vdev, 2)) {
|
||||
/* Defer transport reset event to a vm clock timer so that virtqueue
|
||||
* changes happen after migration has completed.
|
||||
*/
|
||||
assert(!vsock->post_load_timer);
|
||||
vsock->post_load_timer =
|
||||
timer_new_ns(QEMU_CLOCK_VIRTUAL,
|
||||
vhost_vsock_post_load_timer_cb,
|
||||
vsock);
|
||||
timer_mod(vsock->post_load_timer, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VMSTATE_VIRTIO_DEVICE(vhost_vsock, VHOST_VSOCK_SAVEVM_VERSION,
|
||||
vhost_vsock_load, vhost_vsock_save);
|
||||
|
||||
static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
||||
VHostVSock *vsock = VHOST_VSOCK(dev);
|
||||
int vhostfd;
|
||||
int ret;
|
||||
|
||||
/* Refuse to use reserved CID numbers */
|
||||
if (vsock->conf.guest_cid <= 2) {
|
||||
error_setg(errp, "guest-cid property must be greater than 2");
|
||||
return;
|
||||
}
|
||||
|
||||
if (vsock->conf.guest_cid > UINT32_MAX) {
|
||||
error_setg(errp, "guest-cid property must be a 32-bit number");
|
||||
return;
|
||||
}
|
||||
|
||||
if (vsock->conf.vhostfd) {
|
||||
vhostfd = monitor_fd_param(cur_mon, vsock->conf.vhostfd, errp);
|
||||
if (vhostfd == -1) {
|
||||
error_prepend(errp, "vhost-vsock: unable to parse vhostfd: ");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
vhostfd = open("/dev/vhost-vsock", O_RDWR);
|
||||
if (vhostfd < 0) {
|
||||
error_setg_errno(errp, -errno,
|
||||
"vhost-vsock: failed to open vhost device");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
virtio_init(vdev, "vhost-vsock", VIRTIO_ID_VSOCK,
|
||||
sizeof(struct virtio_vsock_config));
|
||||
|
||||
/* Receive and transmit queues belong to vhost */
|
||||
virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE, vhost_vsock_handle_output);
|
||||
virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE, vhost_vsock_handle_output);
|
||||
|
||||
/* The event queue belongs to QEMU */
|
||||
vsock->event_vq = virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE,
|
||||
vhost_vsock_handle_output);
|
||||
|
||||
vsock->vhost_dev.nvqs = ARRAY_SIZE(vsock->vhost_vqs);
|
||||
vsock->vhost_dev.vqs = vsock->vhost_vqs;
|
||||
ret = vhost_dev_init(&vsock->vhost_dev, (void *)(uintptr_t)vhostfd,
|
||||
VHOST_BACKEND_TYPE_KERNEL, 0);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "vhost-vsock: vhost_dev_init failed");
|
||||
goto err_virtio;
|
||||
}
|
||||
|
||||
ret = vhost_vsock_set_guest_cid(vsock);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "vhost-vsock: unable to set guest cid");
|
||||
goto err_vhost_dev;
|
||||
}
|
||||
|
||||
vsock->post_load_timer = NULL;
|
||||
return;
|
||||
|
||||
err_vhost_dev:
|
||||
vhost_dev_cleanup(&vsock->vhost_dev);
|
||||
err_virtio:
|
||||
virtio_cleanup(vdev);
|
||||
close(vhostfd);
|
||||
return;
|
||||
}
|
||||
|
||||
static void vhost_vsock_device_unrealize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
||||
VHostVSock *vsock = VHOST_VSOCK(dev);
|
||||
|
||||
vhost_vsock_post_load_timer_cleanup(vsock);
|
||||
|
||||
/* This will stop vhost backend if appropriate. */
|
||||
vhost_vsock_set_status(vdev, 0);
|
||||
|
||||
vhost_dev_cleanup(&vsock->vhost_dev);
|
||||
virtio_cleanup(vdev);
|
||||
}
|
||||
|
||||
static Property vhost_vsock_properties[] = {
|
||||
DEFINE_PROP_UINT64("guest-cid", VHostVSock, conf.guest_cid, 0),
|
||||
DEFINE_PROP_STRING("vhostfd", VHostVSock, conf.vhostfd),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
|
||||
static void vhost_vsock_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
|
||||
|
||||
dc->props = vhost_vsock_properties;
|
||||
dc->vmsd = &vmstate_virtio_vhost_vsock;
|
||||
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
||||
vdc->realize = vhost_vsock_device_realize;
|
||||
vdc->unrealize = vhost_vsock_device_unrealize;
|
||||
vdc->get_features = vhost_vsock_get_features;
|
||||
vdc->get_config = vhost_vsock_get_config;
|
||||
vdc->set_status = vhost_vsock_set_status;
|
||||
vdc->guest_notifier_mask = vhost_vsock_guest_notifier_mask;
|
||||
vdc->guest_notifier_pending = vhost_vsock_guest_notifier_pending;
|
||||
}
|
||||
|
||||
static const TypeInfo vhost_vsock_info = {
|
||||
.name = TYPE_VHOST_VSOCK,
|
||||
.parent = TYPE_VIRTIO_DEVICE,
|
||||
.instance_size = sizeof(VHostVSock),
|
||||
.class_init = vhost_vsock_class_init,
|
||||
};
|
||||
|
||||
static void vhost_vsock_register_types(void)
|
||||
{
|
||||
type_register_static(&vhost_vsock_info);
|
||||
}
|
||||
|
||||
type_init(vhost_vsock_register_types)
|
|
@ -822,6 +822,9 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
|
|||
struct vhost_virtqueue *vq,
|
||||
unsigned idx)
|
||||
{
|
||||
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
|
||||
VirtioBusState *vbus = VIRTIO_BUS(qbus);
|
||||
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
|
||||
hwaddr s, l, a;
|
||||
int r;
|
||||
int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, idx);
|
||||
|
@ -912,8 +915,19 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
|
|||
vhost_virtqueue_mask(dev, vdev, idx, false);
|
||||
}
|
||||
|
||||
if (k->query_guest_notifiers &&
|
||||
k->query_guest_notifiers(qbus->parent) &&
|
||||
virtio_queue_vector(vdev, idx) == VIRTIO_NO_VECTOR) {
|
||||
file.fd = -1;
|
||||
r = dev->vhost_ops->vhost_set_vring_call(dev, &file);
|
||||
if (r) {
|
||||
goto fail_vector;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
fail_vector:
|
||||
fail_kick:
|
||||
fail_alloc:
|
||||
cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),
|
||||
|
|
|
@ -463,11 +463,24 @@ static void virtio_balloon_device_reset(VirtIODevice *vdev)
|
|||
VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
|
||||
|
||||
if (s->stats_vq_elem != NULL) {
|
||||
virtqueue_discard(s->svq, s->stats_vq_elem, 0);
|
||||
g_free(s->stats_vq_elem);
|
||||
s->stats_vq_elem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void virtio_balloon_set_status(VirtIODevice *vdev, uint8_t status)
|
||||
{
|
||||
VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
|
||||
|
||||
if (!s->stats_vq_elem && vdev->vm_running &&
|
||||
(status & VIRTIO_CONFIG_S_DRIVER_OK) && virtqueue_rewind(s->svq, 1)) {
|
||||
/* poll stats queue for the element we have discarded when the VM
|
||||
* was stopped */
|
||||
virtio_balloon_receive_stats(vdev, s->svq);
|
||||
}
|
||||
}
|
||||
|
||||
static void virtio_balloon_instance_init(Object *obj)
|
||||
{
|
||||
VirtIOBalloon *s = VIRTIO_BALLOON(obj);
|
||||
|
@ -505,6 +518,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data)
|
|||
vdc->get_features = virtio_balloon_get_features;
|
||||
vdc->save = virtio_balloon_save_device;
|
||||
vdc->load = virtio_balloon_load_device;
|
||||
vdc->set_status = virtio_balloon_set_status;
|
||||
}
|
||||
|
||||
static const TypeInfo virtio_balloon_info = {
|
||||
|
|
|
@ -164,7 +164,8 @@ static int set_host_notifier_internal(DeviceState *proxy, VirtioBusState *bus,
|
|||
if (assign) {
|
||||
r = event_notifier_init(notifier, 1);
|
||||
if (r < 0) {
|
||||
error_report("%s: unable to init event notifier: %d", __func__, r);
|
||||
error_report("%s: unable to init event notifier: %s (%d)",
|
||||
__func__, strerror(-r), r);
|
||||
return r;
|
||||
}
|
||||
virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
|
||||
|
|
|
@ -294,6 +294,12 @@ static void virtio_pci_ioeventfd_set_disabled(DeviceState *d, bool disabled)
|
|||
|
||||
#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000
|
||||
|
||||
static inline int virtio_pci_queue_mem_mult(struct VirtIOPCIProxy *proxy)
|
||||
{
|
||||
return (proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ) ?
|
||||
QEMU_VIRTIO_PCI_QUEUE_MEM_MULT : 4;
|
||||
}
|
||||
|
||||
static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
|
||||
int n, bool assign)
|
||||
{
|
||||
|
@ -307,7 +313,7 @@ static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
|
|||
MemoryRegion *modern_mr = &proxy->notify.mr;
|
||||
MemoryRegion *modern_notify_mr = &proxy->notify_pio.mr;
|
||||
MemoryRegion *legacy_mr = &proxy->bar;
|
||||
hwaddr modern_addr = QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
|
||||
hwaddr modern_addr = virtio_pci_queue_mem_mult(proxy) *
|
||||
virtio_get_queue_index(vq);
|
||||
hwaddr legacy_addr = VIRTIO_PCI_QUEUE_NOTIFY;
|
||||
|
||||
|
@ -1370,7 +1376,8 @@ static void virtio_pci_notify_write(void *opaque, hwaddr addr,
|
|||
uint64_t val, unsigned size)
|
||||
{
|
||||
VirtIODevice *vdev = opaque;
|
||||
unsigned queue = addr / QEMU_VIRTIO_PCI_QUEUE_MEM_MULT;
|
||||
VirtIOPCIProxy *proxy = VIRTIO_PCI(DEVICE(vdev)->parent_bus->parent);
|
||||
unsigned queue = addr / virtio_pci_queue_mem_mult(proxy);
|
||||
|
||||
if (queue < VIRTIO_QUEUE_MAX) {
|
||||
virtio_queue_notify(vdev, queue);
|
||||
|
@ -1520,7 +1527,7 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy)
|
|||
¬ify_pio_ops,
|
||||
virtio_bus_get_device(&proxy->bus),
|
||||
"virtio-pci-notify-pio",
|
||||
proxy->notify.size);
|
||||
proxy->notify_pio.size);
|
||||
}
|
||||
|
||||
static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy,
|
||||
|
@ -1609,7 +1616,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
|
|||
struct virtio_pci_notify_cap notify = {
|
||||
.cap.cap_len = sizeof notify,
|
||||
.notify_off_multiplier =
|
||||
cpu_to_le32(QEMU_VIRTIO_PCI_QUEUE_MEM_MULT),
|
||||
cpu_to_le32(virtio_pci_queue_mem_mult(proxy)),
|
||||
};
|
||||
struct virtio_pci_cfg_cap cfg = {
|
||||
.cap.cap_len = sizeof cfg,
|
||||
|
@ -1744,8 +1751,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
|
|||
proxy->device.type = VIRTIO_PCI_CAP_DEVICE_CFG;
|
||||
|
||||
proxy->notify.offset = 0x3000;
|
||||
proxy->notify.size =
|
||||
QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * VIRTIO_QUEUE_MAX;
|
||||
proxy->notify.size = virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MAX;
|
||||
proxy->notify.type = VIRTIO_PCI_CAP_NOTIFY_CFG;
|
||||
|
||||
proxy->notify_pio.offset = 0x0;
|
||||
|
@ -1754,8 +1760,8 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
|
|||
|
||||
/* subclasses can enforce modern, so do this unconditionally */
|
||||
memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci",
|
||||
2 * QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
|
||||
VIRTIO_QUEUE_MAX);
|
||||
/* PCI BAR regions must be powers of 2 */
|
||||
pow2ceil(proxy->notify.offset + proxy->notify.size));
|
||||
|
||||
memory_region_init_alias(&proxy->modern_cfg,
|
||||
OBJECT(proxy),
|
||||
|
@ -1770,6 +1776,14 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
|
|||
proxy->disable_legacy = pcie_port ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
|
||||
}
|
||||
|
||||
if (!virtio_pci_modern(proxy) && !virtio_pci_legacy(proxy)) {
|
||||
error_setg(errp, "device cannot work as neither modern nor legacy mode"
|
||||
" is enabled");
|
||||
error_append_hint(errp, "Set either disable-modern or disable-legacy"
|
||||
" to off\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pcie_port && pci_is_express(pci_dev)) {
|
||||
int pos;
|
||||
|
||||
|
@ -1833,6 +1847,8 @@ static Property virtio_pci_properties[] = {
|
|||
VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT, false),
|
||||
DEFINE_PROP_BIT("x-disable-pcie", VirtIOPCIProxy, flags,
|
||||
VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT, false),
|
||||
DEFINE_PROP_BIT("page-per-vq", VirtIOPCIProxy, flags,
|
||||
VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT, false),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
|
||||
|
@ -2055,6 +2071,54 @@ static const TypeInfo vhost_scsi_pci_info = {
|
|||
};
|
||||
#endif
|
||||
|
||||
/* vhost-vsock-pci */
|
||||
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
static Property vhost_vsock_pci_properties[] = {
|
||||
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
|
||||
static void vhost_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
||||
{
|
||||
VHostVSockPCI *dev = VHOST_VSOCK_PCI(vpci_dev);
|
||||
DeviceState *vdev = DEVICE(&dev->vdev);
|
||||
|
||||
qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
|
||||
object_property_set_bool(OBJECT(vdev), true, "realized", errp);
|
||||
}
|
||||
|
||||
static void vhost_vsock_pci_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
|
||||
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
|
||||
k->realize = vhost_vsock_pci_realize;
|
||||
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
||||
dc->props = vhost_vsock_pci_properties;
|
||||
pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
|
||||
pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK;
|
||||
pcidev_k->revision = 0x00;
|
||||
pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
|
||||
}
|
||||
|
||||
static void vhost_vsock_pci_instance_init(Object *obj)
|
||||
{
|
||||
VHostVSockPCI *dev = VHOST_VSOCK_PCI(obj);
|
||||
|
||||
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
||||
TYPE_VHOST_VSOCK);
|
||||
}
|
||||
|
||||
static const TypeInfo vhost_vsock_pci_info = {
|
||||
.name = TYPE_VHOST_VSOCK_PCI,
|
||||
.parent = TYPE_VIRTIO_PCI,
|
||||
.instance_size = sizeof(VHostVSockPCI),
|
||||
.instance_init = vhost_vsock_pci_instance_init,
|
||||
.class_init = vhost_vsock_pci_class_init,
|
||||
};
|
||||
#endif
|
||||
|
||||
/* virtio-balloon-pci */
|
||||
|
||||
static Property virtio_balloon_pci_properties[] = {
|
||||
|
@ -2485,6 +2549,9 @@ static void virtio_pci_register_types(void)
|
|||
#ifdef CONFIG_VHOST_SCSI
|
||||
type_register_static(&vhost_scsi_pci_info);
|
||||
#endif
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
type_register_static(&vhost_vsock_pci_info);
|
||||
#endif
|
||||
}
|
||||
|
||||
type_init(virtio_pci_register_types)
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#ifdef CONFIG_VHOST_SCSI
|
||||
#include "hw/virtio/vhost-scsi.h"
|
||||
#endif
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
#include "hw/virtio/vhost-vsock.h"
|
||||
#endif
|
||||
|
||||
typedef struct VirtIOPCIProxy VirtIOPCIProxy;
|
||||
typedef struct VirtIOBlkPCI VirtIOBlkPCI;
|
||||
|
@ -44,6 +47,7 @@ typedef struct VirtIOInputPCI VirtIOInputPCI;
|
|||
typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
|
||||
typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
|
||||
typedef struct VirtIOGPUPCI VirtIOGPUPCI;
|
||||
typedef struct VHostVSockPCI VHostVSockPCI;
|
||||
|
||||
/* virtio-pci-bus */
|
||||
|
||||
|
@ -64,6 +68,7 @@ enum {
|
|||
VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
|
||||
VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
|
||||
VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
|
||||
VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
|
||||
};
|
||||
|
||||
/* Need to activate work-arounds for buggy guests at vmstate load. */
|
||||
|
@ -84,6 +89,10 @@ enum {
|
|||
#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
|
||||
(1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
|
||||
|
||||
/* page per vq flag to be used by split drivers within guests */
|
||||
#define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
|
||||
(1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
|
||||
|
||||
typedef struct {
|
||||
MSIMessage msg;
|
||||
int virq;
|
||||
|
@ -324,6 +333,20 @@ struct VirtIOGPUPCI {
|
|||
VirtIOGPU vdev;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_VHOST_VSOCK
|
||||
/*
|
||||
* vhost-vsock-pci: This extends VirtioPCIProxy.
|
||||
*/
|
||||
#define TYPE_VHOST_VSOCK_PCI "vhost-vsock-pci"
|
||||
#define VHOST_VSOCK_PCI(obj) \
|
||||
OBJECT_CHECK(VHostVSockPCI, (obj), TYPE_VHOST_VSOCK_PCI)
|
||||
|
||||
struct VHostVSockPCI {
|
||||
VirtIOPCIProxy parent_obj;
|
||||
VHostVSock vdev;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Virtio ABI version, if we increment this, we break the guest driver. */
|
||||
#define VIRTIO_PCI_ABI_VERSION 0
|
||||
|
||||
|
|
|
@ -272,6 +272,28 @@ void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
|
|||
virtqueue_unmap_sg(vq, elem, len);
|
||||
}
|
||||
|
||||
/* virtqueue_rewind:
|
||||
* @vq: The #VirtQueue
|
||||
* @num: Number of elements to push back
|
||||
*
|
||||
* Pretend that elements weren't popped from the virtqueue. The next
|
||||
* virtqueue_pop() will refetch the oldest element.
|
||||
*
|
||||
* Use virtqueue_discard() instead if you have a VirtQueueElement.
|
||||
*
|
||||
* Returns: true on success, false if @num is greater than the number of in use
|
||||
* elements.
|
||||
*/
|
||||
bool virtqueue_rewind(VirtQueue *vq, unsigned int num)
|
||||
{
|
||||
if (num > vq->inuse) {
|
||||
return false;
|
||||
}
|
||||
vq->last_avail_idx -= num;
|
||||
vq->inuse -= num;
|
||||
return true;
|
||||
}
|
||||
|
||||
void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
|
||||
unsigned int len, unsigned int idx)
|
||||
{
|
||||
|
@ -822,6 +844,7 @@ void virtio_reset(void *opaque)
|
|||
vdev->vq[i].signalled_used_valid = false;
|
||||
vdev->vq[i].notification = true;
|
||||
vdev->vq[i].vring.num = vdev->vq[i].vring.num_default;
|
||||
vdev->vq[i].inuse = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,11 @@
|
|||
#define HW_COMPAT_H
|
||||
|
||||
#define HW_COMPAT_2_7 \
|
||||
/* empty */
|
||||
{\
|
||||
.driver = "virtio-pci",\
|
||||
.property = "page-per-vq",\
|
||||
.value = "on",\
|
||||
},
|
||||
|
||||
#define HW_COMPAT_2_6 \
|
||||
{\
|
||||
|
|
|
@ -368,6 +368,18 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
|
|||
int e820_get_num_entries(void);
|
||||
bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
|
||||
|
||||
#define PC_COMPAT_2_8 \
|
||||
{\
|
||||
.driver = TYPE_X86_CPU,\
|
||||
.property = "l3-cache",\
|
||||
.value = "off",\
|
||||
},
|
||||
|
||||
|
||||
#define PC_COMPAT_2_7 \
|
||||
PC_COMPAT_2_8 \
|
||||
HW_COMPAT_2_7
|
||||
|
||||
#define PC_COMPAT_2_6 \
|
||||
HW_COMPAT_2_6 \
|
||||
{\
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
#define PCI_DEVICE_ID_VIRTIO_SCSI 0x1004
|
||||
#define PCI_DEVICE_ID_VIRTIO_RNG 0x1005
|
||||
#define PCI_DEVICE_ID_VIRTIO_9P 0x1009
|
||||
#define PCI_DEVICE_ID_VIRTIO_VSOCK 0x1012
|
||||
|
||||
#define PCI_VENDOR_ID_REDHAT 0x1b36
|
||||
#define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001
|
||||
|
|
|
@ -73,6 +73,9 @@ typedef int (*vhost_migration_done_op)(struct vhost_dev *dev,
|
|||
typedef bool (*vhost_backend_can_merge_op)(struct vhost_dev *dev,
|
||||
uint64_t start1, uint64_t size1,
|
||||
uint64_t start2, uint64_t size2);
|
||||
typedef int (*vhost_vsock_set_guest_cid_op)(struct vhost_dev *dev,
|
||||
uint64_t guest_cid);
|
||||
typedef int (*vhost_vsock_set_running_op)(struct vhost_dev *dev, int start);
|
||||
|
||||
typedef struct VhostOps {
|
||||
VhostBackendType backend_type;
|
||||
|
@ -102,6 +105,8 @@ typedef struct VhostOps {
|
|||
vhost_requires_shm_log_op vhost_requires_shm_log;
|
||||
vhost_migration_done_op vhost_migration_done;
|
||||
vhost_backend_can_merge_op vhost_backend_can_merge;
|
||||
vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid;
|
||||
vhost_vsock_set_running_op vhost_vsock_set_running;
|
||||
} VhostOps;
|
||||
|
||||
extern const VhostOps user_ops;
|
||||
|
|
41
include/hw/virtio/vhost-vsock.h
Normal file
41
include/hw/virtio/vhost-vsock.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Vhost vsock virtio device
|
||||
*
|
||||
* Copyright 2015 Red Hat, Inc.
|
||||
*
|
||||
* Authors:
|
||||
* Stefan Hajnoczi <stefanha@redhat.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or
|
||||
* (at your option) any later version. See the COPYING file in the
|
||||
* top-level directory.
|
||||
*/
|
||||
|
||||
#ifndef _QEMU_VHOST_VSOCK_H
|
||||
#define _QEMU_VHOST_VSOCK_H
|
||||
|
||||
#include "hw/virtio/virtio.h"
|
||||
#include "hw/virtio/vhost.h"
|
||||
|
||||
#define TYPE_VHOST_VSOCK "vhost-vsock-device"
|
||||
#define VHOST_VSOCK(obj) \
|
||||
OBJECT_CHECK(VHostVSock, (obj), TYPE_VHOST_VSOCK)
|
||||
|
||||
typedef struct {
|
||||
uint64_t guest_cid;
|
||||
char *vhostfd;
|
||||
} VHostVSockConf;
|
||||
|
||||
typedef struct {
|
||||
/*< private >*/
|
||||
VirtIODevice parent;
|
||||
VHostVSockConf conf;
|
||||
struct vhost_virtqueue vhost_vqs[2];
|
||||
struct vhost_dev vhost_dev;
|
||||
VirtQueue *event_vq;
|
||||
QEMUTimer *post_load_timer;
|
||||
|
||||
/*< public >*/
|
||||
} VHostVSock;
|
||||
|
||||
#endif /* _QEMU_VHOST_VSOCK_H */
|
|
@ -154,6 +154,7 @@ void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
|
|||
void virtqueue_flush(VirtQueue *vq, unsigned int count);
|
||||
void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
|
||||
unsigned int len);
|
||||
bool virtqueue_rewind(VirtQueue *vq, unsigned int num);
|
||||
void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
|
||||
unsigned int len, unsigned int idx);
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
#define CPUID_2_L1D_32KB_8WAY_64B 0x2c
|
||||
#define CPUID_2_L1I_32KB_8WAY_64B 0x30
|
||||
#define CPUID_2_L2_2MB_8WAY_64B 0x7d
|
||||
#define CPUID_2_L3_16MB_16WAY_64B 0x4d
|
||||
|
||||
|
||||
/* CPUID Leaf 4 constants: */
|
||||
|
@ -131,11 +132,18 @@
|
|||
#define L2_LINES_PER_TAG 1
|
||||
#define L2_SIZE_KB_AMD 512
|
||||
|
||||
/* No L3 cache: */
|
||||
/* Level 3 unified cache: */
|
||||
#define L3_SIZE_KB 0 /* disabled */
|
||||
#define L3_ASSOCIATIVITY 0 /* disabled */
|
||||
#define L3_LINES_PER_TAG 0 /* disabled */
|
||||
#define L3_LINE_SIZE 0 /* disabled */
|
||||
#define L3_N_LINE_SIZE 64
|
||||
#define L3_N_ASSOCIATIVITY 16
|
||||
#define L3_N_SETS 16384
|
||||
#define L3_N_PARTITIONS 1
|
||||
#define L3_N_DESCRIPTOR CPUID_2_L3_16MB_16WAY_64B
|
||||
#define L3_N_LINES_PER_TAG 1
|
||||
#define L3_N_SIZE_KB_AMD 16384
|
||||
|
||||
/* TLB definitions: */
|
||||
|
||||
|
@ -2279,6 +2287,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
|||
{
|
||||
X86CPU *cpu = x86_env_get_cpu(env);
|
||||
CPUState *cs = CPU(cpu);
|
||||
uint32_t pkg_offset;
|
||||
|
||||
/* test if maximum index reached */
|
||||
if (index & 0x80000000) {
|
||||
|
@ -2332,7 +2341,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
|||
}
|
||||
*eax = 1; /* Number of CPUID[EAX=2] calls required */
|
||||
*ebx = 0;
|
||||
*ecx = 0;
|
||||
if (!cpu->enable_l3_cache) {
|
||||
*ecx = 0;
|
||||
} else {
|
||||
*ecx = L3_N_DESCRIPTOR;
|
||||
}
|
||||
*edx = (L1D_DESCRIPTOR << 16) | \
|
||||
(L1I_DESCRIPTOR << 8) | \
|
||||
(L2_DESCRIPTOR);
|
||||
|
@ -2378,6 +2391,25 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
|||
*ecx = L2_SETS - 1;
|
||||
*edx = CPUID_4_NO_INVD_SHARING;
|
||||
break;
|
||||
case 3: /* L3 cache info */
|
||||
if (!cpu->enable_l3_cache) {
|
||||
*eax = 0;
|
||||
*ebx = 0;
|
||||
*ecx = 0;
|
||||
*edx = 0;
|
||||
break;
|
||||
}
|
||||
*eax |= CPUID_4_TYPE_UNIFIED | \
|
||||
CPUID_4_LEVEL(3) | \
|
||||
CPUID_4_SELF_INIT_LEVEL;
|
||||
pkg_offset = apicid_pkg_offset(cs->nr_cores, cs->nr_threads);
|
||||
*eax |= ((1 << pkg_offset) - 1) << 14;
|
||||
*ebx = (L3_N_LINE_SIZE - 1) | \
|
||||
((L3_N_PARTITIONS - 1) << 12) | \
|
||||
((L3_N_ASSOCIATIVITY - 1) << 22);
|
||||
*ecx = L3_N_SETS - 1;
|
||||
*edx = CPUID_4_INCLUSIVE | CPUID_4_COMPLEX_IDX;
|
||||
break;
|
||||
default: /* end of info */
|
||||
*eax = 0;
|
||||
*ebx = 0;
|
||||
|
@ -2589,9 +2621,15 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
|||
*ecx = (L2_SIZE_KB_AMD << 16) | \
|
||||
(AMD_ENC_ASSOC(L2_ASSOCIATIVITY) << 12) | \
|
||||
(L2_LINES_PER_TAG << 8) | (L2_LINE_SIZE);
|
||||
*edx = ((L3_SIZE_KB/512) << 18) | \
|
||||
(AMD_ENC_ASSOC(L3_ASSOCIATIVITY) << 12) | \
|
||||
(L3_LINES_PER_TAG << 8) | (L3_LINE_SIZE);
|
||||
if (!cpu->enable_l3_cache) {
|
||||
*edx = ((L3_SIZE_KB / 512) << 18) | \
|
||||
(AMD_ENC_ASSOC(L3_ASSOCIATIVITY) << 12) | \
|
||||
(L3_LINES_PER_TAG << 8) | (L3_LINE_SIZE);
|
||||
} else {
|
||||
*edx = ((L3_N_SIZE_KB_AMD / 512) << 18) | \
|
||||
(AMD_ENC_ASSOC(L3_N_ASSOCIATIVITY) << 12) | \
|
||||
(L3_N_LINES_PER_TAG << 8) | (L3_N_LINE_SIZE);
|
||||
}
|
||||
break;
|
||||
case 0x80000007:
|
||||
*eax = 0;
|
||||
|
@ -3368,6 +3406,7 @@ static Property x86_cpu_properties[] = {
|
|||
DEFINE_PROP_STRING("hv-vendor-id", X86CPU, hyperv_vendor_id),
|
||||
DEFINE_PROP_BOOL("cpuid-0xb", X86CPU, enable_cpuid_0xb, true),
|
||||
DEFINE_PROP_BOOL("lmce", X86CPU, enable_lmce, false),
|
||||
DEFINE_PROP_BOOL("l3-cache", X86CPU, enable_l3_cache, true),
|
||||
DEFINE_PROP_END_OF_LIST()
|
||||
};
|
||||
|
||||
|
|
|
@ -1207,6 +1207,12 @@ struct X86CPU {
|
|||
*/
|
||||
bool enable_lmce;
|
||||
|
||||
/* Compatibility bits for old machine types.
|
||||
* If true present virtual l3 cache for VM, the vcpus in the same virtual
|
||||
* socket share an virtual l3 cache.
|
||||
*/
|
||||
bool enable_l3_cache;
|
||||
|
||||
/* Compatibility bits for old machine types: */
|
||||
bool enable_cpuid_0xb;
|
||||
|
||||
|
|
|
@ -711,9 +711,12 @@ static void test_acpi_one(const char *params, test_data *data)
|
|||
{
|
||||
char *args;
|
||||
|
||||
args = g_strdup_printf("-net none -display none %s "
|
||||
/* Disable kernel irqchip to be able to override apic irq0. */
|
||||
args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
|
||||
"-net none -display none %s "
|
||||
"-drive id=hd0,if=none,file=%s,format=raw "
|
||||
"-device ide-hd,drive=hd0 ",
|
||||
data->machine, "kvm:tcg",
|
||||
params ? params : "", disk);
|
||||
|
||||
qtest_start(args);
|
||||
|
@ -758,7 +761,7 @@ static void test_acpi_piix4_tcg(void)
|
|||
data.machine = MACHINE_PC;
|
||||
data.required_struct_types = base_required_struct_types;
|
||||
data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
|
||||
test_acpi_one("-machine accel=tcg", &data);
|
||||
test_acpi_one(NULL, &data);
|
||||
free_test_data(&data);
|
||||
}
|
||||
|
||||
|
@ -771,7 +774,7 @@ static void test_acpi_piix4_tcg_bridge(void)
|
|||
data.variant = ".bridge";
|
||||
data.required_struct_types = base_required_struct_types;
|
||||
data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
|
||||
test_acpi_one("-machine accel=tcg -device pci-bridge,chassis_nr=1", &data);
|
||||
test_acpi_one("-device pci-bridge,chassis_nr=1", &data);
|
||||
free_test_data(&data);
|
||||
}
|
||||
|
||||
|
@ -783,7 +786,7 @@ static void test_acpi_q35_tcg(void)
|
|||
data.machine = MACHINE_Q35;
|
||||
data.required_struct_types = base_required_struct_types;
|
||||
data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
|
||||
test_acpi_one("-machine q35,accel=tcg", &data);
|
||||
test_acpi_one(NULL, &data);
|
||||
free_test_data(&data);
|
||||
}
|
||||
|
||||
|
@ -796,7 +799,7 @@ static void test_acpi_q35_tcg_bridge(void)
|
|||
data.variant = ".bridge";
|
||||
data.required_struct_types = base_required_struct_types;
|
||||
data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types);
|
||||
test_acpi_one("-machine q35,accel=tcg -device pci-bridge,chassis_nr=1",
|
||||
test_acpi_one("-device pci-bridge,chassis_nr=1",
|
||||
&data);
|
||||
free_test_data(&data);
|
||||
}
|
||||
|
@ -808,8 +811,7 @@ static void test_acpi_piix4_tcg_cphp(void)
|
|||
memset(&data, 0, sizeof(data));
|
||||
data.machine = MACHINE_PC;
|
||||
data.variant = ".cphp";
|
||||
test_acpi_one("-machine accel=tcg"
|
||||
" -smp 2,cores=3,sockets=2,maxcpus=6",
|
||||
test_acpi_one("-smp 2,cores=3,sockets=2,maxcpus=6",
|
||||
&data);
|
||||
free_test_data(&data);
|
||||
}
|
||||
|
@ -821,8 +823,7 @@ static void test_acpi_q35_tcg_cphp(void)
|
|||
memset(&data, 0, sizeof(data));
|
||||
data.machine = MACHINE_Q35;
|
||||
data.variant = ".cphp";
|
||||
test_acpi_one("-machine q35,accel=tcg"
|
||||
" -smp 2,cores=3,sockets=2,maxcpus=6",
|
||||
test_acpi_one(" -smp 2,cores=3,sockets=2,maxcpus=6",
|
||||
&data);
|
||||
free_test_data(&data);
|
||||
}
|
||||
|
@ -840,7 +841,7 @@ static void test_acpi_q35_tcg_ipmi(void)
|
|||
data.variant = ".ipmibt";
|
||||
data.required_struct_types = ipmi_required_struct_types;
|
||||
data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
|
||||
test_acpi_one("-machine q35,accel=tcg -device ipmi-bmc-sim,id=bmc0"
|
||||
test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
|
||||
" -device isa-ipmi-bt,bmc=bmc0",
|
||||
&data);
|
||||
free_test_data(&data);
|
||||
|
@ -858,7 +859,7 @@ static void test_acpi_piix4_tcg_ipmi(void)
|
|||
data.variant = ".ipmikcs";
|
||||
data.required_struct_types = ipmi_required_struct_types;
|
||||
data.required_struct_types_len = ARRAY_SIZE(ipmi_required_struct_types);
|
||||
test_acpi_one("-machine accel=tcg -device ipmi-bmc-sim,id=bmc0"
|
||||
test_acpi_one("-device ipmi-bmc-sim,id=bmc0"
|
||||
" -device isa-ipmi-kcs,irq=0,bmc=bmc0",
|
||||
&data);
|
||||
free_test_data(&data);
|
||||
|
@ -876,14 +877,14 @@ int main(int argc, char *argv[])
|
|||
g_test_init(&argc, &argv, NULL);
|
||||
|
||||
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
||||
qtest_add_func("acpi/piix4/tcg", test_acpi_piix4_tcg);
|
||||
qtest_add_func("acpi/piix4/tcg/bridge", test_acpi_piix4_tcg_bridge);
|
||||
qtest_add_func("acpi/q35/tcg", test_acpi_q35_tcg);
|
||||
qtest_add_func("acpi/q35/tcg/bridge", test_acpi_q35_tcg_bridge);
|
||||
qtest_add_func("acpi/piix4/tcg/ipmi", test_acpi_piix4_tcg_ipmi);
|
||||
qtest_add_func("acpi/q35/tcg/ipmi", test_acpi_q35_tcg_ipmi);
|
||||
qtest_add_func("acpi/piix4/tcg/cpuhp", test_acpi_piix4_tcg_cphp);
|
||||
qtest_add_func("acpi/q35/tcg/cpuhp", test_acpi_q35_tcg_cphp);
|
||||
qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
|
||||
qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
|
||||
qtest_add_func("acpi/q35", test_acpi_q35_tcg);
|
||||
qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
|
||||
qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
|
||||
qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
|
||||
qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
|
||||
qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
|
||||
}
|
||||
ret = g_test_run();
|
||||
boot_sector_cleanup(disk);
|
||||
|
|
Loading…
Reference in a new issue