vhost, pc, virtio features, fixes, cleanups
The following changes since commit 6d57410a79d51d92673c54f26624b44f27fa6214:
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20151016' into staging (2015-10-17 12:31:33 +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 4f53cd7788185f437a4275df6456eb60b90d4837:
hw/isa/lpc_ich9: inject the SMI on the VCPU that is writing to APM_CNT (2015-10-21 13:24:49 +0300)
----------------------------------------------------------------
vhost, pc, virtio features, fixes, cleanups
New features:
VT-d support for devices behind a bridge
vhost-user migration support
----------------------------------------------------------------
Cornelia Huck (1):
virtio: add some migration doc
Eduardo Otubo (1):
seccomp: add memfd_create to whitelist
Igor Mammedov (3):
vhost: add vhost_has_free_slot() interface
pc-dimm: add vhost slots limit check before commiting to hotplug
vhost: fail backend intialization early
Knut Omang (1):
intel_iommu: Add support for translation for devices behind bridges
Laszlo Ersek (1):
hw/isa/lpc_ich9: inject the SMI on the VCPU that is writing to APM_CNT
Marc-André Lureau (23):
tests: re-enable vhost-user-test
configure: probe for memfd
linux-headers: add unistd.h
build-sys: split util-obj- on multi-lines
util: add linux-only memfd fallback
util: add memfd helpers
util: add fallback for qemu_memfd_alloc()
vhost: document log resizing
vhost: add vhost_set_log_base op
vhost-user: add vhost_user_requires_shm_log()
vhost: alloc shareable log
vhost-user: send log shm fd along with log_base
vhost-user: add a migration blocker
vhost: use a function for each call
vhost-user: document migration log
net: add trace_vhost_user_event
vhost: add migration block if memfd failed
vhost-user-test: move wait_for_fds() out
vhost-user-test: remove useless static check
vhost-user-test: wrap server in TestServer struct
vhost-user-test: learn to tweak various qemu arguments
vhost-user-test: add live-migration test
vhost-user-test: check ownership during migration
Michael S. Tsirkin (2):
exec: factor out duplicate mmap code
net: don't set native endianness
Thibaut Collet (4):
vhost user: add support of live migration
vhost user: add rarp sending after live migration for legacy guest
vhost-user: use an enum helper for features mask
vhost: set the correct queue index in case of migration with multiqueue
Zhu Guihua (1):
i386: keep cpu_model field in MachineState uptodate
zhanghailiang (1):
piix: fix resource leak reported by Coverity
configure | 20 + include/hw/i386/intel_iommu.h | 16 +- include/hw/i386/pc.h | 2 +- include/hw/virtio/vhost-backend.h | 77 ++- include/hw/virtio/vhost.h | 17 +- include/net/vhost_net.h | 1 + include/qemu/memfd.h | 26 + include/qemu/mmap-alloc.h | 10 + linux-headers/asm-arm/unistd.h | 448 +++++++++++++++ linux-headers/asm-arm64/kvm.h | 37 +- linux-headers/asm-arm64/unistd.h | 16 + linux-headers/asm-mips/unistd.h | 1063 ++++++++++++++++++++++++++++++++++++ linux-headers/asm-powerpc/unistd.h | 392 +++++++++++++ linux-headers/asm-s390/unistd.h | 404 ++++++++++++++ linux-headers/asm-x86/unistd.h | 15 + linux-headers/asm-x86/unistd_32.h | 377 +++++++++++++ linux-headers/asm-x86/unistd_64.h | 330 +++++++++++ linux-headers/asm-x86/unistd_x32.h | 319 +++++++++++ exec.c | 47 +- hw/i386/intel_iommu.c | 89 ++- hw/i386/pc.c | 17 +- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/isa/lpc_ich9.c | 2 +- hw/mem/pc-dimm.c | 7 + hw/net/vhost_net.c | 35 +- hw/pci-host/piix.c | 11 +- hw/pci-host/q35.c | 25 +- hw/scsi/vhost-scsi.c | 7 +- hw/virtio/vhost-backend.c | 138 ++++- hw/virtio/vhost-user.c | 581 +++++++++++++------- hw/virtio/vhost.c | 156 ++++-- net/net.c | 8 + net/vhost-user.c | 36 +- qemu-seccomp.c | 3 +- stubs/vhost.c | 6 + tests/vhost-user-test.c | 372 +++++++++++-- util/memfd.c | 162 ++++++ util/mmap-alloc.c | 71 +++ util/oslib-posix.c | 28 +- docs/specs/vhost-user.txt | 63 ++- docs/virtio-migration.txt | 106 ++++ scripts/update-linux-headers.sh | 7 +- stubs/Makefile.objs | 1 + tests/Makefile | 4 +- trace-events | 3 + util/Makefile.objs | 13 +- 47 files changed, 5109 insertions(+), 463 deletions(-) create mode 100644 include/qemu/memfd.h create mode 100644 include/qemu/mmap-alloc.h create mode 100644 linux-headers/asm-arm/unistd.h create mode 100644 linux-headers/asm-arm64/unistd.h create mode 100644 linux-headers/asm-mips/unistd.h create mode 100644 linux-headers/asm-powerpc/unistd.h create mode 100644 linux-headers/asm-s390/unistd.h create mode 100644 linux-headers/asm-x86/unistd.h create mode 100644 linux-headers/asm-x86/unistd_32.h create mode 100644 linux-headers/asm-x86/unistd_64.h create mode 100644 linux-headers/asm-x86/unistd_x32.h create mode 100644 stubs/vhost.c create mode 100644 util/memfd.c create mode 100644 util/mmap-alloc.c create mode 100644 docs/virtio-migration.txt
[Qemu-devel] [PULL 01/38] intel_iommu: Add support for translation for devices behind bridges
From: Knut Omang <[email protected]>
- Use a hash table indexed on bus pointers to store information about buses instead of using the bus numbers.
Bus pointers are stored in a new VTDBus struct together with the vector of device address space pointers indexed by devfn.
- The bus number is still used for lookup for selective SID based invalidate, in which case the bus number is lazily resolved from the bus hash table and cached in a separate index.
--- include/hw/i386/intel_iommu.h | 16 +++++++- hw/i386/intel_iommu.c | 89 +++++++++++++++++++++++++++++++++++-------- hw/pci-host/q35.c | 25 ++---------- 3 files changed, 90 insertions(+), 40 deletions(-)
include/hw/i386/intel_iommu.h +14 -2
@@ -49,6 +49,7 @@ typedef struct VTDContextCacheEntry VTDContextCacheEntry;typedef struct IntelIOMMUState IntelIOMMUState ;typedef struct VTDAddressSpace VTDAddressSpace ;typedef struct VTDIOTLBEntry VTDIOTLBEntry ; +typedef struct VTDBus VTDBus ;/* Context-Entry */ struct VTDContextEntry {
@@ -65,7 +66,7 @@ struct VTDContextCacheEntry { };struct VTDAddressSpace { -uint8_t bus_num; +PCIBus *bus;uint8_t devfn;AddressSpace as;MemoryRegion iommu;
@@ -73,6 +74,11 @@ struct VTDAddressSpace {VTDContextCacheEntry context_cache_entry; }; +struct VTDBus { +PCIBus * bus;/* A reference to the bus to provide translation for */ +VTDAddressSpace *dev_as[0 ];/* A table of VTDAddressSpace objects indexed by devfn */ +}; +struct VTDIOTLBEntry {uint64_t gfn;uint16_t domain_id;
@@ -114,7 +120,13 @@ struct IntelIOMMUState {GHashTable *iotlb;/* IOTLB */ MemoryRegionIOMMUOps iommu_ops; - VTDAddressSpace **address_spaces[VTD_PCI_BUS_MAX]; +GHashTable *vtd_as_by_busptr;/* VTDBus objects indexed by PCIBus* reference */ + VTDBus *vtd_as_by_bus_num[VTD_PCI_BUS_MAX]; /* VTDBus objects indexed by bus number */ }; +/* Find the VTD Address space associated with the given bus pointer, +* create a new one if none exists +*/ +VTDAddressSpace *vtd_find_add_as (IntelIOMMUState *s,PCIBus *bus,int devfn); +#endif
hw/i386/intel_iommu.c +73 -16
164 lines not on this page · raw message
hw/pci-host/q35.c +3 -22
@@ -426,31 +426,12 @@ static void mch_reset(DeviceState *qdev)static AddressSpace *q35_host_dma_iommu (PCIBus *bus,void *opaque,int devfn) {IntelIOMMUState *s = opaque; -VTDAddressSpace **pvtd_as; -int bus_num =pci_bus_num (bus); +VTDAddressSpace *vtd_as; -assert (0 <= bus_num && bus_num <=VTD_PCI_BUS_MAX );assert (0 <= devfn && devfn <=VTD_PCI_DEVFN_MAX ); - pvtd_as = s->address_spaces[bus_num]; -if (!pvtd_as) { -/* No corresponding free() */ - pvtd_as =g_malloc0 (sizeof (VTDAddressSpace *) *VTD_PCI_DEVFN_MAX ); - s->address_spaces[bus_num] = pvtd_as; - } -if (!pvtd_as[devfn]) { - pvtd_as[devfn] =g_malloc0 (sizeof (VTDAddressSpace)); - - pvtd_as[devfn]->bus_num = (uint8_t )bus_num; - pvtd_as[devfn]->devfn = (uint8_t )devfn; - pvtd_as[devfn]->iommu_state = s; - pvtd_as[devfn]->context_cache_entry.context_cache_gen =0 ; -memory_region_init_iommu (&pvtd_as[devfn]->iommu,OBJECT (s), - &s->iommu_ops,"intel_iommu" ,UINT64_MAX ); -address_space_init (&pvtd_as[devfn]->as, - &pvtd_as[devfn]->iommu,"intel_iommu" ); - } -return &pvtd_as[devfn]->as; + vtd_as =vtd_find_add_as (s, bus, devfn); +return &vtd_as->as; }static void mch_init_dmar (MCHPCIState *mch)
Signature · 1 line
MST
[Qemu-devel] [PULL 02/38] exec: factor out duplicate mmap code
In reply to Michael S. TsirkinAnonymous and file-backed RAM allocation are now almost exactly the same.
Reduce code duplication by moving RAM mmap code out of oslib-posix.c and exec.c.
--- include/qemu/mmap-alloc.h | 10 +++++++ exec.c | 47 +++++++------------------------ util/mmap-alloc.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ util/oslib-posix.c | 28 +++---------------- util/Makefile.objs | 1 + 5 files changed, 96 insertions(+), 61 deletions(-) create mode 100644 include/qemu/mmap-alloc.h create mode 100644 util/mmap-alloc.c
include/qemu/mmap-alloc.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef QEMU_MMAP_ALLOC +#define QEMU_MMAP_ALLOC + +#include "qemu-common.h" + +void *qemu_ram_mmap (int fd,size_t size,size_t align,bool shared); + +void qemu_ram_munmap (void *ptr,size_t size); + +#endif
exec.c +10 -37
100 lines not on this page · raw message
util/mmap-alloc.c new file +71 -0
71 lines not on this page · raw message
util/oslib-posix.c +4 -24
@@ -72,6 +72,8 @@ extern int daemon(int, int);#include <sys/sysctl.h> #endif +#include <qemu/mmap-alloc.h> +int qemu_get_thread_id (void ) {#if defined(__linux__)
@@ -128,10 +130,7 @@ void *qemu_memalign(size_t alignment, size_t size)void *qemu_anon_ram_alloc (size_t size,uint64_t *alignment) {size_t align =QEMU_VMALLOC_ALIGN ; -size_t total = size + align; -void *ptr =mmap (0 , total,PROT_NONE ,MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); -size_t offset =QEMU_ALIGN_UP ((uintptr_t )ptr, align) - (uintptr_t )ptr; -void *ptr1; +void *ptr =qemu_ram_mmap (-1 , size, align, false);if (ptr ==MAP_FAILED ) {return NULL ;
@@ -141,23 +140,6 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment) *alignment = align; } - ptr1 =mmap (ptr + offset, size,PROT_READ |PROT_WRITE , -MAP_FIXED |MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); -if (ptr1 ==MAP_FAILED ) { -munmap (ptr, total); -return NULL ; - } - - ptr += offset; - total -= offset; - -if (offset >0 ) { -munmap (ptr - offset, offset); - } -if (total > size +getpagesize ()) { -munmap (ptr + size +getpagesize (), total - size -getpagesize ()); - } -trace_qemu_anon_ram_alloc (size, ptr);return ptr; }
@@ -171,9 +153,7 @@ void qemu_vfree(void *ptr)void qemu_anon_ram_free (void *ptr,size_t size) {trace_qemu_anon_ram_free (ptr, size); -if (ptr) { -munmap (ptr, size +getpagesize ()); - } +qemu_ram_munmap (ptr, size); }void qemu_set_block (int fd)
util/Makefile.objs +1 -0
@@ -1,6 +1,7 @@ util-obj-y = osdep.o cutils.o unicode.o qemu-timer-common.o util-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o event_notifier-win32.o util-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o event_notifier-posix.o qemu-openpty.o +util-obj-$(CONFIG_POSIX) += mmap-alloc.o util-obj-y += envlist.o path.o module.o util-obj-$(call lnot,$(CONFIG_INT128)) += host-utils.o util-obj-y += bitmap.o bitops.o hbitmap.o
Signature · 1 line
MST
[Qemu-devel] [PULL 03/38] net: don't set native endianness
In reply to Michael S. Tsirkincommit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness
makes vhost net always try to set LE - even if that matches the native endian-ness.
This makes it fail on older kernels on x86 without TUNSETVNETLE support.
To fix, make qemu_set_vnet_le/qemu_set_vnet_be skip the ioctl if it matches the host endian-ness.
--- net/net.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/net.c +8 -0
@@ -524,20 +524,28 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len)int qemu_set_vnet_le (NetClientState *nc,bool is_le) { +#ifdef HOST_WORDS_BIGENDIAN if (!nc || !nc->info->set_vnet_le) {return -ENOSYS ; }return nc->info->set_vnet_le (nc, is_le); +#else +return 0 ; +#endif }int qemu_set_vnet_be (NetClientState *nc,bool is_be) { +#ifdef HOST_WORDS_BIGENDIAN +return 0 ; +#else if (!nc || !nc->info->set_vnet_be) {return -ENOSYS ; }return nc->info->set_vnet_be (nc, is_be); +#endif }int qemu_can_send_packet (NetClientState *sender)
Signature · 1 line
MST
[Qemu-devel] [PULL 04/38] tests: re-enable vhost-user-test
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Commit 7fe34ca9c2e actually disabled vhost-user-test altogether, since CONFIG_VHOST_NET is a per-target config variable.
tests/vhost-user-test is already x86/64 softmmu specific test, in order to enable it correctly, kvm & vhost-net are also conditions. To check that, set CONFIG_VHOST_NET_TEST when kvm is also enabled.
--- configure | 1 + tests/Makefile | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-)
configure +1 -0
@@ -5562,6 +5562,7 @@ case "$target_name" in echo "CONFIG_KVM=y" >> $config_target_mak if test "$vhost_net" = "yes" ; then echo "CONFIG_VHOST_NET=y" >> $config_target_mak + echo "CONFIG_VHOST_NET_TEST=y" >> $config_host_mak fi fi esac
tests/Makefile +1 -3
@@ -191,9 +191,7 @@ gcov-files-i386-y += hw/usb/hcd-xhci.c check-qtest-i386-y += tests/pc-cpu-test$(EXESUF) check-qtest-i386-y += tests/q35-test$(EXESUF) gcov-files-i386-y += hw/pci-host/q35.c -ifeq ($(CONFIG_VHOST_NET),y) -check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF) -endif +check-qtest-i386-$(CONFIG_VHOST_NET_TEST) += tests/vhost-user-test$(EXESUF) check-qtest-i386-y += tests/test-netfilter$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
Signature · 1 line
MST
Re: [Qemu-devel] [PULL 04/38] tests: re-enable vhost-user-test
Quoted 5 lines · Michael S. Tsirkin
From: Marc-André Lureau <[email protected]>
Commit
7fe34ca9c2eactually disabled vhost-user-test altogether, sinceCONFIG_VHOST_NETis a per-target config variable.
Quoted 7 lines
tests/vhost-user-test is already x86/64 softmmu specific test, in order to enable it correctly, kvm & vhost-net are also conditions. To check that, set
CONFIG_VHOST_NET_TESTwhen kvm is also enabled.Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>
I dropped this one since it still breaks on some setups. Marc-André, pls work to re-enable this upstream when you are back.
Quoted 35 lines
--- configure | 1 + tests/Makefile | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-)configure +1
-0@@ -5562,6 +5562,7 @@ case "$target_name" in echo "CONFIG_KVM=y" >> $config_target_mak if test "$vhost_net" = "yes" ; then echo "CONFIG_VHOST_NET=y" >> $config_target_mak + echo "CONFIG_VHOST_NET_TEST=y" >> $config_host_mak fi fi esactests/Makefile +1
-3@@ -191,9 +191,7 @@ gcov-files-i386-y += hw/usb/hcd-xhci.c check-qtest-i386-y += tests/pc-cpu-test$(EXESUF) check-qtest-i386-y += tests/q35-test$(EXESUF) gcov-files-i386-y += hw/pci-host/q35.c -ifeq ($(CONFIG_VHOST_NET),y) -check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF) -endif +check-qtest-i386-$(CONFIG_VHOST_NET_TEST) += tests/vhost-user-test$(EXESUF) check-qtest-i386-y += tests/test-netfilter$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.cSignature · 1 line
MST
[Qemu-devel] [PULL 06/38] pc-dimm: add vhost slots limit check before commiting to hotplug
In reply to Michael S. TsirkinFrom: Igor Mammedov <[email protected]>
it allows safely cancel memory hotplug if vhost backend doesn't support necessary amount of memory slots and prevents QEMU crashing in vhost due to hitting vhost limit on amount of supported memory ranges.
--- hw/mem/pc-dimm.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/mem/pc-dimm.c +7 -0
@@ -25,6 +25,7 @@#include "sysemu/numa.h" #include "sysemu/kvm.h" #include "trace.h" +#include "hw/virtio/vhost.h" typedef struct pc_dimms_capacity { uint64_t size;
@@ -96,6 +97,12 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, goto out; } +if (!vhost_has_free_slot ()) { +error_setg (&local_err,"a used vhost backend has no free" +" memory slots left" ); + goto out; + } +memory_region_add_subregion (&hpms->mr, addr - hpms->base, mr);vmstate_register_ram (mr, dev);numa_set_mem_node_id (addr,memory_region_size (mr), dimm->node);
Signature · 1 line
MST
[Qemu-devel] [PULL 07/38] vhost: fail backend intialization early
In reply to Michael S. TsirkinFrom: Igor Mammedov <[email protected]>
Don't initialize vhost backend if memslots number exceeds the supported limit. This prevents failures down the road when backend
is actually started.
[MST: rewrite commit log]
--- hw/virtio/vhost.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/virtio/vhost.c +6 -0
@@ -933,6 +933,12 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,return -errno; } +if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit (hdev)) { +fprintf (stderr,"vhost backend memory slots limit is less" +" than current number of present memory slots\n" ); +close ((uintptr_t )opaque); +return -1 ; + }QLIST_INSERT_HEAD (&vhost_devices, hdev, entry); r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_OWNER ,NULL );
Signature · 1 line
MST
[Qemu-devel] [PULL 05/38] vhost: add vhost_has_free_slot() interface
In reply to Michael S. TsirkinFrom: Igor Mammedov <[email protected]>
it will allow for other parts of QEMU check if it's safe to map memory region during hotplug/runtime. That way hotplug path will have a chance to cancel hotplug operation instead of crashing in vhost_commit().
--- include/hw/virtio/vhost-backend.h | 2 ++ include/hw/virtio/vhost.h | 2 ++ hw/virtio/vhost-backend.c | 19 +++++++++++++++++++ hw/virtio/vhost-user.c | 6 ++++++ hw/virtio/vhost.c | 21 +++++++++++++++++++++ stubs/vhost.c | 6 ++++++ stubs/Makefile.objs | 1 + 7 files changed, 57 insertions(+) create mode 100644 stubs/vhost.c
include/hw/virtio/vhost-backend.h +2 -0
@@ -26,6 +26,7 @@ typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque);typedef int (*vhost_backend_cleanup )(struct vhost_dev *dev);typedef int (*vhost_backend_get_vq_index )(struct vhost_dev *dev,int idx);typedef int (*vhost_backend_set_vring_enable )(struct vhost_dev *dev,int enable); +typedef int (*vhost_backend_memslots_limit )(struct vhost_dev *dev); typedef struct VhostOps { VhostBackendType backend_type;
@@ -34,6 +35,7 @@ typedef struct VhostOps {vhost_backend_cleanup vhost_backend_cleanup;vhost_backend_get_vq_index vhost_backend_get_vq_index;vhost_backend_set_vring_enable vhost_backend_set_vring_enable; +vhost_backend_memslots_limit vhost_backend_memslots_limit; } VhostOps;extern const VhostOps user_ops;
include/hw/virtio/vhost.h +2 -0
@@ -59,6 +59,7 @@ struct vhost_dev {const VhostOps *vhost_ops;void *opaque;struct vhost_log *log; +QLIST_ENTRY (vhost_dev) entry; }; int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
@@ -83,4 +84,5 @@ uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, uint64_t features);void vhost_ack_features (struct vhost_dev *hdev,const int *feature_bits,uint64_t features); +bool vhost_has_free_slot (void );#endif
hw/virtio/vhost-backend.c +19 -0
@@ -11,6 +11,7 @@#include "hw/virtio/vhost.h" #include "hw/virtio/vhost-backend.h" #include "qemu/error-report.h" +#include "linux/vhost.h" #include <sys/ioctl.h>
@@ -49,12 +50,30 @@ static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx)return idx - dev->vq_index; } +static int vhost_kernel_memslots_limit (struct vhost_dev *dev) +{ +int limit =64 ; +char *s; + +if (g_file_get_contents ("/sys/module/vhost/parameters/max_mem_regions" , + &s,NULL ,NULL )) { +uint64_t val =g_ascii_strtoull (s,NULL ,10 ); +if (!((val ==G_MAXUINT64 || !val) && errno)) { +return val; + } +error_report ("ignoring invalid max_mem_regions value in vhost module:" +" %s" , s); + } +return limit; +} +static const VhostOps kernel_ops = { .backend_type =VHOST_BACKEND_TYPE_KERNEL , .vhost_call = vhost_kernel_call, .vhost_backend_init = vhost_kernel_init, .vhost_backend_cleanup = vhost_kernel_cleanup, .vhost_backend_get_vq_index = vhost_kernel_get_vq_index, + .vhost_backend_memslots_limit = vhost_kernel_memslots_limit, };int vhost_set_backend_type (struct vhost_dev *dev,VhostBackendType backend_type)
hw/virtio/vhost-user.c +6 -0
@@ -440,6 +440,11 @@ static int vhost_user_get_vq_index(struct vhost_dev *dev, int idx)return idx; } +static int vhost_user_memslots_limit (struct vhost_dev *dev) +{ +return VHOST_MEMORY_MAX_NREGIONS ; +} +const VhostOps user_ops = { .backend_type =VHOST_BACKEND_TYPE_USER , .vhost_call = vhost_user_call,
@@ -447,4 +452,5 @@ const VhostOps user_ops = { .vhost_backend_cleanup = vhost_user_cleanup, .vhost_backend_get_vq_index = vhost_user_get_vq_index, .vhost_backend_set_vring_enable = vhost_user_set_vring_enable, + .vhost_backend_memslots_limit = vhost_user_memslots_limit, };
hw/virtio/vhost.c +21 -0
@@ -26,6 +26,22 @@static struct vhost_log *vhost_log; +static unsigned int used_memslots; +static QLIST_HEAD(, vhost_dev) vhost_devices = +QLIST_HEAD_INITIALIZER (vhost_devices); + +bool vhost_has_free_slot (void ) +{ +unsigned int slots_limit = ~0U ; +struct vhost_dev *hdev; + + QLIST_FOREACH(hdev, &vhost_devices, entry) { +unsigned int r = hdev->vhost_ops->vhost_backend_memslots_limit (hdev); + slots_limit =MIN (slots_limit, r); + } +return slots_limit > used_memslots; +} + static void vhost_dev_sync_region(struct vhost_dev *dev, MemoryRegionSection *section, uint64_t mfirst, uint64_t mlast,
@@ -457,6 +473,7 @@ static void vhost_set_memory(MemoryListener *listener, dev->mem_changed_start_addr =MIN (dev->mem_changed_start_addr, start_addr); dev->mem_changed_end_addr =MAX (dev->mem_changed_end_addr, start_addr + size -1 ); dev->memory_changed = true; + used_memslots = dev->mem->nregions; }static bool vhost_section (MemoryRegionSection *section)
@@ -916,6 +933,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,return -errno; } +QLIST_INSERT_HEAD (&vhost_devices, hdev, entry); + r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_OWNER ,NULL );if (r <0 ) { goto fail;
@@ -972,6 +991,7 @@ fail_vq: fail: r = -errno; hdev->vhost_ops->vhost_backend_cleanup (hdev); +QLIST_REMOVE (hdev, entry);return r; }
@@ -989,6 +1009,7 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)g_free (hdev->mem);g_free (hdev->mem_sections); hdev->vhost_ops->vhost_backend_cleanup (hdev); +QLIST_REMOVE (hdev, entry); }/* Stop processing guest IO notifications in qemu.
stubs/vhost.c new file +6 -0
@@ -0,0 +1,6 @@ +#include "hw/virtio/vhost.h" + +bool vhost_has_free_slot (void ) +{ +return true; +}
stubs/Makefile.objs +1 -0
@@ -39,3 +39,4 @@ stub-obj-y += cpus.o stub-obj-y += kvm.o stub-obj-y += qmp_pc_dimm_device_list.o stub-obj-y += target-monitor-defs.o +stub-obj-y += vhost.o
Signature · 1 line
MST
[Qemu-devel] [PULL 08/38] virtio: add some migration doc
In reply to Michael S. TsirkinFrom: Cornelia Huck <[email protected]>
Try to cover the basics of virtio migration.
--- docs/virtio-migration.txt | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 docs/virtio-migration.txt
docs/virtio-migration.txt new file +106 -0
@@ -0,0 +1,106 @@ +Virtio devices and migration +============================ + +Copyright 2015 IBM Corp. + +This work is licensed under the terms of the GNU GPL, version 2 or later. See +the COPYING file in the top-level directory. + +Saving and restoring the state of virtio devices is a bit of a twisty maze, +for several reasons: +- state is distributed between several parts: + - virtio core, for common fields like features, number of queues, ... + - virtio transport (pci, ccw, ...), for the different proxy devices and + transport specific state (msix vectors, indicators, ...) + - virtio device (net, blk, ...), for the different device types and their + state (mac address, request queue, ...) +- most fields are saved via the stream interface; subsequently, subsections + have been added to make cross-version migration possible + +This file attempts to document the current procedure and point out some +caveats. + + +Save state procedure +==================== + +virtio core virtio transport virtio device +----------- ---------------- ------------- + + save() function registered + via register_savevm() +virtio_save() <---------- + ------> save_config() + - save proxy device + - save transport-specific + device fields +- save common device + fields +- save common virtqueue + fields + ------> save_queue() + - save transport-specific + virtqueue fields + ------> save_device() + - save device-specific + fields +- save subsections + - device endianness, + if changed from + default endianness + - 64 bit features, if + any high feature bit + is set + - virtio-1 virtqueue + fields, if VERSION_1 + is set + + +Load state procedure +==================== + +virtio core virtio transport virtio device +----------- ---------------- ------------- + + load() function registered + via register_savevm() +virtio_load() <---------- + ------> load_config() + - load proxy device + - load transport-specific + device fields +- load common device + fields +- load common virtqueue + fields + ------> load_queue() + - load transport-specific + virtqueue fields +- notify guest + ------> load_device() + - load device-specific + fields +- load subsections + - device endianness + - 64 bit features + - virtio-1 virtqueue + fields +- sanitize endianness +- sanitize features +- virtqueue index sanity + check + - feature-dependent setup + + +Implications of this setup +========================== + +Devices need to be careful in their state processing during load: The +load_device() procedure is invoked by the core before subsections have +been loaded. Any code that depends on information transmitted in subsections +therefore has to be invoked in the device's load() function _after_ +virtio_load() returned (like e.g. code depending on features). + +Any extension of the state being migrated should be done in subsections +added to the core for compatibility reasons. If transport or device specific +state is added, core needs to invoke a callback from the new subsection.
Signature · 1 line
MST
[Qemu-devel] [PULL 09/38] configure: probe for memfd
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Check if memfd_create() is part of system libc.
--- configure | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
configure +19 -0
@@ -3495,6 +3495,22 @@ if compile_prog "" "" ; then eventfd=yes fi +# check if memfd is supported +memfd=no +cat > $TMPC << EOF +#include <sys/memfd.h> + +int main(void) +{ + return memfd_create("foo", MFD_ALLOW_SEALING); +} +EOF +if compile_prog "" "" ; then + memfd=yes +fi + + + # check for fallocate fallocate=no cat > $TMPC << EOF
@@ -4889,6 +4905,9 @@ fi if test "$eventfd" = "yes" ; then echo "CONFIG_EVENTFD=y" >> $config_host_mak fi +if test "$memfd" = "yes" ; then + echo "CONFIG_MEMFD=y" >> $config_host_mak +fi if test "$fallocate" = "yes" ; then echo "CONFIG_FALLOCATE=y" >> $config_host_mak fi
Signature · 1 line
MST
[Qemu-devel] [PULL 11/38] build-sys: split util-obj- on multi-lines
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Make it easier to add new unrelated units with shorter lines.
--- util/Makefile.objs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
util/Makefile.objs +8 -3
@@ -1,14 +1,19 @@ util-obj-y = osdep.o cutils.o unicode.o qemu-timer-common.o -util-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o event_notifier-win32.o -util-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o event_notifier-posix.o qemu-openpty.o +util-obj-$(CONFIG_POSIX) += compatfd.o +util-obj-$(CONFIG_POSIX) += event_notifier-posix.o util-obj-$(CONFIG_POSIX) += mmap-alloc.o +util-obj-$(CONFIG_POSIX) += oslib-posix.o +util-obj-$(CONFIG_POSIX) += qemu-openpty.o +util-obj-$(CONFIG_POSIX) += qemu-thread-posix.o +util-obj-$(CONFIG_WIN32) += event_notifier-win32.o +util-obj-$(CONFIG_WIN32) += oslib-win32.o +util-obj-$(CONFIG_WIN32) += qemu-thread-win32.o util-obj-y += envlist.o path.o module.o util-obj-$(call lnot,$(CONFIG_INT128)) += host-utils.o util-obj-y += bitmap.o bitops.o hbitmap.o util-obj-y += fifo8.o util-obj-y += acl.o util-obj-y += error.o qemu-error.o -util-obj-$(CONFIG_POSIX) += compatfd.o util-obj-y += id.o util-obj-y += iov.o qemu-config.o qemu-sockets.o uri.o notify.o util-obj-y += qemu-option.o qemu-progress.o
Signature · 1 line
MST
[Qemu-devel] [PULL 12/38] util: add linux-only memfd fallback
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Implement memfd_create() fallback if not available in system libc. memfd_create() is still not included in glibc today, atlhough it's been available since Linux 3.17 in Oct 2014.
memfd has numerous advantages over traditional shm/mmap for ipc memory sharing with fd handler, which we are going to make use of for vhost-user logging memory in following patches.
The next patches are going to introduce helpers to use best practices of memfd usage and provide some compatibility fallback. memfd.c is thus temporarily useless and eventually empty if memfd_create() is provided by the system.
--- include/qemu/memfd.h | 20 +++++++++++++++++++ util/memfd.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + 3 files changed, 75 insertions(+) create mode 100644 include/qemu/memfd.h create mode 100644 util/memfd.c
include/qemu/memfd.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef QEMU_MEMFD_H +#define QEMU_MEMFD_H + +#include "config-host.h" + +#ifndef F_LINUX_SPECIFIC_BASE +#define F_LINUX_SPECIFIC_BASE 1024 +#endif + +#ifndef F_ADD_SEALS +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) + +#define F_SEAL_SEAL 0x0001/* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002/* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004/* prevent file from growing */ +#define F_SEAL_WRITE 0x0008/* prevent writes */ +#endif + +#endif /* QEMU_MEMFD_H */
util/memfd.c new file +54 -0
54 lines not on this page · raw message
util/Makefile.objs +1 -0
@@ -6,6 +6,7 @@ util-obj-$(CONFIG_POSIX) += oslib-posix.o util-obj-$(CONFIG_POSIX) += qemu-openpty.o util-obj-$(CONFIG_POSIX) += qemu-thread-posix.o util-obj-$(CONFIG_WIN32) += event_notifier-win32.o +util-obj-$(CONFIG_POSIX) += memfd.o util-obj-$(CONFIG_WIN32) += oslib-win32.o util-obj-$(CONFIG_WIN32) += qemu-thread-win32.o util-obj-y += envlist.o path.o module.o
Signature · 1 line
MST
[Qemu-devel] [PULL 13/38] util: add memfd helpers
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Add qemu_memfd_alloc/free() helpers.
The function helps to allocate and seal shared memory.
--- include/qemu/memfd.h | 4 +++ util/memfd.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-)
include/qemu/memfd.h +4 -0
@@ -17,4 +17,8 @@#define F_SEAL_WRITE 0x0008/* prevent writes */ #endif +void *qemu_memfd_alloc (const char *name,size_t size,unsigned int seals, +int *fd); +void qemu_memfd_free (void *ptr,size_t size,int fd); +#endif /* QEMU_MEMFD_H */
util/memfd.c +71 -1
87 lines not on this page · raw message
Signature · 1 line
MST
[Qemu-devel] [PULL 14/38] util: add fallback for qemu_memfd_alloc()
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Add an open/unlink/mmap fallback for system that do not support memfd (only available since 3.17, ~1y ago).
This patch may require additional SELinux policies to work for enforced systems, but should fail gracefully in this case.
--- util/memfd.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
util/memfd.c +18 -2
@@ -97,8 +97,24 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals,return NULL ; } }else { -perror ("memfd" ); -return NULL ; +const char *tmpdir =g_get_tmp_dir (); +gchar *fname; + + fname =g_strdup_printf ("%s/memfd-XXXXXX" , tmpdir); + mfd =mkstemp (fname); +unlink (fname); +g_free (fname); + +if (mfd ==-1 ) { +perror ("mkstemp" ); +return NULL ; + } + +if (ftruncate (mfd, size) ==-1 ) { +perror ("ftruncate" ); +close (mfd); +return NULL ; + } } ptr =mmap (0 , size,PROT_READ |PROT_WRITE ,MAP_SHARED , mfd,0 );
Signature · 1 line
MST
[Qemu-devel] [PULL 15/38] vhost: document log resizing
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
--- hw/virtio/vhost.c | 2 ++ 1 file changed, 2 insertions(+)
hw/virtio/vhost.c +2 -0
@@ -350,6 +350,8 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size)uint64_t log_base = (uintptr_t )log->log;int r; +/* inform backend of log switching, this must be done before +releasing the current log, to ensure no logging is lost */ r = dev->vhost_ops->vhost_call (dev,VHOST_SET_LOG_BASE , &log_base);assert (r >=0 );vhost_log_put (dev, true);
Signature · 1 line
MST
[Qemu-devel] [PULL 10/38] linux-headers: add unistd.h
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
New syscalls are not yet widely distributed. Add them to qemu linux-headers include directory. Update based on v4.3-rc3 kernel headers.
Exclude mips for now, which is more problematic due to extra header inclusion and probably unnecessary here.
--- linux-headers/asm-arm/unistd.h | 448 +++++++++++++++ linux-headers/asm-arm64/kvm.h | 37 +- linux-headers/asm-arm64/unistd.h | 16 + linux-headers/asm-mips/unistd.h | 1063 ++++++++++++++++++++++++++++++++++++ linux-headers/asm-powerpc/unistd.h | 392 +++++++++++++ linux-headers/asm-s390/unistd.h | 404 ++++++++++++++ linux-headers/asm-x86/unistd.h | 15 + linux-headers/asm-x86/unistd_32.h | 377 +++++++++++++ linux-headers/asm-x86/unistd_64.h | 330 +++++++++++ linux-headers/asm-x86/unistd_x32.h | 319 +++++++++++ scripts/update-linux-headers.sh | 7 +- 11 files changed, 3404 insertions(+), 4 deletions(-) create mode 100644 linux-headers/asm-arm/unistd.h create mode 100644 linux-headers/asm-arm64/unistd.h create mode 100644 linux-headers/asm-mips/unistd.h create mode 100644 linux-headers/asm-powerpc/unistd.h create mode 100644 linux-headers/asm-s390/unistd.h create mode 100644 linux-headers/asm-x86/unistd.h create mode 100644 linux-headers/asm-x86/unistd_32.h create mode 100644 linux-headers/asm-x86/unistd_64.h create mode 100644 linux-headers/asm-x86/unistd_x32.h
linux-headers/asm-arm/unistd.h new file +448 -0
@@ -0,0 +1,448 @@ +/* +* arch/arm/include/asm/unistd.h +* +* Copyright (C) 2001-2005 Russell King +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* Please forward _all_ changes to this file to [email protected], +* no matter what the change is. Thanks! +*/ +#ifndef __ASM_ARM_UNISTD_H +#define __ASM_ARM_UNISTD_H + +#define __NR_OABI_SYSCALL_BASE 0x900000 + +#if defined(__thumb__) || defined(__ARM_EABI__) +#define __NR_SYSCALL_BASE 0 +#else +#define __NR_SYSCALL_BASE __NR_OABI_SYSCALL_BASE +#endif + +/* +* This file contains the system call numbers. +*/ + +#define __NR_restart_syscall (__NR_SYSCALL_BASE+ 0) +#define __NR_exit (__NR_SYSCALL_BASE+ 1) +#define __NR_fork (__NR_SYSCALL_BASE+ 2) +#define __NR_read (__NR_SYSCALL_BASE+ 3) +#define __NR_write (__NR_SYSCALL_BASE+ 4) +#define __NR_open (__NR_SYSCALL_BASE+ 5) +#define __NR_close (__NR_SYSCALL_BASE+ 6) +/* 7 was sys_waitpid */ +#define __NR_creat (__NR_SYSCALL_BASE+ 8) +#define __NR_link (__NR_SYSCALL_BASE+ 9) +#define __NR_unlink (__NR_SYSCALL_BASE+ 10) +#define __NR_execve (__NR_SYSCALL_BASE+ 11) +#define __NR_chdir (__NR_SYSCALL_BASE+ 12) +#define __NR_time (__NR_SYSCALL_BASE+ 13) +#define __NR_mknod (__NR_SYSCALL_BASE+ 14) +#define __NR_chmod (__NR_SYSCALL_BASE+ 15) +#define __NR_lchown (__NR_SYSCALL_BASE+ 16) +/* 17 was sys_break */ +/* 18 was sys_stat */ +#define __NR_lseek (__NR_SYSCALL_BASE+ 19) +#define __NR_getpid (__NR_SYSCALL_BASE+ 20) +#define __NR_mount (__NR_SYSCALL_BASE+ 21) +#define __NR_umount (__NR_SYSCALL_BASE+ 22) +#define __NR_setuid (__NR_SYSCALL_BASE+ 23) +#define __NR_getuid (__NR_SYSCALL_BASE+ 24) +#define __NR_stime (__NR_SYSCALL_BASE+ 25) +#define __NR_ptrace (__NR_SYSCALL_BASE+ 26) +#define __NR_alarm (__NR_SYSCALL_BASE+ 27) +/* 28 was sys_fstat */ +#define __NR_pause (__NR_SYSCALL_BASE+ 29) +#define __NR_utime (__NR_SYSCALL_BASE+ 30) +/* 31 was sys_stty */ +/* 32 was sys_gtty */ +#define __NR_access (__NR_SYSCALL_BASE+ 33) +#define __NR_nice (__NR_SYSCALL_BASE+ 34) +/* 35 was sys_ftime */ +#define __NR_sync (__NR_SYSCALL_BASE+ 36) +#define __NR_kill (__NR_SYSCALL_BASE+ 37) +#define __NR_rename (__NR_SYSCALL_BASE+ 38) +#define __NR_mkdir (__NR_SYSCALL_BASE+ 39) +#define __NR_rmdir (__NR_SYSCALL_BASE+ 40) +#define __NR_dup (__NR_SYSCALL_BASE+ 41) +#define __NR_pipe (__NR_SYSCALL_BASE+ 42) +#define __NR_times (__NR_SYSCALL_BASE+ 43) +/* 44 was sys_prof */ +#define __NR_brk (__NR_SYSCALL_BASE+ 45) +#define __NR_setgid (__NR_SYSCALL_BASE+ 46) +#define __NR_getgid (__NR_SYSCALL_BASE+ 47) +/* 48 was sys_signal */ +#define __NR_geteuid (__NR_SYSCALL_BASE+ 49) +#define __NR_getegid (__NR_SYSCALL_BASE+ 50) +#define __NR_acct (__NR_SYSCALL_BASE+ 51) +#define __NR_umount2 (__NR_SYSCALL_BASE+ 52) +/* 53 was sys_lock */ +#define __NR_ioctl (__NR_SYSCALL_BASE+ 54) +#define __NR_fcntl (__NR_SYSCALL_BASE+ 55) +/* 56 was sys_mpx */ +#define __NR_setpgid (__NR_SYSCALL_BASE+ 57) +/* 58 was sys_ulimit */ +/* 59 was sys_olduname */ +#define __NR_umask (__NR_SYSCALL_BASE+ 60) +#define __NR_chroot (__NR_SYSCALL_BASE+ 61) +#define __NR_ustat (__NR_SYSCALL_BASE+ 62) +#define __NR_dup2 (__NR_SYSCALL_BASE+ 63) +#define __NR_getppid (__NR_SYSCALL_BASE+ 64) +#define __NR_getpgrp (__NR_SYSCALL_BASE+ 65) +#define __NR_setsid (__NR_SYSCALL_BASE+ 66) +#define __NR_sigaction (__NR_SYSCALL_BASE+ 67) +/* 68 was sys_sgetmask */ +/* 69 was sys_ssetmask */ +#define __NR_setreuid (__NR_SYSCALL_BASE+ 70) +#define __NR_setregid (__NR_SYSCALL_BASE+ 71) +#define __NR_sigsuspend (__NR_SYSCALL_BASE+ 72) +#define __NR_sigpending (__NR_SYSCALL_BASE+ 73) +#define __NR_sethostname (__NR_SYSCALL_BASE+ 74) +#define __NR_setrlimit (__NR_SYSCALL_BASE+ 75) +#define __NR_getrlimit (__NR_SYSCALL_BASE+ 76)/* Back compat 2GB limited rlimit */ +#define __NR_getrusage (__NR_SYSCALL_BASE+ 77) +#define __NR_gettimeofday (__NR_SYSCALL_BASE+ 78) +#define __NR_settimeofday (__NR_SYSCALL_BASE+ 79) +#define __NR_getgroups (__NR_SYSCALL_BASE+ 80) +#define __NR_setgroups (__NR_SYSCALL_BASE+ 81) +#define __NR_select (__NR_SYSCALL_BASE+ 82) +#define __NR_symlink (__NR_SYSCALL_BASE+ 83) +/* 84 was sys_lstat */ +#define __NR_readlink (__NR_SYSCALL_BASE+ 85) +#define __NR_uselib (__NR_SYSCALL_BASE+ 86) +#define __NR_swapon (__NR_SYSCALL_BASE+ 87) +#define __NR_reboot (__NR_SYSCALL_BASE+ 88) +#define __NR_readdir (__NR_SYSCALL_BASE+ 89) +#define __NR_mmap (__NR_SYSCALL_BASE+ 90) +#define __NR_munmap (__NR_SYSCALL_BASE+ 91) +#define __NR_truncate (__NR_SYSCALL_BASE+ 92) +#define __NR_ftruncate (__NR_SYSCALL_BASE+ 93) +#define __NR_fchmod (__NR_SYSCALL_BASE+ 94) +#define __NR_fchown (__NR_SYSCALL_BASE+ 95) +#define __NR_getpriority (__NR_SYSCALL_BASE+ 96) +#define __NR_setpriority (__NR_SYSCALL_BASE+ 97) +/* 98 was sys_profil */ +#define __NR_statfs (__NR_SYSCALL_BASE+ 99) +#define __NR_fstatfs (__NR_SYSCALL_BASE+100) +/* 101 was sys_ioperm */ +#define __NR_socketcall (__NR_SYSCALL_BASE+102) +#define __NR_syslog (__NR_SYSCALL_BASE+103) +#define __NR_setitimer (__NR_SYSCALL_BASE+104) +#define __NR_getitimer (__NR_SYSCALL_BASE+105) +#define __NR_stat (__NR_SYSCALL_BASE+106) +#define __NR_lstat (__NR_SYSCALL_BASE+107) +#define __NR_fstat (__NR_SYSCALL_BASE+108) +/* 109 was sys_uname */ +/* 110 was sys_iopl */ +#define __NR_vhangup (__NR_SYSCALL_BASE+111) +/* 112 was sys_idle */ +#define __NR_syscall (__NR_SYSCALL_BASE+113)/* syscall to call a syscall! */ +#define __NR_wait4 (__NR_SYSCALL_BASE+114) +#define __NR_swapoff (__NR_SYSCALL_BASE+115) +#define __NR_sysinfo (__NR_SYSCALL_BASE+116) +#define __NR_ipc (__NR_SYSCALL_BASE+117) +#define __NR_fsync (__NR_SYSCALL_BASE+118) +#define __NR_sigreturn (__NR_SYSCALL_BASE+119) +#define __NR_clone (__NR_SYSCALL_BASE+120) +#define __NR_setdomainname (__NR_SYSCALL_BASE+121) +#define __NR_uname (__NR_SYSCALL_BASE+122) +/* 123 was sys_modify_ldt */ +#define __NR_adjtimex (__NR_SYSCALL_BASE+124) +#define __NR_mprotect (__NR_SYSCALL_BASE+125) +#define __NR_sigprocmask (__NR_SYSCALL_BASE+126) +/* 127 was sys_create_module */ +#define __NR_init_module (__NR_SYSCALL_BASE+128) +#define __NR_delete_module (__NR_SYSCALL_BASE+129) +/* 130 was sys_get_kernel_syms */ +#define __NR_quotactl (__NR_SYSCALL_BASE+131) +#define __NR_getpgid (__NR_SYSCALL_BASE+132) +#define __NR_fchdir (__NR_SYSCALL_BASE+133) +#define __NR_bdflush (__NR_SYSCALL_BASE+134) +#define __NR_sysfs (__NR_SYSCALL_BASE+135) +#define __NR_personality (__NR_SYSCALL_BASE+136) +/* 137 was sys_afs_syscall */ +#define __NR_setfsuid (__NR_SYSCALL_BASE+138) +#define __NR_setfsgid (__NR_SYSCALL_BASE+139) +#define __NR__llseek (__NR_SYSCALL_BASE+140) +#define __NR_getdents (__NR_SYSCALL_BASE+141) +#define __NR__newselect (__NR_SYSCALL_BASE+142) +#define __NR_flock (__NR_SYSCALL_BASE+143) +#define __NR_msync (__NR_SYSCALL_BASE+144) +#define __NR_readv (__NR_SYSCALL_BASE+145) +#define __NR_writev (__NR_SYSCALL_BASE+146) +#define __NR_getsid (__NR_SYSCALL_BASE+147) +#define __NR_fdatasync (__NR_SYSCALL_BASE+148) +#define __NR__sysctl (__NR_SYSCALL_BASE+149) +#define __NR_mlock (__NR_SYSCALL_BASE+150) +#define __NR_munlock (__NR_SYSCALL_BASE+151) +#define __NR_mlockall (__NR_SYSCALL_BASE+152) +#define __NR_munlockall (__NR_SYSCALL_BASE+153) +#define __NR_sched_setparam (__NR_SYSCALL_BASE+154) +#define __NR_sched_getparam (__NR_SYSCALL_BASE+155) +#define __NR_sched_setscheduler (__NR_SYSCALL_BASE+156) +#define __NR_sched_getscheduler (__NR_SYSCALL_BASE+157) +#define __NR_sched_yield (__NR_SYSCALL_BASE+158) +#define __NR_sched_get_priority_max (__NR_SYSCALL_BASE+159) +#define __NR_sched_get_priority_min (__NR_SYSCALL_BASE+160) +#define __NR_sched_rr_get_interval (__NR_SYSCALL_BASE+161) +#define __NR_nanosleep (__NR_SYSCALL_BASE+162) +#define __NR_mremap (__NR_SYSCALL_BASE+163) +#define __NR_setresuid (__NR_SYSCALL_BASE+164) +#define __NR_getresuid (__NR_SYSCALL_BASE+165) +/* 166 was sys_vm86 */ +/* 167 was sys_query_module */ +#define __NR_poll (__NR_SYSCALL_BASE+168) +#define __NR_nfsservctl (__NR_SYSCALL_BASE+169) +#define __NR_setresgid (__NR_SYSCALL_BASE+170) +#define __NR_getresgid (__NR_SYSCALL_BASE+171) +#define __NR_prctl (__NR_SYSCALL_BASE+172) +#define __NR_rt_sigreturn (__NR_SYSCALL_BASE+173) +#define __NR_rt_sigaction (__NR_SYSCALL_BASE+174) +#define __NR_rt_sigprocmask (__NR_SYSCALL_BASE+175) +#define __NR_rt_sigpending (__NR_SYSCALL_BASE+176) +#define __NR_rt_sigtimedwait (__NR_SYSCALL_BASE+177) +#define __NR_rt_sigqueueinfo (__NR_SYSCALL_BASE+178) +#define __NR_rt_sigsuspend (__NR_SYSCALL_BASE+179) +#define __NR_pread64 (__NR_SYSCALL_BASE+180) +#define __NR_pwrite64 (__NR_SYSCALL_BASE+181) +#define __NR_chown (__NR_SYSCALL_BASE+182) +#define __NR_getcwd (__NR_SYSCALL_BASE+183) +#define __NR_capget (__NR_SYSCALL_BASE+184) +#define __NR_capset (__NR_SYSCALL_BASE+185) +#define __NR_sigaltstack (__NR_SYSCALL_BASE+186) +#define __NR_sendfile (__NR_SYSCALL_BASE+187) +/* 188 reserved */ +/* 189 reserved */ +#define __NR_vfork (__NR_SYSCALL_BASE+190) +#define __NR_ugetrlimit (__NR_SYSCALL_BASE+191)/* SuS compliant getrlimit */ +#define __NR_mmap2 (__NR_SYSCALL_BASE+192) +#define __NR_truncate64 (__NR_SYSCALL_BASE+193) +#define __NR_ftruncate64 (__NR_SYSCALL_BASE+194) +#define __NR_stat64 (__NR_SYSCALL_BASE+195) +#define __NR_lstat64 (__NR_SYSCALL_BASE+196) +#define __NR_fstat64 (__NR_SYSCALL_BASE+197) +#define __NR_lchown32 (__NR_SYSCALL_BASE+198) +#define __NR_getuid32 (__NR_SYSCALL_BASE+199) +#define __NR_getgid32 (__NR_SYSCALL_BASE+200) +#define __NR_geteuid32 (__NR_SYSCALL_BASE+201) +#define __NR_getegid32 (__NR_SYSCALL_BASE+202) +#define __NR_setreuid32 (__NR_SYSCALL_BASE+203) +#define __NR_setregid32 (__NR_SYSCALL_BASE+204) +#define __NR_getgroups32 (__NR_SYSCALL_BASE+205) +#define __NR_setgroups32 (__NR_SYSCALL_BASE+206) +#define __NR_fchown32 (__NR_SYSCALL_BASE+207) +#define __NR_setresuid32 (__NR_SYSCALL_BASE+208) +#define __NR_getresuid32 (__NR_SYSCALL_BASE+209) +#define __NR_setresgid32 (__NR_SYSCALL_BASE+210) +#define __NR_getresgid32 (__NR_SYSCALL_BASE+211) +#define __NR_chown32 (__NR_SYSCALL_BASE+212) +#define __NR_setuid32 (__NR_SYSCALL_BASE+213) +#define __NR_setgid32 (__NR_SYSCALL_BASE+214) +#define __NR_setfsuid32 (__NR_SYSCALL_BASE+215) +#define __NR_setfsgid32 (__NR_SYSCALL_BASE+216) +#define __NR_getdents64 (__NR_SYSCALL_BASE+217) +#define __NR_pivot_root (__NR_SYSCALL_BASE+218) +#define __NR_mincore (__NR_SYSCALL_BASE+219) +#define __NR_madvise (__NR_SYSCALL_BASE+220) +#define __NR_fcntl64 (__NR_SYSCALL_BASE+221) +/* 222 for tux */ +/* 223 is unused */ +#define __NR_gettid (__NR_SYSCALL_BASE+224) +#define __NR_readahead (__NR_SYSCALL_BASE+225) +#define __NR_setxattr (__NR_SYSCALL_BASE+226) +#define __NR_lsetxattr (__NR_SYSCALL_BASE+227) +#define __NR_fsetxattr (__NR_SYSCALL_BASE+228) +#define __NR_getxattr (__NR_SYSCALL_BASE+229) +#define __NR_lgetxattr (__NR_SYSCALL_BASE+230) +#define __NR_fgetxattr (__NR_SYSCALL_BASE+231) +#define __NR_listxattr (__NR_SYSCALL_BASE+232) +#define __NR_llistxattr (__NR_SYSCALL_BASE+233) +#define __NR_flistxattr (__NR_SYSCALL_BASE+234) +#define __NR_removexattr (__NR_SYSCALL_BASE+235) +#define __NR_lremovexattr (__NR_SYSCALL_BASE+236) +#define __NR_fremovexattr (__NR_SYSCALL_BASE+237) +#define __NR_tkill (__NR_SYSCALL_BASE+238) +#define __NR_sendfile64 (__NR_SYSCALL_BASE+239) +#define __NR_futex (__NR_SYSCALL_BASE+240) +#define __NR_sched_setaffinity (__NR_SYSCALL_BASE+241) +#define __NR_sched_getaffinity (__NR_SYSCALL_BASE+242) +#define __NR_io_setup (__NR_SYSCALL_BASE+243) +#define __NR_io_destroy (__NR_SYSCALL_BASE+244) +#define __NR_io_getevents (__NR_SYSCALL_BASE+245) +#define __NR_io_submit (__NR_SYSCALL_BASE+246) +#define __NR_io_cancel (__NR_SYSCALL_BASE+247) +#define __NR_exit_group (__NR_SYSCALL_BASE+248) +#define __NR_lookup_dcookie (__NR_SYSCALL_BASE+249) +#define __NR_epoll_create (__NR_SYSCALL_BASE+250) +#define __NR_epoll_ctl (__NR_SYSCALL_BASE+251) +#define __NR_epoll_wait (__NR_SYSCALL_BASE+252) +#define __NR_remap_file_pages (__NR_SYSCALL_BASE+253) +/* 254 for set_thread_area */ +/* 255 for get_thread_area */ +#define __NR_set_tid_address (__NR_SYSCALL_BASE+256) +#define __NR_timer_create (__NR_SYSCALL_BASE+257) +#define __NR_timer_settime (__NR_SYSCALL_BASE+258) +#define __NR_timer_gettime (__NR_SYSCALL_BASE+259) +#define __NR_timer_getoverrun (__NR_SYSCALL_BASE+260) +#define __NR_timer_delete (__NR_SYSCALL_BASE+261) +#define __NR_clock_settime (__NR_SYSCALL_BASE+262) +#define __NR_clock_gettime (__NR_SYSCALL_BASE+263) +#define __NR_clock_getres (__NR_SYSCALL_BASE+264) +#define __NR_clock_nanosleep (__NR_SYSCALL_BASE+265) +#define __NR_statfs64 (__NR_SYSCALL_BASE+266) +#define __NR_fstatfs64 (__NR_SYSCALL_BASE+267) +#define __NR_tgkill (__NR_SYSCALL_BASE+268) +#define __NR_utimes (__NR_SYSCALL_BASE+269) +#define __NR_arm_fadvise64_64 (__NR_SYSCALL_BASE+270) +#define __NR_pciconfig_iobase (__NR_SYSCALL_BASE+271) +#define __NR_pciconfig_read (__NR_SYSCALL_BASE+272) +#define __NR_pciconfig_write (__NR_SYSCALL_BASE+273) +#define __NR_mq_open (__NR_SYSCALL_BASE+274) +#define __NR_mq_unlink (__NR_SYSCALL_BASE+275) +#define __NR_mq_timedsend (__NR_SYSCALL_BASE+276) +#define __NR_mq_timedreceive (__NR_SYSCALL_BASE+277) +#define __NR_mq_notify (__NR_SYSCALL_BASE+278) +#define __NR_mq_getsetattr (__NR_SYSCALL_BASE+279) +#define __NR_waitid (__NR_SYSCALL_BASE+280) +#define __NR_socket (__NR_SYSCALL_BASE+281) +#define __NR_bind (__NR_SYSCALL_BASE+282) +#define __NR_connect (__NR_SYSCALL_BASE+283) +#define __NR_listen (__NR_SYSCALL_BASE+284) +#define __NR_accept (__NR_SYSCALL_BASE+285) +#define __NR_getsockname (__NR_SYSCALL_BASE+286) +#define __NR_getpeername (__NR_SYSCALL_BASE+287) +#define __NR_socketpair (__NR_SYSCALL_BASE+288) +#define __NR_send (__NR_SYSCALL_BASE+289) +#define __NR_sendto (__NR_SYSCALL_BASE+290) +#define __NR_recv (__NR_SYSCALL_BASE+291) +#define __NR_recvfrom (__NR_SYSCALL_BASE+292) +#define __NR_shutdown (__NR_SYSCALL_BASE+293) +#define __NR_setsockopt (__NR_SYSCALL_BASE+294) +#define __NR_getsockopt (__NR_SYSCALL_BASE+295) +#define __NR_sendmsg (__NR_SYSCALL_BASE+296) +#define __NR_recvmsg (__NR_SYSCALL_BASE+297) +#define __NR_semop (__NR_SYSCALL_BASE+298) +#define __NR_semget (__NR_SYSCALL_BASE+299) +#define __NR_semctl (__NR_SYSCALL_BASE+300) +#define __NR_msgsnd (__NR_SYSCALL_BASE+301) +#define __NR_msgrcv (__NR_SYSCALL_BASE+302) +#define __NR_msgget (__NR_SYSCALL_BASE+303) +#define __NR_msgctl (__NR_SYSCALL_BASE+304) +#define __NR_shmat (__NR_SYSCALL_BASE+305) +#define __NR_shmdt (__NR_SYSCALL_BASE+306) +#define __NR_shmget (__NR_SYSCALL_BASE+307) +#define __NR_shmctl (__NR_SYSCALL_BASE+308) +#define __NR_add_key (__NR_SYSCALL_BASE+309) +#define __NR_request_key (__NR_SYSCALL_BASE+310) +#define __NR_keyctl (__NR_SYSCALL_BASE+311) +#define __NR_semtimedop (__NR_SYSCALL_BASE+312) +#define __NR_vserver (__NR_SYSCALL_BASE+313) +#define __NR_ioprio_set (__NR_SYSCALL_BASE+314) +#define __NR_ioprio_get (__NR_SYSCALL_BASE+315) +#define __NR_inotify_init (__NR_SYSCALL_BASE+316) +#define __NR_inotify_add_watch (__NR_SYSCALL_BASE+317) +#define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+318) +#define __NR_mbind (__NR_SYSCALL_BASE+319) +#define __NR_get_mempolicy (__NR_SYSCALL_BASE+320) +#define __NR_set_mempolicy (__NR_SYSCALL_BASE+321) +#define __NR_openat (__NR_SYSCALL_BASE+322) +#define __NR_mkdirat (__NR_SYSCALL_BASE+323) +#define __NR_mknodat (__NR_SYSCALL_BASE+324) +#define __NR_fchownat (__NR_SYSCALL_BASE+325) +#define __NR_futimesat (__NR_SYSCALL_BASE+326) +#define __NR_fstatat64 (__NR_SYSCALL_BASE+327) +#define __NR_unlinkat (__NR_SYSCALL_BASE+328) +#define __NR_renameat (__NR_SYSCALL_BASE+329) +#define __NR_linkat (__NR_SYSCALL_BASE+330) +#define __NR_symlinkat (__NR_SYSCALL_BASE+331) +#define __NR_readlinkat (__NR_SYSCALL_BASE+332) +#define __NR_fchmodat (__NR_SYSCALL_BASE+333) +#define __NR_faccessat (__NR_SYSCALL_BASE+334) +#define __NR_pselect6 (__NR_SYSCALL_BASE+335) +#define __NR_ppoll (__NR_SYSCALL_BASE+336) +#define __NR_unshare (__NR_SYSCALL_BASE+337) +#define __NR_set_robust_list (__NR_SYSCALL_BASE+338) +#define __NR_get_robust_list (__NR_SYSCALL_BASE+339) +#define __NR_splice (__NR_SYSCALL_BASE+340) +#define __NR_arm_sync_file_range (__NR_SYSCALL_BASE+341) +#define __NR_sync_file_range2 __NR_arm_sync_file_range +#define __NR_tee (__NR_SYSCALL_BASE+342) +#define __NR_vmsplice (__NR_SYSCALL_BASE+343) +#define __NR_move_pages (__NR_SYSCALL_BASE+344) +#define __NR_getcpu (__NR_SYSCALL_BASE+345) +#define __NR_epoll_pwait (__NR_SYSCALL_BASE+346) +#define __NR_kexec_load (__NR_SYSCALL_BASE+347) +#define __NR_utimensat (__NR_SYSCALL_BASE+348) +#define __NR_signalfd (__NR_SYSCALL_BASE+349) +#define __NR_timerfd_create (__NR_SYSCALL_BASE+350) +#define __NR_eventfd (__NR_SYSCALL_BASE+351) +#define __NR_fallocate (__NR_SYSCALL_BASE+352) +#define __NR_timerfd_settime (__NR_SYSCALL_BASE+353) +#define __NR_timerfd_gettime (__NR_SYSCALL_BASE+354) +#define __NR_signalfd4 (__NR_SYSCALL_BASE+355) +#define __NR_eventfd2 (__NR_SYSCALL_BASE+356) +#define __NR_epoll_create1 (__NR_SYSCALL_BASE+357) +#define __NR_dup3 (__NR_SYSCALL_BASE+358) +#define __NR_pipe2 (__NR_SYSCALL_BASE+359) +#define __NR_inotify_init1 (__NR_SYSCALL_BASE+360) +#define __NR_preadv (__NR_SYSCALL_BASE+361) +#define __NR_pwritev (__NR_SYSCALL_BASE+362) +#define __NR_rt_tgsigqueueinfo (__NR_SYSCALL_BASE+363) +#define __NR_perf_event_open (__NR_SYSCALL_BASE+364) +#define __NR_recvmmsg (__NR_SYSCALL_BASE+365) +#define __NR_accept4 (__NR_SYSCALL_BASE+366) +#define __NR_fanotify_init (__NR_SYSCALL_BASE+367) +#define __NR_fanotify_mark (__NR_SYSCALL_BASE+368) +#define __NR_prlimit64 (__NR_SYSCALL_BASE+369) +#define __NR_name_to_handle_at (__NR_SYSCALL_BASE+370) +#define __NR_open_by_handle_at (__NR_SYSCALL_BASE+371) +#define __NR_clock_adjtime (__NR_SYSCALL_BASE+372) +#define __NR_syncfs (__NR_SYSCALL_BASE+373) +#define __NR_sendmmsg (__NR_SYSCALL_BASE+374) +#define __NR_setns (__NR_SYSCALL_BASE+375) +#define __NR_process_vm_readv (__NR_SYSCALL_BASE+376) +#define __NR_process_vm_writev (__NR_SYSCALL_BASE+377) +#define __NR_kcmp (__NR_SYSCALL_BASE+378) +#define __NR_finit_module (__NR_SYSCALL_BASE+379) +#define __NR_sched_setattr (__NR_SYSCALL_BASE+380) +#define __NR_sched_getattr (__NR_SYSCALL_BASE+381) +#define __NR_renameat2 (__NR_SYSCALL_BASE+382) +#define __NR_seccomp (__NR_SYSCALL_BASE+383) +#define __NR_getrandom (__NR_SYSCALL_BASE+384) +#define __NR_memfd_create (__NR_SYSCALL_BASE+385) +#define __NR_bpf (__NR_SYSCALL_BASE+386) +#define __NR_execveat (__NR_SYSCALL_BASE+387) +#define __NR_userfaultfd (__NR_SYSCALL_BASE+388) +#define __NR_membarrier (__NR_SYSCALL_BASE+389) + +/* +* The following SWIs are ARM private. +*/ +#define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000) +#define __ARM_NR_breakpoint (__ARM_NR_BASE+1) +#define __ARM_NR_cacheflush (__ARM_NR_BASE+2) +#define __ARM_NR_usr26 (__ARM_NR_BASE+3) +#define __ARM_NR_usr32 (__ARM_NR_BASE+4) +#define __ARM_NR_set_tls (__ARM_NR_BASE+5) + +/* +* The following syscalls are obsolete and no longer available for EABI. +*/ +#if defined(__ARM_EABI__) +#undef __NR_time +#undef __NR_umount +#undef __NR_stime +#undef __NR_alarm +#undef __NR_utime +#undef __NR_getrlimit +#undef __NR_select +#undef __NR_readdir +#undef __NR_mmap +#undef __NR_socketcall +#undef __NR_syscall +#undef __NR_ipc +#endif + +#endif /* __ASM_ARM_UNISTD_H */
linux-headers/asm-arm64/kvm.h +35 -2
@@ -53,14 +53,20 @@ struct kvm_regs {struct user_fpsimd_state fp_regs; }; -/* Supported Processor Types */ +/* +* Supported CPU Targets - Adding a new target type is not recommended, +* unless there are some special registers not supported by the +* genericv8 syreg table. +*/ #define KVM_ARM_TARGET_AEM_V8 0#define KVM_ARM_TARGET_FOUNDATION_V8 1#define KVM_ARM_TARGET_CORTEX_A57 2#define KVM_ARM_TARGET_XGENE_POTENZA 3#define KVM_ARM_TARGET_CORTEX_A53 4 +/* Generic ARM v8 target */ +#define KVM_ARM_TARGET_GENERIC_V8 5 -#define KVM_ARM_NUM_TARGETS 5 +#define KVM_ARM_NUM_TARGETS 6/* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */ #define KVM_ARM_DEVICE_TYPE_SHIFT 0
@@ -100,12 +106,39 @@ struct kvm_sregs {struct kvm_fpu { }; +/* +* See v8 ARM ARM D7.3: Debug Registers +* +* The architectural limit is 16 debug registers of each type although +* in practice there are usually less (see ID_AA64DFR0_EL1). +* +* Although the control registers are architecturally defined as 32 +* bits wide we use a 64 bit structure here to keep parity with +* KVM_GET/SET_ONE_REG behaviour which treats all system registers as +* 64 bit values. It also allows for the possibility of the +* architecture expanding the control registers without having to +* change the userspace ABI. +*/ +#define KVM_ARM_MAX_DBG_REGS 16struct kvm_guest_debug_arch { +__u64 dbg_bcr[KVM_ARM_MAX_DBG_REGS ]; +__u64 dbg_bvr[KVM_ARM_MAX_DBG_REGS ]; +__u64 dbg_wcr[KVM_ARM_MAX_DBG_REGS ]; +__u64 dbg_wvr[KVM_ARM_MAX_DBG_REGS ]; };struct kvm_debug_exit_arch { +__u32 hsr; +__u64 far;/* used for watchpoints */ }; +/* +* Architecture specific defines for kvm_guest_debug->control +*/ + +#define KVM_GUESTDBG_USE_SW_BP (1 << 16) +#define KVM_GUESTDBG_USE_HW (1 << 17) +struct kvm_sync_regs { };
linux-headers/asm-arm64/unistd.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#include <asm-generic/unistd.h>
linux-headers/asm-mips/unistd.h new file +1063 -0
1,063 lines not on this page · raw message
linux-headers/asm-powerpc/unistd.h new file +392 -0
392 lines not on this page · raw message
linux-headers/asm-s390/unistd.h new file +404 -0
404 lines not on this page · raw message
linux-headers/asm-x86/unistd.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef _ASM_X86_UNISTD_H +#define _ASM_X86_UNISTD_H + +/* x32 syscall flag bit */ +#define __X32_SYSCALL_BIT 0x40000000 + +# ifdef __i386__ +# include <asm/unistd_32.h> +# elif defined(__ILP32__) +# include <asm/unistd_x32.h> +# else +# include <asm/unistd_64.h> +# endif + +#endif /* _ASM_X86_UNISTD_H */
linux-headers/asm-x86/unistd_32.h new file +377 -0
377 lines not on this page · raw message
linux-headers/asm-x86/unistd_64.h new file +330 -0
224 lines not on this page · raw message
linux-headers/asm-x86/unistd_x32.h new file +319 -0
319 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
MST
Part of the diff is not shown here. View the raw message.
[Qemu-devel] [PULL 16/38] vhost: add vhost_set_log_base op
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Split VHOST_SET_LOG_BASE call in a seperate function callback, so that type safety works and more arguments can be added in the next patches.
--- include/hw/virtio/vhost-backend.h | 3 +++ hw/virtio/vhost-backend.c | 6 ++++++ hw/virtio/vhost-user.c | 16 +++++++++++++++- hw/virtio/vhost.c | 6 +++--- 4 files changed, 27 insertions(+), 4 deletions(-)
include/hw/virtio/vhost-backend.h +3 -0
@@ -28,6 +28,8 @@ typedef int (*vhost_backend_get_vq_index)(struct vhost_dev *dev, int idx);typedef int (*vhost_backend_set_vring_enable )(struct vhost_dev *dev,int enable);typedef int (*vhost_backend_memslots_limit )(struct vhost_dev *dev); +typedef int (*vhost_set_log_base_op )(struct vhost_dev *dev,uint64_t base); + typedef struct VhostOps { VhostBackendType backend_type; vhost_call vhost_call;
@@ -36,6 +38,7 @@ typedef struct VhostOps {vhost_backend_get_vq_index vhost_backend_get_vq_index;vhost_backend_set_vring_enable vhost_backend_set_vring_enable;vhost_backend_memslots_limit vhost_backend_memslots_limit; +vhost_set_log_base_op vhost_set_log_base; } VhostOps;extern const VhostOps user_ops;
hw/virtio/vhost-backend.c +6 -0
@@ -67,6 +67,11 @@ static int vhost_kernel_memslots_limit(struct vhost_dev *dev)return limit; } +static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base) +{ +return vhost_kernel_call (dev,VHOST_SET_LOG_BASE , &base); +} +static const VhostOps kernel_ops = { .backend_type =VHOST_BACKEND_TYPE_KERNEL , .vhost_call = vhost_kernel_call,
@@ -74,6 +79,7 @@ static const VhostOps kernel_ops = { .vhost_backend_cleanup = vhost_kernel_cleanup, .vhost_backend_get_vq_index = vhost_kernel_get_vq_index, .vhost_backend_memslots_limit = vhost_kernel_memslots_limit, + .vhost_set_log_base = vhost_set_log_base, };int vhost_set_backend_type (struct vhost_dev *dev,VhostBackendType backend_type)
hw/virtio/vhost-user.c +15 -1
@@ -242,7 +242,6 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,break ;case VHOST_USER_SET_FEATURES : -case VHOST_USER_SET_LOG_BASE :case VHOST_USER_SET_PROTOCOL_FEATURES : msg.u64 = *((__u64 *) arg); msg.size =sizeof (m.u64);
@@ -367,6 +366,20 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,return 0 ; } +static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base) +{ +VhostUserMsg msg = { + .request =VHOST_USER_SET_LOG_BASE , + .flags =VHOST_USER_VERSION , + .u64 = base, + .size =sizeof (m.u64), + }; + +vhost_user_write (dev, &msg,NULL ,0 ); + +return 0 ; +} +static int vhost_user_init (struct vhost_dev *dev,void *opaque) {unsigned long long features;
@@ -453,4 +466,5 @@ const VhostOps user_ops = { .vhost_backend_get_vq_index = vhost_user_get_vq_index, .vhost_backend_set_vring_enable = vhost_user_set_vring_enable, .vhost_backend_memslots_limit = vhost_user_memslots_limit, + .vhost_set_log_base = vhost_set_log_base, };
hw/virtio/vhost.c +3 -3
@@ -352,7 +352,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size)/* inform backend of log switching, this must be done before releasing the current log, to ensure no logging is lost */ - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_LOG_BASE , &log_base); + r = dev->vhost_ops->vhost_set_log_base (dev, log_base);assert (r >=0 );vhost_log_put (dev, true); dev->log = log;
@@ -1167,8 +1167,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) hdev->log_size =vhost_get_log_size (hdev); hdev->log =vhost_log_get (hdev->log_size); log_base = (uintptr_t )hdev->log->log; - r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_LOG_BASE , - hdev->log_size ? &log_base :NULL ); + r = hdev->vhost_ops->vhost_set_log_base (hdev, + hdev->log_size ? log_base :0 );if (r <0 ) { r = -errno; goto fail_log;
Signature · 1 line
MST
[Qemu-devel] [PULL 17/38] vhost-user: add vhost_user_requires_shm_log()
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Check if the backend has VHOST_USER_PROTOCOL_F_LOG_SHMFD feature and require a shared log.
--- include/hw/virtio/vhost-backend.h | 4 ++++ hw/virtio/vhost-user.c | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)
include/hw/virtio/vhost-backend.h +4 -0
@@ -11,6 +11,8 @@ #ifndef VHOST_BACKEND_H_ #define VHOST_BACKEND_H_ +#include <stdbool.h> + typedef enum VhostBackendType { VHOST_BACKEND_TYPE_NONE = 0, VHOST_BACKEND_TYPE_KERNEL = 1,
@@ -29,6 +31,7 @@ typedef int (*vhost_backend_set_vring_enable)(struct vhost_dev *dev, int enable)typedef int (*vhost_backend_memslots_limit )(struct vhost_dev *dev);typedef int (*vhost_set_log_base_op )(struct vhost_dev *dev,uint64_t base); +typedef bool (*vhost_requires_shm_log_op )(struct vhost_dev *dev); typedef struct VhostOps { VhostBackendType backend_type;
@@ -39,6 +42,7 @@ typedef struct VhostOps {vhost_backend_set_vring_enable vhost_backend_set_vring_enable;vhost_backend_memslots_limit vhost_backend_memslots_limit;vhost_set_log_base_op vhost_set_log_base; +vhost_requires_shm_log_op vhost_requires_shm_log; } VhostOps;extern const VhostOps user_ops;
hw/virtio/vhost-user.c +12 -2
@@ -25,9 +25,10 @@#define VHOST_MEMORY_MAX_NREGIONS 8#define VHOST_USER_F_PROTOCOL_FEATURES 30 -#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x1ULL -#define VHOST_USER_PROTOCOL_F_MQ 0 +#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x3ULL +#define VHOST_USER_PROTOCOL_F_MQ 0 +#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 typedef enum VhostUserRequest { VHOST_USER_NONE = 0,
@@ -458,6 +459,14 @@ static int vhost_user_memslots_limit(struct vhost_dev *dev)return VHOST_MEMORY_MAX_NREGIONS ; } +static bool vhost_user_requires_shm_log (struct vhost_dev *dev) +{ +assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ); + +return virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_LOG_SHMFD ); +} +const VhostOps user_ops = { .backend_type =VHOST_BACKEND_TYPE_USER , .vhost_call = vhost_user_call,
@@ -467,4 +476,5 @@ const VhostOps user_ops = { .vhost_backend_set_vring_enable = vhost_user_set_vring_enable, .vhost_backend_memslots_limit = vhost_user_memslots_limit, .vhost_set_log_base = vhost_set_log_base, + .vhost_requires_shm_log = vhost_user_requires_shm_log, };
Signature · 1 line
MST
[Qemu-devel] [PULL 18/38] vhost: alloc shareable log
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
If the backend is requires it, allocate shareable memory.
vhost_log_get() now uses 2 globals "vhost_log" and "vhost_log_shm", that way there is a common non-shareable log and a common shareable one.
--- include/hw/virtio/vhost.h | 3 ++- hw/virtio/vhost.c | 57 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 11 deletions(-)
include/hw/virtio/vhost.h +2 -1
@@ -31,7 +31,8 @@ typedef unsigned long vhost_log_chunk_t;struct vhost_log {unsigned long long size;int refcnt; -vhost_log_chunk_t log[0 ]; +int fd; +vhost_log_chunk_t *log; };struct vhost_memory ;
hw/virtio/vhost.c +47 -10
107 lines not on this page · raw message
Signature · 1 line
MST
[Qemu-devel] [PULL 19/38] vhost-user: send log shm fd along with log_base
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Send the shm for the dirty pages logging if the backend supports VHOST_USER_PROTOCOL_F_LOG_SHMFD. Wait for a reply to make sure the old log is no longer used.
--- include/hw/virtio/vhost-backend.h | 4 +++- hw/virtio/vhost-backend.c | 3 ++- hw/virtio/vhost-user.c | 27 +++++++++++++++++++++++++-- hw/virtio/vhost.c | 5 +++-- 4 files changed, 33 insertions(+), 6 deletions(-)
include/hw/virtio/vhost-backend.h +3 -1
@@ -21,6 +21,7 @@ typedef enum VhostBackendType { } VhostBackendType;struct vhost_dev ; +struct vhost_log ;typedef int (*vhost_call )(struct vhost_dev *dev,unsigned long int request,void *arg);
@@ -30,7 +31,8 @@ typedef int (*vhost_backend_get_vq_index)(struct vhost_dev *dev, int idx);typedef int (*vhost_backend_set_vring_enable )(struct vhost_dev *dev,int enable);typedef int (*vhost_backend_memslots_limit )(struct vhost_dev *dev); -typedef int (*vhost_set_log_base_op )(struct vhost_dev *dev,uint64_t base); +typedef int (*vhost_set_log_base_op )(struct vhost_dev *dev,uint64_t base, +struct vhost_log *log);typedef bool (*vhost_requires_shm_log_op )(struct vhost_dev *dev); typedef struct VhostOps {
hw/virtio/vhost-backend.c +2 -1
@@ -67,7 +67,8 @@ static int vhost_kernel_memslots_limit(struct vhost_dev *dev)return limit; } -static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base) +static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base, +struct vhost_log *log) {return vhost_kernel_call (dev,VHOST_SET_LOG_BASE , &base); }
hw/virtio/vhost-user.c +25 -2
@@ -367,8 +367,13 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,return 0 ; } -static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base) +static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base, +struct vhost_log *log) { +int fds[VHOST_MEMORY_MAX_NREGIONS ]; +size_t fd_num =0 ; +bool shmfd =virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_LOG_SHMFD );VhostUserMsg msg = { .request =VHOST_USER_SET_LOG_BASE , .flags =VHOST_USER_VERSION ,
@@ -376,7 +381,25 @@ static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base) .size = sizeof(m.u64), }; -vhost_user_write (dev, &msg,NULL ,0 ); +if (shmfd && log->fd !=-1 ) { + fds[fd_num++] = log->fd; + } + +vhost_user_write (dev, &msg, fds, fd_num); + +if (shmfd) { + msg.size =0 ; +if (vhost_user_read (dev, &msg) <0 ) { +return 0 ; + } + +if (msg.request !=VHOST_USER_SET_LOG_BASE ) { +error_report ("Received unexpected msg type. " +"Expected %d received %d" , +VHOST_USER_SET_LOG_BASE , msg.request); +return -1 ; + } + }return 0 ; }
hw/virtio/vhost.c +3 -2
@@ -388,7 +388,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size)/* inform backend of log switching, this must be done before releasing the current log, to ensure no logging is lost */ - r = dev->vhost_ops->vhost_set_log_base (dev, log_base); + r = dev->vhost_ops->vhost_set_log_base (dev, log_base, log);assert (r >=0 );vhost_log_put (dev, true); dev->log = log;
@@ -1205,7 +1205,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) vhost_dev_log_is_shared(hdev)); log_base = (uintptr_t )hdev->log->log; r = hdev->vhost_ops->vhost_set_log_base (hdev, - hdev->log_size ? log_base :0 ); + hdev->log_size ? log_base :0 , + hdev->log);if (r <0 ) { r = -errno; goto fail_log;
Signature · 1 line
MST
[Qemu-devel] [PULL 20/38] vhost-user: add a migration blocker
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
If VHOST_USER_PROTOCOL_F_LOG_SHMFD is not announced, block vhost-user migration. The blocker is removed in vhost_dev_cleanup().
--- hw/virtio/vhost-user.c | 9 +++++++++ hw/virtio/vhost.c | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-)
hw/virtio/vhost-user.c +9 -0
@@ -15,6 +15,7 @@#include "qemu/error-report.h" #include "qemu/sockets.h" #include "exec/ram_addr.h" +#include "migration/migration.h" #include <fcntl.h> #include <unistd.h>
@@ -442,6 +443,14 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque) } } +if (dev->migration_blocker ==NULL && + !virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_LOG_SHMFD )) { +error_setg (&dev->migration_blocker, +"Migration disabled: vhost-user backend lacks " +"VHOST_USER_PROTOCOL_F_LOG_SHMFD feature." ); + } +return 0 ; }
hw/virtio/vhost.c +12 -4
@@ -961,6 +961,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,uint64_t features;int i, r; + hdev->migration_blocker =NULL ; +if (vhost_set_backend_type (hdev, backend_type) <0 ) {close ((uintptr_t )opaque);return -1 ;
@@ -1012,12 +1014,18 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, .eventfd_del = vhost_eventfd_del, .priority = 10 }; - hdev->migration_blocker =NULL ; -if (!(hdev->features & (0x1ULL <<VHOST_F_LOG_ALL ))) { -error_setg (&hdev->migration_blocker, -"Migration disabled: vhost lacks VHOST_F_LOG_ALL feature." ); + +if (hdev->migration_blocker ==NULL ) { +if (!(hdev->features & (0x1ULL <<VHOST_F_LOG_ALL ))) { +error_setg (&hdev->migration_blocker, +"Migration disabled: vhost lacks VHOST_F_LOG_ALL feature." ); + } + } + +if (hdev->migration_blocker !=NULL ) {migrate_add_blocker (hdev->migration_blocker); } + hdev->mem =g_malloc0 (offsetof(struct vhost_memory , regions)); hdev->n_mem_sections =0 ; hdev->mem_sections =NULL ;
Signature · 1 line
MST
[Qemu-devel] [PULL 22/38] vhost-user: document migration log
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
--- docs/specs/vhost-user.txt | 48 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-)
docs/specs/vhost-user.txt +46 -2
@@ -115,11 +115,13 @@ the ones that do: * VHOST_GET_FEATURES * VHOST_GET_PROTOCOL_FEATURES * VHOST_GET_VRING_BASE + * VHOST_SET_LOG_BASE (if VHOST_USER_PROTOCOL_F_LOG_SHMFD) There are several messages that the master sends with file descriptors passed in the ancillary data: * VHOST_SET_MEM_TABLE + * VHOST_SET_LOG_BASE (if VHOST_USER_PROTOCOL_F_LOG_SHMFD) * VHOST_SET_LOG_FD * VHOST_SET_VRING_KICK * VHOST_SET_VRING_CALL
@@ -140,8 +142,7 @@ Multiple queue support Multiple queue is treated as a protocol extension, hence the slave has to implement protocol features first. The multiple queues feature is supported -only when the protocol feature VHOST_USER_PROTOCOL_F_MQ (bit 0) is set: -#define VHOST_USER_PROTOCOL_F_MQ 0 +only when the protocol feature VHOST_USER_PROTOCOL_F_MQ (bit 0) is set. The max number of queues the slave supports can be queried with message VHOST_USER_GET_PROTOCOL_FEATURES. Master should stop when the number of
@@ -152,6 +153,48 @@ queue in the sent message to identify a specified queue. One queue pair is enabled initially. More queues are enabled dynamically, by sending message VHOST_USER_SET_VRING_ENABLE. +Migration +--------- + +During live migration, the master may need to track the modifications +the slave makes to the memory mapped regions. The client should mark +the dirty pages in a log. Once it complies to this logging, it may +declare the VHOST_F_LOG_ALL vhost feature. + +All the modifications to memory pointed by vring "descriptor" should +be marked. Modifications to "used" vring should be marked if +VHOST_VRING_F_LOG is part of ring's features. + +Dirty pages are of size: +#define VHOST_LOG_PAGE 0x1000 + +The log memory fd is provided in the ancillary data of +VHOST_USER_SET_LOG_BASE message when the slave has +VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol feature. + +The size of the log may be computed by using all the known guest +addresses. The log covers from address 0 to the maximum of guest +regions. In pseudo-code, to mark page at "addr" as dirty: + +page = addr / VHOST_LOG_PAGE +log[page / 8] |= 1 << page % 8 + +Use atomic operations, as the log may be concurrently manipulated. + +VHOST_USER_SET_LOG_FD is an optional message with an eventfd in +ancillary data, it may be used to inform the master that the log has +been modified. + +Once the source has finished migration, VHOST_USER_RESET_OWNER message +will be sent by the source. No further update must be done before the +destination takes over with new regions & rings. + +Protocol features +----------------- + +#define VHOST_USER_PROTOCOL_F_MQ 0 +#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 + Message types -------------
@@ -236,6 +279,7 @@ Message types Id: 6 Equivalent ioctl: VHOST_SET_LOG_BASE Master payload: u64 + Slave payload: N/A Sets the logging base address.
Signature · 1 line
MST
[Qemu-devel] [PULL 21/38] vhost: use a function for each call
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Replace the generic vhost_call() by specific functions for each function call to help with type safety and changing arguments.
While doing this, I found that "unsigned long long" and "uint64_t" were used interchangeably and causing compilation warnings, using uint64_t instead, as the vhost & protocol specifies.
--- include/hw/virtio/vhost-backend.h | 63 ++++- include/hw/virtio/vhost.h | 12 +- hw/net/vhost_net.c | 16 +- hw/scsi/vhost-scsi.c | 7 +- hw/virtio/vhost-backend.c | 132 +++++++++- hw/virtio/vhost-user.c | 522 ++++++++++++++++++++++---------------- hw/virtio/vhost.c | 36 +-- 7 files changed, 509 insertions(+), 279 deletions(-)
include/hw/virtio/vhost-backend.h +56 -7
@@ -22,28 +22,77 @@ typedef enum VhostBackendType {struct vhost_dev ;struct vhost_log ; +struct vhost_memory ; +struct vhost_vring_file ; +struct vhost_vring_state ; +struct vhost_vring_addr ; +struct vhost_scsi_target ; -typedef int (*vhost_call )(struct vhost_dev *dev,unsigned long int request, -void *arg);typedef int (*vhost_backend_init )(struct vhost_dev *dev,void *opaque);typedef int (*vhost_backend_cleanup )(struct vhost_dev *dev); -typedef int (*vhost_backend_get_vq_index )(struct vhost_dev *dev,int idx); -typedef int (*vhost_backend_set_vring_enable )(struct vhost_dev *dev,int enable);typedef int (*vhost_backend_memslots_limit )(struct vhost_dev *dev); +typedef int (*vhost_net_set_backend_op )(struct vhost_dev *dev, +struct vhost_vring_file *file); +typedef int (*vhost_scsi_set_endpoint_op )(struct vhost_dev *dev, +struct vhost_scsi_target *target); +typedef int (*vhost_scsi_clear_endpoint_op )(struct vhost_dev *dev, +struct vhost_scsi_target *target); +typedef int (*vhost_scsi_get_abi_version_op )(struct vhost_dev *dev, +int *version);typedef int (*vhost_set_log_base_op )(struct vhost_dev *dev,uint64_t base,struct vhost_log *log); +typedef int (*vhost_set_mem_table_op )(struct vhost_dev *dev, +struct vhost_memory *mem); +typedef int (*vhost_set_vring_addr_op )(struct vhost_dev *dev, +struct vhost_vring_addr *addr); +typedef int (*vhost_set_vring_endian_op )(struct vhost_dev *dev, +struct vhost_vring_state *ring); +typedef int (*vhost_set_vring_num_op )(struct vhost_dev *dev, +struct vhost_vring_state *ring); +typedef int (*vhost_set_vring_base_op )(struct vhost_dev *dev, +struct vhost_vring_state *ring); +typedef int (*vhost_get_vring_base_op )(struct vhost_dev *dev, +struct vhost_vring_state *ring); +typedef int (*vhost_set_vring_kick_op )(struct vhost_dev *dev, +struct vhost_vring_file *file); +typedef int (*vhost_set_vring_call_op )(struct vhost_dev *dev, +struct vhost_vring_file *file); +typedef int (*vhost_set_features_op )(struct vhost_dev *dev, +uint64_t features); +typedef int (*vhost_get_features_op )(struct vhost_dev *dev, +uint64_t *features); +typedef int (*vhost_set_owner_op )(struct vhost_dev *dev); +typedef int (*vhost_reset_device_op )(struct vhost_dev *dev); +typedef int (*vhost_get_vq_index_op )(struct vhost_dev *dev,int idx); +typedef int (*vhost_set_vring_enable_op )(struct vhost_dev *dev, +int enable);typedef bool (*vhost_requires_shm_log_op )(struct vhost_dev *dev);typedef struct VhostOps {VhostBackendType backend_type; -vhost_call vhost_call;vhost_backend_init vhost_backend_init;vhost_backend_cleanup vhost_backend_cleanup; -vhost_backend_get_vq_index vhost_backend_get_vq_index; -vhost_backend_set_vring_enable vhost_backend_set_vring_enable;vhost_backend_memslots_limit vhost_backend_memslots_limit; +vhost_net_set_backend_op vhost_net_set_backend; +vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint; +vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint; +vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version;vhost_set_log_base_op vhost_set_log_base; +vhost_set_mem_table_op vhost_set_mem_table; +vhost_set_vring_addr_op vhost_set_vring_addr; +vhost_set_vring_endian_op vhost_set_vring_endian; +vhost_set_vring_num_op vhost_set_vring_num; +vhost_set_vring_base_op vhost_set_vring_base; +vhost_get_vring_base_op vhost_get_vring_base; +vhost_set_vring_kick_op vhost_set_vring_kick; +vhost_set_vring_call_op vhost_set_vring_call; +vhost_set_features_op vhost_set_features; +vhost_get_features_op vhost_get_features; +vhost_set_owner_op vhost_set_owner; +vhost_reset_device_op vhost_reset_device; +vhost_get_vq_index_op vhost_get_vq_index; +vhost_set_vring_enable_op vhost_set_vring_enable;vhost_requires_shm_log_op vhost_requires_shm_log; }VhostOps ;
include/hw/virtio/vhost.h +6 -6
@@ -45,14 +45,14 @@ struct vhost_dev {int nvqs;/* the first virtqueue which would be used by this vhost dev */ int vq_index; -unsigned long long features; -unsigned long long acked_features; -unsigned long long backend_features; -unsigned long long protocol_features; -unsigned long long max_queues; +uint64_t features; +uint64_t acked_features; +uint64_t backend_features; +uint64_t protocol_features; +uint64_t max_queues;bool started;bool log_enabled; -unsigned long long log_size; +uint64_t log_size;Error *migration_blocker;bool memory_changed;hwaddr mem_changed_start_addr;
hw/net/vhost_net.c +6 -10
@@ -252,8 +252,7 @@ static int vhost_net_start_one(struct vhost_net *net, file.fd = net->backend;for (file.index =0 ; file.index < net->dev.nvqs; ++file.index) {const VhostOps *vhost_ops = net->dev.vhost_ops; - r = vhost_ops->vhost_call (&net->dev,VHOST_NET_SET_BACKEND , - &file); + r = vhost_ops->vhost_net_set_backend (&net->dev, &file);if (r <0 ) { r = -errno; goto fail;
@@ -266,8 +265,7 @@ fail:if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_TAP ) {while (file.index-- >0 ) {const VhostOps *vhost_ops = net->dev.vhost_ops; -int r = vhost_ops->vhost_call (&net->dev,VHOST_NET_SET_BACKEND , - &file); +int r = vhost_ops->vhost_net_set_backend (&net->dev, &file);assert (r >=0 ); } }
@@ -289,15 +287,13 @@ static void vhost_net_stop_one(struct vhost_net *net,if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_TAP ) {for (file.index =0 ; file.index < net->dev.nvqs; ++file.index) {const VhostOps *vhost_ops = net->dev.vhost_ops; -int r = vhost_ops->vhost_call (&net->dev,VHOST_NET_SET_BACKEND , - &file); +int r = vhost_ops->vhost_net_set_backend (&net->dev, &file);assert (r >=0 ); } }else if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ) {for (file.index =0 ; file.index < net->dev.nvqs; ++file.index) {const VhostOps *vhost_ops = net->dev.vhost_ops; -int r = vhost_ops->vhost_call (&net->dev,VHOST_RESET_DEVICE , -NULL ); +int r = vhost_ops->vhost_reset_device (&net->dev);assert (r >=0 ); } }
@@ -428,8 +424,8 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)VHostNetState *net =get_vhost_net (nc);const VhostOps *vhost_ops = net->dev.vhost_ops; -if (vhost_ops->vhost_backend_set_vring_enable) { -return vhost_ops->vhost_backend_set_vring_enable (&net->dev, enable); +if (vhost_ops->vhost_set_vring_enable) { +return vhost_ops->vhost_set_vring_enable (&net->dev, enable); }return 0 ;
hw/scsi/vhost-scsi.c +3 -4
@@ -46,7 +46,7 @@ static int vhost_scsi_set_endpoint(VHostSCSI *s)memset (&backend,0 ,sizeof (backend));pstrcpy (backend.vhost_wwpn,sizeof (backend.vhost_wwpn), vs->conf.wwpn); - ret = vhost_ops->vhost_call (&s->dev,VHOST_SCSI_SET_ENDPOINT , &backend); + ret = vhost_ops->vhost_scsi_set_endpoint (&s->dev, &backend);if (ret <0 ) {return -errno; }
@@ -61,7 +61,7 @@ static void vhost_scsi_clear_endpoint(VHostSCSI *s)memset (&backend,0 ,sizeof (backend));pstrcpy (backend.vhost_wwpn,sizeof (backend.vhost_wwpn), vs->conf.wwpn); - vhost_ops->vhost_call (&s->dev,VHOST_SCSI_CLEAR_ENDPOINT , &backend); + vhost_ops->vhost_scsi_clear_endpoint (&s->dev, &backend); }static int vhost_scsi_start (VHostSCSI *s)
@@ -77,8 +77,7 @@ static int vhost_scsi_start(VHostSCSI *s)return -ENOSYS ; } - ret = vhost_ops->vhost_call (&s->dev, -VHOST_SCSI_GET_ABI_VERSION , &abi_version); + ret = vhost_ops->vhost_scsi_get_abi_version (&s->dev, &abi_version);if (ret <0 ) {return -errno; }
hw/virtio/vhost-backend.c +120 -12
153 lines not on this page · raw message
hw/virtio/vhost-user.c +300 -222
635 lines not on this page · raw message
hw/virtio/vhost.c +18 -18
@@ -555,7 +555,7 @@ static void vhost_commit(MemoryListener *listener) }if (!dev->log_enabled) { - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_MEM_TABLE , dev->mem); + r = dev->vhost_ops->vhost_set_mem_table (dev, dev->mem);assert (r >=0 ); dev->memory_changed = false;return ;
@@ -568,7 +568,7 @@ static void vhost_commit(MemoryListener *listener)if (dev->log_size < log_size) {vhost_dev_log_resize (dev, log_size +VHOST_LOG_BUFFER ); } - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_MEM_TABLE , dev->mem); + r = dev->vhost_ops->vhost_set_mem_table (dev, dev->mem);assert (r >=0 );/* To log less, can only decrease log size after table update. */ if (dev->log_size > log_size +VHOST_LOG_BUFFER ) {
@@ -636,7 +636,7 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev, .log_guest_addr = vq->used_phys, .flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0, }; -int r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_ADDR , &addr); +int r = dev->vhost_ops->vhost_set_vring_addr (dev, &addr);if (r <0 ) {return -errno; }
@@ -650,7 +650,7 @@ static int vhost_dev_set_features(struct vhost_dev *dev, bool enable_log)if (enable_log) { features |=0x1ULL <<VHOST_F_LOG_ALL ; } - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_FEATURES , &features); + r = dev->vhost_ops->vhost_set_features (dev, features);return r <0 ? -errno :0 ; }
@@ -755,7 +755,7 @@ static int vhost_virtqueue_set_vring_endian_legacy(struct vhost_dev *dev, .num = is_big_endian }; -if (!dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_ENDIAN , &s)) { +if (!dev->vhost_ops->vhost_set_vring_endian (dev, &s)) {return 0 ; }
@@ -774,7 +774,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, {hwaddr s, l, a;int r; -int vhost_vq_index = dev->vhost_ops->vhost_backend_get_vq_index (dev, idx); +int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index (dev, idx);struct vhost_vring_file file = { .index = vhost_vq_index };
@@ -785,13 +785,13 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, vq->num = state.num =virtio_queue_get_num (vdev, idx); - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_NUM , &state); + r = dev->vhost_ops->vhost_set_vring_num (dev, &state);if (r) {return -errno; } state.num =virtio_queue_get_last_avail_idx (vdev, idx); - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_BASE , &state); + r = dev->vhost_ops->vhost_set_vring_base (dev, &state);if (r) {return -errno; }
@@ -843,7 +843,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, } file.fd =event_notifier_get_fd (virtio_queue_get_host_notifier (vvq)); - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_KICK , &file); + r = dev->vhost_ops->vhost_set_vring_kick (dev, &file);if (r) { r = -errno; goto fail_kick;
@@ -876,13 +876,13 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev,struct vhost_virtqueue *vq, unsigned idx) { - int vhost_vq_index = dev->vhost_ops->vhost_backend_get_vq_index(dev, idx); + int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, idx);struct vhost_vring_state state = { .index = vhost_vq_index, };int r; - r = dev->vhost_ops->vhost_call (dev,VHOST_GET_VRING_BASE , &state); + r = dev->vhost_ops->vhost_get_vring_base (dev, &state);if (r <0 ) {fprintf (stderr,"vhost VQ %d ring restore failed: %d\n" , idx, r);fflush (stderr);
@@ -929,7 +929,7 @@ static void vhost_eventfd_del(MemoryListener *listener,static int vhost_virtqueue_init (struct vhost_dev *dev,struct vhost_virtqueue *vq,int n) { -int vhost_vq_index = dev->vhost_ops->vhost_backend_get_vq_index (dev, n); +int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index (dev, n);struct vhost_vring_file file = { .index = vhost_vq_index, };
@@ -939,7 +939,7 @@ static int vhost_virtqueue_init(struct vhost_dev *dev, } file.fd =event_notifier_get_fd (&vq->masked_notifier); - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_CALL , &file); + r = dev->vhost_ops->vhost_set_vring_call (dev, &file);if (r) { r = -errno; goto fail_call;
@@ -981,12 +981,12 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, }QLIST_INSERT_HEAD (&vhost_devices, hdev, entry); - r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_OWNER ,NULL ); + r = hdev->vhost_ops->vhost_set_owner (hdev);if (r <0 ) { goto fail; } - r = hdev->vhost_ops->vhost_call (hdev,VHOST_GET_FEATURES , &features); + r = hdev->vhost_ops->vhost_get_features (hdev, &features);if (r <0 ) { goto fail; }
@@ -1147,8 +1147,8 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, file.fd =event_notifier_get_fd (virtio_queue_get_guest_notifier (vvq)); } - file.index = hdev->vhost_ops->vhost_backend_get_vq_index (hdev, n); - r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_VRING_CALL , &file); + file.index = hdev->vhost_ops->vhost_get_vq_index (hdev, n); + r = hdev->vhost_ops->vhost_set_vring_call (hdev, &file);assert (r >=0 ); }
@@ -1190,7 +1190,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)if (r <0 ) { goto fail_features; } - r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_MEM_TABLE , hdev->mem); + r = hdev->vhost_ops->vhost_set_mem_table (hdev, hdev->mem);if (r <0 ) { r = -errno; goto fail_mem;
Signature · 1 line
MST
Re: [Qemu-devel] [PULL 21/38] vhost: use a function for each call
Hello,
There are some errors with gcc 4.4.7 due to the use of an anonymous union in VhostUserMsg in declarations with initialization. Please see below.
Thanks.
Quoted 25 lines · Michael S. Tsirkin
From: Marc-André Lureau <[email protected]>
Replace the generic
vhost_call()by specific functions for each function call to help with type safety and changing arguments.While doing this, I found that "unsigned long long" and "
uint64_t" were used interchangeably and causing compilation warnings, usinguint64_tinstead, as the vhost & protocol specifies.Signed-off-by Marc-André Lureau <[email protected]>[Fix enum usage and MQ - Thibaut Collet]Signed-off-by Thibaut Collet <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Tested-by Thibaut Collet <[email protected]>--- include/hw/virtio/vhost-backend.h | 63 ++++- include/hw/virtio/vhost.h | 12 +- hw/net/vhost_net.c | 16 +- hw/scsi/vhost-scsi.c | 7 +- hw/virtio/vhost-backend.c | 132 +++++++++- hw/virtio/vhost-user.c | 522 ++++++++++++++++++++++---------------- hw/virtio/vhost.c | 36 +-- 7 files changed, 509 insertions(+), 279 deletions(-)
[...]
Quoted 4 lines
hw/virtio/vhost-user.c +0
-0
[...]
Quoted 14 lines
hw/virtio/vhost-user.c +2
-7@@ -190,231 +182,321 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, 0 : -1; } -static bool vhost_user_one_time_request (VhostUserRequest request) +static int vhost_user_set_log_base (struct vhost_dev *dev,uint64_t base, +struct vhost_log *log) { -switch (request) { -case VHOST_USER_SET_OWNER : -case VHOST_USER_RESET_DEVICE : -case VHOST_USER_SET_MEM_TABLE : -case VHOST_USER_GET_QUEUE_NUM : -return true;
hw/virtio/vhost-user.c static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, · line 195
Quoted 10 lines
hw/virtio/vhost-user.c +8
-2-default : -return false; +int fds[VHOST_MEMORY_MAX_NREGIONS ]; +size_t fd_num =0 ; +bool shmfd =virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_LOG_SHMFD ); +VhostUserMsg msg = { + .request =VHOST_USER_SET_LOG_BASE , + .flags =VHOST_USER_VERSION , + .u64 = base,
gcc 4.4.7 on CentOS 6.7 doesn't like this use of anonymous union.
Quoted 107 lines
hw/virtio/vhost-user.c +58
-34+ .size = sizeof(m.u64), + }; + +if (shmfd && log->fd !=-1 ) { + fds[fd_num++] = log->fd; + } + +vhost_user_write (dev, &msg, fds, fd_num); + +if (shmfd) { + msg.size =0 ; +if (vhost_user_read (dev, &msg) <0 ) { +return 0 ; + } + +if (msg.request !=VHOST_USER_SET_LOG_BASE ) { +error_report ("Received unexpected msg type. " +"Expected %d received %d" , +VHOST_USER_SET_LOG_BASE , msg.request); +return -1 ; + } } + +return 0 ; } -static int vhost_user_call (struct vhost_dev *dev,unsigned long int request, -void *arg) +static int vhost_user_set_mem_table (struct vhost_dev *dev, +struct vhost_memory *mem) { -VhostUserMsg msg; -VhostUserRequest msg_request; -struct vhost_vring_file *file =0 ; -int need_reply =0 ;int fds[VHOST_MEMORY_MAX_NREGIONS ];int i, fd;size_t fd_num =0 ; +VhostUserMsg msg = { + .request =VHOST_USER_SET_MEM_TABLE , + .flags =VHOST_USER_VERSION , + }; -assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ); - -/* only translate vhost ioctl requests */ -if (request >VHOST_USER_MAX ) { - msg_request =vhost_user_request_translate (request); - }else { - msg_request = request; +for (i =0 ; i < dev->mem->nregions; ++i) { +struct vhost_memory_region *reg = dev->mem->regions + i; +ram_addr_t ram_addr; + +assert ((uintptr_t )reg->userspace_addr == reg->userspace_addr); +qemu_ram_addr_from_host ((void *)(uintptr_t )reg->userspace_addr, + &ram_addr); + fd =qemu_get_ram_fd (ram_addr); +if (fd >0 ) { + msg.memory.regions[fd_num].userspace_addr = reg->userspace_addr; + msg.memory.regions[fd_num].memory_size = reg->memory_size; + msg.memory.regions[fd_num].guest_phys_addr = reg->guest_phys_addr; + msg.memory.regions[fd_num].mmap_offset = reg->userspace_addr - + (uintptr_t )qemu_get_ram_block_host_ptr (ram_addr); +assert (fd_num <VHOST_MEMORY_MAX_NREGIONS ); + fds[fd_num++] = fd; + } } -/* -* For non-vring specific requests, like VHOST_USER_SET_MEM_TABLE, -* we just need send it once in the first time. For later such -* request, we just ignore it. -*/ -if (vhost_user_one_time_request (msg_request) && dev->vq_index !=0 ) { -return 0 ; + msg.memory.nregions = fd_num; + +if (!fd_num) { +error_report ("Failed initializing vhost-user memory map, " +"consider using -object memory-backend-file share=on" ); +return -1 ; } - msg.request = msg_request; - msg.flags =VHOST_USER_VERSION ; - msg.size =0 ; + msg.size =sizeof (m.memory.nregions); + msg.size +=sizeof (m.memory.padding); + msg.size += fd_num *sizeof (VhostUserMemoryRegion); -switch (msg_request) { -case VHOST_USER_GET_FEATURES : -case VHOST_USER_GET_PROTOCOL_FEATURES : -case VHOST_USER_GET_QUEUE_NUM : - need_reply =1 ; -break ; +vhost_user_write (dev, &msg, fds, fd_num); -case VHOST_USER_SET_FEATURES : -case VHOST_USER_SET_PROTOCOL_FEATURES : - msg.u64 = *((__u64 *) arg); - msg.size =sizeof (m.u64); -break ; +return 0 ; +}
hw/virtio/vhost-user.c static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, · line 275
Quoted 10 lines
hw/virtio/vhost-user.c +7
-3-case VHOST_USER_SET_OWNER : -case VHOST_USER_RESET_DEVICE : -break ; +static int vhost_user_set_vring_addr (struct vhost_dev *dev, +struct vhost_vring_addr *addr) +{ +VhostUserMsg msg = { + .request =VHOST_USER_SET_VRING_ADDR , + .flags =VHOST_USER_VERSION , + .addr = *addr,
Ditto.
Quoted 79 lines
hw/virtio/vhost-user.c +11
-64+ .size = sizeof(*addr), + }; -case VHOST_USER_SET_MEM_TABLE : -for (i =0 ; i < dev->mem->nregions; ++i) { -struct vhost_memory_region *reg = dev->mem->regions + i; -ram_addr_t ram_addr; - -assert ((uintptr_t )reg->userspace_addr == reg->userspace_addr); -qemu_ram_addr_from_host ((void *)(uintptr_t )reg->userspace_addr, &ram_addr); - fd =qemu_get_ram_fd (ram_addr); -if (fd >0 ) { - msg.memory.regions[fd_num].userspace_addr = reg->userspace_addr; - msg.memory.regions[fd_num].memory_size = reg->memory_size; - msg.memory.regions[fd_num].guest_phys_addr = reg->guest_phys_addr; - msg.memory.regions[fd_num].mmap_offset = reg->userspace_addr - - (uintptr_t )qemu_get_ram_block_host_ptr (ram_addr); -assert (fd_num <VHOST_MEMORY_MAX_NREGIONS ); - fds[fd_num++] = fd; - } - } +vhost_user_write (dev, &msg,NULL ,0 ); - msg.memory.nregions = fd_num; +return 0 ; +} -if (!fd_num) { -error_report ("Failed initializing vhost-user memory map, " -"consider using -object memory-backend-file share=on" ); -return -1 ; - } +static int vhost_user_set_vring_endian (struct vhost_dev *dev, +struct vhost_vring_state *ring) +{ +error_report ("vhost-user trying to send unhandled ioctl" ); +return -1 ; +} - msg.size =sizeof (m.memory.nregions); - msg.size +=sizeof (m.memory.padding); - msg.size += fd_num *sizeof (VhostUserMemoryRegion); - -break ; - -case VHOST_USER_SET_LOG_FD : - fds[fd_num++] = *((int *) arg); -break ; - -case VHOST_USER_SET_VRING_NUM : -case VHOST_USER_SET_VRING_BASE : -case VHOST_USER_SET_VRING_ENABLE : -memcpy (&msg.state, arg,sizeof (struct vhost_vring_state )); - msg.size =sizeof (m.state); -break ; - -case VHOST_USER_GET_VRING_BASE : -memcpy (&msg.state, arg,sizeof (struct vhost_vring_state )); - msg.size =sizeof (m.state); - need_reply =1 ; -break ; - -case VHOST_USER_SET_VRING_ADDR : -memcpy (&msg.addr, arg,sizeof (struct vhost_vring_addr )); - msg.size =sizeof (m.addr); -break ; - -case VHOST_USER_SET_VRING_KICK : -case VHOST_USER_SET_VRING_CALL : -case VHOST_USER_SET_VRING_ERR : - file = arg; - msg.u64 = file->index &VHOST_USER_VRING_IDX_MASK ; - msg.size =sizeof (m.u64); -if (ioeventfd_enabled () && file->fd >0 ) { - fds[fd_num++] = file->fd; - }else { - msg.u64 |=VHOST_USER_VRING_NOFD_MASK ; - } -break ;
hw/virtio/vhost-user.c static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, · line 298
Quoted 10 lines
hw/virtio/vhost-user.c +8
-2-default : -error_report ("vhost-user trying to send unhandled ioctl" ); +static int vhost_set_vring (struct vhost_dev *dev, +unsigned long int request, +struct vhost_vring_state *ring) +{ +VhostUserMsg msg = { + .request = request, + .flags =VHOST_USER_VERSION , + .state = *ring,
Ditto.
Quoted 34 lines
hw/virtio/vhost-user.c +29
-2+ .size = sizeof(*ring), + }; + +vhost_user_write (dev, &msg,NULL ,0 ); + +return 0 ; +} + +static int vhost_user_set_vring_num (struct vhost_dev *dev, +struct vhost_vring_state *ring) +{ +return vhost_set_vring (dev,VHOST_USER_SET_VRING_NUM , ring); +} + +static int vhost_user_set_vring_base (struct vhost_dev *dev, +struct vhost_vring_state *ring) +{ +return vhost_set_vring (dev,VHOST_USER_SET_VRING_BASE , ring); +} + +static int vhost_user_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vring_state state = { + .index = dev->vq_index, + .num = enable, + }; + +if (!(dev->protocol_features & (1ULL <<VHOST_USER_PROTOCOL_F_MQ ))) {return -1 ; -break ; } -if (vhost_user_write (dev, &msg, fds, fd_num) <0 ) { +return vhost_set_vring (dev,VHOST_USER_SET_VRING_ENABLE , &state);
hw/virtio/vhost-user.c static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, · line 340
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+} + + +static int vhost_user_get_vring_base (struct vhost_dev *dev, +struct vhost_vring_state *ring) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GET_VRING_BASE , + .flags =VHOST_USER_VERSION , + .state = *ring,
Ditto.
Quoted 63 lines
hw/virtio/vhost-user.c +19
-34+ .size = sizeof(*ring), + }; + +vhost_user_write (dev, &msg,NULL ,0 ); + +if (vhost_user_read (dev, &msg) <0 ) {return 0 ; } -if (need_reply) { -if (vhost_user_read (dev, &msg) <0 ) { -return 0 ; - } - -if (msg_request != msg.request) { -error_report ("Received unexpected msg type." -" Expected %d received %d" , msg_request, msg.request); -return -1 ; - } +if (msg.request !=VHOST_USER_GET_VRING_BASE ) { +error_report ("Received unexpected msg type. Expected %d received %d" , +VHOST_USER_GET_VRING_BASE , msg.request); +return -1 ; + } -switch (msg_request) { -case VHOST_USER_GET_FEATURES : -case VHOST_USER_GET_PROTOCOL_FEATURES : -case VHOST_USER_GET_QUEUE_NUM : -if (msg.size !=sizeof (m.u64)) { -error_report ("Received bad msg size." ); -return -1 ; - } - *((__u64 *) arg) = msg.u64; -break ; -case VHOST_USER_GET_VRING_BASE : -if (msg.size !=sizeof (m.state)) { -error_report ("Received bad msg size." ); -return -1 ; - } -memcpy (arg, &msg.state,sizeof (struct vhost_vring_state )); -break ; -default : -error_report ("Received unexpected msg type." ); -return -1 ; -break ; - } +if (msg.size !=sizeof (m.state)) { +error_report ("Received bad msg size." ); +return -1 ; } + *ring = msg.state; +return 0 ; } -static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base, -struct vhost_log *log) +static int vhost_set_vring_file (struct vhost_dev *dev, +VhostUserRequest request, +struct vhost_vring_file *file) {
hw/virtio/vhost-user.c static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, · line 375
Quoted 10 lines
hw/virtio/vhost-user.c +2
-4int fds[VHOST_MEMORY_MAX_NREGIONS ];size_t fd_num =0 ; -bool shmfd =virtio_has_feature (dev->protocol_features, -VHOST_USER_PROTOCOL_F_LOG_SHMFD );VhostUserMsg msg = { - .request =VHOST_USER_SET_LOG_BASE , + .request = request, .flags =VHOST_USER_VERSION , - .u64 = base, + .u64 = file->index &VHOST_USER_VRING_IDX_MASK ,
Ditto.
Quoted 35 lines
hw/virtio/vhost-user.c +14
-13.size = sizeof(m.u64), }; -if (shmfd && log->fd !=-1 ) { - fds[fd_num++] = log->fd; +if (ioeventfd_enabled () && file->fd >0 ) { + fds[fd_num++] = file->fd; + }else { + msg.u64 |=VHOST_USER_VRING_NOFD_MASK ; }vhost_user_write (dev, &msg, fds, fd_num); -if (shmfd) { - msg.size =0 ; -if (vhost_user_read (dev, &msg) <0 ) { -return 0 ; - } +return 0 ; +} -if (msg.request !=VHOST_USER_SET_LOG_BASE ) { -error_report ("Received unexpected msg type. " -"Expected %d received %d" , -VHOST_USER_SET_LOG_BASE , msg.request); -return -1 ; - } +static int vhost_user_set_vring_kick (struct vhost_dev *dev, +struct vhost_vring_file *file) +{ +return vhost_set_vring_file (dev,VHOST_USER_SET_VRING_KICK , file); +} + +static int vhost_user_set_vring_call (struct vhost_dev *dev, +struct vhost_vring_file *file)
hw/virtio/vhost-user.c static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, · line 407
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+{ +return vhost_set_vring_file (dev,VHOST_USER_SET_VRING_CALL , file); +} + +static int vhost_user_set_u64 (struct vhost_dev *dev,int request,uint64_t u64) +{ +VhostUserMsg msg = { + .request = request, + .flags =VHOST_USER_VERSION , + .u64 = u64,
Ditto.
Thanks,
Laurent
Quoted 175 lines
hw/virtio/vhost-user.c +99
-26+ .size = sizeof(m.u64), + }; + +vhost_user_write (dev, &msg,NULL ,0 ); + +return 0 ; +} + +static int vhost_user_set_features (struct vhost_dev *dev, +uint64_t features) +{ +return vhost_user_set_u64 (dev,VHOST_USER_SET_FEATURES , features); +} + +static int vhost_user_set_protocol_features (struct vhost_dev *dev, +uint64_t features) +{ +return vhost_user_set_u64 (dev,VHOST_USER_SET_PROTOCOL_FEATURES , features); +} + +static int vhost_user_get_u64 (struct vhost_dev *dev,int request,uint64_t *u64) +{ +VhostUserMsg msg = { + .request = request, + .flags =VHOST_USER_VERSION , + }; + +if (vhost_user_one_time_request (request) && dev->vq_index !=0 ) { +return 0 ; } +vhost_user_write (dev, &msg,NULL ,0 ); + +if (vhost_user_read (dev, &msg) <0 ) { +return 0 ; + } + +if (msg.request != request) { +error_report ("Received unexpected msg type. Expected %d received %d" , + request, msg.request); +return -1 ; + } + +if (msg.size !=sizeof (m.u64)) { +error_report ("Received bad msg size." ); +return -1 ; + } + + *u64 = msg.u64; + +return 0 ; +} + +static int vhost_user_get_features (struct vhost_dev *dev,uint64_t *features) +{ +return vhost_user_get_u64 (dev,VHOST_USER_GET_FEATURES , features); +} + +static int vhost_user_set_owner (struct vhost_dev *dev) +{ +VhostUserMsg msg = { + .request =VHOST_USER_SET_OWNER , + .flags =VHOST_USER_VERSION , + }; + +vhost_user_write (dev, &msg,NULL ,0 ); + +return 0 ; +} + +static int vhost_user_reset_device (struct vhost_dev *dev) +{ +VhostUserMsg msg = { + .request =VHOST_USER_RESET_DEVICE , + .flags =VHOST_USER_VERSION , + }; + +vhost_user_write (dev, &msg,NULL ,0 ); +return 0 ; }static int vhost_user_init (struct vhost_dev *dev,void *opaque) { -unsigned long long features; +uint64_t features;int err;assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ); dev->opaque = opaque; - err =vhost_user_call (dev,VHOST_USER_GET_FEATURES , &features); + err =vhost_user_get_features (dev, &features);if (err <0 ) {return err; }@@ -422,21 +504,22 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)if (virtio_has_feature (features,VHOST_USER_F_PROTOCOL_FEATURES )) { dev->backend_features |=1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ; - err =vhost_user_call (dev,VHOST_USER_GET_PROTOCOL_FEATURES , &features); + err =vhost_user_get_u64 (dev,VHOST_USER_GET_PROTOCOL_FEATURES , + &features);if (err <0 ) {return err; } dev->protocol_features = features &VHOST_USER_PROTOCOL_FEATURE_MASK ; - err =vhost_user_call (dev,VHOST_USER_SET_PROTOCOL_FEATURES , - &dev->protocol_features); + err =vhost_user_set_protocol_features (dev, dev->protocol_features);if (err <0 ) {return err; }/* query the max queues we support if backend supports Multiple Queue */ if (dev->protocol_features & (1ULL <<VHOST_USER_PROTOCOL_F_MQ )) { - err =vhost_user_call (dev,VHOST_USER_GET_QUEUE_NUM , &dev->max_queues); + err =vhost_user_get_u64 (dev,VHOST_USER_GET_QUEUE_NUM , + &dev->max_queues);if (err <0 ) {return err; }@@ -454,22 +537,6 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)return 0 ; } -static int vhost_user_set_vring_enable (struct vhost_dev *dev,int enable) -{ -struct vhost_vring_state state = { - .index = dev->vq_index, - .num = enable, - }; - -assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ); - -if (!(dev->protocol_features & (1ULL <<VHOST_USER_PROTOCOL_F_MQ ))) { -return -1 ; - } - -return vhost_user_call (dev,VHOST_USER_SET_VRING_ENABLE , &state); -} -static int vhost_user_cleanup (struct vhost_dev *dev) {assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER );@@ -501,12 +568,23 @@ static bool vhost_user_requires_shm_log(struct vhost_dev *dev)const VhostOps user_ops = { .backend_type =VHOST_BACKEND_TYPE_USER , - .vhost_call = vhost_user_call, .vhost_backend_init = vhost_user_init, .vhost_backend_cleanup = vhost_user_cleanup, - .vhost_backend_get_vq_index = vhost_user_get_vq_index, - .vhost_backend_set_vring_enable = vhost_user_set_vring_enable, .vhost_backend_memslots_limit = vhost_user_memslots_limit, - .vhost_set_log_base = vhost_set_log_base, + .vhost_set_log_base = vhost_user_set_log_base, + .vhost_set_mem_table = vhost_user_set_mem_table, + .vhost_set_vring_addr = vhost_user_set_vring_addr, + .vhost_set_vring_endian = vhost_user_set_vring_endian, + .vhost_set_vring_num = vhost_user_set_vring_num, + .vhost_set_vring_base = vhost_user_set_vring_base, + .vhost_get_vring_base = vhost_user_get_vring_base, + .vhost_set_vring_kick = vhost_user_set_vring_kick, + .vhost_set_vring_call = vhost_user_set_vring_call, + .vhost_set_features = vhost_user_set_features, + .vhost_get_features = vhost_user_get_features, + .vhost_set_owner = vhost_user_set_owner, + .vhost_reset_device = vhost_user_reset_device, + .vhost_get_vq_index = vhost_user_get_vq_index, + .vhost_set_vring_enable = vhost_user_set_vring_enable, .vhost_requires_shm_log = vhost_user_requires_shm_log, };
Re: [Qemu-devel] [PULL 21/38] vhost: use a function for each call
Quoted 7 lines · Laurent Desnogues
Hello,
There are some errors with gcc 4.4.7 due to the use of an anonymous union in VhostUserMsg in declarations with initialization. Please see below.
Thanks.
I don't have this system: want to send a patch?
[Qemu-devel] [PULL 23/38] net: add trace_vhost_user_event
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Replace error_report() and use tracing instead. It's not an error to get a connection or a disconnection, so silence this and trace it instead.
--- net/vhost-user.c | 4 ++-- trace-events | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
net/vhost-user.c +2 -2
@@ -15,6 +15,7 @@#include "qemu/config-file.h" #include "qemu/error-report.h" #include "qmp-commands.h" +#include "trace.h" typedef struct VhostUserState { NetClientState nc;
@@ -148,18 +149,17 @@ static void net_vhost_user_event(void *opaque, int event)NET_CLIENT_OPTIONS_KIND_NIC , MAX_QUEUE_NUM); s =DO_UPCAST (VhostUserState, nc, ncs[0 ]); +trace_vhost_user_event (s->chr->label, event);switch (event) {case CHR_EVENT_OPENED :if (vhost_user_start (queues, ncs) <0 ) {exit (1 ); }qmp_set_link (name, true, &err); -error_report ("chardev \"%s\" went up" , s->chr->label);break ;case CHR_EVENT_CLOSED :qmp_set_link (name, true, &err);vhost_user_stop (queues, ncs); -error_report ("chardev \"%s\" went down" , s->chr->label);break ; }
trace-events +3 -0
@@ -1705,3 +1705,6 @@ qcrypto_tls_creds_x509_load_cert_list(void *creds, const char *file) "TLS creds # crypto/tlssession.c qcrypto_tls_session_new(void *session, void *creds, const char *hostname, const char *aclname, int endpoint) "TLS session new session=%p creds=%p hostname=%s aclname=%s endpoint=%d" + +# net/vhost-user.c +vhost_user_event(const char *chr, int event) "chr: %s got event: %d"
Signature · 1 line
MST
[Qemu-devel] [PULL 24/38] vhost user: add support of live migration
In reply to Michael S. TsirkinFrom: Thibaut Collet <[email protected]>
Some vhost user backends are able to support live migration.
To provide this service the following features must be added:
1. Add the VIRTIO_NET_F_GUEST_ANNOUNCE capability to vhost-net when netdev backend is vhost-user.
2. Provide a nop receive callback to vhost-user.
This callback is called by:
* qemu_announce_self after a migration to send fake RARP to avoid network outage for peers talking to the migrated guest.
- For guest with GUEST_ANNOUNCE capabilities, guest already sends GARP when the bit VIRTIO_NET_S_ANNOUNCE is set.
=> These packets must be discarded.
- For guest without GUEST_ANNOUNCE capabilities, migration termination is notified when the guest sends packets.
=> These packets can be discarded.
* virtio_net_tx_bh with a dummy boot to send fake bootp/dhcp request. BIOS guest manages virtio driver to send 4 bootp/dhcp request in case of dummy boot.
=> These packets must be discarded.
--- hw/net/vhost_net.c | 2 ++ net/vhost-user.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
hw/net/vhost_net.c +2 -0
@@ -85,6 +85,8 @@ static const int user_feature_bits[] = {VIRTIO_NET_F_CTRL_MAC_ADDR ,VIRTIO_NET_F_CTRL_GUEST_OFFLOADS , +VIRTIO_NET_F_GUEST_ANNOUNCE , +VIRTIO_NET_F_MQ ,VHOST_INVALID_FEATURE_BIT
net/vhost-user.c +10 -2
@@ -103,6 +103,15 @@ err:return -1 ; } +static ssize_t vhost_user_receive (NetClientState *nc,const uint8_t *buf, +size_t size) +{ +/* Discard the request that is received and managed by backend +* by an other way. +*/ +return size; +} +static void vhost_user_cleanup (NetClientState *nc) {VhostUserState *s =DO_UPCAST (VhostUserState, nc, nc);
@@ -132,6 +141,7 @@ static bool vhost_user_has_ufo(NetClientState *nc)static NetClientInfo net_vhost_user_info = { .type =NET_CLIENT_OPTIONS_KIND_VHOST_USER , .size =sizeof (VhostUserState), + .receive = vhost_user_receive, .cleanup = vhost_user_cleanup, .has_vnet_hdr = vhost_user_has_vnet_hdr, .has_ufo = vhost_user_has_ufo,
@@ -182,8 +192,6 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,snprintf (nc->info_str,sizeof (nc->info_str),"vhost-user%d to %s" , i, chr->label); -/* We don't provide a receive callback */ - nc->receive_disabled =1 ; nc->queue_index = i; s =DO_UPCAST (VhostUserState, nc, nc);
Signature · 1 line
MST
[Qemu-devel] [PULL 25/38] vhost user: add rarp sending after live migration for legacy guest
In reply to Michael S. TsirkinFrom: Thibaut Collet <[email protected]>
A new vhost user message is added to allow QEMU to ask to vhost user backend to broadcast a fake RARP after live migration for guest without GUEST_ANNOUNCE capability.
This new message is sent only if the backend supports the new VHOST_USER_PROTOCOL_F_RARP protocol feature.
The payload of this new message is the MAC address of the guest (not known by the backend). The MAC address is copied in the first 6 bytes of a u64 to avoid to create a new payload message type.
This new message has no equivalent ioctl so a new callback is added in the userOps structure to send the request.
Upon reception of this new message the vhost user backend must generate and broadcast a fake RARP request to notify the migration is terminated.
--- include/hw/virtio/vhost-backend.h | 3 +++ include/net/vhost_net.h | 1 + hw/net/vhost_net.c | 17 +++++++++++++++++ hw/virtio/vhost-user.c | 32 +++++++++++++++++++++++++++++++- net/vhost-user.c | 24 ++++++++++++++++++++++-- docs/specs/vhost-user.txt | 15 +++++++++++++++ 6 files changed, 89 insertions(+), 3 deletions(-)
include/hw/virtio/vhost-backend.h +3 -0
@@ -68,6 +68,8 @@ typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx);typedef int (*vhost_set_vring_enable_op )(struct vhost_dev *dev,int enable);typedef bool (*vhost_requires_shm_log_op )(struct vhost_dev *dev); +typedef int (*vhost_migration_done_op )(struct vhost_dev *dev, +char *mac_addr); typedef struct VhostOps { VhostBackendType backend_type;
@@ -94,6 +96,7 @@ typedef struct VhostOps {vhost_get_vq_index_op vhost_get_vq_index;vhost_set_vring_enable_op vhost_set_vring_enable;vhost_requires_shm_log_op vhost_requires_shm_log; +vhost_migration_done_op vhost_migration_done; } VhostOps;extern const VhostOps user_ops;
include/net/vhost_net.h +1 -0
@@ -27,6 +27,7 @@ void vhost_net_ack_features(VHostNetState *net, uint64_t features);bool vhost_net_virtqueue_pending (VHostNetState *net,int n);void vhost_net_virtqueue_mask (VHostNetState *net,VirtIODevice *dev,int idx,bool mask); +int vhost_net_notify_migration_done (VHostNetState *net,char * mac_addr);VHostNetState *get_vhost_net (NetClientState *nc);int vhost_set_vring_enable (NetClientState * nc,int enable);
hw/net/vhost_net.c +17 -0
@@ -388,6 +388,18 @@ void vhost_net_cleanup(struct vhost_net *net)g_free (net); } +int vhost_net_notify_migration_done (struct vhost_net *net,char * mac_addr) +{ +const VhostOps *vhost_ops = net->dev.vhost_ops; +int r =-1 ; + +if (vhost_ops->vhost_migration_done) { + r = vhost_ops->vhost_migration_done (&net->dev, mac_addr); + } + +return r; +} +bool vhost_net_virtqueue_pending (VHostNetState *net,int idx) {return vhost_virtqueue_pending (&net->dev, idx);
@@ -479,6 +491,11 @@ void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, { } +int vhost_net_notify_migration_done (struct vhost_net *net,char * mac_addr) +{ +return -1 ; +} +VHostNetState *get_vhost_net (NetClientState *nc) {return 0 ;
hw/virtio/vhost-user.c +31 -1
@@ -10,6 +10,7 @@#include "hw/virtio/vhost.h" #include "hw/virtio/vhost-backend.h" +#include "hw/virtio/virtio-net.h" #include "sysemu/char.h" #include "sysemu/kvm.h" #include "qemu/error-report.h"
@@ -27,9 +28,10 @@#define VHOST_MEMORY_MAX_NREGIONS 8#define VHOST_USER_F_PROTOCOL_FEATURES 30 -#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x3ULL +#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x7ULL#define VHOST_USER_PROTOCOL_F_MQ 0#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 +#define VHOST_USER_PROTOCOL_F_RARP 2 typedef enum VhostUserRequest { VHOST_USER_NONE = 0,
@@ -51,6 +53,7 @@ typedef enum VhostUserRequest {VHOST_USER_SET_PROTOCOL_FEATURES =16 ,VHOST_USER_GET_QUEUE_NUM =17 ,VHOST_USER_SET_VRING_ENABLE =18 , +VHOST_USER_SEND_RARP =19 , VHOST_USER_MAX } VhostUserRequest;
@@ -566,6 +569,32 @@ static bool vhost_user_requires_shm_log(struct vhost_dev *dev) VHOST_USER_PROTOCOL_F_LOG_SHMFD); } +static int vhost_user_migration_done (struct vhost_dev *dev,char * mac_addr) +{ +VhostUserMsg msg = {0 }; +int err; + +assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ); + +/* If guest supports GUEST_ANNOUNCE do nothing */ +if (virtio_has_feature (dev->acked_features,VIRTIO_NET_F_GUEST_ANNOUNCE )) { +return 0 ; + } + +/* if backend supports VHOST_USER_PROTOCOL_F_RARP ask it to send the RARP */ +if (virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_RARP )) { + msg.request =VHOST_USER_SEND_RARP ; + msg.flags =VHOST_USER_VERSION ; +memcpy ((char *)&msg.u64, mac_addr,6 ); + msg.size =sizeof (m.u64); + + err =vhost_user_write (dev, &msg,NULL ,0 ); +return err; + } +return -1 ; +} +const VhostOps user_ops = { .backend_type =VHOST_BACKEND_TYPE_USER , .vhost_backend_init = vhost_user_init,
@@ -587,4 +616,5 @@ const VhostOps user_ops = { .vhost_get_vq_index = vhost_user_get_vq_index, .vhost_set_vring_enable = vhost_user_set_vring_enable, .vhost_requires_shm_log = vhost_user_requires_shm_log, + .vhost_migration_done = vhost_user_migration_done, };
net/vhost-user.c +22 -2
@@ -106,9 +106,29 @@ err:static ssize_t vhost_user_receive (NetClientState *nc,const uint8_t *buf,size_t size) { -/* Discard the request that is received and managed by backend -* by an other way. +/* In case of RARP (message size is 60) notify backup to send a fake RARP. +This fake RARP will be sent by backend only for guest +without GUEST_ANNOUNCE capability. */ +if (size ==60 ) { +VhostUserState *s =DO_UPCAST (VhostUserState, nc, nc); +int r; +static int display_rarp_failure =1 ; +char mac_addr[6 ]; + +/* extract guest mac address from the RARP message */ +memcpy (mac_addr, &buf[6 ],6 ); + + r =vhost_net_notify_migration_done (s->vhost_net, mac_addr); + +if ((r !=0 ) && (display_rarp_failure)) { +fprintf (stderr, +"Vhost user backend fails to broadcast fake RARP\n" ); +fflush (stderr); + display_rarp_failure =0 ; + } + } +return size; }
docs/specs/vhost-user.txt +15 -0
@@ -194,6 +194,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_MQ 0 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 +#define VHOST_USER_PROTOCOL_F_RARP 2 Message types -------------
@@ -381,3 +382,17 @@ Message types Master payload: vring state description Signal slave to enable or disable corresponding vring. + + * VHOST_USER_SEND_RARP + + Id: 19 + Equivalent ioctl: N/A + Master payload: u64 + + Ask vhost user backend to broadcast a fake RARP to notify the migration + is terminated for guest that does not support GUEST_ANNOUNCE. + Only legal if feature bit VHOST_USER_F_PROTOCOL_FEATURES is present in + VHOST_USER_GET_FEATURES and protocol feature bit VHOST_USER_PROTOCOL_F_RARP + is present in VHOST_USER_GET_PROTOCOL_FEATURES. + The first 6 bytes of the payload contain the mac address of the guest to + allow the vhost user backend to construct and broadcast the fake RARP.
Signature · 1 line
MST
[Qemu-devel] [PULL 26/38] vhost-user: use an enum helper for features mask
In reply to Michael S. TsirkinFrom: Thibaut Collet <[email protected]>
The VHOST_USER_PROTOCOL_FEATURE_MASK will be automatically updated when adding new features to the enum.
--- hw/virtio/vhost-user.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
hw/virtio/vhost-user.c +9 -4
@@ -28,10 +28,15 @@#define VHOST_MEMORY_MAX_NREGIONS 8#define VHOST_USER_F_PROTOCOL_FEATURES 30 -#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x7ULL -#define VHOST_USER_PROTOCOL_F_MQ 0 -#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 -#define VHOST_USER_PROTOCOL_F_RARP 2 +enum VhostUserProtocolFeature { +VHOST_USER_PROTOCOL_F_MQ =0 , +VHOST_USER_PROTOCOL_F_LOG_SHMFD =1 , +VHOST_USER_PROTOCOL_F_RARP =2 , + +VHOST_USER_PROTOCOL_F_MAX +}; + +#define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX) - 1) typedef enum VhostUserRequest { VHOST_USER_NONE = 0,
Signature · 1 line
MST
[Qemu-devel] [PULL 27/38] vhost: add migration block if memfd failed
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
--- include/qemu/memfd.h | 2 ++ hw/virtio/vhost.c | 3 +++ util/memfd.c | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+)
include/qemu/memfd.h +2 -0
@@ -2,6 +2,7 @@#define QEMU_MEMFD_H #include "config-host.h" +#include <stdbool.h> #ifndef F_LINUX_SPECIFIC_BASE #define F_LINUX_SPECIFIC_BASE 1024
@@ -20,5 +21,6 @@void *qemu_memfd_alloc (const char *name,size_t size,unsigned int seals,int *fd);void qemu_memfd_free (void *ptr,size_t size,int fd); +bool qemu_memfd_check (void );#endif /* QEMU_MEMFD_H */
hw/virtio/vhost.c +3 -0
@@ -1019,6 +1019,9 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,if (!(hdev->features & (0x1ULL <<VHOST_F_LOG_ALL ))) {error_setg (&hdev->migration_blocker,"Migration disabled: vhost lacks VHOST_F_LOG_ALL feature." ); + }else if (!qemu_memfd_check ()) { +error_setg (&hdev->migration_blocker, +"Migration disabled: failed to allocate shared memory" ); } }
util/memfd.c +22 -0
@@ -138,3 +138,25 @@ void qemu_memfd_free(void *ptr, size_t size, int fd)close (fd); } } + +enum { +MEMFD_KO , +MEMFD_OK , +MEMFD_TODO +}; + +bool qemu_memfd_check (void ) +{ +static int memfd_check =MEMFD_TODO ; + +if (memfd_check ==MEMFD_TODO ) { +int fd; +void *ptr; + + ptr =qemu_memfd_alloc ("test" ,4096 ,0 , &fd); + memfd_check = ptr ?MEMFD_OK :MEMFD_KO ; +qemu_memfd_free (ptr,4096 , fd); + } + +return memfd_check ==MEMFD_OK ; +}
Signature · 1 line
MST
[Qemu-devel] [PULL 28/38] vhost-user-test: move wait_for_fds() out
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
This function is a precondition for most vhost-user tests.
--- tests/vhost-user-test.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
tests/vhost-user-test.c +14 -4
@@ -126,12 +126,9 @@ static gboolean g_cond_wait_until(CompatGCond cond, CompatGMutex mutex, }#endif -static void read_guest_mem (void ) +static void wait_for_fds (void ) { -uint32_t *guest_mem;gint64 end_time; -int i, j; -size_t size;g_mutex_lock (&data_mutex);
@@ -148,6 +145,19 @@ static void read_guest_mem(void) g_assert_cmpint(fds_num, >, 0); g_assert_cmpint(fds_num, ==, memory.nregions); +g_mutex_unlock (&data_mutex); +} + +static void read_guest_mem (void ) +{ +uint32_t *guest_mem; +int i, j; +size_t size; + +wait_for_fds (); + +g_mutex_lock (&data_mutex); +/* iterate all regions */ for (i =0 ; i < fds_num; i++) {
Signature · 1 line
MST
[Qemu-devel] [PULL 29/38] vhost-user-test: remove useless static check
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
--- tests/vhost-user-test.c | 1 - 1 file changed, 1 deletion(-)
tests/vhost-user-test.c +0 -1
@@ -186,7 +186,6 @@ static void read_guest_mem(void)munmap (guest_mem, memory.regions[i].memory_size); } - g_assert_cmpint(1, ==, 1);g_mutex_unlock (&data_mutex); }
Signature · 1 line
MST
[Qemu-devel] [PULL 30/38] vhost-user-test: wrap server in TestServer struct
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
In the coming patches, a test will use several servers simultaneously. Wrap the server in a struct, out of the global scope.
--- tests/vhost-user-test.c | 139 +++++++++++++++++++++++++++++++----------------- 1 file changed, 89 insertions(+), 50 deletions(-)
tests/vhost-user-test.c +89 -50
@@ -108,10 +108,16 @@ static VhostUserMsg m __attribute__ ((unused));#define VHOST_USER_VERSION (0x1)/*****************************************************************************/ -int fds_num =0 , fds[VHOST_MEMORY_MAX_NREGIONS ]; -static VhostUserMemory memory; -static CompatGMutex data_mutex; -static CompatGCond data_cond; +typedef struct TestServer { +gchar *socket_path; +gchar *chr_name; +CharDriverState *chr; +int fds_num; +int fds[VHOST_MEMORY_MAX_NREGIONS ]; +VhostUserMemory memory; +GMutex data_mutex; +GCond data_cond; +}TestServer ;#if !GLIB_CHECK_VERSION (2 ,32 ,0 ) static gboolean g_cond_wait_until(CompatGCond cond, CompatGMutex mutex,
@@ -126,67 +132,68 @@ static gboolean g_cond_wait_until(CompatGCond cond, CompatGMutex mutex, }#endif -static void wait_for_fds (void ) +static void wait_for_fds (TestServer *s) {gint64 end_time; -g_mutex_lock (&data_mutex); +g_mutex_lock (&s->data_mutex); end_time =g_get_monotonic_time () +5 *G_TIME_SPAN_SECOND ; -while (!fds_num) { -if (!g_cond_wait_until (&data_cond, &data_mutex, end_time)) { +while (!s->fds_num) { +if (!g_cond_wait_until (&s->data_cond, &s->data_mutex, end_time)) {/* timeout has passed */ -g_assert (fds_num); +g_assert (s->fds_num);break ; } }/* check for sanity */ - g_assert_cmpint(fds_num, >, 0); - g_assert_cmpint(fds_num, ==, memory.nregions); + g_assert_cmpint(s->fds_num, >, 0); + g_assert_cmpint(s->fds_num, ==, s->memory.nregions); -g_mutex_unlock (&data_mutex); +g_mutex_unlock (&s->data_mutex); } -static void read_guest_mem (void ) +static void read_guest_mem (TestServer *s) {uint32_t *guest_mem;int i, j;size_t size; -wait_for_fds (); +wait_for_fds (s); -g_mutex_lock (&data_mutex); +g_mutex_lock (&s->data_mutex);/* iterate all regions */ -for (i =0 ; i < fds_num; i++) { +for (i =0 ; i < s->fds_num; i++) {/* We'll check only the region statring at 0x0*/ -if (memory.regions[i].guest_phys_addr !=0x0 ) { +if (s->memory.regions[i].guest_phys_addr !=0x0 ) {continue ; } - g_assert_cmpint(memory.regions[i].memory_size, >, 1024); + g_assert_cmpint(s->memory.regions[i].memory_size, >, 1024); - size = memory.regions[i].memory_size + memory.regions[i].mmap_offset; + size = s->memory.regions[i].memory_size + + s->memory.regions[i].mmap_offset; guest_mem =mmap (0 , size,PROT_READ |PROT_WRITE , -MAP_SHARED , fds[i],0 ); +MAP_SHARED , s->fds[i],0 );g_assert (guest_mem !=MAP_FAILED ); - guest_mem += (memory.regions[i].mmap_offset /sizeof (*guest_mem)); + guest_mem += (s->memory.regions[i].mmap_offset /sizeof (*guest_mem));for (j =0 ; j <256 ; j++) { -uint32_t a =readl (memory.regions[i].guest_phys_addr + j*4 ); +uint32_t a =readl (s->memory.regions[i].guest_phys_addr + j*4 );uint32_t b = guest_mem[j]; g_assert_cmpint(a, ==, b); } -munmap (guest_mem, memory.regions[i].memory_size); +munmap (guest_mem, s->memory.regions[i].memory_size); } -g_mutex_unlock (&data_mutex); +g_mutex_unlock (&s->data_mutex); }static void *thread_function (void *data)
@@ -204,7 +211,8 @@ static int chr_can_read(void *opaque)static void chr_read (void *opaque,const uint8_t *buf,int size) { -CharDriverState *chr = opaque; +TestServer *s = opaque; +CharDriverState *chr = s->chr;VhostUserMsg msg;uint8_t *p = (uint8_t *) &msg;int fd;
@@ -214,12 +222,12 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)return ; } -g_mutex_lock (&data_mutex); +g_mutex_lock (&s->data_mutex);memcpy (p, buf,VHOST_USER_HDR_SIZE );if (msg.size) { p +=VHOST_USER_HDR_SIZE ; -qemu_chr_fe_read_all (chr, p, msg.size); + g_assert_cmpint(qemu_chr_fe_read_all(chr, p, msg.size), ==, msg.size); }switch (msg.request) {
@@ -257,11 +265,11 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)case VHOST_USER_SET_MEM_TABLE :/* received the mem table */ -memcpy (&memory, &msg.memory,sizeof (msg.memory)); - fds_num =qemu_chr_fe_get_msgfds (chr, fds,sizeof (fds) /sizeof (int )); +memcpy (&s->memory, &msg.memory,sizeof (msg.memory)); + s->fds_num =qemu_chr_fe_get_msgfds (chr, s->fds,G_N_ELEMENTS (s->fds));/* signal the test that it can continue */ -g_cond_signal (&data_cond); +g_cond_signal (&s->data_cond);break ;case VHOST_USER_SET_VRING_KICK :
@@ -278,7 +286,8 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)default :break ; } -g_mutex_unlock (&data_mutex); + +g_mutex_unlock (&s->data_mutex); }static const char *init_hugepagefs (const char *path)
@@ -308,14 +317,52 @@ static const char *init_hugepagefs(const char *path)return path; } +static TestServer *test_server_new (const gchar *tmpfs,const gchar *name) +{ +TestServer *server =g_new0 (TestServer,1 ); +gchar *chr_path; + + server->socket_path =g_strdup_printf ("%s/%s.sock" , tmpfs, name); + + chr_path =g_strdup_printf ("unix:%s,server,nowait" , server->socket_path); + server->chr_name =g_strdup_printf ("chr-%s" , name); + server->chr =qemu_chr_new (server->chr_name, chr_path,NULL ); +g_free (chr_path); + +qemu_chr_add_handlers (server->chr, chr_can_read, chr_read,NULL , server); + +g_mutex_init (&server->data_mutex); +g_cond_init (&server->data_cond); + +return server; +} + +#define GET_QEMU_CMD (s, root) \ + g_strdup_printf(QEMU_CMD, (root), (s)->socket_path) + + +static void test_server_free (TestServer *server) +{ +int i; + +qemu_chr_delete (server->chr); + +for (i =0 ; i < server->fds_num; i++) { +close (server->fds[i]); + } + +unlink (server->socket_path); +g_free (server->socket_path); + +g_free (server); +} +int main (int argc,char **argv) {QTestState *s =NULL ; -CharDriverState *chr =NULL ; +TestServer *server =NULL ;const char *hugefs; -char *socket_path =0 ; -char *qemu_cmd =0 ; -char *chr_path =0 ; +char *qemu_cmd =NULL ;int ret;char template[] ="/tmp/vhost-test-XXXXXX" ;const char *tmpfs;
@@ -324,10 +371,11 @@ int main(int argc, char **argv)g_test_init (&argc, &argv,NULL );module_call_init (MODULE_INIT_QOM ); +qemu_add_opts (&qemu_chardev_opts); tmpfs =mkdtemp (template);if (!tmpfs) { -g_test_message ("mkdtemp on path (%s): %s\n" , template,strerror (errno)); +g_test_message ("mkdtemp on path (%s): %s\n" , template,strerror (errno)); }g_assert (tmpfs);
@@ -339,25 +387,17 @@ int main(int argc, char **argv) root = tmpfs; } - socket_path =g_strdup_printf ("%s/vhost.sock" , tmpfs); - -/* create char dev and add read handlers */ -qemu_add_opts (&qemu_chardev_opts); - chr_path =g_strdup_printf ("unix:%s,server,nowait" , socket_path); - chr =qemu_chr_new ("chr0" , chr_path,NULL ); -g_free (chr_path); -qemu_chr_add_handlers (chr, chr_can_read, chr_read,NULL , chr); + server =test_server_new (tmpfs,"test" );/* run the main loop thread so the chardev may operate */ -g_mutex_init (&data_mutex); -g_cond_init (&data_cond);g_thread_new (NULL , thread_function,NULL ); - qemu_cmd =g_strdup_printf (QEMU_CMD , root, socket_path); + qemu_cmd =GET_QEMU_CMD (server, root); + s =qtest_start (qemu_cmd);g_free (qemu_cmd); -qtest_add_func ("/vhost-user/read-guest-mem" , read_guest_mem); +qtest_add_data_func ("/vhost-user/read-guest-mem" , server, read_guest_mem); ret =g_test_run ();
@@ -366,8 +406,7 @@ int main(int argc, char **argv) }/* cleanup */ -unlink (socket_path); -g_free (socket_path); +test_server_free (server); ret =rmdir (tmpfs);if (ret !=0 ) {
Signature · 1 line
MST
[Qemu-devel] [PULL 31/38] vhost-user-test: learn to tweak various qemu arguments
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Add a new macro to make the qemu command line with other values of memory size, and specific chardev id.
--- tests/vhost-user-test.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
tests/vhost-user-test.c +15 -10
@@ -30,10 +30,10 @@#endif #define QEMU_CMD_ACCEL " -machine accel=tcg" -#define QEMU_CMD_MEM " -m 512 -object memory-backend-file,id=mem,size=512M,"\ +#define QEMU_CMD_MEM " -m %d -object memory-backend-file,id=mem,size=%dM,"\ "mem-path=%s,share=on -numa node,memdev=mem" -#define QEMU_CMD_CHR " -chardev socket,id=chr0,path=%s" -#define QEMU_CMD_NETDEV " -netdev vhost-user,id=net0,chardev=chr0,vhostforce" +#define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s" +#define QEMU_CMD_NETDEV " -netdev vhost-user,id=net0,chardev=%s,vhostforce"#define QEMU_CMD_NET " -device virtio-net-pci,netdev=net0 "#define QEMU_CMD_ROM " -option-rom ../pc-bios/pxe-virtio.rom"
@@ -132,6 +132,9 @@ static gboolean g_cond_wait_until(CompatGCond cond, CompatGMutex mutex, }#endif +static const char *tmpfs; +static const char *root; +static void wait_for_fds (TestServer *s) {gint64 end_time;
@@ -317,7 +320,7 @@ static const char *init_hugepagefs(const char *path)return path; } -static TestServer *test_server_new (const gchar *tmpfs,const gchar *name) +static TestServer *test_server_new (const gchar *name) {TestServer *server =g_new0 (TestServer,1 );gchar *chr_path;
@@ -337,9 +340,13 @@ static TestServer *test_server_new(const gchar *tmpfs, const gchar *name)return server; } -#define GET_QEMU_CMD (s, root) \ - g_strdup_printf(QEMU_CMD, (root), (s)->socket_path) +#define GET_QEMU_CMD (s) \ + g_strdup_printf(QEMU_CMD, 512, 512, (root), (s)->chr_name, \ + (s)->socket_path, (s)->chr_name) +#define GET_QEMU_CMDE (s, mem, extra, ...) \ + g_strdup_printf(QEMU_CMD extra, (mem), (mem), (root), (s)->chr_name, \ + (s)->socket_path, (s)->chr_name, ##__VA_ARGS__)static void test_server_free (TestServer *server) {
@@ -365,8 +372,6 @@ int main(int argc, char **argv)char *qemu_cmd =NULL ;int ret;char template[] ="/tmp/vhost-test-XXXXXX" ; -const char *tmpfs; -const char *root;g_test_init (&argc, &argv,NULL );
@@ -387,12 +392,12 @@ int main(int argc, char **argv) root = tmpfs; } - server =test_server_new (tmpfs,"test" ); + server =test_server_new ("test" );/* run the main loop thread so the chardev may operate */ g_thread_new (NULL , thread_function,NULL ); - qemu_cmd =GET_QEMU_CMD (server, root); + qemu_cmd =GET_QEMU_CMD (server); s =qtest_start (qemu_cmd);g_free (qemu_cmd);
Signature · 1 line
MST
[Qemu-devel] [PULL 32/38] vhost-user-test: add live-migration test
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
This test checks that the log fd is given to the migration source, and mark dirty pages during migration.
--- tests/vhost-user-test.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 2 deletions(-)
tests/vhost-user-test.c +169 -2
@@ -12,6 +12,7 @@#include "libqtest.h" #include "qemu/option.h" +#include "qemu/range.h" #include "sysemu/char.h" #include "sysemu/sysemu.h"
@@ -47,6 +48,9 @@#define VHOST_MEMORY_MAX_NREGIONS 8#define VHOST_USER_F_PROTOCOL_FEATURES 30 +#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 + +#define VHOST_LOG_PAGE 0x1000 typedef enum VhostUserRequest { VHOST_USER_NONE = 0,
@@ -117,6 +121,7 @@ typedef struct TestServer {VhostUserMemory memory;GMutex data_mutex;GCond data_cond; +int log_fd; } TestServer;#if !GLIB_CHECK_VERSION (2 ,32 ,0 )
@@ -238,7 +243,8 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)/* send back features to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ; msg.size =sizeof (m.u64); - msg.u64 =0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ; + msg.u64 =0x1ULL <<VHOST_F_LOG_ALL | +0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ; p = (uint8_t *) &msg;qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size);break ;
@@ -252,7 +258,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)/* send back features to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ; msg.size =sizeof (m.u64); - msg.u64 =0 ; + msg.u64 =1 <<VHOST_USER_PROTOCOL_F_LOG_SHMFD ; p = (uint8_t *) &msg;qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size);break ;
@@ -286,6 +292,21 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)*/ qemu_set_nonblock (fd);break ; + +case VHOST_USER_SET_LOG_BASE : +if (s->log_fd !=-1 ) { +close (s->log_fd); + s->log_fd =-1 ; + } +qemu_chr_fe_get_msgfds (chr, &s->log_fd,1 ); + msg.flags |=VHOST_USER_REPLY_MASK ; + msg.size =0 ; + p = (uint8_t *) &msg; +qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE ); + +g_cond_signal (&s->data_cond); +break ; +default :break ; }
@@ -337,6 +358,8 @@ static TestServer *test_server_new(const gchar *name)g_mutex_init (&server->data_mutex);g_cond_init (&server->data_cond); + server->log_fd =-1 ; +return server; }
@@ -358,12 +381,155 @@ static void test_server_free(TestServer *server)close (server->fds[i]); } +if (server->log_fd !=-1 ) { +close (server->log_fd); + } +unlink (server->socket_path);g_free (server->socket_path); + +g_free (server->chr_name);g_free (server); } +static void wait_for_log_fd (TestServer *s) +{ +gint64 end_time; + +g_mutex_lock (&s->data_mutex); + end_time =g_get_monotonic_time () +5 *G_TIME_SPAN_SECOND ; +while (s->log_fd ==-1 ) { +if (!g_cond_wait_until (&s->data_cond, &s->data_mutex, end_time)) { +/* timeout has passed */ +g_assert (s->log_fd !=-1 ); +break ; + } + } + +g_mutex_unlock (&s->data_mutex); +} + +static void write_guest_mem (TestServer *s,uint32 seed) +{ +uint32_t *guest_mem; +int i, j; +size_t size; + +wait_for_fds (s); + +/* iterate all regions */ +for (i =0 ; i < s->fds_num; i++) { + +/* We'll write only the region statring at 0x0 */ +if (s->memory.regions[i].guest_phys_addr !=0x0 ) { +continue ; + } + + g_assert_cmpint(s->memory.regions[i].memory_size, >, 1024); + + size = s->memory.regions[i].memory_size + + s->memory.regions[i].mmap_offset; + + guest_mem =mmap (0 , size,PROT_READ |PROT_WRITE , +MAP_SHARED , s->fds[i],0 ); + +g_assert (guest_mem !=MAP_FAILED ); + guest_mem += (s->memory.regions[i].mmap_offset /sizeof (*guest_mem)); + +for (j =0 ; j <256 ; j++) { + guest_mem[j] = seed + j; + } + +munmap (guest_mem, s->memory.regions[i].memory_size); +break ; + } +} + +static guint64 get_log_size (TestServer *s) +{ +guint64 log_size =0 ; +int i; + +for (i =0 ; i < s->memory.nregions; ++i) { +VhostUserMemoryRegion *reg = &s->memory.regions[i]; +guint64 last =range_get_last (reg->guest_phys_addr, + reg->memory_size); + log_size =MAX (log_size, last / (8 *VHOST_LOG_PAGE ) +1 ); + } + +return log_size; +} + +static void test_migrate (void ) +{ +TestServer *s =test_server_new ("src" ); +TestServer *dest =test_server_new ("dest" ); +const char *uri ="tcp:127.0.0.1:1234" ; +QTestState *global = global_qtest, *from, *to; +gchar *cmd; +QDict *rsp; +guint8 *log; +guint64 size; + + cmd =GET_QEMU_CMDE (s,2 ,"" ); + from =qtest_start (cmd); +g_free (cmd); + +wait_for_fds (s); + size =get_log_size (s); + g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8)); + + cmd =GET_QEMU_CMDE (dest,2 ," -incoming %s" , uri); + to =qtest_init (cmd); +g_free (cmd); + +/* slow down migration to have time to fiddle with log */ +/* TODO: qtest could learn to break on some places */ + rsp =qmp ("{ 'execute': 'migrate_set_speed'," +"'arguments': { 'value': 10 } }" ); +g_assert (qdict_haskey (rsp,"return" )); +QDECREF (rsp); + + cmd =g_strdup_printf ("{ 'execute': 'migrate'," +"'arguments': { 'uri': '%s' } }" , + uri); + rsp =qmp (cmd); +g_free (cmd); +g_assert (qdict_haskey (rsp,"return" )); +QDECREF (rsp); + +wait_for_log_fd (s); + + log =mmap (0 , size,PROT_READ |PROT_WRITE ,MAP_SHARED , s->log_fd,0 ); +g_assert (log !=MAP_FAILED ); + +/* modify first page */ +write_guest_mem (s,0x42 ); + log[0 ] =1 ; +munmap (log, size); + +/* speed things up */ + rsp =qmp ("{ 'execute': 'migrate_set_speed'," +"'arguments': { 'value': 0 } }" ); +g_assert (qdict_haskey (rsp,"return" )); +QDECREF (rsp); + +qmp_eventwait ("STOP" ); + + global_qtest = to; +qmp_eventwait ("RESUME" ); + +read_guest_mem (dest); + +qtest_quit (to); +test_server_free (dest); +qtest_quit (from); +test_server_free (s); + + global_qtest = global; +} +int main (int argc,char **argv) {QTestState *s =NULL ;
@@ -403,6 +569,7 @@ int main(int argc, char **argv)g_free (qemu_cmd);qtest_add_data_func ("/vhost-user/read-guest-mem" , server, read_guest_mem); +qtest_add_func ("/vhost-user/migrate" , test_migrate); ret =g_test_run ();
Signature · 1 line
MST
[Qemu-devel] [PULL 33/38] vhost-user-test: check ownership during migration
In reply to Michael S. TsirkinFrom: Marc-André Lureau <[email protected]>
Check that backend source and destination do not have simultaneous ownership during migration.
--- tests/vhost-user-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
tests/vhost-user-test.c +38 -0
@@ -307,6 +307,10 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)g_cond_signal (&s->data_cond);break ; +case VHOST_USER_RESET_DEVICE : + s->fds_num =0 ; +break ; +default :break ; }
@@ -461,12 +465,37 @@ static guint64 get_log_size(TestServer *s)return log_size; } +typedef struct TestMigrateSource { +GSource source; +TestServer *src; +TestServer *dest; +}TestMigrateSource ; + +static gboolean +test_migrate_source_check (GSource *source) +{ +TestMigrateSource *t = (TestMigrateSource *)source; +gboolean overlap = t->src->fds_num >0 && t->dest->fds_num >0 ; + +g_assert (!overlap); + +return FALSE; +} + +GSourceFuncs test_migrate_source_funcs = { +NULL , + test_migrate_source_check, +NULL , +NULL +}; +static void test_migrate (void ) {TestServer *s =test_server_new ("src" );TestServer *dest =test_server_new ("dest" );const char *uri ="tcp:127.0.0.1:1234" ;QTestState *global = global_qtest, *from, *to; +GSource *source;gchar *cmd;QDict *rsp;guint8 *log;
@@ -484,6 +513,12 @@ static void test_migrate(void) to =qtest_init (cmd);g_free (cmd); + source =g_source_new (&test_migrate_source_funcs, +sizeof (TestMigrateSource)); + ((TestMigrateSource *)source)->src = s; + ((TestMigrateSource *)source)->dest = dest; +g_source_attach (source,NULL ); +/* slow down migration to have time to fiddle with log */ /* TODO: qtest could learn to break on some places */ rsp = qmp("{ 'execute': 'migrate_set_speed',"
@@ -522,6 +557,9 @@ static void test_migrate(void)read_guest_mem (dest); +g_source_destroy (source); +g_source_unref (source); +qtest_quit (to);test_server_free (dest);qtest_quit (from);
Signature · 1 line
MST
[Qemu-devel] [PULL 34/38] seccomp: add memfd_create to whitelist
In reply to Michael S. TsirkinFrom: Eduardo Otubo <[email protected]>
This is used by memfd code.
--- qemu-seccomp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
qemu-seccomp.c +2 -1
@@ -237,7 +237,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = { { SCMP_SYS(fadvise64), 240 }, { SCMP_SYS(inotify_init1), 240 }, { SCMP_SYS(inotify_add_watch), 240 }, - { SCMP_SYS(mbind), 240 } + { SCMP_SYS(mbind), 240 }, + { SCMP_SYS(memfd_create), 240 } };int seccomp_start (void )
Signature · 1 line
MST
[Qemu-devel] [PULL 35/38] piix: fix resource leak reported by Coverity
In reply to Michael S. TsirkinFrom: zhanghailiang <[email protected]>
config_fd should be closed before return, or there will be a resource leak error.
--- hw/pci-host/piix.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
hw/pci-host/piix.c +7 -4
@@ -764,6 +764,7 @@ static int host_pci_config_read(int pos, int len, uint32_t val)/* Access real host bridge. */ int rc =snprintf (path, size,"/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s" ,0 ,0 ,0 ,0 ,"config" ); +int ret =0 ;if (rc >= size || rc <0 ) {return -ENODEV ;
@@ -775,16 +776,18 @@ static int host_pci_config_read(int pos, int len, uint32_t val) }if (lseek (config_fd, pos,SEEK_SET ) != pos) { -return -errno; + ret = -errno; + goto out; }do { rc =read (config_fd, (uint8_t *)&val, len); }while (rc <0 && (errno ==EINTR || errno ==EAGAIN ));if (rc != len) { -return -errno; + ret = -errno; } - -return 0 ; +out: +close (config_fd); +return ret; }static int igd_pt_i440fx_initfn (struct PCIDevice *pci_dev)
Signature · 1 line
MST
[Qemu-devel] [PULL 36/38] vhost: set the correct queue index in case of migration with multiqueue
In reply to Michael S. TsirkinFrom: Thibaut Collet <[email protected]>
When a live migration is started the log address to mark dirty pages is provided to the vhost backend through the vhost_dev_set_log function.
This function is called for each queue pairs but the queue index is wrongly set:
always set to the first queue pair. Then vhost backend lost descriptor addresses of the queue pairs greater than 1 and behaviour of the vhost backend is unpredictable.
The queue index is computed by taking account of the vq_index (to retrieve the queue pair index) and calling the vhost_get_vq_index method of the backend.
--- hw/virtio/vhost.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
hw/virtio/vhost.c +5 -3
@@ -656,13 +656,14 @@ static int vhost_dev_set_features(struct vhost_dev *dev, bool enable_log)static int vhost_dev_set_log (struct vhost_dev *dev,bool enable_log) { -int r, t, i; +int r, t, i, idx; r =vhost_dev_set_features (dev, enable_log);if (r <0 ) { goto err_features; }for (i =0 ; i < dev->nvqs; ++i) { - r =vhost_virtqueue_set_addr (dev, dev->vqs + i, i, + idx = dev->vhost_ops->vhost_get_vq_index (dev, dev->vq_index + i); + r =vhost_virtqueue_set_addr (dev, dev->vqs + i, idx, enable_log);if (r <0 ) { goto err_vq;
@@ -671,7 +672,8 @@ static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log)return 0 ; err_vq:for (; i >=0 ; --i) { - t =vhost_virtqueue_set_addr (dev, dev->vqs + i, i, + idx = dev->vhost_ops->vhost_get_vq_index (dev, dev->vq_index + i); + t =vhost_virtqueue_set_addr (dev, dev->vqs + i, idx, dev->log_enabled);assert (t >=0 ); }
Signature · 1 line
MST
[Qemu-devel] [PULL 37/38] i386: keep cpu_model field in MachineState uptodate
In reply to Michael S. TsirkinFrom: Zhu Guihua <[email protected]>
Update cpu_model in MachineState for i386, so that the field can be used for cpu hotplug, instead of using a static variable.
This patch is rebased on the latest master.
--- include/hw/i386/pc.h | 2 +- hw/i386/pc.c | 17 ++++++++--------- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-)
include/hw/i386/pc.h +1 -1
@@ -168,7 +168,7 @@ bool pc_machine_is_smm_enabled(PCMachineState *pcms);void pc_register_ferr_irq (qemu_irq irq);void pc_acpi_smi_interrupt (void *opaque,int irq,int level); -void pc_cpus_init (const char *cpu_model); +void pc_cpus_init (PCMachineState *pcms);void pc_hot_add_cpu (const int64_t id,Error **errp);void pc_acpi_init (const char *default_dsdt);
hw/i386/pc.c +8 -9
@@ -1077,11 +1077,10 @@ out:return cpu; } -static const char *current_cpu_model; -void pc_hot_add_cpu (const int64_t id,Error **errp) {X86CPU *cpu; +MachineState *machine =MACHINE (qdev_get_machine ());int64_t apic_id =x86_cpu_apic_id_from_index (id);Error *local_err =NULL ;
@@ -1109,7 +1108,7 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)return ; } - cpu =pc_new_cpu (current_cpu_model, apic_id, &local_err); + cpu =pc_new_cpu (machine->cpu_model, apic_id, &local_err);if (local_err) {error_propagate (errp, local_err);return ;
@@ -1117,22 +1116,22 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)object_unref (OBJECT (cpu)); } -void pc_cpus_init (const char *cpu_model) +void pc_cpus_init (PCMachineState *pcms) {int i;X86CPU *cpu =NULL ; +MachineState *machine =MACHINE (pcms);Error *error =NULL ;unsigned long apic_id_limit;/* init CPUs */ -if (cpu_model ==NULL ) { +if (machine->cpu_model ==NULL ) {#ifdef TARGET_X86_64 - cpu_model ="qemu64" ; + machine->cpu_model ="qemu64" ;#else - cpu_model ="qemu32" ; + machine->cpu_model ="qemu32" ;#endif } - current_cpu_model = cpu_model; apic_id_limit =pc_apic_id_limit (max_cpus);if (apic_id_limit >ACPI_CPU_HOTPLUG_ID_LIMIT ) {
@@ -1142,7 +1141,7 @@ void pc_cpus_init(const char *cpu_model) }for (i =0 ; i < smp_cpus; i++) { - cpu =pc_new_cpu (cpu_model,x86_cpu_apic_id_from_index (i), + cpu =pc_new_cpu (machine->cpu_model,x86_cpu_apic_id_from_index (i), &error);if (error) {error_report_err (error);
hw/i386/pc_piix.c +1 -1
@@ -139,7 +139,7 @@ static void pc_init1(MachineState *machine,exit (1 ); } -pc_cpus_init (machine->cpu_model); +pc_cpus_init (pcms);if (kvm_enabled () && kvmclock_enabled) {kvmclock_create ();
hw/i386/pc_q35.c +1 -1
@@ -128,7 +128,7 @@ static void pc_q35_init(MachineState *machine)exit (1 ); } -pc_cpus_init (machine->cpu_model); +pc_cpus_init (pcms);pc_acpi_init ("q35-acpi-dsdt.aml" );kvmclock_create ();
Signature · 1 line
MST
[Qemu-devel] [PULL 38/38] hw/isa/lpc_ich9: inject the SMI on the VCPU that is writing to APM_CNT
In reply to Michael S. TsirkinFrom: Laszlo Ersek <[email protected]>
Commit 4d00636e97b7 ("ich9: Add the lpc chip", Nov 14 2012) added the ich9_apm_ctrl_changed() ioport write callback function such that it would inject the SMI, in response to a write to the APM_CNT register, on the first CPU, invariably.
Since this register is used by guest code to trigger an SMI synchronously, the interrupt should be injected on the VCPU that is performing the write.
apm_ioport_writeb() is the .write callback of the "apm_ops" MemoryRegionOps [hw/isa/apm.c]; it is parametrized to call ich9_apm_ctrl_changed() by ich9_lpc_init() [hw/isa/lpc_ich9.c], via apm_init(). Therefore this change affects no other board.
ich9_generate_smi() is an unrelated function that is called by the TCO watchdog; a watchdog is likely in its right to (asynchronously) inject interrupts on the first CPU only.
This patch allows the combined edk2/OVMF SMM driver stack to work with multiple VCPUs on TCG, using both qemu-system-i386 and qemu-system-x86_64.
--- hw/isa/lpc_ich9.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/isa/lpc_ich9.c +1 -1
@@ -394,7 +394,7 @@ static void ich9_apm_ctrl_changed(uint32_t val, void *arg)/* SMI_EN = PMBASE + 30. SMI control and enable register */ if (lpc->pm.smi_en &ICH9_PMIO_SMI_EN_APMC_EN ) { -cpu_interrupt (first_cpu,CPU_INTERRUPT_SMI ); +cpu_interrupt (current_cpu,CPU_INTERRUPT_SMI ); } }
Signature · 1 line
MST
Quoted 15 lines · Michael S. Tsirkin
The following changes since commit
6d57410a79d51d92673c54f26624b44f27fa6214:Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20151016' into staging (2015-10-17 12:31:33 +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
4f53cd7788185f437a4275df6456eb60b90d4837:hw/isa/lpc_ich9: inject the SMI on the VCPU that is writing to
APM_CNT(2015-10-21 13:24:49 +0300)----------------------------------------------------------------
vhost, pc, virtio features, fixes, cleanups
Quoted 7 lines
New features:
VT-d support for devices behind a bridge
vhost-user migration supportSigned-off-by Michael S. Tsirkin <[email protected]>----------------------------------------------------------------
Test failure on 64-bit ARM and 32-bit ARM:
TEST: tests/vhost-user-test... (pid=28701)
Warning: path not on HugeTLBFS: /tmp/vhost-test-pLQQzA
qemu-system-i386: -netdev vhost-user,id=net0,chardev=chr-test,vhostforce: vhost-net support is not compiled in
qemu-system-i386: -netdev vhost-user,id=net0,chardev=chr-test,vhostforce: failed to init vhost_net for queue 0
Broken pipe
FAIL: tests/vhost-user-test
My clang build gives this:
Warning: path not on HugeTLBFS: /tmp/vhost-test-EFF6ul /home/petmay01/linaro/qemu-for-merges/target-i386/translate.c:2421:26:
runtime error: left shift of negative value -8
Warning: path not on HugeTLBFS: /tmp/vhost-test-EFF6ul /home/petmay01/linaro/qemu-for-merges/target-i386/translate.c:2421:26:
runtime error: left shift of negative value -8
Warning: path not on HugeTLBFS: /tmp/vhost-test-EFF6ul /home/petmay01/linaro/qemu-for-merges/target-i386/translate.c:2421:26:
runtime error: left shift of negative value -8
The tests pass, but I'd prefer it if our tests didn't print out random warnings in the non-verbose case if possible; it makes it hard to sift out "this is a problem" from "this test has always been grumpy". (Alternatively, if "path not on HugeTLBFS" is a problem then the test should fail.)
The negative-shift stuff is clang's undefined sanitizer; the code in question has been doing a "-8 << s->dflag" since at least 2013, so this is just your test code exercising something it hadn't before. Sanitizer issues aren't currently something I'm requiring pull requests to deal with, so we can fix this one later.
thanks
-- PMM
Quoted 35 lines · Peter Maydell
Quoted 15 lines · Michael S. Tsirkin
The following changes since commit
6d57410a79d51d92673c54f26624b44f27fa6214:Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20151016' into staging (2015-10-17 12:31:33 +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
4f53cd7788185f437a4275df6456eb60b90d4837:hw/isa/lpc_ich9: inject the SMI on the VCPU that is writing to
APM_CNT(2015-10-21 13:24:49 +0300)----------------------------------------------------------------
vhost, pc, virtio features, fixes, cleanupsQuoted 7 lines
New features:
VT-d support for devices behind a bridge
vhost-user migration supportSigned-off-by Michael S. Tsirkin <[email protected]>----------------------------------------------------------------
Test failure on 64-bit ARM and 32-bit ARM:
TEST: tests/vhost-user-test... (pid=28701)
Warning: path not on HugeTLBFS:/tmp/vhost-test-pLQQzA
qemu-system-i386: -netdev vhost-user,id=net0,chardev=chr-test,vhostforce: vhost-net support is not compiled in
qemu-system-i386: -netdev vhost-user,id=net0,chardev=chr-test,vhostforce: failed to initvhost_netfor queue 0
Quoted 2 lines
Broken pipe
FAIL: tests/vhost-user-test
Sorry about that.
I rebased and dropped the offending patch.
tag moved to 3c23402d4032f69af44a87fdb8019ad3229a4f31
Not resending full pull request since that is the only change.
Quoted 29 lines
My clang build gives this:
Warning: path not on HugeTLBFS:
/tmp/vhost-test-EFF6ul/home/petmay01/linaro/qemu-for-merges/target-i386/translate.c:2421:26:
runtime error: left shift of negative value -8
Warning: path not on HugeTLBFS:/tmp/vhost-test-EFF6ul/home/petmay01/linaro/qemu-for-merges/target-i386/translate.c:2421:26:
runtime error: left shift of negative value -8
Warning: path not on HugeTLBFS:/tmp/vhost-test-EFF6ul/home/petmay01/linaro/qemu-for-merges/target-i386/translate.c:2421:26:
runtime error: left shift of negative value -8The tests pass, but I'd prefer it if our tests didn't print out random warnings in the non-verbose case if possible; it makes it hard to sift out "this is a problem" from "this test has always been grumpy". (Alternatively, if "path not on HugeTLBFS" is a problem then the test should fail.)
The negative-shift stuff is clang's undefined sanitizer; the code in question has been doing a "-8 <<
s->dflag" since at least 2013, so this is just your test code exercising something it hadn't before. Sanitizer issues aren't currently something I'm requiring pull requests to deal with, so we can fix this one later.thanks
-- PMM
Peter Maydell
AppliedQuoted 39 lines · Michael S. Tsirkin
Quoted 35 lines · Peter Maydell
Quoted 15 lines · Michael S. Tsirkin
The following changes since commit
6d57410a79d51d92673c54f26624b44f27fa6214:Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20151016' into staging (2015-10-17 12:31:33 +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
4f53cd7788185f437a4275df6456eb60b90d4837:hw/isa/lpc_ich9: inject the SMI on the VCPU that is writing to
APM_CNT(2015-10-21 13:24:49 +0300)----------------------------------------------------------------
vhost, pc, virtio features, fixes, cleanupsQuoted 7 lines
New features:
VT-d support for devices behind a bridge
vhost-user migration supportSigned-off-by Michael S. Tsirkin <[email protected]>----------------------------------------------------------------
Test failure on 64-bit ARM and 32-bit ARM:
TEST: tests/vhost-user-test... (pid=28701)
Warning: path not on HugeTLBFS:/tmp/vhost-test-pLQQzA
qemu-system-i386: -netdev vhost-user,id=net0,chardev=chr-test,vhostforce: vhost-net support is not compiled in
qemu-system-i386: -netdev vhost-user,id=net0,chardev=chr-test,vhostforce: failed to initvhost_netfor queue 0Quoted 2 lines
Broken pipe
FAIL: tests/vhost-user-test
Quoted 7 lines
Sorry about that.
I rebased and dropped the offending patch.
tag moved to
3c23402d4032f69af44a87fdb8019ad3229a4f31Not resending full pull request since that is the only change.
Applied, thanks.
-- PMM