Skip to contentSkip to conversation

virtio-vhost-user: add virtio-vhost-user device

RFC In review Stefan Hajnoczi 6 participants 31 messages Jan 19, 2018 – Feb 6, 2018

lore
Share & tools
lore
#0 lore raw

cover virtio-vhost-user: add virtio-vhost-user device

These patches implement the virtio-vhost-user device design that I have described here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007

The goal is to let the guest act as the vhost device backend for other guests. This allows virtual networking and storage appliances to run inside guests. This device is particularly interesting for poll mode drivers where exitless VM-to-VM communication is possible, completely bypassing the hypervisor in the data path.

The DPDK driver is here:
https://github.com/stefanha/dpdk/tree/virtio-vhost-user

For more information, see
https://wiki.qemu.org/Features/VirtioVhostUser.

virtio-vhost-user is inspired by Wei Wang and Zhiyong Yang's vhost-pci work. It differs from vhost-pci in that it has:
1. Vhost-user protocol message tunneling, allowing existing vhost-user slave software to be reused inside the guest.
2. Support for all vhost device types.
3. Disconnected operation and reconnection support.
4. Asynchronous vhost-user socket implementation that avoids blocking.

I have written this code to demonstrate how the virtio-vhost-user approach works and that it is more maintainable than vhost-pci because vhost-user slave software can use both AF_UNIX and virtio-vhost-user without significant code changes to the vhost device backends.

One of the main concerns about virtio-vhost-user was that the QEMU virtio-vhost-user device implementation could be complex because it needs to parse all messages. I hope this patch series shows that it's actually very simple because most messages are passed through.

After this patch series has been reviewed, we need to decide whether to follow the original vhost-pci approach or to use this one. Either way, both patch series still require improvements before they can be merged. Here are my todos for this series:

* Implement "Additional Device Resources over PCI" for shared memory, doorbells, and notifications instead of hardcoding a BAR with magic offsets into virtio-vhost-user:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2920007
* Implement the VRING_KICK eventfd - currently vhost-user slaves must be poll mode drivers.
* Optimize VRING_CALL doorbell with ioeventfd to avoid QEMU exit.
* vhost-user log feature
* UUID config field for stable device identification regardless of PCI bus addresses.
* vhost-user IOMMU and SLAVE_REQ_FD feature
* VhostUserMsg little-endian conversion for cross-endian support
* Chardev disconnect using qemu_chr_fe_set_watch() since CHR_CLOSED is only emitted while a read callback is registered. We don't keep a read callback registered all the time.
* Drain txq on reconnection to discard stale messages.

Stefan Hajnoczi (1):
virtio-vhost-user: add virtio-vhost-user device

Wei Wang (1):
vhost-user: share the vhost-user protocol related structures

 configure                                   |   18 +
 hw/virtio/Makefile.objs                     |    1 +
 hw/virtio/virtio-pci.h                      |   21 +
 include/hw/pci/pci.h                        |    1 +
 include/hw/virtio/vhost-user.h              |  106 +++
 include/hw/virtio/virtio-vhost-user.h       |   88 +++
 include/standard-headers/linux/virtio_ids.h |    1 +
 hw/virtio/vhost-user.c                      |  100 +--
 hw/virtio/virtio-pci.c                      |   61 ++
 hw/virtio/virtio-vhost-user.c               | 1047 +++++++++++++++++++++++++++
 hw/virtio/trace-events                      |   22 +
 11 files changed, 1367 insertions(+), 99 deletions(-)
 create mode 100644 include/hw/virtio/vhost-user.h
 create mode 100644 include/hw/virtio/virtio-vhost-user.h
 create mode 100644 hw/virtio/virtio-vhost-user.c
Signature · 1 line
2.14.3
#1 lore raw

RFC 1/2 vhost-user: share the vhost-user protocol related structures

From: Wei Wang <[email protected]>

Put the vhost-user protocol related data structures to vhost-user.h, so that they can be used in other implementations (e.g. a slave implementation).

---
 include/hw/virtio/vhost-user.h | 106 +++++++++++++++++++++++++++++++++++++++++
 hw/virtio/vhost-user.c         | 100 +-------------------------------------
 2 files changed, 107 insertions(+), 99 deletions(-)
 create mode 100644 include/hw/virtio/vhost-user.h
include/hw/virtio/vhost-user.h new file +106 -0
new file mode 100644
index 0000000000..d76e9ada31
@@ -0,0 +1,106 @@
+#ifndef VHOST_USER_H
+#define VHOST_USER_H
+
+#include <linux/vhost.h>
+
+#define VHOST_MEMORY_MAX_NREGIONS    8
+#define VHOST_USER_F_PROTOCOL_FEATURES 30
+
+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_REPLY_ACK = 3,
+    VHOST_USER_PROTOCOL_F_NET_MTU = 4,
+    VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5,
+    VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
+
+    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_MAX
+} VhostUserRequest;
+
+typedef enum VhostUserSlaveRequest {
+    VHOST_USER_SLAVE_NONE = 0,
+    VHOST_USER_SLAVE_IOTLB_MSG = 1,
+    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_MAX_NREGIONS];
+} VhostUserMemory;
+
+typedef struct VhostUserLog {
+    uint64_t mmap_size;
+    uint64_t mmap_offset;
+} VhostUserLog;
+
+typedef struct VhostUserMsg {
+    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;
+    /* The following payload size */
+    uint32_t size;
+    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;
+        VhostUserLog log;
+        struct vhost_iotlb_msg iotlb;
+    } payload;
+} QEMU_PACKED VhostUserMsg;
+
+static VhostUserMsg m __attribute__ ((unused));
+#define VHOST_USER_HDR_SIZE (sizeof(m.request) \
+                            + sizeof(m.flags) \
+                            + sizeof(m.size))
+
+#define VHOST_USER_PAYLOAD_SIZE (sizeof(m) - VHOST_USER_HDR_SIZE)
+
+/* The version of the protocol we support */
+#define VHOST_USER_VERSION    (0x1)
+
+#endif
hw/virtio/vhost-user.c +1 -99

112 lines not on this page · raw message

Signature · 1 line
2.14.3
#2 lore raw

RFC 2/2 virtio-vhost-user: add virtio-vhost-user device

In reply to Stefan Hajnoczi

The 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,nowait \
  -device virtio-vhost-user-pci,chardev=chardev0

The VIRTIO device specification is here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007

For more information about virtio-vhost-user, see
https://wiki.qemu.org/Features/VirtioVhostUser.

---
 configure                                   |   18 +
 hw/virtio/Makefile.objs                     |    1 +
 hw/virtio/virtio-pci.h                      |   21 +
 include/hw/pci/pci.h                        |    1 +
 include/hw/virtio/virtio-vhost-user.h       |   88 +++
 include/standard-headers/linux/virtio_ids.h |    1 +
 hw/virtio/virtio-pci.c                      |   61 ++
 hw/virtio/virtio-vhost-user.c               | 1047 +++++++++++++++++++++++++++
 hw/virtio/trace-events                      |   22 +
 9 files changed, 1260 insertions(+)
 create mode 100644 include/hw/virtio/virtio-vhost-user.h
 create mode 100644 hw/virtio/virtio-vhost-user.c
configure +18 -0
index 9c8aa5a98b..fa0cf4937d 100755
@@ -323,6 +323,7 @@ vhost_net="no"
 vhost_scsi="no"
 vhost_vsock="no"
 vhost_user=""
+virtio_vhost_user=""
 kvm="no"
 hax="no"
 rdma=""
@@ -1299,6 +1300,10 @@ for opt do
           error_exit "vhost-user isn't available on win32"
       fi
   ;;
+  --disable-virtio-vhost-user) virtio_vhost_user="no"
+  ;;
+  --enable-virtio-vhost-user) virtio_vhost_user="yes"
+  ;;
   --disable-capstone) capstone="no"
   ;;
   --enable-capstone) capstone="yes"
@@ -1329,6 +1334,15 @@ if test "$vhost_user" = ""; then
     fi
 fi
 
+# UNIX domain sockets are required
+if test "$virtio_vhost_user" = ""; then
+    if test "$mingw32" = "yes"; then
+        virtio_vhost_user="no"
+    else
+        virtio_vhost_user="yes"
+    fi
+fi
+
 case "$cpu" in
     ppc)
            CPU_CFLAGS="-m32"
@@ -5516,6 +5530,7 @@ echo "vhost-net support $vhost_net"
 echo "vhost-scsi support $vhost_scsi"
 echo "vhost-vsock support $vhost_vsock"
 echo "vhost-user support $vhost_user"
+echo "virtio-vhost-user support $virtio_vhost_user"
 echo "Trace backends    $trace_backends"
 if have_backend "simple"; then
 echo "Trace output file $trace_file-<pid>"
@@ -5954,6 +5969,9 @@ fi
 if test "$vhost_user" = "yes" ; then
   echo "CONFIG_VHOST_USER=y" >> $config_host_mak
 fi
+if test "$virtio_vhost_user" = "yes" ; then
+  echo "CONFIG_VIRTIO_VHOST_USER=y" >> $config_host_mak
+fi
 if test "$blobs" = "yes" ; then
   echo "INSTALL_BLOBS=yes" >> $config_host_mak
 fi
hw/virtio/Makefile.objs +1 -0
index 765d363c1f..4a666b9c7e 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
 obj-y += virtio-crypto.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio-crypto-pci.o
+obj-$(CONFIG_VIRTIO_VHOST_USER) += virtio-vhost-user.o
 endif
 
 common-obj-$(call lnot,$(CONFIG_LINUX)) += vhost-stub.o
hw/virtio/virtio-pci.h +21 -0
index 12d3a90686..4e454d99ab 100644
@@ -37,6 +37,9 @@
 #ifdef CONFIG_VHOST_VSOCK
 #include "hw/virtio/vhost-vsock.h"
 #endif
+#ifdef CONFIG_VIRTIO_VHOST_USER
+#include "hw/virtio/virtio-vhost-user.h"
+#endif
 
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
@@ -53,6 +56,7 @@ typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
 typedef struct VHostVSockPCI VHostVSockPCI;
 typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
+typedef struct VirtIOVhostUserPCI VirtIOVhostUserPCI;
 
 /* virtio-pci-bus */
 
