virtio,vhost,pc: fixes and updates
The following changes since commit c2a57aae9a1c3dd7de77daf5478df10379aeeebf:
Merge remote-tracking branch 'remotes/famz/tags/docker-pull-request' into staging (2016-09-09 12:49:41 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
for you to fetch changes up to fc0b9b0e1cbb49017ea882758634cf876be17bc3:
vhost-vsock: add virtio sockets device (2016-09-10 00:28:08 +0300)
----------------------------------------------------------------
virtio,vhost,pc: fixes and updates
balloon fixes wrt migration
virtio-vsock device support
----------------------------------------------------------------
Greg Kurz (1):
virtio-pci: error out when both legacy and modern modes are disabled
Jason Wang (1):
vhost: don't set vring call if no vector
Ladi Prosek (2):
virtio-balloon: discard virtqueue element on reset
virtio-balloon: fix stats vq migration
Longpeng(Mike) (2):
pc: Add 2.8 machine
target-i386: present virtual L3 cache info for vcpus
Marcel Apfelbaum (2):
virtio-pci: reduce modern_mem_bar size
tests/acpi: speedup acpi tests
Michael S. Tsirkin (2):
virtio-pci: use size from correct structure
virtio-pci: minor refactoring
Stefan Hajnoczi (3):
virtio: zero vq->inuse in virtio_reset()
virtio: add virtqueue_rewind()
vhost-vsock: add virtio sockets device
Thomas Huth (1):
virtio: Tell the user what went wrong when event_notifier_init failed
configure | 10 + hw/s390x/virtio-ccw.h | 15 ++ hw/virtio/virtio-pci.h | 23 +++ include/hw/compat.h | 6 +- include/hw/i386/pc.h | 12 ++ include/hw/pci/pci.h | 1 + include/hw/virtio/vhost-backend.h | 5 + include/hw/virtio/vhost-vsock.h | 41 ++++ include/hw/virtio/virtio.h | 1 + target-i386/cpu.h | 6 + hw/i386/pc_piix.c | 16 +- hw/i386/pc_q35.c | 13 +- hw/s390x/virtio-ccw.c | 54 +++++ hw/virtio/vhost-backend.c | 17 ++ hw/virtio/vhost-vsock.c | 417 ++++++++++++++++++++++++++++++++++++++ hw/virtio/vhost.c | 14 ++ hw/virtio/virtio-balloon.c | 14 ++ hw/virtio/virtio-bus.c | 3 +- hw/virtio/virtio-pci.c | 83 +++++++- hw/virtio/virtio.c | 23 +++ target-i386/cpu.c | 49 ++++- tests/bios-tables-test.c | 39 ++-- hw/virtio/Makefile.objs | 2 + 23 files changed, 825 insertions(+), 39 deletions(-) create mode 100644 include/hw/virtio/vhost-vsock.h create mode 100644 hw/virtio/vhost-vsock.c
[Qemu-devel] [PULL v2 01/14] virtio: Tell the user what went wrong when event_notifier_init failed
From: Thomas Huth <[email protected]>
event_notifier_init() can fail in real life, for example when there are not enough open file handles available (EMFILE) when using a lot of devices. So instead of leaving the average user with a cryptic error number only, print out a proper error message with strerror() instead, so that the user has a better way to figure out what is going on and that using "ulimit -n" might help here for example.
--- hw/virtio/virtio-bus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/virtio/virtio-bus.c +2 -1
@@ -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);
Signature · 1 line
MST
[Qemu-devel] [PULL v2 02/14] virtio-pci: use size from correct structure
In reply to Michael S. TsirkinPIO MR registration should use size from the correct notify struct. Doesn't affect any visible behaviour because the field values are the same (both are 4).
--- hw/virtio/virtio-pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-pci.c +1 -1
@@ -1520,7 +1520,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,
Signature · 1 line
MST
[Qemu-devel] [PULL v2 03/14] pc: Add 2.8 machine
In reply to Michael S. TsirkinFrom: "Longpeng(Mike)" <[email protected]>
This will used by the next patch.
--- include/hw/i386/pc.h | 3 +++ hw/i386/pc_piix.c | 16 +++++++++++++--- hw/i386/pc_q35.c | 13 +++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-)
include/hw/i386/pc.h +3 -0
@@ -368,6 +368,9 @@ 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_7 \ + HW_COMPAT_2_7 +#define PC_COMPAT_2_6 \ HW_COMPAT_2_6 \ {\
hw/i386/pc_piix.c +13 -3
@@ -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 ); }
hw/i386/pc_q35.c +11 -2
@@ -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 ); }
Signature · 1 line
MST
[Qemu-devel] [PULL v2 04/14] target-i386: present virtual L3 cache info for vcpus
In reply to Michael S. TsirkinFrom: "Longpeng(Mike)" <[email protected]>
Some software algorithms are based on the hardware's cache info, for example, for x86 linux kernel, when cpu1 want to wakeup a task on cpu2, cpu1 will trigger a resched IPI and told cpu2 to do the wakeup if they don't share low level cache. Oppositely, cpu1 will access cpu2's runqueue directly if they share llc. The relevant linux-kernel code as bellow:
static void ttwu_queue(struct task_struct *p, int cpu)
{
struct rq *rq = cpu_rq(cpu);
......
if (... && !cpus_share_cache(smp_processor_id(), cpu)) {
......
ttwu_queue_remote(p, cpu); /* will trigger RES IPI */
return;
}
......
ttwu_do_activate(rq, p, 0); /* access target's rq directly */
......
}In real hardware, the cpus on the same socket share L3 cache, so one won't trigger a resched IPIs when wakeup a task on others. But QEMU doesn't present a virtual L3 cache info for VM, then the linux guest will trigger lots of RES IPIs under some workloads even if the virtual cpus belongs to the same virtual socket.
For KVM, there will be lots of vmexit due to guest send IPIs.
The workload is a SAP HANA's testsuite, we run it one round(about 40 minuates) and observe the (Suse11sp3)Guest's amounts of RES IPIs which triggering during the period:
No-L3 With-L3(applied this patch)
cpu0: 363890 44582
cpu1: 373405 43109
cpu2: 340783 43797
cpu3: 333854 43409
cpu4: 327170 40038
cpu5: 325491 39922
cpu6: 319129 42391
cpu7: 306480 41035
cpu8: 161139 32188
cpu9: 164649 31024
cpu10: 149823 30398
cpu11: 149823 32455
cpu12: 164830 35143
cpu13: 172269 35805
cpu14: 179979 33898
cpu15: 194505 32754
avg: 268963.6 40129.8
The VM's topology is "1*socket 8*cores 2*threads".
After present virtual L3 cache info for VM, the amounts of RES IPIs in guest reduce 85%.
For KVM, vcpus send IPIs will cause vmexit which is expensive, so it can cause severe performance degradation. We had tested the overall system performance if vcpus actually run on sparate physical socket. With L3 cache, the performance improves 7.2%~33.1%(avg:15.7%).
--- include/hw/i386/pc.h | 9 +++++++++ target-i386/cpu.h | 6 ++++++ target-i386/cpu.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 59 insertions(+), 5 deletions(-)
include/hw/i386/pc.h +9 -0
@@ -368,7 +368,16 @@ 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 \
target-i386/cpu.h +6 -0
@@ -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;
target-i386/cpu.c +44 -5
95 lines not on this page · raw message
Signature · 1 line
MST
[Qemu-devel] [PULL v2 05/14] virtio-pci: reduce modern_mem_bar size
In reply to Michael S. TsirkinFrom: Marcel Apfelbaum <[email protected]>
Currently each VQ Notification Virtio Capability is allocated on a different page. The idea is to enable split drivers within guests, however there are no known plans to do that. The allocation will result in a 8MB BAR, more than various guest firmwares pre-allocates for PCI Bridges hotplug process.
Reserve 4 bytes per VQ by default and add a new parameter "page-per-vq" to be used with split drivers.
--- hw/virtio/virtio-pci.h | 5 +++++ include/hw/compat.h | 6 +++++- hw/virtio/virtio-pci.c | 22 +++++++++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-)
hw/virtio/virtio-pci.h +5 -0
@@ -64,6 +64,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 +85,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;
include/hw/compat.h +5 -1
@@ -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 \ {\
hw/virtio/virtio-pci.c +15 -7
@@ -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);
@@ -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),
@@ -1833,6 +1839,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(), };
Signature · 1 line
MST
[Qemu-devel] [PULL v2 06/14] virtio: zero vq->inuse in virtio_reset()
In reply to Michael S. TsirkinFrom: Stefan Hajnoczi <[email protected]>
vq->inuse must be zeroed upon device reset like most other virtqueue fields.
In theory, virtio_reset() just needs assert(vq->inuse == 0) since devices must clean up in-flight requests during reset (requests cannot not be leaked!).
In practice, it is difficult to achieve vq->inuse == 0 across reset because balloon, blk, 9p, etc implement various different strategies for cleaning up requests. Most devices call g_free(elem) directly without telling virtio.c that the VirtQueueElement is cleaned up. Therefore vq->inuse is not decremented during reset.
This patch zeroes vq->inuse and trusts that devices are not leaking VirtQueueElements across reset.
I will send a follow-up series that refactors request life-cycle across all devices and converts vq->inuse = 0 into assert(vq->inuse == 0) but this more invasive approach is not appropriate for stable trees.
--- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+)
hw/virtio/virtio.c +1 -0
@@ -822,6 +822,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 ; } }
Signature · 1 line
MST
[Qemu-devel] [PULL v2 07/14] virtio-balloon: discard virtqueue element on reset
In reply to Michael S. TsirkinFrom: Ladi Prosek <[email protected]>
The one pending element is being freed but not discarded on device reset, which causes svq->inuse to creep up, eventually hitting the "Virtqueue size exceeded" error.
Properly discarding the element on device reset makes sure that its buffers are unmapped and the inuse counter stays balanced.
--- hw/virtio/virtio-balloon.c | 1 + 1 file changed, 1 insertion(+)
hw/virtio/virtio-balloon.c +1 -0
@@ -463,6 +463,7 @@ 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 ; }
Signature · 1 line
MST
[Qemu-devel] [PULL v2 09/14] virtio-balloon: fix stats vq migration
In reply to Michael S. TsirkinFrom: Ladi Prosek <[email protected]>
The statistics virtqueue is not migrated properly because virtio-balloon does not include s->stats_vq_elem in the migration stream.
After migration the statistics virtqueue hangs because the host never completes the last element (s->stats_vq_elem is NULL on the destination QEMU). Therefore the guest never submits new elements and the virtqueue is hung.
Instead of changing the migration stream format in an incompatible way, detect the migration case and rewind the virtqueue so the last element can be completed.
--- hw/virtio/virtio-balloon.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/virtio/virtio-balloon.c +13 -0
@@ -469,6 +469,18 @@ static void virtio_balloon_device_reset(VirtIODevice *vdev) } } +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);
@@ -506,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 = {
Signature · 1 line
MST
[Qemu-devel] [PULL v2 10/14] virtio-pci: error out when both legacy and modern modes are disabled
In reply to Michael S. TsirkinFrom: Greg Kurz <[email protected]>
Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.
--- hw/virtio/virtio-pci.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +8 -0
@@ -1776,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;
Signature · 1 line
MST
[Qemu-devel] [PULL v2 08/14] virtio: add virtqueue_rewind()
In reply to Michael S. TsirkinFrom: Stefan Hajnoczi <[email protected]>
virtqueue_discard() requires a VirtQueueElement but virtio-balloon does not migrate its in-use element. Introduce a new function that is similar to virtqueue_discard() but doesn't require a VirtQueueElement.
This will allow virtio-balloon to access element again after migration with the usual proviso that the guest may have modified the vring since last time.
--- include/hw/virtio/virtio.h | 1 + hw/virtio/virtio.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+)
include/hw/virtio/virtio.h +1 -0
@@ -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);
hw/virtio/virtio.c +22 -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) {
Signature · 1 line
MST
[Qemu-devel] [PULL v2 11/14] vhost: don't set vring call if no vector
In reply to Michael S. TsirkinFrom: Jason Wang <[email protected]>
We used to set vring call fd unconditionally even if guest driver does not use MSIX for this vritqueue at all. This will cause lots of unnecessary userspace access and other checks for drivers does not use interrupt at all (e.g virtio-net pmd). So check and clean vring call fd if guest does not use any vector for this virtqueue at all.
Perf diffs (on rx) shows lots of cpus wasted on vhost_signal() were saved:
#
28.12% -27.82% [vhost] [k] vhost_signal
14.44% -1.69% [kernel.vmlinux] [k] copy_user_generic_string
7.05% +1.53% [kernel.vmlinux] [k] __free_page_frag
6.51% +5.53% [vhost] [k] vhost_get_vq_desc...
Pktgen tests shows 15.8% improvement on rx pps and 6.5% on tx pps.
Before: RX 2.08Mpps TX 1.35Mpps After: RX 2.41Mpps TX 1.44Mpps
--- hw/virtio/vhost.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
hw/virtio/vhost.c +14 -0
@@ -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),
Signature · 1 line
MST
[Qemu-devel] [PULL v2 12/14] virtio-pci: minor refactoring
In reply to Michael S. Tsirkin!legacy && !modern is shorter than !(legacy || modern). I also perfer this (less ()s) as a matter of taste.
--- hw/virtio/virtio-pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-pci.c +1 -1
@@ -1776,7 +1776,7 @@ 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))) { +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"
Signature · 1 line
MST
[Qemu-devel] [PULL v2 13/14] tests/acpi: speedup acpi tests
In reply to Michael S. TsirkinFrom: Marcel Apfelbaum <[email protected]>
Use kvm acceleration if available.
Disable kernel-irqchip and use qemu64 cpu for both kvm and tcg cases.
Using kvm acceleration saves about a second and disabling kernel-irqchip has no visible performance impact.
--- tests/bios-tables-test.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-)
tests/bios-tables-test.c +20 -19
@@ -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);
Signature · 1 line
MST
[Qemu-devel] [PULL v2 14/14] vhost-vsock: add virtio sockets device
In reply to Michael S. TsirkinFrom: Stefan Hajnoczi <[email protected]>
Implement the new virtio sockets device for host<->guest communication using the Sockets API. Most of the work is done in a vhost kernel driver so that virtio-vsock can hook into the AF_VSOCK address family. The QEMU vhost-vsock device handles configuration and live migration while the rx/tx happens in the vhost_vsock.ko Linux kernel driver.
The vsock device must be given a CID (host-wide unique address):
# qemu -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3 ...
For more information see:
http://qemu-project.org/Features/VirtioVsock
[Endianness fixes and virtio-ccw support by Claudio Imbrenda <[email protected]>]
--- configure | 10 + hw/s390x/virtio-ccw.h | 15 ++ hw/virtio/virtio-pci.h | 18 ++ include/hw/pci/pci.h | 1 + include/hw/virtio/vhost-backend.h | 5 + include/hw/virtio/vhost-vsock.h | 41 ++++ hw/s390x/virtio-ccw.c | 54 +++++ hw/virtio/vhost-backend.c | 17 ++ hw/virtio/vhost-vsock.c | 417 ++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.c | 51 +++++ hw/virtio/Makefile.objs | 2 + 11 files changed, 631 insertions(+) create mode 100644 include/hw/virtio/vhost-vsock.h create mode 100644 hw/virtio/vhost-vsock.c
configure +10 -0
@@ -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
hw/s390x/virtio-ccw.h +15 -0
@@ -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
hw/virtio/virtio-pci.h +18 -0
@@ -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 */
@@ -329,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
include/hw/pci/pci.h +1 -0
@@ -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
include/hw/virtio/vhost-backend.h +5 -0
@@ -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;
include/hw/virtio/vhost-vsock.h new file +41 -0
41 lines not on this page · raw message
hw/s390x/virtio-ccw.c +54 -0
66 lines not on this page · raw message
hw/virtio/vhost-backend.c +17 -0
@@ -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)
hw/virtio/vhost-vsock.c new file +417 -0
417 lines not on this page · raw message
hw/virtio/virtio-pci.c +51 -0
63 lines not on this page · raw message
hw/virtio/Makefile.objs +2 -0
@@ -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
Signature · 1 line
MST
Peter Maydell
AppliedRe: [Qemu-devel] [PULL v2 00/14] virtio, vhost, pc: fixes and updates
In reply to Michael S. TsirkinQuoted 12 lines · Michael S. Tsirkin
The following changes since commit
c2a57aae9a1c3dd7de77daf5478df10379aeeebf:Merge remote-tracking branch 'remotes/famz/tags/docker-pull-request' into staging (2016-09-09 12:49:41 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gittags/for_upstreamfor you to fetch changes up to
fc0b9b0e1cbb49017ea882758634cf876be17bc3:vhost-vsock: add virtio sockets device (2016-09-10 00:28:08 +0300)
Quoted 8 lines
----------------------------------------------------------------
virtio,vhost,pc: fixes and updatesballoon fixes wrt migration
virtio-vsock device supportSigned-off-by Michael S. Tsirkin <[email protected]>
Applied, thanks.
-- PMM