vhost: add virtio-vhost-user transport
Subsystems (2)
cover vhost: add virtio-vhost-user transport
This patch series implements the virtio-vhost-user device, which tunnels vhost-user protocol messages over virtio. This lets guests act as vhost device backends for other guests.
The virtio-vhost-user device is the result of discussion about Wei Wang and Zhiyong Yang's vhost-pci device. This patch series demonstrates that vhost device backends, such as the vhost vdev driver, can work over both AF_UNIX and virtio-vhost-user without significant modifications. This allows a lot of code to be shared between traditional AF_UNIX vhost-user and virtio-vhost-user. The vhost-pci patches duplicated the vhost net device backend and didn't reuse librte_vhost:
http://dpdk.org/ml/archives/dev/2017-November/082615.html
User-visible changes
--------------------
The vhost vdev can now be used when DPDK runs inside a guest with a virtio-vhost-user PCI device:
--vdev net_vhost0,iface="0000:00:04.0",virtio-transport=1
The vhost-scsi example has also been extended to support virtio-vhost-user:
./vhost-scsi ... -- --virtio-vhost-user-pci "0000:00:04.0"
For more information (including instructions for running the code), see
https://wiki.qemu.org/Features/VirtioVhostUser
Virtio device design
--------------------
The virtio-vhost-user device is a new virtio device type. It acts as a vhost-user transport and is an alternative for the traditional AF_UNIX transport.
You can find the virtio-vhost-user VIRTIO device specification here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007
librte_vhost API changes
------------------------
This patch series extends librte_vhost so that it now accepts:
rte_vhost_driver_register("0000:00:04.0",
RTE_VHOST_USER_VIRTIO_TRANSPORT);
All other librte_vhost API usage remains unchanged, except that the file descriptors exposed in some <rte_vhost.h> structs will be -1 since there is no file descriptor passing involved.
This makes it extremely easy to support virtio-vhost-user in existing vhost device backends! I have extended the vhost vdev driver and the vhost-scsi example application in this patch series.
Patch series overview
---------------------
This series is based on commit 814339ba7eea13d132508af2cccec2f73568e2d0 from dpdk-next-virtio/master. You can also get my git branch here:
https://github.com/stefanha/dpdk/tree/virtio-vhost-user
The initial patches refactor librte_vhost so that AF_UNIX-specific code is moved to a new trans_af_unix.c file. This also introduces a struct vhost_transport_ops interface that all transports will implement:
adf412c3c vhost: move vring_call() into trans_af_unix.c 04079a077 vhost: move AF_UNIX code from socket.c to trans_af_unix.c 885642091 vhost: allocate per-socket transport state
9c48377df vhost: move socket_fd and un sockaddr into trans_af_unix.c c646e6292 vhost: move start_server/client() calls to trans_af_unix.c db07ef7a8 vhost: move vhost_user_connection to trans_af_unix.c d10b80163 vhost: move vhost_user_reconnect_init() into trans_af_unix.c 1258bcd68 vhost: move vhost_user.fdset to trans_af_unix.c bc7f6d7ab vhost: pass vhost_transport_ops through vhost_new_device() b82187a29 vhost: embed struct virtio_net inside struct vhost_user_connection abbd544f2 vhost: extract vhost_user.c socket I/O into transport 0658d711b vhost: move slave_req_fd field to AF_UNIX transport e2ecf78ed vhost: move mmap/munmap to AF_UNIX transport
I was about to add the virtio-vhost-user PCI driver when I realized that lib/librte_vhost/ cannot have a dependency on rte_bus_pci.h (it lives in drivers/). The solution I chose is to move all of librte_vhost to drivers/librte_vhost/, but I'm open to suggestions if this is undesirable.
8615c2140 vhost: move librte_vhost to drivers/
Since virtio-vhost-user is a virtio device it's necessary to perform a sequence of device initialization steps and set up virtqueues. I didn't see a virtio API in DPDK and didn't have time to create one myself. I copied the virtio code from drivers/net/virtio/ as a quick hack, but really there needs to be a librte_virtio that is shared.
c26937c66 vhost: add virtio pci framework
Next the virtio-vhost-user transport is added along with the RTE_VHOST_USER_VIRTIO_TRANSPORT flag:
7fad5adc4 vhost: remember a vhost_virtqueue's queue index d26922892 vhost: add virtio-vhost-user transport f562a70ab vhost: add RTE_VHOST_USER_VIRTIO_TRANSPORT flag
Then I extended the vhost vdev and vhost-scsi example application to support virtio-vhost-user:
47434f2a2 net/vhost: add virtio-vhost-user support 22ca05d1b examples/vhost_scsi: add --socket-file argument db3b391dc examples/vhost_scsi: add virtio-vhost-user support
It was also necessary to tweak dpdk-devbind.py to support virtio-vhost-user:
4aee6f653 usertools: add virtio-vhost-user devices to dpdk-devbind.py
Finally, vhost-scsi seems broken to me so two workarounds were needed so it can be tested again:
b9d17bfaf WORKAROUND revert virtio-net mq vring deletion cadb25e7d WORKAROUND examples/vhost_scsi: avoid broken EVENT_IDX
Stefan Hajnoczi (24):
vhost: move vring_call() into trans_af_unix.c
vhost: move AF_UNIX code from socket.c to trans_af_unix.c
vhost: allocate per-socket transport state
vhost: move socket_fd and un sockaddr into trans_af_unix.c
vhost: move start_server/client() calls to trans_af_unix.c
vhost: move vhost_user_connection to trans_af_unix.c
vhost: move vhost_user_reconnect_init() into trans_af_unix.c
vhost: move vhost_user.fdset to trans_af_unix.c
vhost: pass vhost_transport_ops through vhost_new_device()
vhost: embed struct virtio_net inside struct vhost_user_connection
vhost: extract vhost_user.c socket I/O into transport
vhost: move slave_req_fd field to AF_UNIX transport
vhost: move mmap/munmap to AF_UNIX transport
vhost: move librte_vhost to drivers/
vhost: add virtio pci framework
vhost: remember a vhost_virtqueue's queue index
vhost: add virtio-vhost-user transport
vhost: add RTE_VHOST_USER_VIRTIO_TRANSPORT flag net/vhost: add virtio-vhost-user support examples/vhost_scsi: add --socket-file argument examples/vhost_scsi: add virtio-vhost-user support
usertools: add virtio-vhost-user devices to dpdk-devbind.py WORKAROUND revert virtio-net mq vring deletion WORKAROUND examples/vhost_scsi: avoid broken EVENT_IDX
drivers/Makefile | 2 +
{lib => drivers}/librte_vhost/Makefile | 5 +-
lib/Makefile | 3 -
{lib => drivers}/librte_vhost/fd_man.h | 0
{lib => drivers}/librte_vhost/iotlb.h | 0
{lib => drivers}/librte_vhost/rte_vhost.h | 1 +
{lib => drivers}/librte_vhost/vhost.h | 193 +++-
{lib => drivers}/librte_vhost/vhost_user.h | 9 +-
drivers/librte_vhost/virtio_pci.h | 267 +++++
drivers/librte_vhost/virtio_vhost_user.h | 18 +
drivers/librte_vhost/virtqueue.h | 181 ++++
{lib => drivers}/librte_vhost/fd_man.c | 0
{lib => drivers}/librte_vhost/iotlb.c | 0
drivers/librte_vhost/socket.c | 282 ++++++
drivers/librte_vhost/trans_af_unix.c | 795 +++++++++++++++
drivers/librte_vhost/trans_virtio_vhost_user.c | 1050 ++++++++++++++++++++
{lib => drivers}/librte_vhost/vhost.c | 18 +-
{lib => drivers}/librte_vhost/vhost_user.c | 200 +---
{lib => drivers}/librte_vhost/virtio_net.c | 0
drivers/librte_vhost/virtio_pci.c | 504 ++++++++++
drivers/net/vhost/rte_eth_vhost.c | 13 +
examples/vhost_scsi/vhost_scsi.c | 104 +-
lib/librte_vhost/socket.c | 828 ---------------
.../librte_vhost/rte_vhost_version.map | 0
usertools/dpdk-devbind.py | 8 +
25 files changed, 3455 insertions(+), 1026 deletions(-)
rename {lib => drivers}/librte_vhost/Makefile (86%)
rename {lib => drivers}/librte_vhost/fd_man.h (100%)
rename {lib => drivers}/librte_vhost/iotlb.h (100%)
rename {lib => drivers}/librte_vhost/rte_vhost.h (99%)
rename {lib => drivers}/librte_vhost/vhost.h (68%)
rename {lib => drivers}/librte_vhost/vhost_user.h (93%)
create mode 100644 drivers/librte_vhost/virtio_pci.h
create mode 100644 drivers/librte_vhost/virtio_vhost_user.h
create mode 100644 drivers/librte_vhost/virtqueue.h
rename {lib => drivers}/librte_vhost/fd_man.c (100%)
rename {lib => drivers}/librte_vhost/iotlb.c (100%)
create mode 100644 drivers/librte_vhost/socket.c
create mode 100644 drivers/librte_vhost/trans_af_unix.c
create mode 100644 drivers/librte_vhost/trans_virtio_vhost_user.c
rename {lib => drivers}/librte_vhost/vhost.c (97%)
rename {lib => drivers}/librte_vhost/vhost_user.c (89%)
rename {lib => drivers}/librte_vhost/virtio_net.c (100%)
create mode 100644 drivers/librte_vhost/virtio_pci.c
delete mode 100644 lib/librte_vhost/socket.c
rename {lib => drivers}/librte_vhost/rte_vhost_version.map (100%)Signature · 1 line
2.14.3
RFC 1/24 vhost: move vring_call() into trans_af_unix.c
File descriptor passing is specific to the AF_UNIX vhost-user protocol transport. In order to add support for additional transports it is necessary to extract transport-specific code from the main vhost-user code.
This patch introduces struct vhost_transport_ops and associates each device with a transport. Core vhost-user code calls into vhost_transport_ops to perform transport-specific operations.
Notifying callfd is a transport-specific operation so it belongs in trans_af_unix.c.
Several more patches follow this one to complete the task of moving AF_UNIX transport code out of core vhost-user code.
--- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/vhost.h | 35 +++++++++++++++++++++++----- lib/librte_vhost/trans_af_unix.c | 49 ++++++++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 1 + 4 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 lib/librte_vhost/trans_af_unix.c
lib/librte_vhost/Makefile +1 -1
@@ -21,7 +21,7 @@ LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev -lrte_net # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \ - vhost_user.c virtio_net.c + vhost_user.c virtio_net.c trans_af_unix.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h
lib/librte_vhost/vhost.h +29 -6
@@ -200,6 +200,30 @@ struct guest_page {uint64_t size; }; +struct virtio_net ; + +/** +* A structure containing function pointers for transport-specific operations. +*/ +struct vhost_transport_ops { +/** +* Notify the guest that used descriptors have been added to the vring. +* The VRING_AVAIL_F_NO_INTERRUPT flag has already been checked so this +* function just needs to perform the notification. +* +* @param dev +* vhost device +* @param vq +* vhost virtqueue +* @return +* 0 on success, -1 on failure +*/ +int (*vring_call)(struct virtio_net *dev,struct vhost_virtqueue *vq); +}; + +/** The traditional AF_UNIX vhost-user protocol transport. */ +extern const struct vhost_transport_ops af_unix_trans_ops; +/** * Device structure contains all configuration information relating * to the device.
@@ -226,6 +250,7 @@ struct virtio_net {uint16_t mtu;struct vhost_device_ops const *notify_ops; +struct vhost_transport_ops const *trans_ops;uint32_t nr_guest_pages;uint32_t max_guest_pages;
@@ -405,16 +430,14 @@ vhost_vring_call(struct virtio_net *dev, struct vhost_virtqueue *vq) __func__,vhost_used_event (vq), old, new); -if (vhost_need_event (vhost_used_event (vq), new, old) - && (vq->callfd >=0 )) { +if (vhost_need_event (vhost_used_event (vq), new, old)) { vq->signalled_used = vq->last_used_idx; -eventfd_write (vq->callfd, (eventfd_t )1 ); + dev->trans_ops->vring_call (dev, vq); } }else {/* Kick the guest if necessary. */ -if (!(vq->avail->flags &VRING_AVAIL_F_NO_INTERRUPT ) - && (vq->callfd >=0 )) -eventfd_write (vq->callfd, (eventfd_t )1 ); +if (!(vq->avail->flags &VRING_AVAIL_F_NO_INTERRUPT )) + dev->trans_ops->vring_call (dev, vq); } }
lib/librte_vhost/trans_af_unix.c new file +49 -0
49 lines not on this page · raw message
lib/librte_vhost/vhost.c +1 -0
@@ -287,6 +287,7 @@ vhost_new_device(void) vhost_devices[i] = dev; dev->vid = i; dev->slave_req_fd =-1 ; + dev->trans_ops = &af_unix_trans_ops;return i; }
Signature · 1 line
2.14.3
RFC 2/24 vhost: move AF_UNIX code from socket.c to trans_af_unix.c
In reply to Stefan HajnocziThe socket.c file serves two purposes:
1. librte_vhost public API entry points, e.g. rte_vhost_driver_register().
2. AF_UNIX socket management.
Move AF_UNIX socket code into trans_af_unix.c so that socket.c only handles the librte_vhost public API entry points. This will make it possible to support other transports besides AF_UNIX.
This patch is a preparatory step that simply moves code from socket.c to trans_af_unix.c unmodified, besides dropping 'static' qualifiers where necessary because socket.c now calls into trans_af_unix.c.
A lot of socket.c state is exposed in vhost.h but this is a temporary measure and will be cleaned up in later patches. By simply moving code unmodified in this patch it will be easier to review the actual refactoring that follows.
--- lib/librte_vhost/vhost.h | 65 +++++ lib/librte_vhost/socket.c | 501 +-------------------------------------- lib/librte_vhost/trans_af_unix.c | 451 +++++++++++++++++++++++++++++++++++ 3 files changed, 517 insertions(+), 500 deletions(-)
lib/librte_vhost/vhost.h +65 -0
@@ -5,6 +5,7 @@#ifndef _VHOST_NET_CDEV_H_#define _VHOST_NET_CDEV_H_#include <stdint.h> +#include <stdbool.h> #include <stdio.h> #include <sys/types.h> #include <sys/queue.h>
@@ -12,12 +13,15 @@#include <linux/vhost.h> #include <linux/virtio_net.h> #include <sys/socket.h> +#include <sys/un.h> /* TODO remove when trans_af_unix.c refactoring is done */ #include <linux/if.h> +#include <pthread.h> #include <rte_log.h> #include <rte_ether.h> #include <rte_rwlock.h> +#include "fd_man.h" #include "rte_vhost.h" /* Used to indicate that the device is running on a data core */
@@ -259,6 +263,67 @@ struct virtio_net {int slave_req_fd; } __rte_cache_aligned; +/* The vhost_user, vhost_user_socket, vhost_user_connection, and reconnect +* declarations are temporary measures for moving AF_UNIX code into +* trans_af_unix.c. They will be cleaned up as socket.c is untangled from +* trans_af_unix.c. +*/ +TAILQ_HEAD (vhost_user_connection_list, vhost_user_connection); + +/* +* Every time rte_vhost_driver_register() is invoked, an associated +* vhost_user_socket struct will be created. +*/ +struct vhost_user_socket { +struct vhost_user_connection_list conn_list; +pthread_mutex_t conn_mutex; +char *path; +int socket_fd; +struct sockaddr_un un; +bool is_server; +bool reconnect; +bool dequeue_zero_copy; +bool iommu_support; + +/* +* The "supported_features" indicates the feature bits the +* vhost driver supports. The "features" indicates the feature +* bits after the rte_vhost_driver_features_disable/enable(). +* It is also the final feature bits used for vhost-user +* features negotiation. +*/ +uint64_t supported_features; +uint64_t features; + +struct vhost_device_ops const *notify_ops; +}; + +struct vhost_user_connection { +struct vhost_user_socket *vsocket; +int connfd; +int vid; + +TAILQ_ENTRY (vhost_user_connection) next; +}; + +#define MAX_VHOST_SOCKET 1024 +struct vhost_user { +struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET ]; +struct fdset fdset; +int vsocket_cnt; +pthread_mutex_t mutex; +}; + +extern struct vhost_user vhost_user; + +int create_unix_socket (struct vhost_user_socket *vsocket); +int vhost_user_start_server (struct vhost_user_socket *vsocket); +int vhost_user_start_client (struct vhost_user_socket *vsocket); + +extern pthread_t reconn_tid; + +int vhost_user_reconnect_init (void ); +bool vhost_user_remove_reconnect (struct vhost_user_socket *vsocket);#define VHOST_LOG_PAGE 4096
lib/librte_vhost/socket.c +1 -500
533 lines not on this page · raw message
lib/librte_vhost/trans_af_unix.c +451 -0
458 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC 3/24 vhost: allocate per-socket transport state
In reply to Stefan Hajnoczivhost-user transports have per-socket state (like file descriptors). Make it possible for transports to keep state beyond what is included in struct vhost_user_socket.
This patch makes it possible to move AF_UNIX-specific fields from struct vhost_user_socket into trans_af_unix.c in later patches.
--- lib/librte_vhost/vhost.h | 9 +++++++++ lib/librte_vhost/socket.c | 6 ++++-- lib/librte_vhost/trans_af_unix.c | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-)
lib/librte_vhost/vhost.h +9 -0
@@ -210,6 +210,9 @@ struct virtio_net;* A structure containing function pointers for transport-specific operations. */ struct vhost_transport_ops { +/** Size of struct vhost_user_socket-derived per-socket state */ +size_t socket_size; +/** * Notify the guest that used descriptors have been added to the vring. * The VRING_AVAIL_F_NO_INTERRUPT flag has already been checked so this
@@ -273,6 +276,11 @@ TAILQ_HEAD(vhost_user_connection_list, vhost_user_connection);/* * Every time rte_vhost_driver_register() is invoked, an associated * vhost_user_socket struct will be created. +* +* Transport-specific per-socket state can be kept by embedding this struct at +* the beginning of a transport-specific struct. Set +* vhost_transport_ops->socket_size to the size of the transport-specific +* struct. */ struct vhost_user_socket {struct vhost_user_connection_list conn_list;
@@ -296,6 +304,7 @@ struct vhost_user_socket {uint64_t features;struct vhost_device_ops const *notify_ops; +struct vhost_transport_ops const *trans_ops; };struct vhost_user_connection {
lib/librte_vhost/socket.c +4 -2
@@ -128,6 +128,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) {int ret =-1 ;struct vhost_user_socket *vsocket; +const struct vhost_transport_ops *trans_ops = &af_unix_trans_ops;if (!path)return -1 ;
@@ -140,10 +141,11 @@ rte_vhost_driver_register(const char *path, uint64_t flags) goto out; } - vsocket =malloc (sizeof (struct vhost_user_socket )); + vsocket =malloc (trans_ops->socket_size);if (!vsocket) goto out; -memset (vsocket,0 ,sizeof (struct vhost_user_socket )); +memset (vsocket,0 , trans_ops->socket_size); + vsocket->trans_ops = trans_ops; vsocket->path =strdup (path);if (vsocket->path ==NULL ) { RTE_LOG(ERR, VHOST_CONFIG,
lib/librte_vhost/trans_af_unix.c +5 -0
@@ -42,6 +42,10 @@#define MAX_VIRTIO_BACKLOG 128 +struct af_unix_socket { +struct vhost_user_socket socket;/* must be the first field! */ +}; +static void vhost_user_read_cb (int connfd,void *dat,int *remove);/* return bytes# of read on success or negative val on failure. */
@@ -496,5 +500,6 @@ af_unix_vring_call(struct virtio_net *dev __rte_unused, }const struct vhost_transport_ops af_unix_trans_ops = { + .socket_size =sizeof (struct af_unix_socket ), .vring_call = af_unix_vring_call, };
Signature · 1 line
2.14.3
RFC 4/24 vhost: move socket_fd and un sockaddr into trans_af_unix.c
In reply to Stefan HajnocziThe socket file descriptor and AF_UNIX sockaddr are specific to the AF_UNIX transport, so move them into trans_af_unix.c.
In order to do this we need to begin defining the vhost_transport_ops interface that will allow librte_vhost to support multiple transports. This patch adds socket_init() and socket_cleanup() to vhost_transport_ops.
--- lib/librte_vhost/vhost.h | 31 +++++++++++++++++----- lib/librte_vhost/socket.c | 10 ++------ lib/librte_vhost/trans_af_unix.c | 55 ++++++++++++++++++++++++++++++++-------- 3 files changed, 72 insertions(+), 24 deletions(-)
lib/librte_vhost/vhost.h +25 -6
@@ -12,8 +12,6 @@#include <unistd.h> #include <linux/vhost.h> #include <linux/virtio_net.h> -#include <sys/socket.h> -#include <sys/un.h> /* TODO remove when trans_af_unix.c refactoring is done */ #include <linux/if.h> #include <pthread.h>
@@ -205,6 +203,7 @@ struct guest_page { };struct virtio_net ; +struct vhost_user_socket ;/** * A structure containing function pointers for transport-specific operations.
@@ -213,6 +212,30 @@ struct vhost_transport_ops {/** Size of struct vhost_user_socket-derived per-socket state */ size_t socket_size; +/** +* Initialize a vhost-user socket that is being created by +* rte_vhost_driver_register(). This function checks that the flags +* are valid but does not establish a vhost-user connection. +* +* @param vsocket +* new socket +* @param flags +* flags argument from rte_vhost_driver_register() +* @return +* 0 on success, -1 on failure +*/ +int (*socket_init)(struct vhost_user_socket *vsocket,uint64_t flags); + +/** +* Free resources associated with a socket, including any established +* connections. This function calls vhost_destroy_device() to destroy +* established connections for this socket. +* +* @param vsocket +* vhost socket +*/ +void (*socket_cleanup)(struct vhost_user_socket *vsocket); +/** * Notify the guest that used descriptors have been added to the vring. * The VRING_AVAIL_F_NO_INTERRUPT flag has already been checked so this
@@ -286,8 +309,6 @@ struct vhost_user_socket {struct vhost_user_connection_list conn_list;pthread_mutex_t conn_mutex;char *path; -int socket_fd; -struct sockaddr_un un;bool is_server;bool reconnect;bool dequeue_zero_copy;
@@ -325,14 +346,12 @@ struct vhost_user {extern struct vhost_user vhost_user; -int create_unix_socket (struct vhost_user_socket *vsocket);int vhost_user_start_server (struct vhost_user_socket *vsocket);int vhost_user_start_client (struct vhost_user_socket *vsocket);extern pthread_t reconn_tid;int vhost_user_reconnect_init (void ); -bool vhost_user_remove_reconnect (struct vhost_user_socket *vsocket);#define VHOST_LOG_PAGE 4096
lib/librte_vhost/socket.c +2 -8
@@ -191,7 +191,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) }else { vsocket->is_server = true; } - ret =create_unix_socket (vsocket); + ret = trans_ops->socket_init (vsocket, flags);if (ret <0 ) { goto out_mutex; }
@@ -231,13 +231,7 @@ rte_vhost_driver_unregister(const char *path)struct vhost_user_socket *vsocket = vhost_user.vsockets[i];if (!strcmp (vsocket->path, path)) { -if (vsocket->is_server) { -fdset_del (&vhost_user.fdset, vsocket->socket_fd); -close (vsocket->socket_fd); -unlink (path); - }else if (vsocket->reconnect) { -vhost_user_remove_reconnect (vsocket); - } + vsocket->trans_ops->socket_cleanup (vsocket);pthread_mutex_lock (&vsocket->conn_mutex); for (conn = TAILQ_FIRST(&vsocket->conn_list);
lib/librte_vhost/trans_af_unix.c +45 -10
126 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC 5/24 vhost: move start_server/client() calls to trans_af_unix.c
In reply to Stefan HajnocziIntroduce a vhost_transport_ops->socket_start() interface so the transport can begin establishing vhost-user connections. This is part of the AF_UNIX transport refactoring and removes AF_UNIX code from vhost.h and socket.c.
--- lib/librte_vhost/vhost.h | 16 +++++++++++++--- lib/librte_vhost/socket.c | 5 +---- lib/librte_vhost/trans_af_unix.c | 16 ++++++++++++++-- 3 files changed, 28 insertions(+), 9 deletions(-)
lib/librte_vhost/vhost.h +13 -3
@@ -236,6 +236,19 @@ struct vhost_transport_ops {*/ void (*socket_cleanup)(struct vhost_user_socket *vsocket); +/** +* Start establishing vhost-user connections. This function is +* asynchronous and connections may be established after it has +* returned. Call vhost_user_add_connection() to register new +* connections. +* +* @param vsocket +* vhost socket +* @return +* 0 on success, -1 on failure +*/ +int (*socket_start)(struct vhost_user_socket *vsocket); +/** * Notify the guest that used descriptors have been added to the vring. * The VRING_AVAIL_F_NO_INTERRUPT flag has already been checked so this
@@ -346,9 +359,6 @@ struct vhost_user {extern struct vhost_user vhost_user; -int vhost_user_start_server (struct vhost_user_socket *vsocket); -int vhost_user_start_client (struct vhost_user_socket *vsocket); -extern pthread_t reconn_tid;int vhost_user_reconnect_init (void );
lib/librte_vhost/socket.c +1 -4
@@ -318,8 +318,5 @@ rte_vhost_driver_start(const char *path) "failed to create fdset handling thread"); } -if (vsocket->is_server) -return vhost_user_start_server (vsocket); -else -return vhost_user_start_client (vsocket); +return vsocket->trans_ops->socket_start (vsocket); }
lib/librte_vhost/trans_af_unix.c +14 -2
@@ -51,6 +51,8 @@ struct af_unix_socket { };static int create_unix_socket (struct vhost_user_socket *vsocket); +static int vhost_user_start_server (struct vhost_user_socket *vsocket); +static int vhost_user_start_client (struct vhost_user_socket *vsocket);static void vhost_user_read_cb (int connfd,void *dat,int *remove);/* return bytes# of read on success or negative val on failure. */
@@ -276,7 +278,7 @@ create_unix_socket(struct vhost_user_socket *vsocket)return 0 ; } -int +static int vhost_user_start_server (struct vhost_user_socket *vsocket) { struct af_unix_socket *s =
@@ -433,7 +435,7 @@ vhost_user_reconnect_init(void)return ret; } -int +static int vhost_user_start_client (struct vhost_user_socket *vsocket) { struct af_unix_socket *s =
@@ -523,6 +525,15 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket) } } +static int +af_unix_socket_start (struct vhost_user_socket *vsocket) +{ +if (vsocket->is_server) +return vhost_user_start_server (vsocket); +else +return vhost_user_start_client (vsocket); +} +static int af_unix_vring_call(struct virtio_net *dev __rte_unused,struct vhost_virtqueue *vq)
@@ -536,5 +547,6 @@ const struct vhost_transport_ops af_unix_trans_ops = { .socket_size = sizeof(struct af_unix_socket), .socket_init = af_unix_socket_init, .socket_cleanup = af_unix_socket_cleanup, + .socket_start = af_unix_socket_start, .vring_call = af_unix_vring_call, };
Signature · 1 line
2.14.3
RFC 6/24 vhost: move vhost_user_connection to trans_af_unix.c
In reply to Stefan HajnocziThe AF_UNIX transport can accept multiple client connections on a server socket. Each connection instantiates a separate vhost-user device, which is stored as a vhost_user_connection. This behavior is specific to AF_UNIX and other transports may not support N connections per socket endpoint.
Move struct vhost_user_connection to trans_af_unix.c and conn_list/conn_mutex into struct af_unix_socket.
--- lib/librte_vhost/vhost.h | 19 ++----------- lib/librte_vhost/socket.c | 36 ++---------------------- lib/librte_vhost/trans_af_unix.c | 60 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 56 deletions(-)
lib/librte_vhost/vhost.h +3 -16
@@ -302,13 +302,10 @@ struct virtio_net {int slave_req_fd; } __rte_cache_aligned; -/* The vhost_user, vhost_user_socket, vhost_user_connection, and reconnect -* declarations are temporary measures for moving AF_UNIX code into -* trans_af_unix.c. They will be cleaned up as socket.c is untangled from -* trans_af_unix.c. +/* The vhost_user, vhost_user_socket, and reconnect declarations are temporary +* measures for moving AF_UNIX code into trans_af_unix.c. They will be cleaned +* up as socket.c is untangled from trans_af_unix.c. */ -TAILQ_HEAD (vhost_user_connection_list, vhost_user_connection); -/* * Every time rte_vhost_driver_register() is invoked, an associated * vhost_user_socket struct will be created.
@@ -319,8 +316,6 @@ TAILQ_HEAD(vhost_user_connection_list, vhost_user_connection);* struct. */ struct vhost_user_socket { -struct vhost_user_connection_list conn_list; -pthread_mutex_t conn_mutex;char *path;bool is_server;bool reconnect;
@@ -341,14 +336,6 @@ struct vhost_user_socket {struct vhost_transport_ops const *trans_ops; }; -struct vhost_user_connection { -struct vhost_user_socket *vsocket; -int connfd; -int vid; - -TAILQ_ENTRY (vhost_user_connection) next; -}; -#define MAX_VHOST_SOCKET 1024struct vhost_user {struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET ];
lib/librte_vhost/socket.c +2 -34
@@ -153,13 +153,6 @@ rte_vhost_driver_register(const char *path, uint64_t flags)free (vsocket); goto out; } -TAILQ_INIT (&vsocket->conn_list); - ret =pthread_mutex_init (&vsocket->conn_mutex,NULL ); -if (ret) { -RTE_LOG (ERR ,VHOST_CONFIG , -"error: failed to init connection mutex\n" ); - goto out_free; - } vsocket->dequeue_zero_copy = flags &RTE_VHOST_USER_DEQUEUE_ZERO_COPY ;/*
@@ -186,14 +179,14 @@ rte_vhost_driver_register(const char *path, uint64_t flags) vsocket->reconnect = !(flags &RTE_VHOST_USER_NO_RECONNECT );if (vsocket->reconnect && reconn_tid ==0 ) {if (vhost_user_reconnect_init () !=0 ) - goto out_mutex; + goto out_free; } }else { vsocket->is_server = true; } ret = trans_ops->socket_init (vsocket, flags);if (ret <0 ) { - goto out_mutex; + goto out_free; } vhost_user.vsockets[vhost_user.vsocket_cnt++] = vsocket;
@@ -201,11 +194,6 @@ rte_vhost_driver_register(const char *path, uint64_t flags)pthread_mutex_unlock (&vhost_user.mutex);return ret; -out_mutex: -if (pthread_mutex_destroy (&vsocket->conn_mutex)) { -RTE_LOG (ERR ,VHOST_CONFIG , -"error: failed to destroy connection mutex\n" ); - } out_free:free (vsocket->path);free (vsocket);
@@ -223,7 +211,6 @@ rte_vhost_driver_unregister(const char *path) {int i;int count; -struct vhost_user_connection *conn, *next;pthread_mutex_lock (&vhost_user.mutex);
@@ -232,25 +219,6 @@ rte_vhost_driver_unregister(const char *path)if (!strcmp (vsocket->path, path)) { vsocket->trans_ops->socket_cleanup (vsocket); - -pthread_mutex_lock (&vsocket->conn_mutex); -for (conn =TAILQ_FIRST (&vsocket->conn_list); - conn !=NULL ; - conn = next) { - next =TAILQ_NEXT (conn, next); - -fdset_del (&vhost_user.fdset, conn->connfd); -RTE_LOG (INFO ,VHOST_CONFIG , -"free connfd = %d for device '%s'\n" , - conn->connfd, path); -close (conn->connfd); -vhost_destroy_device (conn->vid); -TAILQ_REMOVE (&vsocket->conn_list, conn, next); -free (conn); - } -pthread_mutex_unlock (&vsocket->conn_mutex); - -pthread_mutex_destroy (&vsocket->conn_mutex);free (vsocket->path);free (vsocket);
lib/librte_vhost/trans_af_unix.c +54 -6
110 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC 7/24 vhost: move vhost_user_reconnect_init() into trans_af_unix.c
In reply to Stefan HajnocziThe socket reconnection code is highly specific to AF_UNIX, so move the remaining pieces of it into trans_af_unix.c.
--- lib/librte_vhost/vhost.h | 10 +++------- lib/librte_vhost/socket.c | 4 ---- lib/librte_vhost/trans_af_unix.c | 9 +++++++-- 3 files changed, 10 insertions(+), 13 deletions(-)
lib/librte_vhost/vhost.h +3 -7
@@ -302,9 +302,9 @@ struct virtio_net {int slave_req_fd; } __rte_cache_aligned; -/* The vhost_user, vhost_user_socket, and reconnect declarations are temporary -* measures for moving AF_UNIX code into trans_af_unix.c. They will be cleaned -* up as socket.c is untangled from trans_af_unix.c. +/* The vhost_user and vhost_user_socket declarations are temporary measures for +* moving AF_UNIX code into trans_af_unix.c. They will be cleaned up as +* socket.c is untangled from trans_af_unix.c. */ /* * Every time rte_vhost_driver_register() is invoked, an associated
@@ -346,10 +346,6 @@ struct vhost_user {extern struct vhost_user vhost_user; -extern pthread_t reconn_tid; - -int vhost_user_reconnect_init (void ); -#define VHOST_LOG_PAGE 4096/*
lib/librte_vhost/socket.c +0 -4
@@ -177,10 +177,6 @@ rte_vhost_driver_register(const char *path, uint64_t flags)if ((flags &RTE_VHOST_USER_CLIENT ) !=0 ) { vsocket->reconnect = !(flags &RTE_VHOST_USER_NO_RECONNECT ); -if (vsocket->reconnect && reconn_tid ==0 ) { -if (vhost_user_reconnect_init () !=0 ) - goto out_free; - } }else { vsocket->is_server = true; }
lib/librte_vhost/trans_af_unix.c +7 -2
@@ -347,7 +347,7 @@ struct vhost_user_reconnect_list { };static struct vhost_user_reconnect_list reconn_list; -pthread_t reconn_tid; +static pthread_t reconn_tid;static int vhost_user_connect_nonblock (int fd,struct sockaddr *un,size_t sz)
@@ -417,7 +417,7 @@ vhost_user_client_reconnect(void *arg __rte_unused)return NULL ; } -int +static int vhost_user_reconnect_init (void ) {int ret;
@@ -527,6 +527,11 @@ af_unix_socket_init(struct vhost_user_socket *vsocket, container_of(vsocket, struct af_unix_socket, socket);int ret; +if (vsocket->reconnect && reconn_tid ==0 ) { +if (vhost_user_reconnect_init () !=0 ) +return -1 ; + } +TAILQ_INIT (&s->conn_list); ret =pthread_mutex_init (&s->conn_mutex,NULL );if (ret) {
Signature · 1 line
2.14.3
RFC 8/24 vhost: move vhost_user.fdset to trans_af_unix.c
In reply to Stefan HajnocziThe fdset is used by the AF_UNIX transport code but other transports may not need it. Move it to trans_af_unix.c and then make struct vhost_user private again since nothing outside socket.c needs it.
--- lib/librte_vhost/vhost.h | 15 --------------- lib/librte_vhost/socket.c | 21 +++++++-------------- lib/librte_vhost/trans_af_unix.c | 25 +++++++++++++++++++++---- 3 files changed, 28 insertions(+), 33 deletions(-)
lib/librte_vhost/vhost.h +0 -15
@@ -19,7 +19,6 @@#include <rte_ether.h> #include <rte_rwlock.h> -#include "fd_man.h" #include "rte_vhost.h" /* Used to indicate that the device is running on a data core */
@@ -302,10 +301,6 @@ struct virtio_net {int slave_req_fd; } __rte_cache_aligned; -/* The vhost_user and vhost_user_socket declarations are temporary measures for -* moving AF_UNIX code into trans_af_unix.c. They will be cleaned up as -* socket.c is untangled from trans_af_unix.c. -*/ /* * Every time rte_vhost_driver_register() is invoked, an associated * vhost_user_socket struct will be created.
@@ -336,16 +331,6 @@ struct vhost_user_socket {struct vhost_transport_ops const *trans_ops; }; -#define MAX_VHOST_SOCKET 1024 -struct vhost_user { -struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET ]; -struct fdset fdset; -int vsocket_cnt; -pthread_mutex_t mutex; -}; - -extern struct vhost_user vhost_user; -#define VHOST_LOG_PAGE 4096/*
lib/librte_vhost/socket.c +7 -14
@@ -20,12 +20,14 @@#include "vhost.h" #include "vhost_user.h" +#define MAX_VHOST_SOCKET 1024 +struct vhost_user { +struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET ]; +int vsocket_cnt; +pthread_mutex_t mutex; +}; +struct vhost_user vhost_user = { - .fdset = { - .fd = { [0 ...MAX_FDS -1 ] = {-1 ,NULL ,NULL ,NULL ,0 } }, - .fd_mutex =PTHREAD_MUTEX_INITIALIZER , - .num =0 - }, .vsocket_cnt =0 , .mutex =PTHREAD_MUTEX_INITIALIZER , };
@@ -265,7 +267,6 @@ int rte_vhost_driver_start(const char *path) {struct vhost_user_socket *vsocket; -static pthread_t fdset_tid;pthread_mutex_lock (&vhost_user.mutex); vsocket =find_vhost_user_socket (path);
@@ -274,13 +275,5 @@ rte_vhost_driver_start(const char *path)if (!vsocket)return -1 ; -if (fdset_tid ==0 ) { -int ret =pthread_create (&fdset_tid,NULL , fdset_event_dispatch, - &vhost_user.fdset); -if (ret !=0 ) -RTE_LOG (ERR ,VHOST_CONFIG , -"failed to create fdset handling thread" ); - } -return vsocket->trans_ops->socket_start (vsocket); }
lib/librte_vhost/trans_af_unix.c +21 -4
@@ -39,11 +39,18 @@#include <rte_log.h> +#include "fd_man.h" #include "vhost.h" #include "vhost_user.h" #define MAX_VIRTIO_BACKLOG 128 +static struct fdset af_unix_fdset = { + .fd = { [0 ...MAX_FDS -1 ] = {-1 ,NULL ,NULL ,NULL ,0 } }, + .fd_mutex =PTHREAD_MUTEX_INITIALIZER , + .num =0 +}; +TAILQ_HEAD (vhost_user_connection_list, vhost_user_connection);struct vhost_user_connection {
@@ -195,7 +202,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) conn->connfd = fd; conn->vsocket = vsocket; conn->vid = vid; - ret =fdset_add (&vhost_user.fdset, fd, vhost_user_read_cb, + ret =fdset_add (&af_unix_fdset, fd, vhost_user_read_cb,NULL , conn);if (ret <0 ) { RTE_LOG(ERR, VHOST_CONFIG,
@@ -316,7 +323,7 @@ vhost_user_start_server(struct vhost_user_socket *vsocket)if (ret <0 ) goto err; - ret =fdset_add (&vhost_user.fdset, fd, vhost_user_server_new_connection, + ret =fdset_add (&af_unix_fdset, fd, vhost_user_server_new_connection,NULL , vsocket);if (ret <0 ) { RTE_LOG(ERR, VHOST_CONFIG,
@@ -551,7 +558,7 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket)struct vhost_user_connection *conn, *next;if (vsocket->is_server) { -fdset_del (&vhost_user.fdset, s->socket_fd); +fdset_del (&af_unix_fdset, s->socket_fd);close (s->socket_fd);unlink (vsocket->path); }else if (vsocket->reconnect) {
@@ -564,7 +571,7 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket) conn = next) { next =TAILQ_NEXT (conn, next); -fdset_del (&vhost_user.fdset, conn->connfd); +fdset_del (&af_unix_fdset, conn->connfd);RTE_LOG (INFO ,VHOST_CONFIG ,"free connfd = %d for device '%s'\n" , conn->connfd, vsocket->path);
@@ -581,6 +588,16 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket)static int af_unix_socket_start (struct vhost_user_socket *vsocket) { +static pthread_t fdset_tid; + +if (fdset_tid ==0 ) { +int ret =pthread_create (&fdset_tid,NULL , fdset_event_dispatch, + &af_unix_fdset); +if (ret !=0 ) +RTE_LOG (ERR ,VHOST_CONFIG , +"failed to create fdset handling thread" ); + } +if (vsocket->is_server)return vhost_user_start_server (vsocket);else
Signature · 1 line
2.14.3
RFC 9/24 vhost: pass vhost_transport_ops through vhost_new_device()
In reply to Stefan HajnocziThis patch propagates struct vhost_user_socket's vhost_transport_ops into the newly created vhost device.
This patch completes the initial refactoring of socket.c, with the AF_UNIX-specific code now in trans_af_unix.c and the librte_vhost API entrypoints in socket.c.
Now it is time to turn towards vhost_user.c and its mixture of vhost-user protocol processing and socket I/O. The socket I/O will be moved into trans_af_unix.c so that other transports can be added that don't use file descriptors.
--- lib/librte_vhost/vhost.h | 2 +- lib/librte_vhost/trans_af_unix.c | 2 +- lib/librte_vhost/vhost.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
lib/librte_vhost/vhost.h +1 -1
@@ -434,7 +434,7 @@ gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)struct virtio_net *get_device (int vid); -int vhost_new_device (void ); +int vhost_new_device (const struct vhost_transport_ops *trans_ops);void cleanup_device (struct virtio_net *dev,int destroy);void reset_device (struct virtio_net *dev);void vhost_destroy_device (int );
lib/librte_vhost/trans_af_unix.c +1 -1
@@ -176,7 +176,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)return ; } - vid =vhost_new_device (); + vid =vhost_new_device (vsocket->trans_ops);if (vid ==-1 ) { goto err; }
lib/librte_vhost/vhost.c +2 -2
@@ -261,7 +261,7 @@ reset_device(struct virtio_net *dev)* there is a new virtio device being attached). */ int -vhost_new_device (void ) +vhost_new_device (const struct vhost_transport_ops *trans_ops) {struct virtio_net *dev;int i;
@@ -287,7 +287,7 @@ vhost_new_device(void) vhost_devices[i] = dev; dev->vid = i; dev->slave_req_fd =-1 ; - dev->trans_ops = &af_unix_trans_ops; + dev->trans_ops = trans_ops;return i; }
Signature · 1 line
2.14.3
RFC 10/24 vhost: embed struct virtio_net inside struct vhost_user_connection
In reply to Stefan HajnocziThere is a 1:1 relationship between struct virtio_net and struct vhost_user_connection. They share the same lifetime. struct virtio_net is the per-device state that is part of the vhost.h API. struct vhost_user_connection is the AF_UNIX-specific per-device state and is private to trans_af_unix.c. It will be necessary to go between these two structs.
This patch embeds struct virtio_net within struct vhost_user_connection so that AF_UNIX transport code can convert a struct virtio_net pointer into a struct vhost_user_connection pointer. There is now just a single malloc/free for both of these structs together.
--- lib/librte_vhost/vhost.h | 11 +++++++++- lib/librte_vhost/trans_af_unix.c | 44 +++++++++++++++++----------------------- lib/librte_vhost/vhost.c | 10 ++++----- 3 files changed, 34 insertions(+), 31 deletions(-)
lib/librte_vhost/vhost.h +10 -1
@@ -211,6 +211,9 @@ struct vhost_transport_ops {/** Size of struct vhost_user_socket-derived per-socket state */ size_t socket_size; +/** Size of struct virtio_net-derived per-device state */ +size_t device_size; +/** * Initialize a vhost-user socket that is being created by * rte_vhost_driver_register(). This function checks that the flags
@@ -269,6 +272,11 @@ extern const struct vhost_transport_ops af_unix_trans_ops;/** * Device structure contains all configuration information relating * to the device. +* +* Transport-specific per-device state can be kept by embedding this struct at +* the beginning of a transport-specific struct. Set +* vhost_transport_ops->device_size to the size of the transport-specific +* struct. */ struct virtio_net {/* Frontend (QEMU) memory and memory region information */
@@ -434,7 +442,8 @@ gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)struct virtio_net *get_device (int vid); -int vhost_new_device (const struct vhost_transport_ops *trans_ops); +struct virtio_net * +vhost_new_device (const struct vhost_transport_ops *trans_ops);void cleanup_device (struct virtio_net *dev,int destroy);void reset_device (struct virtio_net *dev);void vhost_destroy_device (int );
lib/librte_vhost/trans_af_unix.c +19 -25
119 lines not on this page · raw message
lib/librte_vhost/vhost.c +5 -5
@@ -260,17 +260,17 @@ reset_device(struct virtio_net *dev)* Invoked when there is a new vhost-user connection established (when * there is a new virtio device being attached). */ -int +struct virtio_net *vhost_new_device (const struct vhost_transport_ops *trans_ops) {struct virtio_net *dev;int i; - dev =rte_zmalloc (NULL ,sizeof (struct virtio_net ),0 ); + dev =rte_zmalloc (NULL , trans_ops->device_size,0 );if (dev ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG ,"Failed to allocate memory for new dev.\n" ); -return -1 ; +return NULL ; }for (i =0 ; i <MAX_VHOST_DEVICE ; i++) {
@@ -281,7 +281,7 @@ vhost_new_device(const struct vhost_transport_ops *trans_ops)RTE_LOG (ERR ,VHOST_CONFIG ,"Failed to find a free slot for new device.\n" );rte_free (dev); -return -1 ; +return NULL ; } vhost_devices[i] = dev;
@@ -289,7 +289,7 @@ vhost_new_device(const struct vhost_transport_ops *trans_ops) dev->slave_req_fd =-1 ; dev->trans_ops = trans_ops; -return i; +return dev; }/*
Signature · 1 line
2.14.3
RFC 11/24 vhost: extract vhost_user.c socket I/O into transport
In reply to Stefan HajnocziThe core vhost-user protocol code should not do socket I/O because the details are transport-specific. Move code to send and receive vhost-user messages into trans_af_unix.c.
--- lib/librte_vhost/vhost.h | 26 ++++++++++++ lib/librte_vhost/vhost_user.h | 6 +-- lib/librte_vhost/trans_af_unix.c | 70 +++++++++++++++++++++++++++++++-- lib/librte_vhost/vhost_user.c | 85 +++++++++++----------------------------- 4 files changed, 115 insertions(+), 72 deletions(-)
lib/librte_vhost/vhost.h +26 -0
@@ -203,6 +203,7 @@ struct guest_page {struct virtio_net ;struct vhost_user_socket ; +struct VhostUserMsg ;/** * A structure containing function pointers for transport-specific operations.
@@ -264,6 +265,31 @@ struct vhost_transport_ops {* 0 on success, -1 on failure */ int (*vring_call)(struct virtio_net *dev,struct vhost_virtqueue *vq); + +/** +* Send a reply to the master. +* +* @param dev +* vhost device +* @param reply +* reply message +* @return +* 0 on success, -1 on failure +*/ +int (*send_reply)(struct virtio_net *dev,struct VhostUserMsg *reply); + +/** +* Send a slave request to the master. +* +* @param dev +* vhost device +* @param req +* request message +* @return +* 0 on success, -1 on failure +*/ +int (*send_slave_req)(struct virtio_net *dev, +struct VhostUserMsg *req); };/** The traditional AF_UNIX vhost-user protocol transport. */
lib/librte_vhost/vhost_user.h +1 -5
@@ -110,11 +110,7 @@ typedef struct VhostUserMsg {/* vhost_user.c */ -int vhost_user_msg_handler (int vid,int fd); +int vhost_user_msg_handler (int vid,const struct VhostUserMsg *msg);int vhost_user_iotlb_miss (struct virtio_net *dev,uint64_t iova,uint8_t perm); -/* socket.c */ -int read_fd_message (int sockfd,char *buf,int buflen,int *fds,int fd_num); -int send_fd_message (int sockfd,char *buf,int buflen,int *fds,int fd_num); -#endif
lib/librte_vhost/trans_af_unix.c +66 -4
107 lines not on this page · raw message
lib/librte_vhost/vhost_user.c +22 -63
154 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC 12/24 vhost: move slave_req_fd field to AF_UNIX transport
In reply to Stefan HajnocziThe slave request file descriptor is specific to the AF_UNIX transport. Move the field out of struct virtio_net and into the trans_af_unix.c private struct vhost_user_connection struct.
This change will allow future transports to implement the slave request fd without relying on socket I/O.
--- lib/librte_vhost/vhost.h | 27 ++++++++++++++++++++++++-- lib/librte_vhost/trans_af_unix.c | 41 +++++++++++++++++++++++++++++++++++++++- lib/librte_vhost/vhost.c | 3 ++- lib/librte_vhost/vhost_user.c | 18 +----------------- 4 files changed, 68 insertions(+), 21 deletions(-)
lib/librte_vhost/vhost.h +25 -2
@@ -252,6 +252,16 @@ struct vhost_transport_ops {*/ int (*socket_start)(struct vhost_user_socket *vsocket); +/** +* Free resources associated with this device. +* +* @param dev +* vhost device +* @param destroy +* 0 on device reset, 1 on full cleanup. +*/ +void (*cleanup_device)(struct virtio_net *dev,int destroy); +/** * Notify the guest that used descriptors have been added to the vring. * The VRING_AVAIL_F_NO_INTERRUPT flag has already been checked so this
@@ -290,6 +300,21 @@ struct vhost_transport_ops {*/ int (*send_slave_req)(struct virtio_net *dev,struct VhostUserMsg *req); + +/** +* Process VHOST_USER_SET_SLAVE_REQ_FD message. After this function +* succeeds send_slave_req() may be called to submit requests to the +* master. +* +* @param dev +* vhost device +* @param msg +* message +* @return +* 0 on success, -1 on failure +*/ +int (*set_slave_req_fd)(struct virtio_net *dev, +struct VhostUserMsg *msg); };/** The traditional AF_UNIX vhost-user protocol transport. */
@@ -331,8 +356,6 @@ struct virtio_net {uint32_t nr_guest_pages;uint32_t max_guest_pages;struct guest_page *guest_pages; - -int slave_req_fd; } __rte_cache_aligned;/*
lib/librte_vhost/trans_af_unix.c +40 -1
75 lines not on this page · raw message
lib/librte_vhost/vhost.c +2 -1
@@ -96,6 +96,8 @@ cleanup_device(struct virtio_net *dev, int destroy)for (i =0 ; i < dev->nr_vring; i++)cleanup_vq (dev->virtqueue[i], destroy); + + dev->trans_ops->cleanup_device (dev, destroy); }void
@@ -286,7 +288,6 @@ vhost_new_device(const struct vhost_transport_ops *trans_ops) vhost_devices[i] = dev; dev->vid = i; - dev->slave_req_fd =-1 ; dev->trans_ops = trans_ops;return dev;
lib/librte_vhost/vhost_user.c +1 -17
@@ -96,11 +96,6 @@ vhost_backend_cleanup(struct virtio_net *dev)munmap ((void *)(uintptr_t )dev->log_addr, dev->log_size); dev->log_addr =0 ; } - -if (dev->slave_req_fd >=0 ) { -close (dev->slave_req_fd); - dev->slave_req_fd =-1 ; - } }/*
@@ -1030,18 +1025,7 @@ vhost_user_net_set_mtu(struct virtio_net *dev, struct VhostUserMsg *msg)static int vhost_user_set_req_fd (struct virtio_net *dev,struct VhostUserMsg *msg) { -int fd = msg->fds[0 ]; - -if (fd <0 ) { -RTE_LOG (ERR ,VHOST_CONFIG , -"Invalid file descriptor for slave channel (%d)\n" , - fd); -return -1 ; - } - - dev->slave_req_fd = fd; - -return 0 ; +return dev->trans_ops->set_slave_req_fd (dev, msg); } static int
Signature · 1 line
2.14.3
RFC 13/24 vhost: move mmap/munmap to AF_UNIX transport
In reply to Stefan HajnocziHow mem table regions are mapped is transport-specific, so move the mmap code into trans_af_unix.c. The new .map_mem_table()/.unmap_mem_table() interfaces allow transports to perform the mapping and unmapping.
Drop the "mmap align:" debug output because the alignment is no longer available from vhost_user.c.
--- lib/librte_vhost/vhost.h | 17 +++++++ lib/librte_vhost/vhost_user.h | 3 ++ lib/librte_vhost/trans_af_unix.c | 78 +++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost_user.c | 95 ++++++++++------------------------------ 4 files changed, 121 insertions(+), 72 deletions(-)
lib/librte_vhost/vhost.h +17 -0
@@ -315,6 +315,23 @@ struct vhost_transport_ops {*/ int (*set_slave_req_fd)(struct virtio_net *dev,struct VhostUserMsg *msg); + +/** +* Map memory table regions in dev->mem->regions[]. +* +* @param dev +* vhost device +*/ +int (*map_mem_regions)(struct virtio_net *dev); + +/** +* Unmap memory table regions in dev->mem->regions[] and free any +* resources, such as file descriptors. +* +* @param dev +* vhost device +*/ +void (*unmap_mem_regions)(struct virtio_net *dev); };/** The traditional AF_UNIX vhost-user protocol transport. */
lib/librte_vhost/vhost_user.h +3 -0
@@ -110,6 +110,9 @@ typedef struct VhostUserMsg {/* vhost_user.c */ +void vhost_add_guest_pages (struct virtio_net *dev, +struct rte_vhost_mem_region *reg, +uint64_t page_size);int vhost_user_msg_handler (int vid,const struct VhostUserMsg *msg);int vhost_user_iotlb_miss (struct virtio_net *dev,uint64_t iova,uint8_t perm);
lib/librte_vhost/trans_af_unix.c +78 -0
94 lines not on this page · raw message
lib/librte_vhost/vhost_user.c +23 -72
156 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC 14/24 vhost: move librte_vhost to drivers/
In reply to Stefan HajnocziPCI drivers depend on the rte_bus_pci.h header file which is only available when drivers/ is built. Code in lib/ cannot depend on code in drivers/ because lib/ is built first during make install.
This patch moves librte_vhost into drivers/ so that later patches can add a virtio-vhost-pci driver to librte_vhost without exporting all private vhost.h symbols.
---
Is there a better way of giving a PCI driver access to librte_vhost transport (not a public API that apps should use)?
---
drivers/Makefile | 2 ++
{lib => drivers}/librte_vhost/Makefile | 0
lib/Makefile | 3 ---
{lib => drivers}/librte_vhost/fd_man.h | 0
{lib => drivers}/librte_vhost/iotlb.h | 0
{lib => drivers}/librte_vhost/rte_vhost.h | 0
{lib => drivers}/librte_vhost/vhost.h | 0
{lib => drivers}/librte_vhost/vhost_user.h | 0
{lib => drivers}/librte_vhost/fd_man.c | 0
{lib => drivers}/librte_vhost/iotlb.c | 0
{lib => drivers}/librte_vhost/socket.c | 0
{lib => drivers}/librte_vhost/trans_af_unix.c | 0
{lib => drivers}/librte_vhost/vhost.c | 0
{lib => drivers}/librte_vhost/vhost_user.c | 0
{lib => drivers}/librte_vhost/virtio_net.c | 0
{lib => drivers}/librte_vhost/rte_vhost_version.map | 0
16 files changed, 2 insertions(+), 3 deletions(-)
rename {lib => drivers}/librte_vhost/Makefile (100%)
rename {lib => drivers}/librte_vhost/fd_man.h (100%)
rename {lib => drivers}/librte_vhost/iotlb.h (100%)
rename {lib => drivers}/librte_vhost/rte_vhost.h (100%)
rename {lib => drivers}/librte_vhost/vhost.h (100%)
rename {lib => drivers}/librte_vhost/vhost_user.h (100%)
rename {lib => drivers}/librte_vhost/fd_man.c (100%)
rename {lib => drivers}/librte_vhost/iotlb.c (100%)
rename {lib => drivers}/librte_vhost/socket.c (100%)
rename {lib => drivers}/librte_vhost/trans_af_unix.c (100%)
rename {lib => drivers}/librte_vhost/vhost.c (100%)
rename {lib => drivers}/librte_vhost/vhost_user.c (100%)
rename {lib => drivers}/librte_vhost/virtio_net.c (100%)
rename {lib => drivers}/librte_vhost/rte_vhost_version.map (100%)drivers/Makefile +2 -0
@@ -12,5 +12,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += crypto DEPDIRS-crypto := bus mempool DIRS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += event DEPDIRS-event := bus mempool net +DIRS-$(CONFIG_RTE_LIBRTE_VHOST) += librte_vhost +DEPDIRS-librte_vhost := bus include $(RTE_SDK)/mk/rte.subdir.mk
drivers/librte_vhost/Makefile renamed from lib/librte_vhost/Makefile +0 -0
lib/Makefile +0 -3
@@ -30,9 +30,6 @@ DEPDIRS-librte_security += librte_ether DEPDIRS-librte_security += librte_cryptodev DIRS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += librte_eventdev DEPDIRS-librte_eventdev := librte_eal librte_ring librte_ether librte_hash -DIRS-$(CONFIG_RTE_LIBRTE_VHOST) += librte_vhost -DEPDIRS-librte_vhost := librte_eal librte_mempool librte_mbuf librte_ether \ - librte_net DIRS-$(CONFIG_RTE_LIBRTE_HASH) += librte_hash DEPDIRS-librte_hash := librte_eal librte_ring DIRS-$(CONFIG_RTE_LIBRTE_EFD) += librte_efd
drivers/librte_vhost/fd_man.h renamed from lib/librte_vhost/fd_man.h +0 -0
drivers/librte_vhost/iotlb.h renamed from lib/librte_vhost/iotlb.h +0 -0
drivers/librte_vhost/rte_vhost.h renamed from lib/librte_vhost/rte_vhost.h +0 -0
drivers/librte_vhost/vhost.h renamed from lib/librte_vhost/vhost.h +0 -0
drivers/librte_vhost/vhost_user.h renamed from lib/librte_vhost/vhost_user.h +0 -0
drivers/librte_vhost/fd_man.c renamed from lib/librte_vhost/fd_man.c +0 -0
drivers/librte_vhost/iotlb.c renamed from lib/librte_vhost/iotlb.c +0 -0
drivers/librte_vhost/socket.c renamed from lib/librte_vhost/socket.c +0 -0
drivers/librte_vhost/trans_af_unix.c renamed from lib/librte_vhost/trans_af_unix.c +0 -0
drivers/librte_vhost/vhost.c renamed from lib/librte_vhost/vhost.c +0 -0
drivers/librte_vhost/vhost_user.c renamed from lib/librte_vhost/vhost_user.c +0 -0
drivers/librte_vhost/virtio_net.c renamed from lib/librte_vhost/virtio_net.c +0 -0
drivers/librte_vhost/rte_vhost_version.map renamed from lib/librte_vhost/rte_vhost_version.map +0 -0
Signature · 1 line
2.14.3
RFC 15/24 vhost: add virtio pci framework
In reply to Stefan HajnocziThe virtio-vhost-user transport will involve a virtio pci device driver. There is currently no librte_virtio API that we can reusable.
This commit is a hack that duplicates the virtio pci code from drivers/net/. A better solution would be to extract the code cleanly from drivers/net/ and share it. Or perhaps we could backport SPDK's lib/virtio. I don't have time to do either right now so I've just copied the code, removed virtio-net and ethdev parts, and renamed symbols to avoid link errors.
--- drivers/librte_vhost/Makefile | 4 +- drivers/librte_vhost/virtio_pci.h | 267 ++++++++++++++++++++ drivers/librte_vhost/virtqueue.h | 181 ++++++++++++++ drivers/librte_vhost/virtio_pci.c | 504 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 955 insertions(+), 1 deletion(-) create mode 100644 drivers/librte_vhost/virtio_pci.h create mode 100644 drivers/librte_vhost/virtqueue.h create mode 100644 drivers/librte_vhost/virtio_pci.c
drivers/librte_vhost/Makefile +3 -1
@@ -21,7 +21,9 @@ LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev -lrte_net # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \ - vhost_user.c virtio_net.c trans_af_unix.c + vhost_user.c virtio_net.c \ + trans_af_unix.c \ + virtio_pci.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h
drivers/librte_vhost/virtio_pci.h new file +267 -0
267 lines not on this page · raw message
drivers/librte_vhost/virtqueue.h new file +181 -0
181 lines not on this page · raw message
drivers/librte_vhost/virtio_pci.c new file +504 -0
504 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC 16/24 vhost: remember a vhost_virtqueue's queue index
In reply to Stefan HajnocziCurrently the only way of determining a struct vhost_virtqueue's index is to search struct virtio_net->virtqueue[] for its address. Stash the index in struct vhost_virtqueue so we won't have to search the array.
This new field will be used by virtio-vhost-user.
--- drivers/librte_vhost/vhost.h | 1 + drivers/librte_vhost/vhost.c | 2 ++ 2 files changed, 3 insertions(+)
drivers/librte_vhost/vhost.h +1 -0
@@ -72,6 +72,7 @@ struct vhost_virtqueue {struct vring_avail *avail;struct vring_used *used;uint32_t size; +uint32_t vring_idx;uint16_t last_avail_idx;uint16_t last_used_idx;
drivers/librte_vhost/vhost.c +2 -0
@@ -191,6 +191,8 @@ init_vring_queue(struct virtio_net *dev, uint32_t vring_idx)memset (vq,0 ,sizeof (struct vhost_virtqueue )); + vq->vring_idx = vring_idx; + vq->kickfd =VIRTIO_UNINITIALIZED_EVENTFD ; vq->callfd =VIRTIO_UNINITIALIZED_EVENTFD ;
Signature · 1 line
2.14.3
RFC 17/24 vhost: add virtio-vhost-user transport
In reply to Stefan HajnocziThis patch adds a new transport to librte_vhost for the virtio-vhost-user device. This device replaces the AF_UNIX socket used by traditional vhost-user with a virtio device that tunnels vhost-user protocol messages. This allows a guest to act as a vhost device backend for other guests.
The intended use case is for running DPDK inside a guest. Other guests can communicate via DPDK's "vhost" vdev driver.
For more information on virtio-vhost-user, see
https://wiki.qemu.org/Features/VirtioVhostUser.
--- drivers/librte_vhost/Makefile | 1 + drivers/librte_vhost/vhost.h | 3 + drivers/librte_vhost/virtio_vhost_user.h | 18 + drivers/librte_vhost/trans_virtio_vhost_user.c | 1050 ++++++++++++++++++++++++ 4 files changed, 1072 insertions(+) create mode 100644 drivers/librte_vhost/virtio_vhost_user.h create mode 100644 drivers/librte_vhost/trans_virtio_vhost_user.c
drivers/librte_vhost/Makefile +1 -0
@@ -23,6 +23,7 @@ LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev -lrte_net SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \ vhost_user.c virtio_net.c \ trans_af_unix.c \ + trans_virtio_vhost_user.c \ virtio_pci.c # install includes
drivers/librte_vhost/vhost.h +3 -0
@@ -338,6 +338,9 @@ struct vhost_transport_ops {/** The traditional AF_UNIX vhost-user protocol transport. */ extern const struct vhost_transport_ops af_unix_trans_ops; +/** The virtio-vhost-user PCI vhost-user protocol transport. */ +extern const struct vhost_transport_ops virtio_vhost_user_trans_ops; +/** * Device structure contains all configuration information relating * to the device.
drivers/librte_vhost/virtio_vhost_user.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (C) 2018 Red Hat, Inc. +*/ + +#ifndef _LINUX_VIRTIO_VHOST_USER_H +#define _LINUX_VIRTIO_VHOST_USER_H + +#include <stdint.h> + +struct virtio_vhost_user_config { +uint32_t status; +#define VIRTIO_VHOST_USER_STATUS_SLAVE_UP 0 +#define VIRTIO_VHOST_USER_STATUS_MASTER_UP 1 +uint32_t max_vhost_queues; +uint8_t uuid[16 ]; +}; + +#endif /* _LINUX_VIRTIO_VHOST_USER_H */
drivers/librte_vhost/trans_virtio_vhost_user.c new file +1050 -0
1,050 lines not on this page · raw message
Signature · 1 line
2.14.3
RFC 18/24 vhost: add RTE_VHOST_USER_VIRTIO_TRANSPORT flag
In reply to Stefan HajnocziExtend the <rte_vhost.h> API to support the virtio-vhost-user transport as an alternative to the AF_UNIX transport. The caller provides a PCI DomBDF address:
rte_vhost_driver_register("0000:00:04.0",
RTE_VHOST_USER_VIRTIO_TRANSPORT);
--- drivers/librte_vhost/rte_vhost.h | 1 + drivers/librte_vhost/socket.c | 3 +++ 2 files changed, 4 insertions(+)
drivers/librte_vhost/rte_vhost.h +1 -0
@@ -28,6 +28,7 @@ extern "C" {#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)#define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2)#define RTE_VHOST_USER_IOMMU_SUPPORT (1ULL << 3) +#define RTE_VHOST_USER_VIRTIO_TRANSPORT (1ULL << 4)/** * Information relating to memory regions including offsets to
drivers/librte_vhost/socket.c +3 -0
@@ -132,6 +132,9 @@ rte_vhost_driver_register(const char *path, uint64_t flags)struct vhost_user_socket *vsocket;const struct vhost_transport_ops *trans_ops = &af_unix_trans_ops; +if (flags &RTE_VHOST_USER_VIRTIO_TRANSPORT ) + trans_ops = &virtio_vhost_user_trans_ops; +if (!path)return -1 ;
Signature · 1 line
2.14.3
RFC 19/24 net/vhost: add virtio-vhost-user support
In reply to Stefan HajnocziThe new virtio-transport=0|1 argument enables virtio-vhost-user support:
testpmd ... --pci-whitelist 0000:00:04.0 \
--vdev vhost,iface=0000:00:04.0,virtio-transport=1--- drivers/net/vhost/rte_eth_vhost.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/net/vhost/rte_eth_vhost.c +13 -0
@@ -53,6 +53,7 @@ enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};#define ETH_VHOST_CLIENT_ARG "client"#define ETH_VHOST_DEQUEUE_ZERO_COPY "dequeue-zero-copy"#define ETH_VHOST_IOMMU_SUPPORT "iommu-support" +#define ETH_VHOST_VIRTIO_TRANSPORT "virtio-transport"#define VHOST_MAX_PKT_BURST 32static const char *valid_arguments[] = {
@@ -61,6 +62,7 @@ static const char *valid_arguments[] = {ETH_VHOST_CLIENT_ARG ,ETH_VHOST_DEQUEUE_ZERO_COPY ,ETH_VHOST_IOMMU_SUPPORT , +ETH_VHOST_VIRTIO_TRANSPORT , NULL };
@@ -1167,6 +1169,7 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev)int client_mode =0 ;int dequeue_zero_copy =0 ;int iommu_support =0 ; +uint16_t virtio_transport =0 ;RTE_LOG (INFO ,PMD ,"Initializing pmd_vhost for %s\n" ,rte_vdev_device_name (dev));
@@ -1224,6 +1227,16 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev) flags |=RTE_VHOST_USER_IOMMU_SUPPORT ; } +if (rte_kvargs_count (kvlist,ETH_VHOST_VIRTIO_TRANSPORT ) ==1 ) { + ret =rte_kvargs_process (kvlist,ETH_VHOST_VIRTIO_TRANSPORT , + &open_int, &virtio_transport); +if (ret <0 ) + goto out_free; + +if (virtio_transport) + flags |=RTE_VHOST_USER_VIRTIO_TRANSPORT ; + } +if (dev->device.numa_node ==SOCKET_ID_ANY ) dev->device.numa_node =rte_socket_id ();
Signature · 1 line
2.14.3
RFC 20/24 examples/vhost_scsi: add --socket-file argument
In reply to Stefan HajnocziThe default filename built into examples/vhost_scsi may not be convenient. Allow the user to specify the full UNIX domain socket path on the command-line.
--- examples/vhost_scsi/vhost_scsi.c | 93 ++++++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 18 deletions(-)
examples/vhost_scsi/vhost_scsi.c +75 -18
@@ -2,6 +2,7 @@* Copyright(c) 2010-2017 Intel Corporation */ +#include <getopt.h> #include <stdint.h> #include <unistd.h> #include <stdbool.h>
@@ -359,26 +360,10 @@ static const struct vhost_device_ops vhost_scsi_device_ops = { };static struct vhost_scsi_ctrlr * -vhost_scsi_ctrlr_construct (const char *ctrlr_name) +vhost_scsi_ctrlr_construct (void ) {int ret;struct vhost_scsi_ctrlr *ctrlr; -char *path; -char cwd[PATH_MAX ]; - -/* always use current directory */ - path =getcwd (cwd,PATH_MAX ); -if (!path) { -fprintf (stderr,"Cannot get current working directory\n" ); -return NULL ; - } -snprintf (dev_pathname,sizeof (dev_pathname),"%s/%s" , path, ctrlr_name); - -if (access (dev_pathname,F_OK ) !=-1 ) { -if (unlink (dev_pathname) !=0 ) -rte_exit (EXIT_FAILURE ,"Cannot remove %s.\n" , - dev_pathname); - }if (rte_vhost_driver_register (dev_pathname,0 ) !=0 ) {fprintf (stderr,"socket %s already exists\n" , dev_pathname);
@@ -412,6 +397,71 @@ signal_handler(__rte_unused int signum)exit (0 ); } +static void +set_dev_pathname (const char *path) +{ +if (dev_pathname[0 ]) +rte_exit (EXIT_FAILURE ,"--socket-file can only be given once.\n" ); + +snprintf (dev_pathname,sizeof (dev_pathname),"%s" , path); +} + +static void +vhost_scsi_usage (const char *prgname) +{ +fprintf (stderr,"%s [EAL options] --\n" +" --socket-file PATH: The path of the UNIX domain socket\n" , + prgname); +} + +static void +vhost_scsi_parse_args (int argc,char **argv) +{ +int opt; +int option_index; +const char *prgname = argv[0 ]; +static struct option long_option[] = { + {"socket-file" , required_argument,NULL ,0 }, + {NULL ,0 ,0 ,0 }, + }; + +while ((opt =getopt_long (argc, argv,"" , long_option, + &option_index)) !=-1 ) { +switch (opt) { +case 0 : +if (!strcmp (long_option[option_index].name, +"socket-file" )) { +set_dev_pathname (optarg); + } +break ; +default : +vhost_scsi_usage (prgname); +rte_exit (EXIT_FAILURE ,"Invalid argument\n" ); + } + } +} + +static void +vhost_scsi_set_default_dev_pathname (void ) +{ +char *path; +char cwd[PATH_MAX ]; + +/* always use current directory */ + path =getcwd (cwd,PATH_MAX ); +if (!path) { +rte_exit (EXIT_FAILURE , +"Cannot get current working directory\n" ); + } +snprintf (dev_pathname,sizeof (dev_pathname),"%s/vhost.socket" , path); + +if (access (dev_pathname,F_OK ) !=-1 ) { +if (unlink (dev_pathname) !=0 ) +rte_exit (EXIT_FAILURE ,"Cannot remove %s.\n" , + dev_pathname); + } +} +int main (int argc,char *argv[]) {int ret;
@@ -422,8 +472,15 @@ int main(int argc, char *argv[]) ret =rte_eal_init (argc, argv);if (ret <0 )rte_exit (EXIT_FAILURE ,"Error with EAL initialization\n" ); + argc -= ret; + argv += ret; - g_vhost_ctrlr =vhost_scsi_ctrlr_construct ("vhost.socket" ); +vhost_scsi_parse_args (argc, argv); + +if (!dev_pathname[0 ]) +vhost_scsi_set_default_dev_pathname (); + + g_vhost_ctrlr =vhost_scsi_ctrlr_construct ();if (g_vhost_ctrlr ==NULL ) {fprintf (stderr,"Construct vhost scsi controller failed\n" );return 0 ;
Signature · 1 line
2.14.3
RFC 21/24 examples/vhost_scsi: add virtio-vhost-user support
In reply to Stefan HajnocziThe new --virtio-vhost-user-pci command-line argument uses virtio-vhost-user instead of the default AF_UNIX transport.
--- examples/vhost_scsi/vhost_scsi.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
examples/vhost_scsi/vhost_scsi.c +11 -3
@@ -28,6 +28,7 @@/* Path to folder where character device will be created. Can be set by user. */ static char dev_pathname[PATH_MAX ] ="" ; +static uint64_t dev_flags;/* for rte_vhost_driver_register() */ static struct vhost_scsi_ctrlr *g_vhost_ctrlr;static int g_should_stop;
@@ -365,7 +366,7 @@ vhost_scsi_ctrlr_construct(void)int ret;struct vhost_scsi_ctrlr *ctrlr; -if (rte_vhost_driver_register (dev_pathname,0 ) !=0 ) { +if (rte_vhost_driver_register (dev_pathname, dev_flags) !=0 ) {fprintf (stderr,"socket %s already exists\n" , dev_pathname);return NULL ; }
@@ -401,7 +402,8 @@ static void set_dev_pathname(const char *path) {if (dev_pathname[0 ]) -rte_exit (EXIT_FAILURE ,"--socket-file can only be given once.\n" ); +rte_exit (EXIT_FAILURE ,"Only one of --socket-file or " +"--virtio-vhost-user-pci can be given.\n" );snprintf (dev_pathname,sizeof (dev_pathname),"%s" , path); }
@@ -410,7 +412,8 @@ static void vhost_scsi_usage(const char *prgname) {fprintf (stderr,"%s [EAL options] --\n" -" --socket-file PATH: The path of the UNIX domain socket\n" , +" --socket-file PATH: The path of the UNIX domain socket\n" +" --virtio-vhost-user-pci DomBDF: PCI adapter address\n" , prgname); }
@@ -422,6 +425,7 @@ vhost_scsi_parse_args(int argc, char **argv)const char *prgname = argv[0 ];static struct option long_option[] = { {"socket-file" , required_argument,NULL ,0 }, + {"virtio-vhost-user-pci" , required_argument,NULL ,0 }, {NULL ,0 ,0 ,0 }, };
@@ -432,6 +436,10 @@ vhost_scsi_parse_args(int argc, char **argv)if (!strcmp (long_option[option_index].name,"socket-file" )) {set_dev_pathname (optarg); + }else if (!strcmp (long_option[option_index].name, +"virtio-vhost-user-pci" )) { +set_dev_pathname (optarg); + dev_flags =RTE_VHOST_USER_VIRTIO_TRANSPORT ; }break ;default :
Signature · 1 line
2.14.3
RFC 22/24 usertools: add virtio-vhost-user devices to dpdk-devbind.py
In reply to Stefan HajnocziThe virtio-vhost-user PCI adapter is not detected in any existing group of devices supported by dpdk-devbind.py. Add a new "Others" group for miscellaneous devices like this one.
--- usertools/dpdk-devbind.py | 8 ++++++++ 1 file changed, 8 insertions(+)
usertools/dpdk-devbind.py +8 -0
@@ -22,11 +22,14 @@ 'SVendor': None, 'SDevice': None} cavium_pkx = {'Class': '08', 'Vendor': '177d', 'Device': 'a0dd,a049', 'SVendor': None, 'SDevice': None} +virtio_vhost_user = {'Class': '00', 'Vendor': '1af4', 'Device': '1017,1058', + 'SVendor': None, 'SDevice': None} network_devices = [network_class, cavium_pkx] crypto_devices = [encryption_class, intel_processor_class] eventdev_devices = [cavium_sso] mempool_devices = [cavium_fpa] +other_devices = [virtio_vhost_user] # global dict ethernet devices present. Dictionary indexed by PCI address. # Each device within this is itself a dictionary of device properties
@@ -596,6 +599,9 @@ def show_status(): if status_dev == "mempool" or status_dev == "all": show_device_status(mempool_devices, "Mempool") + if status_dev == 'other' or status_dev == 'all': + show_device_status(other_devices, "Other") + def parse_args(): '''Parses the command-line arguments given by the user and takes the appropriate action for each'''
@@ -669,6 +675,7 @@ def do_arg_actions(): get_device_details(crypto_devices) get_device_details(eventdev_devices) get_device_details(mempool_devices) + get_device_details(other_devices) show_status()
@@ -681,6 +688,7 @@ def main(): get_device_details(crypto_devices) get_device_details(eventdev_devices) get_device_details(mempool_devices) + get_device_details(other_devices) do_arg_actions() if __name__ == "__main__":
Signature · 1 line
2.14.3
RFC 23/24 WORKAROUND revert virtio-net mq vring deletion
In reply to Stefan HajnocziThe virtio-net mq vring deletion code should be in virtio_net.c, not in the generic vhost_user.c code where it breaks non-virtio-net devices.
--- drivers/librte_vhost/vhost_user.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/librte_vhost/vhost_user.c +2 -0
@@ -163,6 +163,7 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off"); +#if 0 if (!(dev->features & (1ULL <<VIRTIO_NET_F_MQ ))) {/* * Remove all but first queue pair if MQ hasn't been
@@ -181,6 +182,7 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) free_vq(vq); } } +#endif return 0 ; }
Signature · 1 line
2.14.3
Re: [RFC 23/24] WORKAROUND revert virtio-net mq vring deletion
Hi Stefan,
Quoted 22 lines · Stefan Hajnoczi
The virtio-net mq vring deletion code should be in
virtio_net.c, not in the genericvhost_user.ccode where it breaks non-virtio-net devices.Signed-off-by Stefan Hajnoczi <[email protected]>--- drivers/librte_vhost/vhost_user.c | 2 ++ 1 file changed, 2 insertions(+)drivers/librte_vhost/vhost_user.c +1
-0@@ -163,6 +163,7 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off"); +#if 0 if (!(dev->features & (1ULL <<VIRTIO_NET_F_MQ ))) {/* * Remove all but first queue pair if MQ hasn't been
drivers/librte_vhost/vhost_user.c vhost_user_set_features(struct virtio_net *dev, uint64_t features) · line 188
Quoted 7 lines
drivers/librte_vhost/vhost_user.c +1
-0@@ -181,6 +182,7 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) free_vq(vq); } } +#endif return 0 ; }
Thanks for reporting the issue.
It seems difficult to move this check in virtio-net.c without a deep rework.
But I think we can workaround by ensuring the backend supports VIRTIO_NET_F_MQ, but it has not been negotiated. Something like:
if ((vhost_features & (1ULL << VIRTIO_NET_F_MQ)) &&
!(dev->features & (1ULL << VIRTIO_NET_F_MQ)) {...
}
Any thoughts?
Thanks,
Maxime
RFC 24/24 WORKAROUND examples/vhost_scsi: avoid broken EVENT_IDX
In reply to Stefan HajnocziThe EVENT_IDX code in DPDK is broken. It's missing the signalled_used_valid flag that handles the corner cases (startup and wrapping). Disable it for now.
--- examples/vhost_scsi/vhost_scsi.c | 1 - 1 file changed, 1 deletion(-)
examples/vhost_scsi/vhost_scsi.c +0 -1
@@ -22,7 +22,6 @@#include "scsi_spec.h" #define VIRTIO_SCSI_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY) |\ - (1 << VIRTIO_RING_F_EVENT_IDX) |\ (1 << VIRTIO_SCSI_F_INOUT) |\ (1 << VIRTIO_SCSI_F_CHANGE))
Signature · 1 line
2.14.3
Re: [RFC 24/24] WORKAROUND examples/vhost_scsi: avoid broken EVENT_IDX
Quoted 5 lines · Stefan Hajnoczi
The
EVENT_IDXcode in DPDK is broken. It's missing thesignalled_used_validflag that handles the corner cases (startup and wrapping). Disable it for now.Signed-off-by Stefan Hajnoczi <[email protected]>
FYI signalled_used_valid isn't strictly required,
there are ways to handle event idx without that,
e.g. like virtio within guest.
Quoted 18 lines
--- examples/vhost_scsi/vhost_scsi.c | 1 - 1 file changed, 1 deletion(-)examples/vhost_scsi/vhost_scsi.c +0
-1@@ -22,7 +22,6 @@#include "scsi_spec.h" #define VIRTIO_SCSI_FEATURES ((1 << VIRTIO_F_NOTIFY_ON_EMPTY) |\ - (1 << VIRTIO_RING_F_EVENT_IDX) |\ (1 << VIRTIO_SCSI_F_INOUT) |\ (1 << VIRTIO_SCSI_F_CHANGE))Signature · 1 line
2.14.3
Hi Stefan,
I went through the series, and I really like how it fits with existing vhost-user over af_unix socket.
I will post the change I suggested to fix the regression met with SPDK and multiqueue.
Thanks,
Maxime
Quoted 189 lines · Stefan Hajnoczi
This patch series implements the virtio-vhost-user device, which tunnels vhost-user protocol messages over virtio. This lets guests act as vhost device backends for other guests.
The virtio-vhost-user device is the result of discussion about Wei Wang and Zhiyong Yang's vhost-pci device. This patch series demonstrates that vhost device backends, such as the vhost vdev driver, can work over both
AF_UNIXand virtio-vhost-user without significant modifications. This allows a lot of code to be shared between traditionalAF_UNIXvhost-user and virtio-vhost-user. The vhost-pci patches duplicated the vhost net device backend and didn't reuselibrte_vhost:http://dpdk.org/ml/archives/dev/2017-November/082615.htmlUser-visible changes
--------------------
The vhost vdev can now be used when DPDK runs inside a guest with a virtio-vhost-user PCI device:--vdev net_vhost0,iface="0000:00:04.0",virtio-transport=1The vhost-scsi example has also been extended to support virtio-vhost-user:
./vhost-scsi ... -- --virtio-vhost-user-pci "0000:00:04.0"For more information (including instructions for running the code), see
https://wiki.qemu.org/Features/VirtioVhostUserVirtio device design
--------------------
The virtio-vhost-user device is a new virtio device type. It acts as a vhost-user transport and is an alternative for the traditionalAF_UNIXtransport.You can find the virtio-vhost-user VIRTIO device specification here:
https://stefanha.github.io/virtio/vhost-user-slave.html#x1-2830007
librte_vhostAPI changes
------------------------
This patch series extendslibrte_vhostso that it now accepts:rte_vhost_driver_register("0000:00:04.0", RTE_VHOST_USER_VIRTIO_TRANSPORT);All other
librte_vhostAPI usage remains unchanged, except that the file descriptors exposed in some <rte_vhost.h> structs will be -1 since there is no file descriptor passing involved.This makes it extremely easy to support virtio-vhost-user in existing vhost device backends! I have extended the vhost vdev driver and the vhost-scsi example application in this patch series.
Patch series overview
---------------------
This series is based on commit814339ba7eea13d132508af2cccec2f73568e2d0from dpdk-next-virtio/master. You can also get my git branch here:https://github.com/stefanha/dpdk/tree/virtio-vhost-user
The initial patches refactor
librte_vhostso that AF_UNIX-specific code is moved to a newtrans_af_unix.cfile. This also introduces a structvhost_transport_opsinterface that all transports will implement:
adf412c3cvhost: movevring_call()intotrans_af_unix.c04079a077vhost: moveAF_UNIXcode fromsocket.ctotrans_af_unix.c885642091 vhost: allocate per-socket transport state
9c48377dfvhost: movesocket_fdand un sockaddr intotrans_af_unix.cc646e6292vhost: move start_server/client() calls totrans_af_unix.cdb07ef7a8vhost: movevhost_user_connectiontotrans_af_unix.cd10b80163vhost: movevhost_user_reconnect_init()intotrans_af_unix.c1258bcd68vhost: move vhost_user.fdset totrans_af_unix.cbc7f6d7abvhost: passvhost_transport_opsthroughvhost_new_device()b82187a29vhost: embed structvirtio_netinside structvhost_user_connectionabbd544f2vhost: extractvhost_user.csocket I/O into transport0658d711bvhost: moveslave_req_fdfield toAF_UNIXtransporte2ecf78edvhost: move mmap/munmap toAF_UNIXtransportI was about to add the virtio-vhost-user PCI driver when I realized that
lib/librte_vhost/cannot have a dependency onrte_bus_pci.h(it lives indrivers/). The solution I chose is to move all oflibrte_vhosttodrivers/librte_vhost/, but I'm open to suggestions if this is undesirable.
8615c2140vhost: movelibrte_vhosttodrivers/Since virtio-vhost-user is a virtio device it's necessary to perform a sequence of device initialization steps and set up virtqueues. I didn't see a virtio API in DPDK and didn't have time to create one myself. I copied the virtio code from
drivers/net/virtio/as a quick hack, but really there needs to be alibrte_virtiothat is shared.
c26937c66vhost: add virtio pci frameworkNext the virtio-vhost-user transport is added along with the
RTE_VHOST_USER_VIRTIO_TRANSPORTflag:
7fad5adc4vhost: remember a vhost_virtqueue's queue indexd26922892vhost: add virtio-vhost-user transportf562a70abvhost: addRTE_VHOST_USER_VIRTIO_TRANSPORTflagThen I extended the vhost vdev and vhost-scsi example application to support virtio-vhost-user:
47434f2a2 net/vhost: add virtio-vhost-user support 22ca05d1b examples/vhost_scsi: add --socket-file argument db3b391dc examples/vhost_scsi: add virtio-vhost-user supportIt was also necessary to tweak
dpdk-devbind.pyto support virtio-vhost-user:
4aee6f653usertools: add virtio-vhost-user devices todpdk-devbind.pyFinally, vhost-scsi seems broken to me so two workarounds were needed so it can be tested again:
b9d17bfafWORKAROUND revert virtio-net mq vring deletioncadb25e7dWORKAROUND examples/vhost_scsi: avoid brokenEVENT_IDXStefan Hajnoczi (24):
vhost: movevring_call()intotrans_af_unix.c
vhost: moveAF_UNIXcode fromsocket.ctotrans_af_unix.c
vhost: allocate per-socket transport state
vhost: movesocket_fdand un sockaddr intotrans_af_unix.c
vhost: move start_server/client() calls totrans_af_unix.c
vhost: movevhost_user_connectiontotrans_af_unix.c
vhost: movevhost_user_reconnect_init()intotrans_af_unix.c
vhost: move vhost_user.fdset totrans_af_unix.c
vhost: passvhost_transport_opsthroughvhost_new_device()
vhost: embed structvirtio_netinside structvhost_user_connection
vhost: extractvhost_user.csocket I/O into transport
vhost: moveslave_req_fdfield toAF_UNIXtransport
vhost: move mmap/munmap toAF_UNIXtransport
vhost: movelibrte_vhosttodrivers/
vhost: add virtio pci framework
vhost: remember a vhost_virtqueue's queue index
vhost: add virtio-vhost-user transport
vhost: addRTE_VHOST_USER_VIRTIO_TRANSPORTflag net/vhost: add virtio-vhost-user support examples/vhost_scsi: add --socket-file argument examples/vhost_scsi: add virtio-vhost-user support
usertools: add virtio-vhost-user devices todpdk-devbind.pyWORKAROUND revert virtio-net mq vring deletion WORKAROUND examples/vhost_scsi: avoid brokenEVENT_IDXdrivers/Makefile | 2 + {lib => drivers}/librte_vhost/Makefile | 5 +- lib/Makefile | 3 - {lib => drivers}/librte_vhost/fd_man.h | 0 {lib => drivers}/librte_vhost/iotlb.h | 0 {lib => drivers}/librte_vhost/rte_vhost.h | 1 + {lib => drivers}/librte_vhost/vhost.h | 193 +++- {lib => drivers}/librte_vhost/vhost_user.h | 9 +- drivers/librte_vhost/virtio_pci.h | 267 +++++ drivers/librte_vhost/virtio_vhost_user.h | 18 + drivers/librte_vhost/virtqueue.h | 181 ++++ {lib => drivers}/librte_vhost/fd_man.c | 0 {lib => drivers}/librte_vhost/iotlb.c | 0 drivers/librte_vhost/socket.c | 282 ++++++ drivers/librte_vhost/trans_af_unix.c | 795 +++++++++++++++ drivers/librte_vhost/trans_virtio_vhost_user.c | 1050 ++++++++++++++++++++ {lib => drivers}/librte_vhost/vhost.c | 18 +- {lib => drivers}/librte_vhost/vhost_user.c | 200 +--- {lib => drivers}/librte_vhost/virtio_net.c | 0 drivers/librte_vhost/virtio_pci.c | 504 ++++++++++ drivers/net/vhost/rte_eth_vhost.c | 13 + examples/vhost_scsi/vhost_scsi.c | 104 +- lib/librte_vhost/socket.c | 828 --------------- .../librte_vhost/rte_vhost_version.map | 0 usertools/dpdk-devbind.py | 8 + 25 files changed, 3455 insertions(+), 1026 deletions(-)rename {lib => drivers}/librte_vhost/Makefile (86%) rename {lib =>
drivers}/librte_vhost/fd_man.h(100%) rename {lib =>drivers}/librte_vhost/iotlb.h(100%) rename {lib =>drivers}/librte_vhost/rte_vhost.h(99%) rename {lib =>drivers}/librte_vhost/vhost.h(68%) rename {lib =>drivers}/librte_vhost/vhost_user.h(93%) create mode 100644drivers/librte_vhost/virtio_pci.hcreate mode 100644drivers/librte_vhost/virtio_vhost_user.hcreate mode 100644drivers/librte_vhost/virtqueue.hrename {lib =>drivers}/librte_vhost/fd_man.c(100%) rename {lib =>drivers}/librte_vhost/iotlb.c(100%) create mode 100644drivers/librte_vhost/socket.ccreate mode 100644drivers/librte_vhost/trans_af_unix.ccreate mode 100644drivers/librte_vhost/trans_virtio_vhost_user.crename {lib =>drivers}/librte_vhost/vhost.c(97%) rename {lib =>drivers}/librte_vhost/vhost_user.c(89%) rename {lib =>drivers}/librte_vhost/virtio_net.c(100%) create mode 100644drivers/librte_vhost/virtio_pci.cdelete mode 100644lib/librte_vhost/socket.c
rename {lib => drivers}/librte_vhost/rte_vhost_version.map (100%)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · Stefan Hajnoczi
Wei: Are you still interested in this?
In order to make further progress a review of this patch series is required.
If it's not a priority for you, that's fine too. We can leave it and pick it up (or replace it with something better) in the future.
Hi Stefan,
Yes, I'm interested in it. But apologize that this task is postponed due to some higher priority tasks on my worklist. I think I would be able to allocate some bandwidth for this project after the live migration related patches get merged.
When coming back, I plan to discuss with you about the QEMU patches, and finalize the device part first. Then we will need dpdk guys' help on the driver patches.
Thanks a lot for your hard work on the new prototype.
Best,
Wei