@@ -396,6 +400,23 @@ struct VirtIOCryptoPCI {
     VirtIOCrypto vdev;
 };
 
+/*
+ * virtio-vhost-user-pci: This extends VirtioPCIProxy.
+ */
+
+#ifdef CONFIG_VIRTIO_VHOST_USER
+
+#define TYPE_VIRTIO_VHOST_USER_PCI "virtio-vhost-user-pci"
+#define VIRTIO_VHOST_USER_PCI(obj) \
+        OBJECT_CHECK(VirtIOVhostUserPCI, (obj), TYPE_VIRTIO_VHOST_USER_PCI)
+
+struct VirtIOVhostUserPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIOVhostUser vdev;
+};
+
+#endif /* CONFIG_VIRTIO_VHOST_USER */
+
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION          0
 
include/hw/pci/pci.h +1 -0
index 8d02a0a383..e9fa33d973 100644
@@ -85,6 +85,7 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_VIRTIO_RNG         0x1005
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
 #define PCI_DEVICE_ID_VIRTIO_VSOCK       0x1012
+#define PCI_DEVICE_ID_VIRTIO_VHOST_USER  0x1017
 
 #define PCI_VENDOR_ID_REDHAT             0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE      0x0001
include/hw/virtio/virtio-vhost-user.h new file +88 -0

88 lines not on this page · raw message

include/standard-headers/linux/virtio_ids.h +1 -0
index 6d5c3b2d4f..ab45ace2e3 100644
@@ -43,5 +43,6 @@
 #define VIRTIO_ID_INPUT        18 /* virtio input */
 #define VIRTIO_ID_VSOCK        19 /* virtio vsock transport */
 #define VIRTIO_ID_CRYPTO       20 /* virtio crypto */
+#define VIRTIO_ID_VHOST_USER   24 /* virtio vhost-user */
 
 #endif /* _LINUX_VIRTIO_IDS_H */
hw/virtio/virtio-pci.c +61 -0

79 lines not on this page · raw message

hw/virtio/virtio-vhost-user.c new file +1047 -0

1,047 lines not on this page · raw message

hw/virtio/trace-events +22 -0
index 775461ae98..a5849ba5af 100644
@@ -25,3 +25,25 @@ virtio_balloon_handle_output(const char *name, uint64_t gpa) "section name: %s g
 virtio_balloon_get_config(uint32_t num_pages, uint32_t actual) "num_pages: %d actual: %d"
 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_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"
Signature · 1 line
2.14.3
#4 lore raw
In reply to Stefan Hajnoczi
Quoted 3 lines · Stefan Hajnoczi

These patches implement the virtio-vhost-user device design that I have described here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007

Thanks for the patches, looks rather interesting and similar to split device model used by Xen.

Quoted 3 lines

The goal is to let the guest act as the vhost device backend for other guests. This allows virtual networking and storage appliances to run inside guests.

So the question still, what kind of protocol do you want to run on top? If it was ethernet based, virtio-net work pretty well and it can even do migration.

Quoted 3 lines

This device is particularly interesting for poll mode drivers where exitless VM-to-VM communication is possible, completely bypassing the hypervisor in the data path.

It's better to clarify the reason of hypervisor bypassing. (performance, security or scalability).

Probably not for the following cases:

1) kick/call
2) device IOTLB / IOMMU transaction (or any other case that backends needs metadata from qemu).

Quoted 15 lines

The DPDK driver is here:
https://github.com/stefanha/dpdk/tree/virtio-vhost-user

For more information, see
https://wiki.qemu.org/Features/VirtioVhostUser.

virtio-vhost-user is inspired by Wei Wang and Zhiyong Yang's vhost-pci work. It differs from vhost-pci in that it has:
1. Vhost-user protocol message tunneling, allowing existing vhost-user slave software to be reused inside the guest.
2. Support for all vhost device types.
3. Disconnected operation and reconnection support.
4. Asynchronous vhost-user socket implementation that avoids blocking.

Quoted 4 lines

I have written this code to demonstrate how the virtio-vhost-user approach works and that it is more maintainable than vhost-pci because vhost-user slave software can use both AF_UNIX and virtio-vhost-user without significant code changes to the vhost device backends.

Yes, this looks cleaner than vhost-pci.

Quoted 11 lines

One of the main concerns about virtio-vhost-user was that the QEMU virtio-vhost-user device implementation could be complex because it needs to parse all messages. I hope this patch series shows that it's actually very simple because most messages are passed through.

After this patch series has been reviewed, we need to decide whether to follow the original vhost-pci approach or to use this one. Either way, both patch series still require improvements before they can be merged. Here are my todos for this series:

Quoted 4 lines

* Implement "Additional Device Resources over PCI" for shared memory, doorbells, and notifications instead of hardcoding a BAR with magic offsets into virtio-vhost-user:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2920007

Does this mean we need to standardize vhost-user protocol first?

Quoted 3 lines

* Implement the VRING_KICK eventfd - currently vhost-user slaves must be poll mode drivers.
* Optimize VRING_CALL doorbell with ioeventfd to avoid QEMU exit.

The performance implication needs to be measured. It looks to me both kick and call will introduce more latency form the point of guest.

Quoted 4 lines

* vhost-user log feature
* UUID config field for stable device identification regardless of PCI bus addresses.
* vhost-user IOMMU and SLAVE_REQ_FD feature

So an assumption is the VM that implements vhost backends should be at least as secure as vhost-user backend process on host. Could we have this conclusion?

Quoted 24 lines

* VhostUserMsg little-endian conversion for cross-endian support
* Chardev disconnect using qemu_chr_fe_set_watch() since CHR_CLOSED is only emitted while a read callback is registered. We don't keep a read callback registered all the time.
* Drain txq on reconnection to discard stale messages.

Stefan Hajnoczi (1):
virtio-vhost-user: add virtio-vhost-user device

Wei Wang (1):
vhost-user: share the vhost-user protocol related structures

  configure                                   |   18 +
  hw/virtio/Makefile.objs                     |    1 +
  hw/virtio/virtio-pci.h                      |   21 +
  include/hw/pci/pci.h                        |    1 +
  include/hw/virtio/vhost-user.h              |  106 +++
  include/hw/virtio/virtio-vhost-user.h       |   88 +++
  include/standard-headers/linux/virtio_ids.h |    1 +
  hw/virtio/vhost-user.c                      |  100 +--
  hw/virtio/virtio-pci.c                      |   61 ++
  hw/virtio/virtio-vhost-user.c               | 1047 +++++++++++++++++++++++++++
  hw/virtio/trace-events                      |   22 +
  11 files changed, 1367 insertions(+), 99 deletions(-)
Quoted 4 lines

create mode 100644 include/hw/virtio/vhost-user.h create mode 100644 include/hw/virtio/virtio-vhost-user.h create mode 100644 hw/virtio/virtio-vhost-user.c

Btw, it's better to have some early numbers, e.g what testpmd reports during forwarding.

Thanks

#5 lore raw
Quoted 16 lines · Jason Wang
Quoted 3 lines · Stefan Hajnoczi

These patches implement the virtio-vhost-user device design that I have described here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007

Thanks for the patches, looks rather interesting and similar to split device model used by Xen.

Quoted 3 lines

The goal is to let the guest act as the vhost device backend for other guests. This allows virtual networking and storage appliances to run inside guests.

So the question still, what kind of protocol do you want to run on top? If it was ethernet based, virtio-net work pretty well and it can even do migration.

Quoted 6 lines
Quoted 3 lines

This device is particularly interesting for poll mode drivers where exitless VM-to-VM communication is possible, completely bypassing the hypervisor in the data path.

It's better to clarify the reason of hypervisor bypassing. (performance, security or scalability).

Performance - yes, definitely. Exitless VM-to-VM is the fastest possible way to communicate between VMs. Today it can only be done using ivshmem. This patch series allows virtio devices to take advantage of it and will encourage people to use virtio instead of non-standard ivshmem devices.

Security - I don't think this feature is a security improvement. It reduces isolation because VM1 has full shared memory access to VM2. In fact, this is a reason for users to consider carefully whether they even want to use this feature.

Scalability - much for the same reasons as the Performance section above. Bypassing the hypervisor eliminates scalability bottlenecks (e.g. host network stack and bridge).

Quoted 3 lines

Probably not for the following cases:

1) kick/call

I disagree here because kick/call is actually very efficient!

VM1's irqfd is the ioeventfd for VM2. When VM2 writes to the ioeventfd there is a single lightweight vmexit which injects an interrupt into VM1. QEMU is not involved and the host kernel scheduler is not involved so this is a low-latency operation.

I haven't tested this yet but the ioeventfd code looks like this will work.

Quoted 2 lines

2) device IOTLB / IOMMU transaction (or any other case that backends needs metadata from qemu).

Yes, this is the big weakness of vhost-user in general. The IOMMU feature doesn't offer good isolation and even when it does, performance will be an issue.

Quoted 6 lines
Quoted 4 lines

* Implement "Additional Device Resources over PCI" for shared memory, doorbells, and notifications instead of hardcoding a BAR with magic offsets into virtio-vhost-user:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2920007

Does this mean we need to standardize vhost-user protocol first?

Currently the draft spec says:

This section relies on definitions from the Vhost-user Protocol [1].

[1] https://git.qemu.org/?p=qemu.git;a=blob_plain;f=docs/interop/vhost-user.txt;hb=HEAD

Michael: Is it okay to simply include this link?

Quoted 6 lines
Quoted 3 lines

* Implement the VRING_KICK eventfd - currently vhost-user slaves must be poll mode drivers.
* Optimize VRING_CALL doorbell with ioeventfd to avoid QEMU exit.

The performance implication needs to be measured. It looks to me both kick and call will introduce more latency form the point of guest.

I described the irqfd + ioeventfd approach above. It should be faster than virtio-net + bridge today.

Quoted 8 lines
Quoted 4 lines

* vhost-user log feature
* UUID config field for stable device identification regardless of PCI bus addresses.
* vhost-user IOMMU and SLAVE_REQ_FD feature

So an assumption is the VM that implements vhost backends should be at least as secure as vhost-user backend process on host. Could we have this conclusion?

Yes.

