Introduce virtio-vhost-user device
cover Introduce virtio-vhost-user device
The virtio-vhost-user (vvu) allows moving the vhost-user process inside a VM. This is done by moving vhost device backend into a guest and tunneling the vhost-user protocol over a new type of device called virtio-vhost-user.
A usecase for this is live-updating the host kernel which has the DPDK application running inside a VM with vvu device. The DPDK application doesn't need to be restarted after the host kernel has been updated as the DPDK VM is snapshotted before host kernel update, allowing DPDK state to be saved.
There should potentially be further usecases, as it allows isolating the vhost-user process inside a VM, with more components like SPDK.
vvu is based on the work initially done by Stefan Hajnoczi [1] and continued by Nikos Dragazis [2], [3].
The virtio-spec changes for vvu are currently in review[4]. A HTML version with the changes is available at [5].
A working prototype showcasing vvu can be reproduced using instructions in [6].
Thanks and looking forward to your response!
Usama
[1] https://wiki.qemu.org/Features/VirtioVhostUser
[2] https://ndragazis.github.io/dpdk-vhost-vvu-demo.html
[3] https://lists.oasis-open.org/archives/virtio-dev/202005/msg00132.html
[4] https://lists.oasis-open.org/archives/virtio-dev/202204/msg00022.html
[5] https://uarif1.github.io/vvu/v2/virtio-v1.1-cs01
[6] https://uarif1.github.io/vvu/dpdk-vvu-instructions
Usama Arif (2):
vhost-user: share the vhost-user protocol related structures
virtio-vhost-user: add virtio-vhost-user device
hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 2 + hw/virtio/trace-events | 26 + hw/virtio/vhost-user.c | 160 --- hw/virtio/virtio-pci.c | 13 +- hw/virtio/virtio-vhost-user-pci.c | 471 ++++++++ hw/virtio/virtio-vhost-user.c | 1066 +++++++++++++++++++ hw/virtio/virtio.c | 7 +- include/hw/pci/pci.h | 1 + include/hw/virtio/vhost-user.h | 163 +++ include/hw/virtio/virtio-pci.h | 7 + include/hw/virtio/virtio-vhost-user.h | 126 +++ include/hw/virtio/virtio.h | 2 + include/standard-headers/linux/virtio_ids.h | 1 + 14 files changed, 1880 insertions(+), 170 deletions(-) create mode 100644 hw/virtio/virtio-vhost-user-pci.c create mode 100644 hw/virtio/virtio-vhost-user.c create mode 100644 include/hw/virtio/virtio-vhost-user.h
Signature · 1 line
2.25.1
RFC 1/2 vhost-user: share the vhost-user protocol related structures
Put the vhost-user protocol related data structures to vhost-user.h, so that they can be used in other implementations (e.g. a backend implementation).
--- hw/virtio/vhost-user.c | 160 -------------------------------- include/hw/virtio/vhost-user.h | 163 +++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 160 deletions(-)
hw/virtio/vhost-user.c +0 -160
@@ -21,7 +21,6 @@#include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" -#include "sysemu/cryptodev.h" #include "migration/migration.h" #include "migration/postcopy-ram.h" #include "trace.h"
@@ -37,10 +36,6 @@#include <linux/userfaultfd.h> #endif -#define VHOST_MEMORY_BASELINE_NREGIONS 8 -#define VHOST_USER_F_PROTOCOL_FEATURES 30 -#define VHOST_USER_SLAVE_MAX_FDS 8 -/* * Set maximum number of RAM slots supported to * the maximum number supported by the target
@@ -59,11 +54,6 @@#define VHOST_USER_MAX_RAM_SLOTS 512#endif -/* -* Maximum size of virtio device config space -*/ -#define VHOST_USER_MAX_CONFIG_SIZE 256 -enum VhostUserProtocolFeature {VHOST_USER_PROTOCOL_F_MQ =0 ,VHOST_USER_PROTOCOL_F_LOG_SHMFD =1 ,
@@ -84,157 +74,7 @@ enum VhostUserProtocolFeature {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 , -VHOST_USER_GET_FEATURES =1 , -VHOST_USER_SET_FEATURES =2 , -VHOST_USER_SET_OWNER =3 , -VHOST_USER_RESET_OWNER =4 , -VHOST_USER_SET_MEM_TABLE =5 , -VHOST_USER_SET_LOG_BASE =6 , -VHOST_USER_SET_LOG_FD =7 , -VHOST_USER_SET_VRING_NUM =8 , -VHOST_USER_SET_VRING_ADDR =9 , -VHOST_USER_SET_VRING_BASE =10 , -VHOST_USER_GET_VRING_BASE =11 , -VHOST_USER_SET_VRING_KICK =12 , -VHOST_USER_SET_VRING_CALL =13 , -VHOST_USER_SET_VRING_ERR =14 , -VHOST_USER_GET_PROTOCOL_FEATURES =15 , -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_NET_SET_MTU =20 , -VHOST_USER_SET_SLAVE_REQ_FD =21 , -VHOST_USER_IOTLB_MSG =22 , -VHOST_USER_SET_VRING_ENDIAN =23 , -VHOST_USER_GET_CONFIG =24 , -VHOST_USER_SET_CONFIG =25 , -VHOST_USER_CREATE_CRYPTO_SESSION =26 , -VHOST_USER_CLOSE_CRYPTO_SESSION =27 , -VHOST_USER_POSTCOPY_ADVISE =28 , -VHOST_USER_POSTCOPY_LISTEN =29 , -VHOST_USER_POSTCOPY_END =30 , -VHOST_USER_GET_INFLIGHT_FD =31 , -VHOST_USER_SET_INFLIGHT_FD =32 , -VHOST_USER_GPU_SET_SOCKET =33 , -VHOST_USER_RESET_DEVICE =34 , -/* Message number 35 reserved for VHOST_USER_VRING_KICK. */ -VHOST_USER_GET_MAX_MEM_SLOTS =36 , -VHOST_USER_ADD_MEM_REG =37 , -VHOST_USER_REM_MEM_REG =38 , -VHOST_USER_MAX -}VhostUserRequest ; - -typedef enum VhostUserSlaveRequest { -VHOST_USER_SLAVE_NONE =0 , -VHOST_USER_SLAVE_IOTLB_MSG =1 , -VHOST_USER_SLAVE_CONFIG_CHANGE_MSG =2 , -VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG =3 , -VHOST_USER_SLAVE_MAX -}VhostUserSlaveRequest ; - -typedef struct VhostUserMemoryRegion { -uint64_t guest_phys_addr; -uint64_t memory_size; -uint64_t userspace_addr; -uint64_t mmap_offset; -}VhostUserMemoryRegion ; - -typedef struct VhostUserMemory { -uint32_t nregions; -uint32_t padding; -VhostUserMemoryRegion regions[VHOST_MEMORY_BASELINE_NREGIONS ]; -}VhostUserMemory ; - -typedef struct VhostUserMemRegMsg { -uint64_t padding; -VhostUserMemoryRegion region; -}VhostUserMemRegMsg ; - -typedef struct VhostUserLog { -uint64_t mmap_size; -uint64_t mmap_offset; -}VhostUserLog ; - -typedef struct VhostUserConfig { -uint32_t offset; -uint32_t size; -uint32_t flags; -uint8_t region[VHOST_USER_MAX_CONFIG_SIZE ]; -}VhostUserConfig ; - -#define VHOST_CRYPTO_SYM_HMAC_MAX_KEY_LEN 512 -#define VHOST_CRYPTO_SYM_CIPHER_MAX_KEY_LEN 64 - -typedef struct VhostUserCryptoSession { -/* session id for success, -1 on errors */ -int64_t session_id; -CryptoDevBackendSymSessionInfo session_setup_data; -uint8_t key[VHOST_CRYPTO_SYM_CIPHER_MAX_KEY_LEN ]; -uint8_t auth_key[VHOST_CRYPTO_SYM_HMAC_MAX_KEY_LEN ]; -}VhostUserCryptoSession ; - -static VhostUserConfig c __attribute__ ((unused)); -#define VHOST_USER_CONFIG_HDR_SIZE (sizeof(c.offset) \ - + sizeof(c.size) \ - + sizeof(c.flags)) - -typedef struct VhostUserVringArea { -uint64_t u64; -uint64_t size; -uint64_t offset; -}VhostUserVringArea ; - -typedef struct VhostUserInflight { -uint64_t mmap_size; -uint64_t mmap_offset; -uint16_t num_queues; -uint16_t queue_size; -}VhostUserInflight ; - -typedef struct { -VhostUserRequest request; - -#define VHOST_USER_VERSION_MASK (0x3) -#define VHOST_USER_REPLY_MASK (0x1<<2) -#define VHOST_USER_NEED_REPLY_MASK (0x1 << 3) -uint32_t flags; -uint32_t size;/* the following payload size */ -} QEMU_PACKED VhostUserHeader; - -typedef union { -#define VHOST_USER_VRING_IDX_MASK (0xff) -#define VHOST_USER_VRING_NOFD_MASK (0x1<<8) -uint64_t u64; -struct vhost_vring_state state; -struct vhost_vring_addr addr; -VhostUserMemory memory; -VhostUserMemRegMsg mem_reg; -VhostUserLog log; -struct vhost_iotlb_msg iotlb; -VhostUserConfig config; -VhostUserCryptoSession session; -VhostUserVringArea area; -VhostUserInflight inflight; -}VhostUserPayload ; - -typedef struct VhostUserMsg { -VhostUserHeader hdr; -VhostUserPayload payload; -} QEMU_PACKED VhostUserMsg; - static VhostUserMsg m __attribute__ ((unused)); -#define VHOST_USER_HDR_SIZE (sizeof(VhostUserHeader)) - -#define VHOST_USER_PAYLOAD_SIZE (sizeof(VhostUserPayload)) - -/* The version of the protocol we support */ -#define VHOST_USER_VERSION (0x1) - struct vhost_user { struct vhost_dev *dev; /* Shared between vhost devs of the same virtio device */
include/hw/virtio/vhost-user.h +163 -0
169 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC 2/2 virtio-vhost-user: add virtio-vhost-user device
In reply to Usama ArifThe virtio-vhost-user device lets a guest act as a vhost device backend. It works by tunneling vhost-user protocol messages into a guest. The new device syntax is as follows:
-chardev socket,id=chardev0,path=vhost-user.sock,server=on,wait=off \ -device virtio-vhost-user-pci,chardev=chardev0
The VIRTIO device specification is here:
https://uarif1.github.io/vvu/v2/virtio-v1.1-cs01
For more information about virtio-vhost-user, see
https://wiki.qemu.org/Features/VirtioVhostUser.
--- hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 2 + hw/virtio/trace-events | 26 + hw/virtio/virtio-pci.c | 13 +- hw/virtio/virtio-vhost-user-pci.c | 471 ++++++++ hw/virtio/virtio-vhost-user.c | 1066 +++++++++++++++++++ hw/virtio/virtio.c | 7 +- include/hw/pci/pci.h | 1 + include/hw/virtio/virtio-pci.h | 7 + include/hw/virtio/virtio-vhost-user.h | 126 +++ include/hw/virtio/virtio.h | 2 + include/standard-headers/linux/virtio_ids.h | 1 + 12 files changed, 1717 insertions(+), 10 deletions(-) create mode 100644 hw/virtio/virtio-vhost-user-pci.c create mode 100644 hw/virtio/virtio-vhost-user.c create mode 100644 include/hw/virtio/virtio-vhost-user.h
hw/virtio/Kconfig +5 -0
@@ -80,3 +80,8 @@ config VHOST_USER_FS bool default y depends on VIRTIO && VHOST_USER + +config VIRTIO_VHOST_USER + bool + default y + depends on VIRTIO && VHOST_USER
hw/virtio/meson.build +2 -0
@@ -29,6 +29,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) +virtio_ss.add(when: 'CONFIG_VIRTIO_VHOST_USER', if_true: files('virtio-vhost-user.c')) virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
@@ -54,6 +55,7 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-serial-pc virtio_pci_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem-pci.c')) +virtio_pci_ss.add(when: 'CONFIG_VIRTIO_VHOST_USER', if_true: files('virtio-vhost-user-pci.c')) virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
hw/virtio/trace-events +26 -0
@@ -85,6 +85,32 @@ virtio_balloon_get_config(uint32_t num_pages, uint32_t actual) "num_pages: %d ac virtio_balloon_set_config(uint32_t actual, uint32_t oldactual) "actual: %d oldactual: %d" virtio_balloon_to_target(uint64_t target, uint32_t num_pages) "balloon target: 0x%"PRIx64" num_pages: %d" +# hw/virtio/virtio-vhost-user.c +virtio_vhost_user_m2s_bad_version(void *s, unsigned int version) "s %p version %u" +virtio_vhost_user_m2s_unexpected_reply(void *s) "s %p" +virtio_vhost_user_m2s_bad_payload_size(void *s, unsigned int size) "s %p size %u" +virtio_vhost_user_m2s_bad_request(void *s, unsigned request) "s %p request %u" +virtio_vhost_user_m2s_request(void *s, unsigned int request) "s %p request %u" +virtio_vhost_user_m2s_unknown_request(void *s, unsigned int request) "s %p request %u" +virtio_vhost_user_s2m_bad_version(void *s, unsigned int version) "s %p version %u" +virtio_vhost_user_s2m_expected_reply(void *s) "s %p" +virtio_vhost_user_s2m_bad_payload_size(void *s, unsigned int size) "s %p size %u" +virtio_vhost_user_s2m_bad_request(void *s, unsigned request) "s %p request %u" +virtio_vhost_user_s2m_request(void *s, unsigned int request) "s %p request %u" +virtio_vhost_user_s2m_unknown_request(void *s, unsigned int request) "s %p request %u" +virtio_vhost_user_rxq_empty(void *s) "s %p" +virtio_vhost_user_tx_done(void *s) "s %p" +virtio_vhost_user_chr_event(void *s, int event) "s %p event %d" +virtio_vhost_user_chr_change(void *s) "s %p" +virtio_vhost_user_conn_state_transition(void *s, int old_state, int event, int new_state) "s %p old_state %d event %d new_state %d" +virtio_vhost_user_set_config(void *s, unsigned int old_status, unsigned int new_status) "s %p old_status %u new_status %u" +virtio_vhost_user_doorbell_write(void *s, unsigned int vq_idx, ssize_t nwritten) "s %p vq_idx %u nwritten %zd" +virtio_vhost_user_notification_read(void *s, uint64_t addr, uint64_t return_val) "s %p addr 0x%"PRIx64" return_val 0x%"PRIx64 +virtio_vhost_user_notification_write(void *s, uint64_t addr, uint64_t val) "s %p addr 0x%"PRIx64" val 0x%"PRIx64 +virtio_vhost_user_guest_notifier_read(int kickfd, uint16_t vector) "kickfd %d vector 0x%"PRIx16 +virtio_vhost_user_memory_region(void *s, uint64_t guest_phys_addr, uint64_t memory_size, uint64_t userspace_addr, uint64_t mmap_offset, void *mmap_addr) "s %p guest_phys_addr 0x%"PRIx64" memory_size 0x%"PRIx64" userspace_addr 0x%"PRIx64" mmap_offset 0x%"PRIx64" mmap_addr %p" + + # virtio-mmio.c virtio_mmio_read(uint64_t offset) "virtio_mmio_read offset 0x%" PRIx64 virtio_mmio_write_offset(uint64_t offset, uint64_t value) "virtio_mmio_write offset 0x%" PRIx64 " value 0x%" PRIx64
hw/virtio/virtio-pci.c +6 -7
@@ -18,7 +18,6 @@#include "qemu/osdep.h" #include "exec/memop.h" -#include "standard-headers/linux/virtio_pci.h" #include "hw/boards.h" #include "hw/virtio/virtio.h" #include "migration/qemu-file-types.h"
@@ -222,7 +221,7 @@ static bool virtio_pci_ioeventfd_enabled(DeviceState *d)#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000 -static inline int virtio_pci_queue_mem_mult (struct VirtIOPCIProxy *proxy) +inline int virtio_pci_queue_mem_mult (struct VirtIOPCIProxy *proxy) {return (proxy->flags &VIRTIO_PCI_FLAG_PAGE_PER_VQ ) ?QEMU_VIRTIO_PCI_QUEUE_MEM_MULT :4 ;
@@ -1558,11 +1557,11 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy, proxy->notify_pio.size); } -static void virtio_pci_modern_region_map (VirtIOPCIProxy *proxy, -VirtIOPCIRegion *region, -struct virtio_pci_cap *cap, -MemoryRegion *mr, -uint8_t bar) +void virtio_pci_modern_region_map (VirtIOPCIProxy *proxy, +VirtIOPCIRegion *region, +struct virtio_pci_cap *cap, +MemoryRegion *mr, +uint8_t bar) {memory_region_add_subregion (mr, region->offset, ®ion->mr);
hw/virtio/virtio-vhost-user-pci.c new file +471 -0
471 lines not on this page · raw message
hw/virtio/virtio-vhost-user.c new file +1066 -0
1,066 lines not on this page · raw message
hw/virtio/virtio.c +4 -3
@@ -171,7 +171,8 @@ const char *virtio_device_names[] = { [VIRTIO_ID_PARAM_SERV] = "virtio-param-serv", [VIRTIO_ID_AUDIO_POLICY] = "virtio-audio-pol", [VIRTIO_ID_BT] = "virtio-bluetooth", - [VIRTIO_ID_GPIO] = "virtio-gpio" + [VIRTIO_ID_GPIO] = "virtio-gpio", + [VIRTIO_ID_VHOST_USER] = "virtio-vhost-user" };static const char *virtio_id_to_name (uint16_t device_id)
@@ -1937,7 +1938,7 @@ void qemu_put_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, }/* virtio device */ -static void virtio_notify_vector (VirtIODevice *vdev,uint16_t vector) +void virtio_notify_vector (VirtIODevice *vdev,uint16_t vector) {BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (qbus);
@@ -2454,7 +2455,7 @@ void virtio_del_queue(VirtIODevice *vdev, int n)virtio_delete_queue (&vdev->vq[n]); } -static void virtio_set_isr (VirtIODevice *vdev,int value) +void virtio_set_isr (VirtIODevice *vdev,int value) {uint8_t old =qatomic_read (&vdev->isr);
include/hw/pci/pci.h +1 -0
@@ -86,6 +86,7 @@ extern bool pci_available;#define PCI_DEVICE_ID_VIRTIO_PMEM 0x1013#define PCI_DEVICE_ID_VIRTIO_IOMMU 0x1014#define PCI_DEVICE_ID_VIRTIO_MEM 0x1015 +#define PCI_DEVICE_ID_VIRTIO_VHOST_USER 0x1016#define PCI_VENDOR_ID_REDHAT 0x1b36#define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001
include/hw/virtio/virtio-pci.h +7 -0
@@ -18,6 +18,7 @@#include "hw/pci/msi.h" #include "hw/virtio/virtio-bus.h" #include "qom/object.h" +#include "standard-headers/linux/virtio_pci.h" /* virtio-pci-bus */
@@ -252,4 +253,10 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);*/ unsigned virtio_pci_optimal_num_queues (unsigned fixed_queues); +int virtio_pci_queue_mem_mult (struct VirtIOPCIProxy *proxy); +void virtio_pci_modern_region_map (VirtIOPCIProxy *proxy, +VirtIOPCIRegion *region, +struct virtio_pci_cap *cap, +MemoryRegion *mr, +uint8_t bar);#endif
include/hw/virtio/virtio-vhost-user.h new file +126 -0
126 lines not on this page · raw message
include/hw/virtio/virtio.h +2 -0
@@ -324,6 +324,8 @@ void virtio_queue_aio_attach_host_notifier_no_poll(VirtQueue *vq, AioContext *ctvoid virtio_queue_aio_detach_host_notifier (VirtQueue *vq,AioContext *ctx);VirtQueue *virtio_vector_first_queue (VirtIODevice *vdev,uint16_t vector);VirtQueue *virtio_vector_next_queue (VirtQueue *vq); +void virtio_set_isr (VirtIODevice *vdev,int value); +void virtio_notify_vector (VirtIODevice *vdev,uint16_t vector);static inline void virtio_add_feature (uint64_t *features,unsigned int fbit) {
include/standard-headers/linux/virtio_ids.h +1 -0
@@ -68,6 +68,7 @@#define VIRTIO_ID_AUDIO_POLICY 39/* virtio audio policy */ #define VIRTIO_ID_BT 40/* virtio bluetooth */ #define VIRTIO_ID_GPIO 41/* virtio gpio */ +#define VIRTIO_ID_VHOST_USER 43/* virtio vhost-user */ /* * Virtio Transitional IDs
Signature · 1 line
2.25.1