vhost-vDPA multiqueue
v4 cover vhost-vDPA multiqueue
Hi All:
This patch implements the multiqueue support for vhost-vDPA. The most important requirement si the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated vhost_net device which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. This means the control virtqueue will bypass the Qemu. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.
For the future, if we want to support live migration, we can either do shadow cvq on top or introduce new interfaces for reporting device states.
Tests are done via the vp_vdpa driver in L1 guest.
Changes since V3:
- fix build with vhost disabled
Changes since V2:
- rebase to qemu master
- use "queue_pairs" instead of "qps"
- typo fixes
Changes since V1:
- start and stop vhost devices when all queues were setup
- fix the case when driver doesn't support MQ but device support
- correctly set the batching capability to avoid a map/unmap storm
- various other tweaks
Jason Wang (10):
vhost-vdpa: open device fd in net_init_vhost_vdpa()
vhost-vdpa: classify one time request
vhost-vdpa: prepare for the multiqueue support
vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState *
net: introduce control client
vhost-net: control virtqueue support
virtio-net: use "queue_pairs" instead of "queues" when possible
vhost: record the last virtqueue index for the virtio device
virtio-net: vhost control virtqueue support
vhost-vdpa: multiqueue support
hw/net/vhost_net-stub.c | 4 +- hw/net/vhost_net.c | 55 ++++++++--- hw/net/virtio-net.c | 165 ++++++++++++++++++--------------- hw/virtio/vhost-vdpa.c | 56 +++++++++-- include/hw/virtio/vhost-vdpa.h | 1 + include/hw/virtio/vhost.h | 2 + include/hw/virtio/virtio-net.h | 5 +- include/net/net.h | 5 + include/net/vhost_net.h | 6 +- net/net.c | 24 ++++- net/vhost-vdpa.c | 127 ++++++++++++++++++++++--- 11 files changed, 330 insertions(+), 120 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 1/10 vhost-vdpa: open device fd in net_init_vhost_vdpa()
This patch switches to open device fd in net_init_vhost_vpda(). This is used to prepare for the multiqueue support.
Message-Id: <[email protected]>
--- net/vhost-vdpa.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
net/vhost-vdpa.c +15 -8
@@ -156,24 +156,19 @@ static NetClientInfo net_vhost_vdpa_info = { };static int net_vhost_vdpa_init (NetClientState *peer,const char *device, -const char *name,const char *vhostdev) +const char *name,int vdpa_device_fd) {NetClientState *nc =NULL ;VhostVDPAState *s; -int vdpa_device_fd =-1 ;int ret =0 ;assert (name); nc =qemu_new_net_client (&net_vhost_vdpa_info, peer, device, name);snprintf (nc->info_str,sizeof (nc->info_str),TYPE_VHOST_VDPA ); s =DO_UPCAST (VhostVDPAState, nc, nc); - vdpa_device_fd =qemu_open_old (vhostdev,O_RDWR ); -if (vdpa_device_fd ==-1 ) { -return -errno; - } + s->vhost_vdpa.device_fd = vdpa_device_fd; ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa);if (ret) { -qemu_close (vdpa_device_fd);qemu_del_net_client (nc); }return ret;
@@ -201,6 +196,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) {const NetdevVhostVDPAOptions *opts; +int vdpa_device_fd, ret;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;
@@ -209,5 +205,16 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, (char *)name, errp)) {return -1 ; } -return net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, opts->vhostdev); + + vdpa_device_fd =qemu_open_old (opts->vhostdev,O_RDWR ); +if (vdpa_device_fd ==-1 ) { +return -errno; + } + + ret =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, vdpa_device_fd); +if (ret) { +qemu_close (vdpa_device_fd); + } + +return ret; }
Signature · 1 line
2.25.1
PATCH v4 2/10 vhost-vdpa: classify one time request
In reply to Jason WangVhost-vdpa uses one device multiqueue queue (pairs) model. So we need to classify the one time request (e.g SET_OWNER) and make sure those request were only called once per device.
This is used for multiqueue support.
Message-Id: <[email protected]>
--- hw/virtio/vhost-vdpa.c | 52 ++++++++++++++++++++++++++++++---- include/hw/virtio/vhost-vdpa.h | 1 + 2 files changed, 47 insertions(+), 6 deletions(-)
hw/virtio/vhost-vdpa.c +46 -6
@@ -279,6 +279,13 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &s); } +static bool vhost_vdpa_one_time_request (struct vhost_dev *dev) +{ +struct vhost_vdpa *v = dev->opaque; + +return v->index !=0 ; +} +static int vhost_vdpa_init (struct vhost_dev *dev,void *opaque,Error **errp) {struct vhost_vdpa *v;
@@ -291,6 +298,10 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) v->listener = vhost_vdpa_memory_listener; v->msg_type =VHOST_IOTLB_MSG_V2 ; +if (vhost_vdpa_one_time_request (dev)) { +return 0 ; + } +vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_ACKNOWLEDGE |VIRTIO_CONFIG_S_DRIVER );
@@ -401,6 +412,10 @@ static int vhost_vdpa_memslots_limit(struct vhost_dev *dev)static int vhost_vdpa_set_mem_table (struct vhost_dev *dev,struct vhost_memory *mem) { +if (vhost_vdpa_one_time_request (dev)) { +return 0 ; + } +trace_vhost_vdpa_set_mem_table (dev, mem->nregions, mem->padding);if (trace_event_get_state_backends (TRACE_VHOST_VDPA_SET_MEM_TABLE ) &&trace_event_get_state_backends (TRACE_VHOST_VDPA_DUMP_REGIONS )) {
@@ -424,6 +439,11 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev, uint64_t features) {int ret; + +if (vhost_vdpa_one_time_request (dev)) { +return 0 ; + } +trace_vhost_vdpa_set_features (dev, features); ret =vhost_vdpa_call (dev,VHOST_SET_FEATURES , &features);uint8_t status =0 ;
@@ -448,9 +468,12 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) } features &= f; - r =vhost_vdpa_call (dev,VHOST_SET_BACKEND_FEATURES , &features); -if (r) { -return -EFAULT ; + +if (vhost_vdpa_one_time_request (dev)) { + r =vhost_vdpa_call (dev,VHOST_SET_BACKEND_FEATURES , &features); +if (r) { +return -EFAULT ; + } } dev->backend_cap = features;
@@ -559,11 +582,21 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) {struct vhost_vdpa *v = dev->opaque;trace_vhost_vdpa_dev_start (dev, started); +if (started) { -uint8_t status =0 ; -memory_listener_register (&v->listener, &address_space_memory);vhost_vdpa_host_notifiers_init (dev);vhost_vdpa_set_vring_ready (dev); + }else { +vhost_vdpa_host_notifiers_uninit (dev, dev->nvqs); + } + +if (vhost_vdpa_one_time_request (dev)) { +return 0 ; + } + +if (started) { +uint8_t status =0 ; +memory_listener_register (&v->listener, &address_space_memory);vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_DRIVER_OK );vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status);
@@ -572,7 +605,6 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)vhost_vdpa_reset_device (dev);vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_ACKNOWLEDGE |VIRTIO_CONFIG_S_DRIVER ); -vhost_vdpa_host_notifiers_uninit (dev, dev->nvqs);memory_listener_unregister (&v->listener);return 0 ;
@@ -582,6 +614,10 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)static int vhost_vdpa_set_log_base (struct vhost_dev *dev,uint64_t base,struct vhost_log *log) { +if (vhost_vdpa_one_time_request (dev)) { +return 0 ; + } +trace_vhost_vdpa_set_log_base (dev, base, log->size, log->refcnt, log->fd, log->log);return vhost_vdpa_call (dev,VHOST_SET_LOG_BASE , &base);
@@ -647,6 +683,10 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev,static int vhost_vdpa_set_owner (struct vhost_dev *dev) { +if (vhost_vdpa_one_time_request (dev)) { +return 0 ; + } +trace_vhost_vdpa_set_owner (dev);return vhost_vdpa_call (dev,VHOST_SET_OWNER ,NULL ); }
include/hw/virtio/vhost-vdpa.h +1 -0
@@ -21,6 +21,7 @@ typedef struct VhostVDPAHostNotifier { typedef struct vhost_vdpa { int device_fd; + int index; uint32_t msg_type; bool iotlb_batch_begin_sent; MemoryListener listener;
Signature · 1 line
2.25.1
PATCH v4 3/10 vhost-vdpa: prepare for the multiqueue support
In reply to Jason WangUnlike vhost-kernel, vhost-vdpa adapts a single device multiqueue model. So we need to simply use virtqueue index as the vhost virtqueue index. This is a must for multiqueue to work for vhost-vdpa.
Message-Id: <[email protected]>
--- hw/virtio/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost-vdpa.c +2 -2
@@ -504,8 +504,8 @@ static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) {assert (idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs); -trace_vhost_vdpa_get_vq_index (dev, idx, idx - dev->vq_index); -return idx - dev->vq_index; +trace_vhost_vdpa_get_vq_index (dev, idx, idx); +return idx; }static int vhost_vdpa_set_vring_ready (struct vhost_dev *dev)
Signature · 1 line
2.25.1
Re: [PATCH V4 03/10] vhost-vdpa: prepare for the multiqueue support
Quoted 17 lines · Jason Wang
Unlike vhost-kernel, vhost-vdpa adapts a single device multiqueue model. So we need to simply use virtqueue index as the vhost virtqueue index. This is a must for multiqueue to work for vhost-vdpa.
Signed-off-by Jason Wang <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
hw/virtio/vhost-vdpa.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)hw/virtio/vhost-vdpa.c +0
-0
hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) · line 505
Quoted 2 lines
hw/virtio/vhost-vdpa.c +0
-0@@ -504,8 +504,8 @@ static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) {assert (idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs);
Should we also change this assert?
Thanks,
Stefano
Quoted 12 lines
hw/virtio/vhost-vdpa.c +2
-2-trace_vhost_vdpa_get_vq_index (dev, idx, idx - dev->vq_index); -return idx - dev->vq_index; +trace_vhost_vdpa_get_vq_index (dev, idx, idx); +return idx; }static int vhost_vdpa_set_vring_ready (struct vhost_dev *dev)Signature · 1 line
2.25.1
Re: [PATCH V4 03/10] vhost-vdpa: prepare for the multiqueue support
Quoted 14 lines · Stefano Garzarella
Quoted 12 lines · Jason Wang
Unlike vhost-kernel, vhost-vdpa adapts a single device multiqueue model. So we need to simply use virtqueue index as the vhost virtqueue index. This is a must for multiqueue to work for vhost-vdpa.
Signed-off-by Jason Wang <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
hw/virtio/vhost-vdpa.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 9 lines
hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) · line 505
Quoted 7 lines
hw/virtio/vhost-vdpa.c +0
-0@@ -504,8 +504,8 @@ static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx) {assert (idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs);Should we also change this assert?
I think this assert applies to multi-queue as well.
Thanks
Quoted 17 lines
Thanks,
StefanoQuoted 12 lines
hw/virtio/vhost-vdpa.c +2
-3-trace_vhost_vdpa_get_vq_index (dev, idx, idx - dev->vq_index); -return idx - dev->vq_index; +trace_vhost_vdpa_get_vq_index (dev, idx, idx); +return idx; }static int vhost_vdpa_set_vring_ready (struct vhost_dev *dev) --2.25.1
PATCH v4 4/10 vhost-vdpa: let net_vhost_vdpa_init() returns NetClientState *
In reply to Jason WangThis patch switches to let net_vhost_vdpa_init() to return NetClientState *. This is used for the callers to allocate multiqueue NetClientState for multiqueue support.
Message-Id: <[email protected]>
--- net/vhost-vdpa.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
net/vhost-vdpa.c +12 -7
@@ -155,8 +155,10 @@ static NetClientInfo net_vhost_vdpa_info = { .has_ufo = vhost_vdpa_has_ufo, }; -static int net_vhost_vdpa_init (NetClientState *peer,const char *device, -const char *name,int vdpa_device_fd) +static NetClientState *net_vhost_vdpa_init (NetClientState *peer, +const char *device, +const char *name, +int vdpa_device_fd) {NetClientState *nc =NULL ;VhostVDPAState *s;
@@ -170,8 +172,9 @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa);if (ret) {qemu_del_net_client (nc); +return NULL ; } -return ret; +return nc; }static int net_vhost_check_net (void *opaque,QemuOpts *opts,Error **errp)
@@ -196,7 +199,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) {const NetdevVhostVDPAOptions *opts; -int vdpa_device_fd, ret; +int vdpa_device_fd; +NetClientState *nc;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;
@@ -211,10 +215,11 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,return -errno; } - ret =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, vdpa_device_fd); -if (ret) { + nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, vdpa_device_fd); +if (!nc) {qemu_close (vdpa_device_fd); +return -1 ; } -return ret; +return 0 ; }
Signature · 1 line
2.25.1
PATCH v4 5/10 net: introduce control client
In reply to Jason WangThis patch introduces a boolean for the device has control queue which can accepts control command via network queue.
The first user would be the control virtqueue support for vhost.
Message-Id: <[email protected]>
--- include/net/net.h | 5 +++++ net/net.c | 24 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-)
include/net/net.h +5 -0
@@ -103,6 +103,7 @@ struct NetClientState {int vnet_hdr_len;bool is_netdev;bool do_not_pad;/* do not pad to the minimum ethernet frame length */ +bool is_datapath; QTAILQ_HEAD(, NetFilterState) filters; };
@@ -134,6 +135,10 @@ NetClientState *qemu_new_net_client(NetClientInfo *info,NetClientState *peer, const char *model, const char *name); +NetClientState *qemu_new_net_control_client (NetClientInfo *info, +NetClientState *peer, +const char *model, +const char *name); NICState *qemu_new_nic(NetClientInfo *info, NICConf *conf, const char *model,
net/net.c +21 -3
@@ -239,7 +239,8 @@ static void qemu_net_client_setup(NetClientState *nc,NetClientState *peer, const char *model, const char *name, - NetClientDestructor *destructor) + NetClientDestructor *destructor, + bool is_datapath) { nc->info = info; nc->model =g_strdup (model);
@@ -258,6 +259,7 @@ static void qemu_net_client_setup(NetClientState *nc, nc->incoming_queue =qemu_new_net_queue (qemu_deliver_packet_iov, nc); nc->destructor = destructor; + nc->is_datapath = is_datapath;QTAILQ_INIT (&nc->filters); }
@@ -272,7 +274,23 @@ NetClientState *qemu_new_net_client(NetClientInfo *info, nc =g_malloc0 (info->size);qemu_net_client_setup (nc, info, peer, model, name, - qemu_net_client_destructor); + qemu_net_client_destructor, true); + +return nc; +} + +NetClientState *qemu_new_net_control_client (NetClientInfo *info, +NetClientState *peer, +const char *model, +const char *name) +{ +NetClientState *nc; + +assert (info->size >=sizeof (NetClientState)); + + nc =g_malloc0 (info->size); +qemu_net_client_setup (nc, info, peer, model, name, + qemu_net_client_destructor, false);return nc; }
@@ -297,7 +315,7 @@ NICState *qemu_new_nic(NetClientInfo *info,for (i =0 ; i < queues; i++) {qemu_net_client_setup (&nic->ncs[i], info, peers[i], model, name, -NULL ); +NULL , true); nic->ncs[i].queue_index = i; }
Signature · 1 line
2.25.1
PATCH v4 6/10 vhost-net: control virtqueue support
In reply to Jason WangWe assume there's no cvq in the past, this is not true when we need control virtqueue support for vhost-user backends. So this patch implements the control virtqueue support for vhost-net. As datapath, the control virtqueue is also required to be coupled with the NetClientState. The vhost_net_start/stop() are tweaked to accept the number of datapath queue pairs plus the the number of control virtqueue for us to start and stop the vhost device.
Message-Id: <[email protected]>
--- hw/net/vhost_net-stub.c | 4 ++-- hw/net/vhost_net.c | 43 ++++++++++++++++++++++++++++++----------- hw/net/virtio-net.c | 4 ++-- include/net/vhost_net.h | 6 ++++-- 4 files changed, 40 insertions(+), 17 deletions(-)
hw/net/vhost_net-stub.c +2 -2
@@ -33,13 +33,13 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)int vhost_net_start (VirtIODevice *dev,NetClientState *ncs, -int total_queues) +int data_queue_pairs,int cvq) {return -ENOSYS ; }void vhost_net_stop (VirtIODevice *dev,NetClientState *ncs, -int total_queues) +int data_queue_pairs,int cvq) { }
hw/net/vhost_net.c +32 -11
91 lines not on this page · raw message
hw/net/virtio-net.c +2 -2
@@ -285,14 +285,14 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) } n->vhost_started =1 ; - r =vhost_net_start (vdev, n->nic->ncs, queues); + r =vhost_net_start (vdev, n->nic->ncs, queues,0 );if (r <0 ) {error_report ("unable to start vhost net: %d: " "falling back on userspace virtio" , -r); n->vhost_started =0 ; } }else { -vhost_net_stop (vdev, n->nic->ncs, queues); +vhost_net_stop (vdev, n->nic->ncs, queues,0 ); n->vhost_started =0 ; } }
include/net/vhost_net.h +4 -2
@@ -21,8 +21,10 @@ typedef struct VhostNetOptions {uint64_t vhost_net_get_max_queues (VHostNetState *net);struct vhost_net *vhost_net_init (VhostNetOptions *options); -int vhost_net_start (VirtIODevice *dev,NetClientState *ncs,int total_queues); -void vhost_net_stop (VirtIODevice *dev,NetClientState *ncs,int total_queues); +int vhost_net_start (VirtIODevice *dev,NetClientState *ncs, +int data_queue_pairs,int cvq); +void vhost_net_stop (VirtIODevice *dev,NetClientState *ncs, +int data_queue_pairs,int cvq);void vhost_net_cleanup (VHostNetState *net);
Signature · 1 line
2.25.1
PATCH v4 7/10 virtio-net: use "queue_pairs" instead of "queues" when possible
In reply to Jason WangMost of the time, "queues" really means queue pairs. So this patch switch to use "queue_pairs" to avoid confusion.
Message-Id: <[email protected]>
--- hw/net/vhost_net.c | 6 +- hw/net/virtio-net.c | 150 ++++++++++++++++----------------- include/hw/virtio/virtio-net.h | 4 +- 3 files changed, 80 insertions(+), 80 deletions(-)
hw/net/vhost_net.c +3 -3
@@ -337,7 +337,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,if (i < data_queue_pairs) { peer =qemu_get_peer (ncs, i); }else {/* Control Virtqueue */ - peer =qemu_get_peer (ncs, n->max_queues); + peer =qemu_get_peer (ncs, n->max_queue_pairs); } net =get_vhost_net (peer);
@@ -362,7 +362,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,if (i < data_queue_pairs) { peer =qemu_get_peer (ncs, i); }else { - peer =qemu_get_peer (ncs, n->max_queues); + peer =qemu_get_peer (ncs, n->max_queue_pairs); } r =vhost_net_start_one (get_vhost_net (peer), dev);
@@ -412,7 +412,7 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,if (i < data_queue_pairs) { peer =qemu_get_peer (ncs, i); }else { - peer =qemu_get_peer (ncs, n->max_queues); + peer =qemu_get_peer (ncs, n->max_queue_pairs); }vhost_net_stop_one (get_vhost_net (peer), dev); }
hw/net/virtio-net.c +75 -75
447 lines not on this page · raw message
include/hw/virtio/virtio-net.h +2 -2
@@ -194,8 +194,8 @@ struct VirtIONet {NICConf nic_conf;DeviceState *qdev;int multiqueue; -uint16_t max_queues; -uint16_t curr_queues; +uint16_t max_queue_pairs; +uint16_t curr_queue_pairs;size_t config_size;char *netclient_name;char *netclient_type;
Signature · 1 line
2.25.1
PATCH v4 8/10 vhost: record the last virtqueue index for the virtio device
In reply to Jason WangThis patch introduces a new field in the vhost_dev structure to record the last virtqueue index for the virtio device. This will be useful for the vhost backends with 1:N model to start or stop the device after all the vhost_dev structures were started or stopped.
Message-Id: <[email protected]>
--- hw/net/vhost_net.c | 12 +++++++++--- include/hw/virtio/vhost.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-)
hw/net/vhost_net.c +9 -3
@@ -231,9 +231,11 @@ fail:return NULL ; } -static void vhost_net_set_vq_index (struct vhost_net *net,int vq_index) +static void vhost_net_set_vq_index (struct vhost_net *net,int vq_index, +int last_index) { net->dev.vq_index = vq_index; + net->dev.last_index = last_index; } static int vhost_net_start_one(struct vhost_net *net,
@@ -324,9 +326,13 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,VirtIONet *n =VIRTIO_NET (dev);int nvhosts = data_queue_pairs + cvq;struct vhost_net *net; -int r, e, i; +int r, e, i, last_index = data_qps *2 ;NetClientState *peer; +if (!cvq) { + last_index -=1 ; + } +if (!k->set_guest_notifiers) {error_report ("binding does not support guest notifiers" );return -ENOSYS ;
@@ -341,7 +347,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } net =get_vhost_net (peer); -vhost_net_set_vq_index (net, i *2 ); +vhost_net_set_vq_index (net, i *2 , last_index);/* Suppress the masking guest notifiers on vhost user * because vhost user doesn't interrupt masking/unmasking
include/hw/virtio/vhost.h +2 -0
@@ -74,6 +74,8 @@ struct vhost_dev {unsigned int nvqs;/* the first virtqueue which would be used by this vhost dev */ int vq_index; +/* the last vq index for the virtio device (not vhost) */ +int last_index;/* if non-zero, minimum required value for max_queues */ int num_queues;uint64_t features;
Signature · 1 line
2.25.1
PATCH v4 9/10 virtio-net: vhost control virtqueue support
In reply to Jason WangThis patch implements the control virtqueue support for vhost. This requires virtio-net to figure out the datapath queue pairs and control virtqueue via is_datapath and pass the number of those two types of virtqueues to vhost_net_start()/vhost_net_stop().
Message-Id: <[email protected]>
--- hw/net/vhost_net.c | 2 +- hw/net/virtio-net.c | 23 +++++++++++++++++++---- include/hw/virtio/virtio-net.h | 1 + 3 files changed, 21 insertions(+), 5 deletions(-)
hw/net/vhost_net.c +1 -1
@@ -326,7 +326,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,VirtIONet *n =VIRTIO_NET (dev);int nvhosts = data_queue_pairs + cvq;struct vhost_net *net; -int r, e, i, last_index = data_qps *2 ; +int r, e, i, last_index = data_queue_pairs *2 ;NetClientState *peer;if (!cvq) {
hw/net/virtio-net.c +19 -4
@@ -244,6 +244,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)VirtIODevice *vdev =VIRTIO_DEVICE (n);NetClientState *nc =qemu_get_queue (n->nic);int queue_pairs = n->multiqueue ? n->max_queue_pairs :1 ; +int cvq = n->max_ncs - n->max_queue_pairs;if (!get_vhost_net (nc->peer)) {return ;
@@ -285,14 +286,14 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) } n->vhost_started =1 ; - r =vhost_net_start (vdev, n->nic->ncs, queue_pairs,0 ); + r =vhost_net_start (vdev, n->nic->ncs, queue_pairs, cvq);if (r <0 ) {error_report ("unable to start vhost net: %d: " "falling back on userspace virtio" , -r); n->vhost_started =0 ; } }else { -vhost_net_stop (vdev, n->nic->ncs, queue_pairs,0 ); +vhost_net_stop (vdev, n->nic->ncs, queue_pairs, cvq); n->vhost_started =0 ; } }
@@ -3393,9 +3394,23 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)return ; } - n->max_queue_pairs =MAX (n->nic_conf.peers.queues,1 ); + n->max_ncs =MAX (n->nic_conf.peers.queues,1 ); + +/* +* Figure out the datapath queue pairs since the backend could +* provide control queue via peers as well. +*/ +if (n->nic_conf.peers.queues) { +for (i =0 ; i < n->max_ncs; i++) { +if (n->nic_conf.peers.ncs[i]->is_datapath) { + ++n->max_queue_pairs; + } + } + } + n->max_queue_pairs =MAX (n->max_queue_pairs,1 ); +if (n->max_queue_pairs *2 +1 >VIRTIO_QUEUE_MAX ) { -error_setg (errp,"Invalid number of queue_pairs (= %" PRIu32"), " +error_setg (errp,"Invalid number of queue pairs (= %" PRIu32"), " "must be a positive integer less than %d." , n->max_queue_pairs, (VIRTIO_QUEUE_MAX -1 ) /2 );virtio_cleanup (vdev);
include/hw/virtio/virtio-net.h +1 -0
@@ -196,6 +196,7 @@ struct VirtIONet {int multiqueue;uint16_t max_queue_pairs;uint16_t curr_queue_pairs; +uint16_t max_ncs;size_t config_size;char *netclient_name;char *netclient_type;
Signature · 1 line
2.25.1
PATCH v4 10/10 vhost-vdpa: multiqueue support
In reply to Jason WangThis patch implements the multiqueue support for vhost-vdpa. This is done simply by reading the number of queue pairs from the config space and initialize the datapath and control path net client.
Message-Id: <[email protected]>
--- hw/virtio/vhost-vdpa.c | 2 +- net/vhost-vdpa.c | 105 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 97 insertions(+), 10 deletions(-)
hw/virtio/vhost-vdpa.c +1 -1
@@ -590,7 +590,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)vhost_vdpa_host_notifiers_uninit (dev, dev->nvqs); } -if (vhost_vdpa_one_time_request (dev)) { +if (dev->vq_index + dev->nvqs != dev->last_index) {return 0 ; }
net/vhost-vdpa.c +96 -9
163 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 12 lines · Jason Wang
Hi All:
This patch implements the multiqueue support for vhost-vDPA. The most important requirement si the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated
vhost_netdevice which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. This means the control virtqueue will bypass the Qemu. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.
Quoted 3 lines
For the future, if we want to support live migration, we can either do shadow cvq on top or introduce new interfaces for reporting device states.
I had to defer this due to rework I picked up. I pushed an experimental tree - it still has issues but if you rebase on top of that I can apply.
Quoted 46 lines
Tests are done via the
vp_vdpadriver in L1 guest.Changes since V3:
- fix build with vhost disabled
Changes since V2:
- rebase to qemu master
- use "queue_pairs" instead of "qps"
- typo fixesChanges since V1:
- start and stop vhost devices when all queues were setup
- fix the case when driver doesn't support MQ but device support
- correctly set the batching capability to avoid a map/unmap storm
- various other tweaksJason Wang (10):
vhost-vdpa: open device fd innet_init_vhost_vdpa()
vhost-vdpa: classify one time request
vhost-vdpa: prepare for the multiqueue support
vhost-vdpa: letnet_vhost_vdpa_init()returns NetClientState *
net: introduce control client
vhost-net: control virtqueue support
virtio-net: use "queue_pairs" instead of "queues" when possible
vhost: record the last virtqueue index for the virtio device
virtio-net: vhost control virtqueue support
vhost-vdpa: multiqueue supporthw/net/vhost_net-stub.c | 4 +- hw/net/vhost_net.c | 55 ++++++++--- hw/net/virtio-net.c | 165 ++++++++++++++++++--------------- hw/virtio/vhost-vdpa.c | 56 +++++++++-- include/hw/virtio/vhost-vdpa.h | 1 + include/hw/virtio/vhost.h | 2 + include/hw/virtio/virtio-net.h | 5 +- include/net/net.h | 5 + include/net/vhost_net.h | 6 +- net/net.c | 24 ++++- net/vhost-vdpa.c | 127 ++++++++++++++++++++++--- 11 files changed, 330 insertions(+), 120 deletions(-)Signature · 1 line
2.25.1
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Jason Wang
Hi All:
This patch implements the multiqueue support for vhost-vDPA. The most important requirement si the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated
vhost_netdevice which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. This means the control virtqueue will bypass the Qemu. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.
Quoted 8 lines
Quoted 3 lines
For the future, if we want to support live migration, we can either do shadow cvq on top or introduce new interfaces for reporting device states.
I had to defer this due to rework I picked up. I pushed an experimental tree - it still has issues but if you rebase on top of that I can apply.
Will do. For the tree, is itgit://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git next?
Thanks
Quoted 48 lines
Quoted 47 lines
Tests are done via the
vp_vdpadriver in L1 guest.Changes since V3:
- fix build with vhost disabled
Changes since V2:
- rebase to qemu master
- use "queue_pairs" instead of "qps"
- typo fixesChanges since V1:
- start and stop vhost devices when all queues were setup
- fix the case when driver doesn't support MQ but device support
- correctly set the batching capability to avoid a map/unmap storm
- various other tweaksJason Wang (10):
vhost-vdpa: open device fd innet_init_vhost_vdpa()
vhost-vdpa: classify one time request
vhost-vdpa: prepare for the multiqueue support
vhost-vdpa: letnet_vhost_vdpa_init()returns NetClientState *
net: introduce control client
vhost-net: control virtqueue support
virtio-net: use "queue_pairs" instead of "queues" when possible
vhost: record the last virtqueue index for the virtio device
virtio-net: vhost control virtqueue support
vhost-vdpa: multiqueue supporthw/net/vhost_net-stub.c | 4 +- hw/net/vhost_net.c | 55 ++++++++--- hw/net/virtio-net.c | 165 ++++++++++++++++++--------------- hw/virtio/vhost-vdpa.c | 56 +++++++++-- include/hw/virtio/vhost-vdpa.h | 1 + include/hw/virtio/vhost.h | 2 + include/hw/virtio/virtio-net.h | 5 +- include/net/net.h | 5 + include/net/vhost_net.h | 6 +- net/net.c | 24 ++++- net/vhost-vdpa.c | 127 ++++++++++++++++++++++--- 11 files changed, 330 insertions(+), 120 deletions(-)--
2.25.1
Quoted 20 lines · Jason Wang
Quoted 19 lines · Michael S. Tsirkin
Quoted 15 lines · Jason Wang
Hi All:
This patch implements the multiqueue support for vhost-vDPA. The most important requirement si the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated
vhost_netdevice which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. This means the control virtqueue will bypass the Qemu. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.For the future, if we want to support live migration, we can either do shadow cvq on top or introduce new interfaces for reporting device states.
Quoted 9 lines
Quoted 3 lines
I had to defer this due to rework I picked up. I pushed an experimental tree - it still has issues but if you rebase on top of that I can apply.
Will do. For the tree, is it
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gitnext?Thanks
pci
Quoted 48 lines
Quoted 48 lines
Quoted 47 lines
Tests are done via the
vp_vdpadriver in L1 guest.Changes since V3:
- fix build with vhost disabled
Changes since V2:
- rebase to qemu master
- use "queue_pairs" instead of "qps"
- typo fixesChanges since V1:
- start and stop vhost devices when all queues were setup
- fix the case when driver doesn't support MQ but device support
- correctly set the batching capability to avoid a map/unmap storm
- various other tweaksJason Wang (10):
vhost-vdpa: open device fd innet_init_vhost_vdpa()
vhost-vdpa: classify one time request
vhost-vdpa: prepare for the multiqueue support
vhost-vdpa: letnet_vhost_vdpa_init()returns NetClientState *
net: introduce control client
vhost-net: control virtqueue support
virtio-net: use "queue_pairs" instead of "queues" when possible
vhost: record the last virtqueue index for the virtio device
virtio-net: vhost control virtqueue support
vhost-vdpa: multiqueue supporthw/net/vhost_net-stub.c | 4 +- hw/net/vhost_net.c | 55 ++++++++--- hw/net/virtio-net.c | 165 ++++++++++++++++++--------------- hw/virtio/vhost-vdpa.c | 56 +++++++++-- include/hw/virtio/vhost-vdpa.h | 1 + include/hw/virtio/vhost.h | 2 + include/hw/virtio/virtio-net.h | 5 +- include/net/net.h | 5 + include/net/vhost_net.h | 6 +- net/net.c | 24 ++++- net/vhost-vdpa.c | 127 ++++++++++++++++++++++--- 11 files changed, 330 insertions(+), 120 deletions(-)--
2.25.1
Quoted 25 lines · Michael S. Tsirkin
Quoted 24 lines · Jason Wang
Quoted 22 lines · Michael S. Tsirkin
Quoted 12 lines · Jason Wang
Hi All:
This patch implements the multiqueue support for vhost-vDPA. The most important requirement si the control virtqueue support. The virtio-net and vhost-net core are tweak to support control virtqueue as if what data queue pairs are done: a dedicated
vhost_netdevice which is coupled with the NetClientState is intrdouced so most of the existing vhost codes could be reused with minor changes. This means the control virtqueue will bypass the Qemu. With the control virtqueue, vhost-vDPA are extend to support creating and destroying multiqueue queue pairs plus the control virtqueue.Quoted 3 lines
For the future, if we want to support live migration, we can either do shadow cvq on top or introduce new interfaces for reporting device states.
I had to defer this due to rework I picked up. I pushed an experimental tree - it still has issues but if you rebase on top of that I can apply.
Quoted 7 lines
Quoted 5 lines
Will do. For the tree, is it
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gitnext?Thanks
pci
pushed now
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 47 lines
Tests are done via the
vp_vdpadriver in L1 guest.Changes since V3:
- fix build with vhost disabled
Changes since V2:
- rebase to qemu master
- use "queue_pairs" instead of "qps"
- typo fixesChanges since V1:
- start and stop vhost devices when all queues were setup
- fix the case when driver doesn't support MQ but device support
- correctly set the batching capability to avoid a map/unmap storm
- various other tweaksJason Wang (10):
vhost-vdpa: open device fd innet_init_vhost_vdpa()
vhost-vdpa: classify one time request
vhost-vdpa: prepare for the multiqueue support
vhost-vdpa: letnet_vhost_vdpa_init()returns NetClientState *
net: introduce control client
vhost-net: control virtqueue support
virtio-net: use "queue_pairs" instead of "queues" when possible
vhost: record the last virtqueue index for the virtio device
virtio-net: vhost control virtqueue support
vhost-vdpa: multiqueue supporthw/net/vhost_net-stub.c | 4 +- hw/net/vhost_net.c | 55 ++++++++--- hw/net/virtio-net.c | 165 ++++++++++++++++++--------------- hw/virtio/vhost-vdpa.c | 56 +++++++++-- include/hw/virtio/vhost-vdpa.h | 1 + include/hw/virtio/vhost.h | 2 + include/hw/virtio/virtio-net.h | 5 +- include/net/net.h | 5 + include/net/vhost_net.h | 6 +- net/net.c | 24 ++++- net/vhost-vdpa.c | 127 ++++++++++++++++++++++--- 11 files changed, 330 insertions(+), 120 deletions(-)--
2.25.1