Sadly the vhost-user IOMMU protocol feature does not provide isolation. At the moment IOMMU is basically a layer of indirection (mapping) but the vhost-user backend process still has full access to guest RAM :(.

Quoted 2 lines

Btw, it's better to have some early numbers, e.g what testpmd reports during forwarding.

I need to rely on others to do this (and many other things!) because virtio-vhost-user isn't the focus of my work.

These patches were written to demonstrate my suggestions for vhost-pci. They were written at work but also on weekends, early mornings, and late nights to avoid delaying Wei and Zhiyong's vhost-pci work too much.

If this approach has merit then I hope others will take over and I'll play a smaller role addressing some of the todo items and cleanups.

Stefan

#6 lore raw
Quoted 30 lines · Stefan Hajnoczi
Quoted 16 lines · Jason Wang
Quoted 3 lines · Stefan Hajnoczi

These patches implement the virtio-vhost-user device design that I have described here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007

Thanks for the patches, looks rather interesting and similar to split device model used by Xen.

Quoted 3 lines

The goal is to let the guest act as the vhost device backend for other guests. This allows virtual networking and storage appliances to run inside guests.

So the question still, what kind of protocol do you want to run on top? If it was ethernet based, virtio-net work pretty well and it can even do migration.

Quoted 6 lines
Quoted 3 lines

This device is particularly interesting for poll mode drivers where exitless VM-to-VM communication is possible, completely bypassing the hypervisor in the data path.

It's better to clarify the reason of hypervisor bypassing. (performance, security or scalability).

Performance - yes, definitely. Exitless VM-to-VM is the fastest possible way to communicate between VMs. Today it can only be done using ivshmem. This patch series allows virtio devices to take advantage of it and will encourage people to use virtio instead of non-standard ivshmem devices.

Quoted 4 lines

Security - I don't think this feature is a security improvement. It reduces isolation because VM1 has full shared memory access to VM2. In fact, this is a reason for users to consider carefully whether they even want to use this feature.

True without an IOMMU, however using a vIOMMU within VM2 can protect the VM2, can't it?

Quoted 15 lines

Scalability - much for the same reasons as the Performance section above. Bypassing the hypervisor eliminates scalability bottlenecks (e.g. host network stack and bridge).

Quoted 3 lines

Probably not for the following cases:

1) kick/call

I disagree here because kick/call is actually very efficient!

VM1's irqfd is the ioeventfd for VM2. When VM2 writes to the ioeventfd there is a single lightweight vmexit which injects an interrupt into VM1. QEMU is not involved and the host kernel scheduler is not involved so this is a low-latency operation.

Quoted 8 lines

I haven't tested this yet but the ioeventfd code looks like this will work.

Quoted 2 lines

2) device IOTLB / IOMMU transaction (or any other case that backends needs metadata from qemu).

Yes, this is the big weakness of vhost-user in general. The IOMMU feature doesn't offer good isolation

I think that's an implementation issue, not a protocol issue.

Quoted 2 lines

and even when it does, performance
will be an issue.

If the IOMMU mappings are dynamic - but they are mostly static with e.g. dpdk, right?

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

* Implement "Additional Device Resources over PCI" for shared memory, doorbells, and notifications instead of hardcoding a BAR with magic offsets into virtio-vhost-user:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2920007

Does this mean we need to standardize vhost-user protocol first?

Quoted 7 lines

Currently the draft spec says:

This section relies on definitions from the Vhost-user Protocol [1].

[1] https://git.qemu.org/?p=qemu.git;a=blob_plain;f=docs/interop/vhost-user.txt;hb=HEAD

Michael: Is it okay to simply include this link?

It is OK to include normative and non-normative references, they go in the introduction and then you refer to them anywhere in the document.

I'm still reviewing the draft. At some level, this is a general tunnel feature, it can tunnel any protocol. That would be one way to isolate it.

Quoted 19 lines
Quoted 6 lines
Quoted 3 lines

* Implement the VRING_KICK eventfd - currently vhost-user slaves must be poll mode drivers.
* Optimize VRING_CALL doorbell with ioeventfd to avoid QEMU exit.

The performance implication needs to be measured. It looks to me both kick and call will introduce more latency form the point of guest.

I described the irqfd + ioeventfd approach above. It should be faster than virtio-net + bridge today.

Quoted 8 lines
Quoted 4 lines

* vhost-user log feature
* UUID config field for stable device identification regardless of PCI bus addresses.
* vhost-user IOMMU and SLAVE_REQ_FD feature

So an assumption is the VM that implements vhost backends should be at least as secure as vhost-user backend process on host. Could we have this conclusion?

Quoted 5 lines

Yes.

Sadly the vhost-user IOMMU protocol feature does not provide isolation. At the moment IOMMU is basically a layer of indirection (mapping) but the vhost-user backend process still has full access to guest RAM :(.

An important feature would be to do the isolation in the qemu. So trust the qemu running VM2 but not VM2 itself.

Quoted 14 lines
Quoted 2 lines

Btw, it's better to have some early numbers, e.g what testpmd reports during forwarding.

I need to rely on others to do this (and many other things!) because virtio-vhost-user isn't the focus of my work.

These patches were written to demonstrate my suggestions for vhost-pci. They were written at work but also on weekends, early mornings, and late nights to avoid delaying Wei and Zhiyong's vhost-pci work too much.

If this approach has merit then I hope others will take over and I'll play a smaller role addressing some of the todo items and cleanups.

Stefan

#7 lore raw
Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Stefan Hajnoczi
Quoted 13 lines · Jason Wang
Quoted 3 lines · Stefan Hajnoczi

These patches implement the virtio-vhost-user device design that I have described here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007

Thanks for the patches, looks rather interesting and similar to split device model used by Xen.

Quoted 2 lines

The goal is to let the guest act as the vhost device backend for other guests. This allows virtual networking and storage appliances to run inside guests.

So the question still, what kind of protocol do you want to run on top? If it was ethernet based, virtio-net work pretty well and it can even do migration.

Quoted 5 lines
Quoted 3 lines

This device is particularly interesting for poll mode drivers where exitless VM-to-VM communication is possible, completely bypassing the hypervisor in the data path.

It's better to clarify the reason of hypervisor bypassing. (performance, security or scalability).

Performance - yes, definitely. Exitless VM-to-VM is the fastest possible way to communicate between VMs. Today it can only be done using ivshmem. This patch series allows virtio devices to take advantage of it and will encourage people to use virtio instead of non-standard ivshmem devices.

Quoted 6 lines
Quoted 4 lines

Security - I don't think this feature is a security improvement. It reduces isolation because VM1 has full shared memory access to VM2. In fact, this is a reason for users to consider carefully whether they even want to use this feature.

True without an IOMMU, however using a vIOMMU within VM2 can protect the VM2, can't it?

It's not clear to me how to do this. E.g need a way to report failure to VM2 or #PF?

Quoted 7 lines
Quoted 7 lines

Scalability - much for the same reasons as the Performance section above. Bypassing the hypervisor eliminates scalability bottlenecks (e.g. host network stack and bridge).

Quoted 2 lines

Probably not for the following cases:

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

1) kick/call

I disagree here because kick/call is actually very efficient!

VM1's irqfd is the ioeventfd for VM2. When VM2 writes to the ioeventfd there is a single lightweight vmexit which injects an interrupt into VM1. QEMU is not involved and the host kernel scheduler is not involved so this is a low-latency operation.

Right, looks like I was wrong. But consider irqfd may do wakup which means scheduler is still needed.

Quoted 29 lines
Quoted 7 lines

I haven't tested this yet but the ioeventfd code looks like this will work.

Quoted 2 lines

2) device IOTLB / IOMMU transaction (or any other case that backends needs metadata from qemu).

Yes, this is the big weakness of vhost-user in general. The IOMMU feature doesn't offer good isolation

I think that's an implementation issue, not a protocol issue.

Quoted 2 lines

and even when it does, performance
will be an issue.

If the IOMMU mappings are dynamic - but they are mostly static with e.g. dpdk, right?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

* Implement "Additional Device Resources over PCI" for shared memory, doorbells, and notifications instead of hardcoding a BAR with magic offsets into virtio-vhost-user:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2920007

Quoted 8 lines
Quoted 1 line

Does this mean we need to standardize vhost-user protocol first?

Currently the draft spec says:

This section relies on definitions from the Vhost-user Protocol [1].

   [1] https://git.qemu.org/?p=qemu.git;a=blob_plain;f=docs/interop/vhost-user.txt;hb=HEAD

Michael: Is it okay to simply include this link?

Quoted 8 lines

It is OK to include normative and non-normative references, they go in the introduction and then you refer to them anywhere in the document.

I'm still reviewing the draft. At some level, this is a general tunnel feature, it can tunnel any protocol. That would be one way to isolate it.

Right, but it should not be the main motivation, consider we can tunnel any protocol on top of ethernet too.

Quoted 16 lines
Quoted 16 lines
Quoted 6 lines
Quoted 4 lines

* Implement the VRING_KICK eventfd - currently vhost-user slaves must be poll mode drivers.
* Optimize VRING_CALL doorbell with ioeventfd to avoid QEMU exit.

The performance implication needs to be measured. It looks to me both kick and call will introduce more latency form the point of guest.

I described the irqfd + ioeventfd approach above. It should be faster than virtio-net + bridge today.

Quoted 7 lines
Quoted 4 lines

* vhost-user log feature
* UUID config field for stable device identification regardless of PCI bus addresses.
* vhost-user IOMMU and SLAVE_REQ_FD feature

So an assumption is the VM that implements vhost backends should be at least as secure as vhost-user backend process on host. Could we have this conclusion?

Quoted 7 lines
Quoted 5 lines

Yes.

Sadly the vhost-user IOMMU protocol feature does not provide isolation. At the moment IOMMU is basically a layer of indirection (mapping) but the vhost-user backend process still has full access to guest RAM :(.

An important feature would be to do the isolation in the qemu. So trust the qemu running VM2 but not VM2 itself.

Agree, we'd better not consider VM is as secure as qemu.

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

Btw, it's better to have some early numbers, e.g what testpmd reports during forwarding.

I need to rely on others to do this (and many other things!) because virtio-vhost-user isn't the focus of my work.

These patches were written to demonstrate my suggestions for vhost-pci. They were written at work but also on weekends, early mornings, and late nights to avoid delaying Wei and Zhiyong's vhost-pci work too much.

Thanks a lot for the effort! If anyone want to benchmark, I would expect compare the following three solutions:

1) vhost-pci
2) virtio-vhost-user
3) testpmd with two vhost-user ports

Performance number is really important to show the advantages of new ideas.

Quoted 3 lines
Quoted 3 lines

If this approach has merit then I hope others will take over and I'll play a smaller role addressing some of the todo items and cleanups.

It looks to me the advantages are 1) generic virtio layer (vhost-pci can achieve this too if necessary) 2) some kind of code reusing (vhost pmd). And I'd expect they have similar performance result consider no major differences between them.

Thanks

Quoted 2 lines
Quoted 1 line

Stefan

#8 lore raw
Quoted 33 lines · Jason Wang
Quoted 30 lines · Michael S. Tsirkin
Quoted 29 lines · Stefan Hajnoczi
Quoted 13 lines · Jason Wang
Quoted 3 lines · Stefan Hajnoczi

These patches implement the virtio-vhost-user device design that I have described here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007

Thanks for the patches, looks rather interesting and similar to split device model used by Xen.

Quoted 2 lines

The goal is to let the guest act as the vhost device backend for other guests. This allows virtual networking and storage appliances to run inside guests.

So the question still, what kind of protocol do you want to run on top? If it was ethernet based, virtio-net work pretty well and it can even do migration.

Quoted 5 lines
Quoted 3 lines

This device is particularly interesting for poll mode drivers where exitless VM-to-VM communication is possible, completely bypassing the hypervisor in the data path.

It's better to clarify the reason of hypervisor bypassing. (performance, security or scalability).

Performance - yes, definitely. Exitless VM-to-VM is the fastest possible way to communicate between VMs. Today it can only be done using ivshmem. This patch series allows virtio devices to take advantage of it and will encourage people to use virtio instead of non-standard ivshmem devices.

Security - I don't think this feature is a security improvement. It reduces isolation because VM1 has full shared memory access to VM2. In fact, this is a reason for users to consider carefully whether they even want to use this feature.

Quoted 5 lines
Quoted 2 lines

True without an IOMMU, however using a vIOMMU within VM2 can protect the VM2, can't it?

It's not clear to me how to do this. E.g need a way to report failure to VM2 or #PF?

Why would there be a failure? qemu running vm1 would be responsible for preventing access to vm2's memory not mapped through an IOMMU. Basically munmap these.

Quoted 119 lines
Quoted 7 lines
Quoted 7 lines

Scalability - much for the same reasons as the Performance section above. Bypassing the hypervisor eliminates scalability bottlenecks (e.g. host network stack and bridge).

Quoted 2 lines

Probably not for the following cases:

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

1) kick/call

I disagree here because kick/call is actually very efficient!

VM1's irqfd is the ioeventfd for VM2. When VM2 writes to the ioeventfd there is a single lightweight vmexit which injects an interrupt into VM1. QEMU is not involved and the host kernel scheduler is not involved so this is a low-latency operation.

Right, looks like I was wrong. But consider irqfd may do wakup which means scheduler is still needed.

Quoted 29 lines
Quoted 7 lines

I haven't tested this yet but the ioeventfd code looks like this will work.

Quoted 2 lines

2) device IOTLB / IOMMU transaction (or any other case that backends needs metadata from qemu).

Yes, this is the big weakness of vhost-user in general. The IOMMU feature doesn't offer good isolation

I think that's an implementation issue, not a protocol issue.

Quoted 2 lines

and even when it does, performance
will be an issue.

If the IOMMU mappings are dynamic - but they are mostly static with e.g. dpdk, right?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

* Implement "Additional Device Resources over PCI" for shared memory, doorbells, and notifications instead of hardcoding a BAR with magic offsets into virtio-vhost-user:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2920007

Quoted 8 lines
Quoted 1 line

Does this mean we need to standardize vhost-user protocol first?

Currently the draft spec says:

This section relies on definitions from the Vhost-user Protocol [1].

   [1] https://git.qemu.org/?p=qemu.git;a=blob_plain;f=docs/interop/vhost-user.txt;hb=HEAD

Michael: Is it okay to simply include this link?

Quoted 8 lines

It is OK to include normative and non-normative references, they go in the introduction and then you refer to them anywhere in the document.

I'm still reviewing the draft. At some level, this is a general tunnel feature, it can tunnel any protocol. That would be one way to isolate it.

Right, but it should not be the main motivation, consider we can tunnel any protocol on top of ethernet too.

Quoted 16 lines
Quoted 16 lines
Quoted 6 lines
Quoted 4 lines

* Implement the VRING_KICK eventfd - currently vhost-user slaves must be poll mode drivers.
* Optimize VRING_CALL doorbell with ioeventfd to avoid QEMU exit.

The performance implication needs to be measured. It looks to me both kick and call will introduce more latency form the point of guest.

I described the irqfd + ioeventfd approach above. It should be faster than virtio-net + bridge today.

Quoted 7 lines
Quoted 4 lines

* vhost-user log feature
* UUID config field for stable device identification regardless of PCI bus addresses.
* vhost-user IOMMU and SLAVE_REQ_FD feature

So an assumption is the VM that implements vhost backends should be at least as secure as vhost-user backend process on host. Could we have this conclusion?

Quoted 7 lines
Quoted 5 lines

Yes.

Sadly the vhost-user IOMMU protocol feature does not provide isolation. At the moment IOMMU is basically a layer of indirection (mapping) but the vhost-user backend process still has full access to guest RAM :(.

An important feature would be to do the isolation in the qemu. So trust the qemu running VM2 but not VM2 itself.

Agree, we'd better not consider VM is as secure as qemu.

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

Btw, it's better to have some early numbers, e.g what testpmd reports during forwarding.

I need to rely on others to do this (and many other things!) because virtio-vhost-user isn't the focus of my work.

These patches were written to demonstrate my suggestions for vhost-pci. They were written at work but also on weekends, early mornings, and late nights to avoid delaying Wei and Zhiyong's vhost-pci work too much.

Thanks a lot for the effort! If anyone want to benchmark, I would expect compare the following three solutions:

1) vhost-pci
2) virtio-vhost-user
3) testpmd with two vhost-user ports

Performance number is really important to show the advantages of new ideas.

Quoted 3 lines
Quoted 3 lines

If this approach has merit then I hope others will take over and I'll play a smaller role addressing some of the todo items and cleanups.

It looks to me the advantages are 1) generic virtio layer (vhost-pci can achieve this too if necessary) 2) some kind of code reusing (vhost pmd). And I'd expect they have similar performance result consider no major differences between them.

Thanks

Quoted 2 lines
Quoted 1 line

Stefan

#9 lore raw
Quoted 6 lines · Michael S. Tsirkin
Quoted 2 lines

It's not clear to me how to do this. E.g need a way to report failure to VM2 or #PF?

Why would there be a failure? qemu running vm1 would be responsible for preventing access to vm2's memory not mapped through an IOMMU. Basically munmap these.

Access to VM2's memory would use VM2's configured IOVAs for VM1's requester id. VM2's QEMU send device IOTLB messages to VM1's QEMU, which would remap VM2's memory on the fly into VM1's BAR2.

It's not trivial to do it efficiently, but it's possible. The important thing is that, if VM2 has an IOMMU, QEMU must *not* connect to a virtio-vhost-user device that lacks IOTLB support. But that would be a vhost-user bug, not a virtio-vhost-user bug---and that's the beauty of Stefan's approach. :)

Paolo

#10 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 6 lines · Michael S. Tsirkin
Quoted 2 lines

It's not clear to me how to do this. E.g need a way to report failure to VM2 or #PF?

Why would there be a failure? qemu running vm1 would be responsible for preventing access to vm2's memory not mapped through an IOMMU. Basically munmap these.

Access to VM2's memory would use VM2's configured IOVAs for VM1's requester id. VM2's QEMU send device IOTLB messages to VM1's QEMU, which would remap VM2's memory on the fly into VM1's BAR2.

Right. Almost.

One problem is that IOVA range is bigger than RAM range, so you will have trouble making arbitrary virtual addresses fit in a BAR.

This is why I suggested a hybrid approach where translation happens within guest, qemu only does protection.

Another problem with it is that IOMMU has page granularity while with hugetlbfs we might not be able to remap at that granularity.

Not sure what to do about it - teach host to break up pages? Pass limitation to guest through virtio-iommu?

Ideas?

Quoted 7 lines

It's not trivial to do it efficiently, but it's possible. The important thing is that, if VM2 has an IOMMU, QEMU must *not* connect to a virtio-vhost-user device that lacks IOTLB support. But that would be a vhost-user bug, not a virtio-vhost-user bug---and that's the beauty of Stefan's approach. :)

Paolo

#11 lore raw
Quoted 11 lines · Michael S. Tsirkin
Quoted 9 lines · Paolo Bonzini
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

It's not clear to me how to do this. E.g need a way to report failure to VM2 or #PF?

Why would there be a failure? qemu running vm1 would be responsible for preventing access to vm2's memory not mapped through an IOMMU. Basically munmap these.

Access to VM2's memory would use VM2's configured IOVAs for VM1's requester id. VM2's QEMU send device IOTLB messages to VM1's QEMU, which would remap VM2's memory on the fly into VM1's BAR2.

Right. Almost.

That would be extremely slow for dynamic mappings.

Quoted 8 lines

One problem is that IOVA range is bigger than RAM range, so you will have trouble making arbitrary virtual addresses fit in a BAR.

This is why I suggested a hybrid approach where translation happens within guest, qemu only does protection.

Quoted 6 lines

Another problem with it is that IOMMU has page granularity while with hugetlbfs we might not be able to remap at that granularity.

Not sure what to do about it - teach host to break up pages? Pass limitation to guest through virtio-iommu?

If we decide to go virtio IOMMU, maybe device can limit its IOVA range too.

Thanks

Quoted 10 lines

Ideas?

Quoted 7 lines

It's not trivial to do it efficiently, but it's possible. The important thing is that, if VM2 has an IOMMU, QEMU must *not* connect to a virtio-vhost-user device that lacks IOTLB support. But that would be a vhost-user bug, not a virtio-vhost-user bug---and that's the beauty of Stefan's approach. :)

Paolo

#12 lore raw
In reply to Michael S. Tsirkin
Quoted 38 lines · Michael S. Tsirkin
Quoted 30 lines · Stefan Hajnoczi
Quoted 16 lines · Jason Wang
Quoted 3 lines · Stefan Hajnoczi

These patches implement the virtio-vhost-user device design that I have described here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007

Thanks for the patches, looks rather interesting and similar to split device model used by Xen.

Quoted 3 lines

The goal is to let the guest act as the vhost device backend for other guests. This allows virtual networking and storage appliances to run inside guests.

So the question still, what kind of protocol do you want to run on top? If it was ethernet based, virtio-net work pretty well and it can even do migration.

Quoted 6 lines
Quoted 3 lines

This device is particularly interesting for poll mode drivers where exitless VM-to-VM communication is possible, completely bypassing the hypervisor in the data path.

It's better to clarify the reason of hypervisor bypassing. (performance, security or scalability).

Performance - yes, definitely. Exitless VM-to-VM is the fastest possible way to communicate between VMs. Today it can only be done using ivshmem. This patch series allows virtio devices to take advantage of it and will encourage people to use virtio instead of non-standard ivshmem devices.

Quoted 4 lines

Security - I don't think this feature is a security improvement. It reduces isolation because VM1 has full shared memory access to VM2. In fact, this is a reason for users to consider carefully whether they even want to use this feature.

True without an IOMMU, however using a vIOMMU within VM2 can protect the VM2, can't it?

[...]

Quoted 4 lines
Quoted 2 lines

Yes, this is the big weakness of vhost-user in general. The IOMMU feature doesn't offer good isolation

I think that's an implementation issue, not a protocol issue.

The IOMMU feature in the vhost-user protocol adds address translation and permissions but the underlying memory region file descriptors still expose all of guest RAM.

An implementation that offers true isolation has to enforce the IOMMU state on the shared memory (e.g. read & write access).

Quoted 5 lines
Quoted 2 lines

and even when it does, performance
will be an issue.

If the IOMMU mappings are dynamic - but they are mostly static with e.g. dpdk, right?

Excellent idea! My understanding is that DPDK's memory area for mbufs is static.

The question is whether this area contains only packet payload buffers? Then it would be feasible to map only this memory (plus vrings) and achieve isolation.

If other data is intermingled with the packet payload buffers then it's difficult to guarantee security since an evil VM can modify the non-payload data to trigger race conditions, out-of-bounds memory accesses, and other bugs.

Anyway, what you've suggested sounds like the most realistic option for achieving isolation without losing performance.

Quoted 19 lines
Quoted 19 lines
Quoted 6 lines
Quoted 3 lines

* Implement the VRING_KICK eventfd - currently vhost-user slaves must be poll mode drivers.
* Optimize VRING_CALL doorbell with ioeventfd to avoid QEMU exit.

The performance implication needs to be measured. It looks to me both kick and call will introduce more latency form the point of guest.

I described the irqfd + ioeventfd approach above. It should be faster than virtio-net + bridge today.

Quoted 8 lines
Quoted 4 lines

* vhost-user log feature
* UUID config field for stable device identification regardless of PCI bus addresses.
* vhost-user IOMMU and SLAVE_REQ_FD feature

So an assumption is the VM that implements vhost backends should be at least as secure as vhost-user backend process on host. Could we have this conclusion?

Quoted 8 lines
Quoted 5 lines

Yes.

Sadly the vhost-user IOMMU protocol feature does not provide isolation. At the moment IOMMU is basically a layer of indirection (mapping) but the vhost-user backend process still has full access to guest RAM :(.

An important feature would be to do the isolation in the qemu. So trust the qemu running VM2 but not VM2 itself.

I think what you suggested above about DPDK's static mappings is even better. It does not require trusting VM2's QEMU. It's also simpler than implementing isolation in QEMU.

#13 lore raw
In reply to Stefan Hajnoczi
Quoted 8 lines · Stefan Hajnoczi
Quoted 5 lines · Jason Wang

On 2018年01月19日 21:06, Stefan Hajnoczi wrote:

Probably not for the following cases:

1) kick/call

I disagree here because kick/call is actually very efficient!

Quoted 7 lines

VM1's irqfd is the ioeventfd for VM2. When VM2 writes to the ioeventfd there is a single lightweight vmexit which injects an interrupt into VM1. QEMU is not involved and the host kernel scheduler is not involved so this is a low-latency operation.

I haven't tested this yet but the ioeventfd code looks like this will work.

This have been tested in vhost-pci v2 patches which worked with with a kernel driver. It worked pretty well.

Quoted 11 lines
Quoted 2 lines

Btw, it's better to have some early numbers, e.g what testpmd reports during forwarding.

I need to rely on others to do this (and many other things!) because virtio-vhost-user isn't the focus of my work.

These patches were written to demonstrate my suggestions for vhost-pci. They were written at work but also on weekends, early mornings, and late nights to avoid delaying Wei and Zhiyong's vhost-pci work too much.

If this approach has merit then I hope others will take over and I'll play a smaller role addressing some of the todo items and cleanups.

Thanks again for the great effort, your implementation looks nice.

If we finally decide to go with the virtio-vhost-user approach, I think zhiyong and I can help take over the work to continue, too.

I'm still thinking about solutions to the two issues that I shared yesterday - it should be like a normal PCI device, and if we unbind its driver, and bind back, it should also work.

Best,
Wei

#14 lore raw
In reply to Stefan Hajnoczi
Quoted 17 lines · Stefan Hajnoczi

These patches implement the virtio-vhost-user device design that I have described here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007

  configure                                   |   18 +
  hw/virtio/Makefile.objs                     |    1 +
  hw/virtio/virtio-pci.h                      |   21 +
  include/hw/pci/pci.h                        |    1 +
  include/hw/virtio/vhost-user.h              |  106 +++
  include/hw/virtio/virtio-vhost-user.h       |   88 +++
  include/standard-headers/linux/virtio_ids.h |    1 +
  hw/virtio/vhost-user.c                      |  100 +--
  hw/virtio/virtio-pci.c                      |   61 ++
  hw/virtio/virtio-vhost-user.c               | 1047 +++++++++++++++++++++++++++
  hw/virtio/trace-events                      |   22 +
  11 files changed, 1367 insertions(+), 99 deletions(-)
Quoted 4 lines

create mode 100644 include/hw/virtio/vhost-user.h create mode 100644 include/hw/virtio/virtio-vhost-user.h create mode 100644 hw/virtio/virtio-vhost-user.c

Thanks for the quick implementation. Not sure if the following issues could be solved with this approach:
- After we boot the slave VM, if we don't run the virtio-vhost-user
driver (i.e. testpmd), then the master VM couldn't boot, because the booting of the virtio-net device relies on a negotiation with the virtio-vhost-user driver.
- Suppose in the future there is also a kernel virtio-vhost-user
driver as other PCI devices, can we unbind the kernel driver first, and then bind the device to the dpdk driver? A normal PCI device should be able to smoothly switch between the kernel driver and dpdk driver.

Best,
Wei

#15 lore raw
Quoted 6 lines · Wei Wang

On 01/19/2018 09:06 PM, Stefan Hajnoczi wrote:
Thanks for the quick implementation. Not sure if the following issues could be solved with this approach:
- After we boot the slave VM, if we don't run the virtio-vhost-user driver
(i.e. testpmd), then the master VM couldn't boot, because the booting of the virtio-net device relies on a negotiation with the virtio-vhost-user driver.

This is a limitation of QEMU's vhost-user master implementation which also affects AF_UNIX. It cannot be solved by this patch series since this is the slave side.

Here is what I suggest. Introduce a new VIRTIO feature bit:

  #define VIRTIO_F_DEVICE_READY 34

When the device supports this bit we extend the device initialization procedure. If the device is not yet ready, the FEATURES_OK status bit is not accepted by the device. Device initialization fails temporarily but the device may raise the configuration change interrupt to indicate that device initialization should be retried.

Using a feature bit guarantees that existing device and driver behavior remains unchanged.

On the QEMU side the changes are:

1. Virtio hardware registers and configuration space are available even when vhost-user is disconnected. This shouldn't be difficult to implement because QEMU always has a virtio device model for each vhost-user device. We just need to put dummy values in the registers/configuration space until vhost-user has connected.

2. When vhost-user connects, raise the configuration change interrupt and allow vhost-user to process.

On the guest side the changes are:

1. virtio_pci.ko must set VIRTIO_F_DEVICE_READY and handle !FEATURES_OK by waiting for the configuration change interrupt and retrying.

This doesn't fully solve the problem because it assumes that a connected slave always responds to VIRTIO hardware register accesses (e.g. get/set features). If the slave crashes but leaves the virtio-vhost-user PCI adapter connected then vhost-user requests from the master go unanswered and cause hangs...

Quoted 4 lines

- Suppose in the future there is also a kernel virtio-vhost-user driver as
other PCI devices, can we unbind the kernel driver first, and then bind the device to the dpdk driver? A normal PCI device should be able to smoothly switch between the kernel driver and dpdk driver.

It depends what you mean by "smoothly switch".

If you mean whether it's possible to go from a kernel driver to vfio-pci, then the answer is yes.

But if the kernel driver has an established vhost-user connection then it will be closed. This is the same as reconnecting with AF_UNIX vhost-user.

Stefan

#16 lore raw
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Wei Wang

On 01/19/2018 09:06 PM, Stefan Hajnoczi wrote:

- Suppose in the future there is also a kernel virtio-vhost-user driver as
other PCI devices, can we unbind the kernel driver first, and then bind the device to the dpdk driver? A normal PCI device should be able to smoothly switch between the kernel driver and dpdk driver.

Quoted 9 lines

It depends what you mean by "smoothly switch".

If you mean whether it's possible to go from a kernel driver to vfio-pci, then the answer is yes.

But if the kernel driver has an established vhost-user connection then it will be closed. This is the same as reconnecting with AF_UNIX vhost-user.

Actually not only the case of switching to testpmd after kernel establishes the connection, but also for several runs of testpmd. That is, if we run testpmd, then exit testpmd. I think the second run of testpmd won't work. I'm thinking about caching the received master msgs in QEMU when virtio_vhost_user_parse_m2s().

Btw, I'm trying to run the code, but couldn't bind the virito-vhost-user device to vfio-pci (reports Unknown device), not sure if it is because the device type is "Unclassified device".

Best,
Wei

#17 lore raw
Quoted 14 lines · Wei Wang
Quoted 13 lines · Stefan Hajnoczi
Quoted 7 lines · Wei Wang

On 01/19/2018 09:06 PM, Stefan Hajnoczi wrote:

- Suppose in the future there is also a kernel virtio-vhost-user driver as
other PCI devices, can we unbind the kernel driver first, and then bind the device to the dpdk driver? A normal PCI device should be able to smoothly switch between the kernel driver and dpdk driver.

It depends what you mean by "smoothly switch".

If you mean whether it's possible to go from a kernel driver to vfio-pci, then the answer is yes.

Quoted 8 lines
Quoted 4 lines

But if the kernel driver has an established vhost-user connection then it will be closed. This is the same as reconnecting with AF_UNIX vhost-user.

Actually not only the case of switching to testpmd after kernel establishes the connection, but also for several runs of testpmd. That is, if we run testpmd, then exit testpmd. I think the second run of testpmd won't work.

The vhost-user master must reconnect and initialize again (SET_FEATURES, SET_MEM_TABLE, etc). Is your master reconnecting after the AF_UNIX connection is closed?

Quoted 2 lines

I'm thinking about caching the received master msgs in QEMU when virtio_vhost_user_parse_m2s().

Why is that necessary and how does QEMU know they are still up-to-date when a new connection is made?

Quoted 3 lines

Btw, I'm trying to run the code, but couldn't bind the virito-vhost-user device to vfio-pci (reports Unknown device), not sure if it is because the device type is "Unclassified device".

You need to use the modified usertools/dpdk-devbind.py from my patch series inside the guest. Please see:
https://dpdk.org/ml/archives/dev/2018-January/088177.html

Stefan

#18 lore raw
Quoted 19 lines · Stefan Hajnoczi
Quoted 18 lines · Wei Wang
Quoted 17 lines · Stefan Hajnoczi
Quoted 7 lines · Wei Wang

On 01/19/2018 09:06 PM, Stefan Hajnoczi wrote:

- Suppose in the future there is also a kernel virtio-vhost-user driver as
other PCI devices, can we unbind the kernel driver first, and then bind the device to the dpdk driver? A normal PCI device should be able to smoothly switch between the kernel driver and dpdk driver.

It depends what you mean by "smoothly switch".

If you mean whether it's possible to go from a kernel driver to vfio-pci, then the answer is yes.

But if the kernel driver has an established vhost-user connection then it will be closed. This is the same as reconnecting with AF_UNIX vhost-user.

Quoted 6 lines
Quoted 3 lines

Actually not only the case of switching to testpmd after kernel establishes the connection, but also for several runs of testpmd. That is, if we run testpmd, then exit testpmd. I think the second run of testpmd won't work.

The vhost-user master must reconnect and initialize again (SET_FEATURES, SET_MEM_TABLE, etc). Is your master reconnecting after the AF_UNIX connection is closed?

Is this an explicit qmp operation to make the master re-connect?

Quoted 5 lines
Quoted 3 lines

I'm thinking about caching the received master msgs in QEMU when virtio_vhost_user_parse_m2s().

Why is that necessary and how does QEMU know they are still up-to-date when a new connection is made?

OK. I think that's not needed if the master can reconnect.

Quoted 7 lines
Quoted 4 lines

Btw, I'm trying to run the code, but couldn't bind the virito-vhost-user device to vfio-pci (reports Unknown device), not sure if it is because the device type is "Unclassified device".

You need to use the modified usertools/dpdk-devbind.py from my patch series inside the guest. Please see:
https://dpdk.org/ml/archives/dev/2018-January/088177.html

Thanks. I haven't got time on this yet due to some more urgent things. I'll try.

Best,
Wei

#19 lore raw
Quoted 20 lines · Wei Wang
Quoted 19 lines · Stefan Hajnoczi
Quoted 18 lines · Wei Wang
Quoted 17 lines · Stefan Hajnoczi
Quoted 7 lines · Wei Wang

On 01/19/2018 09:06 PM, Stefan Hajnoczi wrote:

- Suppose in the future there is also a kernel virtio-vhost-user driver as
other PCI devices, can we unbind the kernel driver first, and then bind the device to the dpdk driver? A normal PCI device should be able to smoothly switch between the kernel driver and dpdk driver.

It depends what you mean by "smoothly switch".

If you mean whether it's possible to go from a kernel driver to vfio-pci, then the answer is yes.

But if the kernel driver has an established vhost-user connection then it will be closed. This is the same as reconnecting with AF_UNIX vhost-user.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Actually not only the case of switching to testpmd after kernel establishes the connection, but also for several runs of testpmd. That is, if we run testpmd, then exit testpmd. I think the second run of testpmd won't work.

The vhost-user master must reconnect and initialize again (SET_FEATURES, SET_MEM_TABLE, etc). Is your master reconnecting after the AF_UNIX connection is closed?

Is this an explicit qmp operation to make the master re-connect?

I haven't tested it myself but I'm aware of two modes of operation:

1. -chardev socket,id=chardev0,...,server
-netdev vhost-user,chardev=chardev0

When the vhost-user socket is disconnected the peer needs to reconnect. In this case no special commands are necessary.

Here we're relying on DPDK librte_vhost's reconnection behavior.

Or

2. -chardev socket,id=chardev0,...,reconnect=3
-netdev vhost-user,chardev=chardev0

When the vhost-user socket is disconnected a new connection attempt will be made after 3 seconds.

In both cases vhost-user negotiation will resume when the new connection is established.

Stefan

#20 lore raw
Quoted 43 lines · Stefan Hajnoczi
Quoted 20 lines · Wei Wang
Quoted 19 lines · Stefan Hajnoczi
Quoted 18 lines · Wei Wang
Quoted 17 lines · Stefan Hajnoczi
Quoted 7 lines · Wei Wang

On 01/19/2018 09:06 PM, Stefan Hajnoczi wrote:

- Suppose in the future there is also a kernel virtio-vhost-user driver as
other PCI devices, can we unbind the kernel driver first, and then bind the device to the dpdk driver? A normal PCI device should be able to smoothly switch between the kernel driver and dpdk driver.

It depends what you mean by "smoothly switch".

If you mean whether it's possible to go from a kernel driver to vfio-pci, then the answer is yes.

But if the kernel driver has an established vhost-user connection then it will be closed. This is the same as reconnecting with AF_UNIX vhost-user.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Actually not only the case of switching to testpmd after kernel establishes the connection, but also for several runs of testpmd. That is, if we run testpmd, then exit testpmd. I think the second run of testpmd won't work.

The vhost-user master must reconnect and initialize again (SET_FEATURES, SET_MEM_TABLE, etc). Is your master reconnecting after the AF_UNIX connection is closed?

Is this an explicit qmp operation to make the master re-connect?

I haven't tested it myself but I'm aware of two modes of operation:

1. -chardev socket,id=chardev0,...,server
-netdev vhost-user,chardev=chardev0

When the vhost-user socket is disconnected the peer needs to reconnect. In this case no special commands are necessary.

Here we're relying on DPDK librte_vhost's reconnection behavior.

Or

2. -chardev socket,id=chardev0,...,reconnect=3
-netdev vhost-user,chardev=chardev0

Quoted 7 lines

When the vhost-user socket is disconnected a new connection attempt will be made after 3 seconds.

In both cases vhost-user negotiation will resume when the new connection is established.

Stefan

I've been thinking about the issues, and it looks vhost-pci outperforms in this aspect.
Vhost-pci is like using a mail box. messages are just dropped into the box, and whenever vhost-pci pmd gets booted, it can always get the messages from the box, the negotiation between vhost-pci pmd and virtio-net is asynchronous. Virtio-vhost-user is like a phone call, which is a synchronous communication. If one side is absent, then the other side will hang on without knowing when it could get connected or hang up with messages not passed (lost).

I also think the above solutions won't help. Please see below:

Background:
The vhost-user negotiation is split into 2 phases currently. The 1st phase happens when the connection is established, and we can find what's done in the 1st phase in vhost_user_init(). The 2nd phase happens when the master driver is loaded (e.g. run of virtio-net pmd) and set status to the device, and we can find what's done in the 2nd phase in vhost_dev_start(), which includes sending the memory info and virtqueue info. The socket is connected, till one of the QEMU devices exits, so pmd exiting won't end the QEMU side socket connection.

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost pmd won't work.

Any thoughts?

Best,
Wei

#21 lore raw
Quoted 8 lines · Wei Wang

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost pmd won't work.

Quoted 4 lines

Any thoughts?

Best,
Wei

So vhost in qemu must resend all configuration on reconnect. Does this address the issues?

Signature · 1 line
MST
#22 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Wei Wang

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost pmd won't work.

Quoted 7 lines
Quoted 4 lines

Any thoughts?

Best,
Wei

So vhost in qemu must resend all configuration on reconnect. Does this address the issues?

Yes, but the issues are
1) there is no reconnecting when a pmd exits (the socket connection seems still on at the device layer);
2) If we find a way to break the QEMU layer socket connection when pmd exits and get it reconnect, virtio-net device still won't send all the configure when reconnecting, because socket connecting only triggers phase 1 of vhost-user negotiation (i.e. vhost_user_init). Phase 2 is triggered after the driver loads (i.e. vhost_net_start). If the virtio-net pmd doesn't reload, there are no phase 2 messages (like virtqueue addresses which are allocated by the pmd). I think we need to think more about this before moving forward.

Best,
Wei

#23 lore raw
Quoted 14 lines · Wei Wang
Quoted 13 lines · Michael S. Tsirkin
Quoted 12 lines · Wei Wang

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost pmd won't work.

Any thoughts?

Best,
Wei

Quoted 7 lines
Quoted 3 lines

So vhost in qemu must resend all configuration on reconnect. Does this address the issues?

Yes, but the issues are
1) there is no reconnecting when a pmd exits (the socket connection seems still on at the device layer);

This is how real hardware works too. If the driver suddenly stops running then the device remains operational. When the driver is started again it resets the device and initializes it.

Quoted 8 lines

2) If we find a way to break the QEMU layer socket connection when pmd exits and get it reconnect, virtio-net device still won't send all the configure when reconnecting, because socket connecting only triggers phase 1 of vhost-user negotiation (i.e. vhost_user_init). Phase 2 is triggered after the driver loads (i.e. vhost_net_start). If the virtio-net pmd doesn't reload, there are no phase 2 messages (like virtqueue addresses which are allocated by the pmd). I think we need to think more about this before moving forward.

Marc-André: How does vhost-user reconnect work when the master goes away and a new master comes online? Wei found that the QEMU slave implementation only does partial vhost-user initialization upon reconnect, so the new master doesn't get the virtqueue address and related information. Is this a QEMU bug?

Stefan

#24 lore raw
Quoted 37 lines · Stefan Hajnoczi
Quoted 9 lines · Wei Wang
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Wei Wang

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost

pmd won't work.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Any thoughts?

Best,
Wei

Quoted 7 lines
Quoted 3 lines

So vhost in qemu must resend all configuration on reconnect. Does this address the issues?

Yes, but the issues are
1) there is no reconnecting when a pmd exits (the socket connection seems still on at the device layer);

This is how real hardware works too. If the driver suddenly stops running then the device remains operational. When the driver is started again it resets the device and initializes it.

Quoted 8 lines

2) If we find a way to break the QEMU layer socket connection when pmd exits and get it reconnect, virtio-net device still won't send all the configure when reconnecting, because socket connecting only triggers phase 1 of vhost-user negotiation (i.e. vhost_user_init). Phase 2 is triggered after the driver loads (i.e. vhost_net_start). If the virtio-net pmd doesn't reload, there are no phase 2 messages (like virtqueue addresses which are allocated by the pmd). I think we need to think more about this before moving forward.

Quoted 5 lines

Marc-André: How does vhost-user reconnect work when the master goes away and a new master comes online? Wei found that the QEMU slave implementation only does partial vhost-user initialization upon reconnect, so the new master doesn't get the virtqueue address and related information. Is this a QEMU bug?

Actually we are discussing the slave (vhost is the slave, right?) going away. When a slave exits and some moment later a new slave runs, the master (virtio-net) won't send the virtqueue addresses to the new vhost slave.

Best,
Wei

#25 lore raw
Quoted 38 lines · Wei W
Quoted 37 lines · Stefan Hajnoczi
Quoted 9 lines · Wei Wang
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Wei Wang

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost

pmd won't work.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Any thoughts?

Best,
Wei

Quoted 7 lines
Quoted 3 lines

So vhost in qemu must resend all configuration on reconnect. Does this address the issues?

Yes, but the issues are
1) there is no reconnecting when a pmd exits (the socket connection seems still on at the device layer);

This is how real hardware works too. If the driver suddenly stops running then the device remains operational. When the driver is started again it resets the device and initializes it.

Quoted 8 lines

2) If we find a way to break the QEMU layer socket connection when pmd exits and get it reconnect, virtio-net device still won't send all the configure when reconnecting, because socket connecting only triggers phase 1 of vhost-user negotiation (i.e. vhost_user_init). Phase 2 is triggered after the driver loads (i.e. vhost_net_start). If the virtio-net pmd doesn't reload, there are no phase 2 messages (like virtqueue addresses which are allocated by the pmd). I think we need to think more about this before moving forward.

Quoted 7 lines
Quoted 5 lines

Marc-André: How does vhost-user reconnect work when the master goes away and a new master comes online? Wei found that the QEMU slave implementation only does partial vhost-user initialization upon reconnect, so the new master doesn't get the virtqueue address and related information. Is this a QEMU bug?

Actually we are discussing the slave (vhost is the slave, right?) going away. When a slave exits and some moment later a new slave runs, the master (virtio-net) won't send the virtqueue addresses to the new vhost slave.

Yes, apologies for the typo. s/QEMU slave/QEMU master/

Yesterday I asked Marc-André for help on IRC and we found the code path where the QEMU master performs phase 2 negotiation upon reconnect. It's not obvious but the qmp_set_link() calls in net_vhost_user_event() will do it.

I'm going to try to reproduce the issue you're seeing now. Will let you know what I find.

Stefan

#26 lore raw
Quoted 54 lines · Stefan Hajnoczi
Quoted 30 lines · Wei W
Quoted 29 lines · Stefan Hajnoczi
Quoted 10 lines · Wei Wang
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Wei Wang

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost

pmd won't work.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Any thoughts?

Best,
Wei

Quoted 7 lines
Quoted 3 lines

So vhost in qemu must resend all configuration on reconnect. Does this address the issues?

Yes, but the issues are
1) there is no reconnecting when a pmd exits (the socket connection seems still on at the device layer);

This is how real hardware works too. If the driver suddenly stops running then the device remains operational. When the driver is started again it resets the device and initializes it.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

2) If we find a way to break the QEMU layer socket connection when pmd exits and get it reconnect, virtio-net device still won't send all the configure when reconnecting, because socket connecting only triggers phase 1 of vhost-user negotiation (i.e. vhost_user_init). Phase 2 is triggered after the driver loads (i.e. vhost_net_start). If the virtio-net pmd doesn't reload, there are no phase 2 messages (like virtqueue addresses which are allocated by the pmd). I think we need to think more about this before

moving forward.

Quoted 6 lines
Quoted 6 lines

Marc-André: How does vhost-user reconnect work when the master goes away and a new master comes online? Wei found that the QEMU slave implementation only does partial vhost-user initialization upon reconnect, so the new master doesn't get the virtqueue address and

related information.

Quoted 3 lines
Quoted 1 line

Is this a QEMU bug?

Actually we are discussing the slave (vhost is the slave, right?) going away.

When a slave exits and some moment later a new slave runs, the master (virtio-net) won't send the virtqueue addresses to the new vhost slave.

Quoted 9 lines

Yes, apologies for the typo. s/QEMU slave/QEMU master/

Yesterday I asked Marc-André for help on IRC and we found the code
path where the QEMU master performs phase 2 negotiation upon
reconnect. It's not obvious but the qmp_set_link() calls in net_vhost_user_event() will do it.

I'm going to try to reproduce the issue you're seeing now. Will let you know what I find.

OK. Thanks. I observed no messages after re-run virtio-vhost-user pmd, and found there is no re-connection event happening in the device side.

I also tried to switch the role of client/server - virtio-net to run a server socket, and virtio-vhost-user to run the client, and it seems the current code fails to run that way. The reason is the virtio-net side vhost_user_get_features() doesn't return. On the vhost side, I don't see virtio_vhost_user_deliver_m2s being invoked to deliver the GET_FEATURES message. I'll come back to continue later.

Best,
Wei

#27 lore raw
Quoted 61 lines · Wei W
Quoted 60 lines · Stefan Hajnoczi
Quoted 30 lines · Wei W
Quoted 29 lines · Stefan Hajnoczi
Quoted 10 lines · Wei Wang
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Wei Wang

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost

pmd won't work.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Any thoughts?

Best,
Wei

Quoted 7 lines
Quoted 3 lines

So vhost in qemu must resend all configuration on reconnect. Does this address the issues?

Yes, but the issues are
1) there is no reconnecting when a pmd exits (the socket connection seems still on at the device layer);

This is how real hardware works too. If the driver suddenly stops running then the device remains operational. When the driver is started again it resets the device and initializes it.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

2) If we find a way to break the QEMU layer socket connection when pmd exits and get it reconnect, virtio-net device still won't send all the configure when reconnecting, because socket connecting only triggers phase 1 of vhost-user negotiation (i.e. vhost_user_init). Phase 2 is triggered after the driver loads (i.e. vhost_net_start). If the virtio-net pmd doesn't reload, there are no phase 2 messages (like virtqueue addresses which are allocated by the pmd). I think we need to think more about this before

moving forward.

Quoted 6 lines
Quoted 6 lines

Marc-André: How does vhost-user reconnect work when the master goes away and a new master comes online? Wei found that the QEMU slave implementation only does partial vhost-user initialization upon reconnect, so the new master doesn't get the virtqueue address and

related information.

Quoted 3 lines
Quoted 1 line

Is this a QEMU bug?

Actually we are discussing the slave (vhost is the slave, right?) going away.

When a slave exits and some moment later a new slave runs, the master (virtio-net) won't send the virtqueue addresses to the new vhost slave.

Yes, apologies for the typo. s/QEMU slave/QEMU master/

Yesterday I asked Marc-André for help on IRC and we found the code
path where the QEMU master performs phase 2 negotiation upon
reconnect. It's not obvious but the qmp_set_link() calls in net_vhost_user_event() will do it.

Quoted 7 lines
Quoted 3 lines

I'm going to try to reproduce the issue you're seeing now. Will let you know what I find.

OK. Thanks. I observed no messages after re-run virtio-vhost-user pmd, and found there is no re-connection event happening in the device side.

I also tried to switch the role of client/server - virtio-net to run a server socket, and virtio-vhost-user to run the client, and it seems the current code fails to run that way. The reason is the virtio-net side vhost_user_get_features() doesn't return. On the vhost side, I don't see virtio_vhost_user_deliver_m2s being invoked to deliver the GET_FEATURES message. I'll come back to continue later.

This morning I reached the conclusion that reconnection is currently broken in the QEMU vhost-user master. It's a bug in the QEMU vhost-user master implementation, not a design or protocol problem.

On my machine the following QEMU command-line does not launch because vhost-user.c gets stuck while trying to connect/negotiate:

  qemu -M accel=kvm -cpu host -m 1G \
       -object memory-backend-file,id=mem0,mem-path=/var/tmp/foo,size=1G,share=on \
       -numa node,memdev=mem0 \
       -drive if=virtio,file=test.img,format=raw \
       -chardev socket,id=chardev0,path=vhost-user.sock,reconnect=1 \
       -netdev vhost-user,chardev=chardev0,id=netdev0 \
       -device virtio-net-pci,netdev=netdev0

Commit c89804d674e4e3804bd3ac1fe79650896044b4e8 ("vhost-user: wait until backend init is completed") broke reconnect by introducing a call to qemu_chr_fe_wait_connected().

qemu_chr_fe_wait_connected() doesn't work together with -chardev ...,reconnect=1. This is because reconnect=1 connects asynchronously and then qemu_chr_fe_wait_connect() connects synchronously (if the async connect hasn't completed yet). This means there will be 2 sockets connecting to the vhost-user slave!

The virtio-vhost-user slave accepts the first connection but never receives any data because the QEMU master is trying to use the 2nd socket instead.

Reconnection probably worked when Marc-André implemented it since QEMU wasn't using qemu_chr_fe_wait_connected().

Marc-André: How do you think this should be fixed?

Stefan

#28 lore raw
In reply to Wei Wang
Quoted 75 lines · Wei Wang
Quoted 43 lines · Stefan Hajnoczi
Quoted 20 lines · Wei Wang
Quoted 19 lines · Stefan Hajnoczi
Quoted 18 lines · Wei Wang
Quoted 17 lines · Stefan Hajnoczi
Quoted 7 lines · Wei Wang

On 01/19/2018 09:06 PM, Stefan Hajnoczi wrote:

- Suppose in the future there is also a kernel virtio-vhost-user driver as
other PCI devices, can we unbind the kernel driver first, and then bind the device to the dpdk driver? A normal PCI device should be able to smoothly switch between the kernel driver and dpdk driver.

It depends what you mean by "smoothly switch".

If you mean whether it's possible to go from a kernel driver to vfio-pci, then the answer is yes.

But if the kernel driver has an established vhost-user connection then it will be closed. This is the same as reconnecting with AF_UNIX vhost-user.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Actually not only the case of switching to testpmd after kernel establishes the connection, but also for several runs of testpmd. That is, if we run testpmd, then exit testpmd. I think the second run of testpmd won't work.

The vhost-user master must reconnect and initialize again (SET_FEATURES, SET_MEM_TABLE, etc). Is your master reconnecting after the AF_UNIX connection is closed?

Is this an explicit qmp operation to make the master re-connect?

I haven't tested it myself but I'm aware of two modes of operation:

1. -chardev socket,id=chardev0,...,server
-netdev vhost-user,chardev=chardev0

When the vhost-user socket is disconnected the peer needs to reconnect. In this case no special commands are necessary.

Here we're relying on DPDK librte_vhost's reconnection behavior.

Or

2. -chardev socket,id=chardev0,...,reconnect=3
-netdev vhost-user,chardev=chardev0

Quoted 7 lines

When the vhost-user socket is disconnected a new connection attempt will be made after 3 seconds.

In both cases vhost-user negotiation will resume when the new connection is established.

Stefan

I've been thinking about the issues, and it looks vhost-pci outperforms in this aspect.
Vhost-pci is like using a mail box. messages are just dropped into the box, and whenever vhost-pci pmd gets booted, it can always get the messages from the box, the negotiation between vhost-pci pmd and virtio-net is asynchronous.
Virtio-vhost-user is like a phone call, which is a synchronous communication. If one side is absent, then the other side will hang on without knowing when it could get connected or hang up with messages not passed (lost).

I also think the above solutions won't help. Please see below:

Background:
The vhost-user negotiation is split into 2 phases currently. The 1st phase happens when the connection is established, and we can find what's done in the 1st phase in vhost_user_init(). The 2nd phase happens when the master driver is loaded (e.g. run of virtio-net pmd) and set status to the device, and we can find what's done in the 2nd phase in vhost_dev_start(), which includes sending the memory info and virtqueue info. The socket is connected, till one of the QEMU devices exits, so pmd exiting won't end the QEMU side socket connection.

Quoted 7 lines

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost pmd won't work.

This isn't a problem for virtio-vhost-user since the vhost-pmd resets the virtio-vhost-user device when it restarts. The vhost-user AF_UNIX socket reconnects and negotiation restarts.

Stefan

#29 lore raw
Quoted 19 lines · Stefan Hajnoczi
Quoted 10 lines · Wei Wang

Background:
The vhost-user negotiation is split into 2 phases currently. The 1st phase happens when the connection is established, and we can find what's done in the 1st phase in vhost_user_init(). The 2nd phase happens when the master driver is loaded (e.g. run of virtio-net pmd) and set status to the device, and we can find what's done in the 2nd phase in vhost_dev_start(), which includes sending the memory info and virtqueue info. The socket is connected, till one of the QEMU devices exits, so pmd exiting won't end the QEMU side socket connection.

Quoted 7 lines

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost pmd won't work.

Quoted 3 lines

This isn't a problem for virtio-vhost-user since the vhost-pmd resets the virtio-vhost-user device when it restarts. The vhost-user AF_UNIX socket reconnects and negotiation restarts.

I'm not sure if you've agreed that vhost-user negotiation is split into two phases as described above. If not, it's also not difficult to check, thanks to the RTE_LOG put at the vhost_user_msg_handler:
RTE_LOG(INFO, VHOST_CONFIG, "read message %s\n",

                        vhost_message_str[msg.request.master]);

It tells us what messages are received and when they are received.

Before trying the virtio-vhost-user setup, please make sure the virtio-net side VM doesn't have the virtio-net kernel driver loaded (blacklist the module or disable it in .config).
VM1: the VM with virtio-vhost-user
VM2: the VM with virtio-net

1) After we boot VM1 and the virtio-vhost-user pmd, we boot VM2, and we will see the following log in VM1:
VHOST_CONFIG: new device, handle is 0
VHOST_CONFIG: read message VHOST_USER_GET_FEATURES
VHOST_CONFIG: read message VHOST_USER_GET_PROTOCOL_FEATURES
VHOST_CONFIG: read message VHOST_USER_SET_PROTOCOL_FEATURES
VHOST_CONFIG: read message VHOST_USER_GET_QUEUE_NUM
VHOST_CONFIG: read message VHOST_USER_SET_OWNER
VHOST_CONFIG: read message VHOST_USER_GET_FEATURES
VHOST_CONFIG: read message VHOST_USER_SET_VRING_CALL
VHOST_CONFIG: vring call idx:0 file:-1
VHOST_CONFIG: read message VHOST_USER_SET_VRING_CALL
VHOST_CONFIG: vring call idx:1 file:-1

Those messages are what I called phase1 negotiation. They are negotiated when the AF_UNIX socket connects.

2) Then in VM2 we load the virtio-net pmd, we will see phase2 messages showing up in VM1, like:
VHOST_CONFIG: read message VHOST_USER_SET_VRING_NUM
VHOST_CONFIG: read message VHOST_USER_SET_VRING_BASE
VHOST_CONFIG: read message VHOST_USER_SET_VRING_ADDR
...
Those messages are sent to virtio-vhost-user only when the VM2's virtio-net pmd loads.

AF_UNIX socket reconnection only triggers phase1 negotiation. If virtio-net pmd in VM2 doesn't reload, virtio-vhost-user pmd won't get the above phase2 messages. Do you agree with the issue?

Best,
Wei

#30 lore raw
Quoted 48 lines · Wei W
Quoted 19 lines · Stefan Hajnoczi
Quoted 10 lines · Wei Wang

Background:
The vhost-user negotiation is split into 2 phases currently. The 1st phase happens when the connection is established, and we can find what's done in the 1st phase in vhost_user_init(). The 2nd phase happens when the master driver is loaded (e.g. run of virtio-net pmd) and set status to the device, and we can find what's done in the 2nd phase in vhost_dev_start(), which includes sending the memory info and virtqueue info. The socket is connected, till one of the QEMU devices exits, so pmd exiting won't end the QEMU side socket connection.

Quoted 7 lines

Issues:
Suppose we have both the vhost and virtio-net set up, and vhost pmd <-> virtio-net pmd communication works well. Now, vhost pmd exits (virtio-net pmd is still there). Some time later, we re-run vhost pmd, the vhost pmd doesn't know the virtqueue addresses of the virtio-net pmd, unless the virtio-net pmd reloads to start the 2nd phase of the vhost-user protocol. So the second run of the vhost pmd won't work.

Quoted 3 lines

This isn't a problem for virtio-vhost-user since the vhost-pmd resets the virtio-vhost-user device when it restarts. The vhost-user AF_UNIX socket reconnects and negotiation restarts.

I'm not sure if you've agreed that vhost-user negotiation is split into two phases as described above. If not, it's also not difficult to check, thanks to the RTE_LOG put at the vhost_user_msg_handler:
RTE_LOG(INFO, VHOST_CONFIG, "read message %s\n",

                        vhost_message_str[msg.request.master]);

It tells us what messages are received and when they are received.

Before trying the virtio-vhost-user setup, please make sure the virtio-net side VM doesn't have the virtio-net kernel driver loaded (blacklist the module or disable it in .config).
VM1: the VM with virtio-vhost-user
VM2: the VM with virtio-net

1) After we boot VM1 and the virtio-vhost-user pmd, we boot VM2, and we will see the following log in VM1:
VHOST_CONFIG: new device, handle is 0
VHOST_CONFIG: read message VHOST_USER_GET_FEATURES
VHOST_CONFIG: read message VHOST_USER_GET_PROTOCOL_FEATURES
VHOST_CONFIG: read message VHOST_USER_SET_PROTOCOL_FEATURES
VHOST_CONFIG: read message VHOST_USER_GET_QUEUE_NUM
VHOST_CONFIG: read message VHOST_USER_SET_OWNER
VHOST_CONFIG: read message VHOST_USER_GET_FEATURES
VHOST_CONFIG: read message VHOST_USER_SET_VRING_CALL
VHOST_CONFIG: vring call idx:0 file:-1
VHOST_CONFIG: read message VHOST_USER_SET_VRING_CALL
VHOST_CONFIG: vring call idx:1 file:-1

Those messages are what I called phase1 negotiation. They are negotiated when the AF_UNIX socket connects.

Quoted 8 lines

2) Then in VM2 we load the virtio-net pmd, we will see phase2 messages showing up in VM1, like:
VHOST_CONFIG: read message VHOST_USER_SET_VRING_NUM
VHOST_CONFIG: read message VHOST_USER_SET_VRING_BASE
VHOST_CONFIG: read message VHOST_USER_SET_VRING_ADDR
...
Those messages are sent to virtio-vhost-user only when the VM2's virtio-net pmd loads.

AF_UNIX socket reconnection only triggers phase1 negotiation. If virtio-net pmd in VM2 doesn't reload, virtio-vhost-user pmd won't get the above phase2 messages. Do you agree with the issue?

I'll reply on the subthread with Michael where you posted a similar response.

Stefan