[PATCH v3 06/13] vhost: introduce new VhostOps vhost_dev_start
This patch introduces new VhostOps vhost_dev_start callback which allows the vhost_net set the start/stop status to backend Signed-off-by: Cindy Lu --- include/hw/virtio/vhost-backend.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 6f6670783f..b80f344cd6 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -112,6 +112,7 @@ typedef int (*vhost_get_inflight_fd_op)(struct vhost_dev *dev, typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, struct vhost_inflight *inflight); +typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -152,6 +153,7 @@ typedef struct VhostOps { vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter; vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; +vhost_dev_start_op vhost_dev_start; } VhostOps; extern const VhostOps user_ops; -- 2.21.1
[PATCH v3 04/13] virtio-pci: implement queue_enabled method
From: Jason Wang With version 1, we can detect whether a queue is enabled via queue_enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 13 + 1 file changed, 13 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 7bc8c1c056..8554cf2a03 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1107,6 +1107,18 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d) return pci_get_address_space(dev); } +static bool virtio_pci_queue_enabled(DeviceState *d, int n) +{ +VirtIOPCIProxy *proxy = VIRTIO_PCI(d); +VirtIODevice *vdev = virtio_bus_get_device(>bus); + +if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { +return proxy->vqs[vdev->queue_sel].enabled; +} + +return virtio_queue_enabled(vdev, n); +} + static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, struct virtio_pci_cap *cap) { @@ -2064,6 +2076,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; k->ioeventfd_assign = virtio_pci_ioeventfd_assign; k->get_dma_as = virtio_pci_get_dma_as; +k->queue_enabled = virtio_pci_queue_enabled; } static const TypeInfo virtio_pci_bus_info = { -- 2.21.1
[PATCH v3 05/13] vhost: check the existence of vhost_set_iotlb_callback
From: Jason Wang Add the check of vhost_set_iotlb_callback before calling Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/vhost.c | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 5fd25fe520..10304b583e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1686,8 +1686,9 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) } } -if (vhost_dev_has_iommu(hdev)) { -hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); +if (vhost_dev_has_iommu(hdev) && +hdev->vhost_ops->vhost_set_iotlb_callback) { +hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); /* Update used ring information for IOTLB to work correctly, * vhost-kernel code requires for this.*/ @@ -1730,7 +1731,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) } if (vhost_dev_has_iommu(hdev)) { -hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false); +if (hdev->vhost_ops->vhost_set_iotlb_callback) { +hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false); +} memory_listener_unregister(>iommu_listener); } vhost_log_put(hdev, true); -- 2.21.1
[PATCH v3 03/13] virtio-bus: introduce queue_enabled method
From: Jason Wang This patch introduces queue_enabled() method which allows the transport to implement its own way to report whether or not a queue is enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/virtio.c | 6 ++ include/hw/virtio/virtio-bus.h | 4 2 files changed, 10 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index cc9c9dc162..5bd2a2f621 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3286,6 +3286,12 @@ hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n) bool virtio_queue_enabled(VirtIODevice *vdev, int n) { +BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); +VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + +if (k->queue_enabled) { +return k->queue_enabled(qbus->parent, n); +} return virtio_queue_get_desc_addr(vdev, n) != 0; } diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index 38c9399cd4..0f6f215925 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -83,6 +83,10 @@ typedef struct VirtioBusClass { */ int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier, int n, bool assign); +/* + * Whether queue number n is enabled. + */ +bool (*queue_enabled)(DeviceState *d, int n); /* * Does the transport have variable vring alignment? * (ie can it ever call virtio_queue_set_align()?) -- 2.21.1
[PATCH v3 02/13] vhost_net: use the function qemu_get_peer
user the qemu_get_peer to replace the old process Signed-off-by: Cindy Lu Reviewed-by: Laurent Vivier --- hw/net/vhost_net.c | 16 ++-- 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6b82803fa7..4096d64aaf 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -306,7 +306,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus = VIRTIO_BUS(qbus); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); +struct vhost_net *net; int r, e, i; +NetClientState *peer; if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); @@ -314,9 +316,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -struct vhost_net *net; -net = get_vhost_net(ncs[i].peer); +peer = qemu_get_peer(ncs, i); +net = get_vhost_net(peer); vhost_net_set_vq_index(net, i * 2); /* Suppress the masking guest notifiers on vhost user @@ -335,15 +337,16 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs, i); +r = vhost_net_start_one(get_vhost_net(peer), dev); if (r < 0) { goto err_start; } -if (ncs[i].peer->vring_enable) { +if (peer->vring_enable) { /* restore vring enable state */ -r = vhost_set_vring_enable(ncs[i].peer, ncs[i].peer->vring_enable); +r = vhost_set_vring_enable(peer, peer->vring_enable); if (r < 0) { goto err_start; @@ -355,7 +358,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, err_start: while (--i >= 0) { -vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs , i); +vhost_net_stop_one(get_vhost_net(peer), dev); } e = k->set_guest_notifiers(qbus->parent, total_queues * 2, false); if (e < 0) { -- 2.21.1
[PATCH v3 01/13] net: introduce qemu_get_peer
This is a small function that can get the peer from given NetClientState and queue_index Signed-off-by: Cindy Lu --- include/net/net.h | 1 + net/net.c | 7 +++ 2 files changed, 8 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 39085d9444..e7ef42d62b 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -176,6 +176,7 @@ void hmp_info_network(Monitor *mon, const QDict *qdict); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, bool vnet_hdr); +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); /* NIC info */ diff --git a/net/net.c b/net/net.c index d1130296e1..9099a327dd 100644 --- a/net/net.c +++ b/net/net.c @@ -325,6 +325,13 @@ void *qemu_get_nic_opaque(NetClientState *nc) return nic->opaque; } +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) +{ +assert(nc != NULL); +NetClientState *ncs = nc + queue_index; +return ncs->peer; +} + static void qemu_cleanup_net_client(NetClientState *nc) { QTAILQ_REMOVE(_clients, nc, next); -- 2.21.1
[PATCH v3 00/13] vDPA support in qemu
vDPA device is a device that uses a datapath which complies with the virtio specifications with vendor specific control path. vDPA devices can be both physically located on the hardware or emulated by software. This PATCH introduce the vDPA support in qemu TODO 1) vIOMMU support 2) live migration support 3) docs for vhost-vdpa 4) config interrupt support Change from v1 separate the patch of vhost_vq_get_addr separate the patch of vhost_dev_start introduce the docmation for vhost-vdpa.rst other comments form last version github address: https://github.com/lulu-github-name/qemutmp.git PATCHV2 Change from v2 fix the complie problem separate the patch of vhost_force_iommu other comments form last version github address: https://github.com/lulu-github-name/qemutmp.git PATCHV3 Cindy Lu (10): net: introduce qemu_get_peer vhost_net: use the function qemu_get_peer vhost: introduce new VhostOps vhost_dev_start vhost: implement vhost_dev_start method vhost: introduce new VhostOps vhost_vq_get_addr vhost: implement vhost_vq_get_addr method vhost: introduce new VhostOps vhost_force_iommu vhost: implement vhost_force_iommu method vhost-vdpa: introduce vhost-vdpa backend vhost-vdpa: introduce vhost-vdpa net client Jason Wang (3): virtio-bus: introduce queue_enabled method virtio-pci: implement queue_enabled method vhost: check the existence of vhost_set_iotlb_callback configure | 21 ++ docs/interop/index.rst| 1 + docs/interop/vhost-vdpa.rst | 17 ++ hw/net/vhost_net.c| 35 ++- hw/net/virtio-net.c | 20 ++ hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 6 + hw/virtio/vhost-vdpa.c| 475 ++ hw/virtio/vhost.c | 52 +++- hw/virtio/virtio-pci.c| 13 + hw/virtio/virtio.c| 6 + include/hw/virtio/vhost-backend.h | 19 +- include/hw/virtio/vhost-vdpa.h| 26 ++ include/hw/virtio/vhost.h | 7 + include/hw/virtio/virtio-bus.h| 4 + include/net/net.h | 1 + include/net/vhost-vdpa.h | 22 ++ net/Makefile.objs | 2 +- net/clients.h | 2 + net/net.c | 10 + net/vhost-vdpa.c | 228 ++ qapi/net.json | 28 +- qemu-options.hx | 12 + 23 files changed, 978 insertions(+), 30 deletions(-) create mode 100644 docs/interop/vhost-vdpa.rst create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c -- 2.21.1
Re: [PATCH v2 11/12] vhost-vdpa: introduce vhost-vdpa backend
Thanks Jason, will fix all these and send the new version soon On Wed, Jul 1, 2020 at 12:22 PM Jason Wang wrote: > > > On 2020/7/1 上午1:49, Cindy Lu wrote: > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > > qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > > -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > > -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Signed-off-by: Lingshan zhu > > Signed-off-by: Tiwei Bie > > > I would like to add my sob here. > > > > Signed-off-by: Cindy Lu > > --- > > configure | 21 ++ > > docs/interop/index.rst| 1 + > > docs/interop/vhost-vdpa.rst | 17 ++ > > hw/net/vhost_net.c| 19 +- > > hw/net/virtio-net.c | 22 +- > > hw/virtio/Makefile.objs | 1 + > > hw/virtio/vhost-backend.c | 7 +- > > hw/virtio/vhost-vdpa.c| 469 ++ > > hw/virtio/vhost.c | 7 +- > > include/hw/virtio/vhost-backend.h | 4 +- > > include/hw/virtio/vhost-vdpa.h| 26 ++ > > include/hw/virtio/vhost.h | 7 + > > qemu-options.hx | 12 + > > 13 files changed, 601 insertions(+), 12 deletions(-) > > create mode 100644 docs/interop/vhost-vdpa.rst > > create mode 100644 hw/virtio/vhost-vdpa.c > > create mode 100644 include/hw/virtio/vhost-vdpa.h > > > > diff --git a/configure b/configure > > index 4a22dcd563..3db7f20185 100755 > > --- a/configure > > +++ b/configure > > @@ -1575,6 +1575,10 @@ for opt do > > ;; > > --enable-vhost-user) vhost_user="yes" > > ;; > > + --disable-vhost-vdpa) vhost_vdpa="no" > > + ;; > > + --enable-vhost-vdpa) vhost_vdpa="yes" > > + ;; > > --disable-vhost-kernel) vhost_kernel="no" > > ;; > > --enable-vhost-kernel) vhost_kernel="yes" > > @@ -1883,6 +1887,7 @@ disabled with --disable-FEATURE, default is enabled > > if available: > > vhost-cryptovhost-user-crypto backend support > > vhost-kernelvhost kernel backend support > > vhost-user vhost-user backend support > > + vhost-vdpa vhost-vdpa kernel backend support > > spice spice > > rbd rados block device (rbd) > > libiscsiiscsi support > > @@ -2394,6 +2399,10 @@ test "$vhost_user" = "" && vhost_user=yes > > if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then > > error_exit "vhost-user isn't available on win32" > > fi > > +test "$vhost_vdpa" = "" && vhost_vdpa=$linux > > +if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then > > + error_exit "vhost-vdpa is only available on Linux" > > +fi > > test "$vhost_kernel" = "" && vhost_kernel=$linux > > if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then > > error_exit "vhost-kernel is only available on Linux" > > @@ -2422,6 +2431,11 @@ test "$vhost_user_fs" = "" && > > vhost_user_fs=$vhost_user > > if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then > > error_exit "--enable-vhost-user-fs requires --enable-vhost-user" > > fi > > +#vhost-vdpa backends > > +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa > > +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then > > + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" > > +fi > > > > # OR the vhost-kernel and vhost-user values for simplicity > > if test "$vhost_net" = ""; then > > @@ -6936,6 +6950,7 @@ echo "vhost-scsi support $vhost_scsi" > > echo "vhost-vsock supp
Re: [PATCH v2 00/12] vDPA support in qemu
Thanks Jason, I'm working in this, Will update a new version soon On Wed, Jul 1, 2020 at 1:29 PM Jason Wang wrote: > > > On 2020/7/1 上午2:06, no-re...@patchew.org wrote: > > Patchew URL: > > https://patchew.org/QEMU/20200630174937.25560-1-l...@redhat.com/ > > > > > > > > Hi, > > > > This series failed the docker-mingw@fedora build test. Please find the > > testing commands and > > their output below. If you have Docker installed, you can probably > > reproduce it > > locally. > > > > === TEST SCRIPT BEGIN === > > #! /bin/bash > > export ARCH=x86_64 > > make docker-image-fedora V=1 NETWORK=1 > > time make docker-test-mingw@fedora J=14 NETWORK=1 > > > Please fix this. You can reproduce this with the above commands. > > Thanks > > > > === TEST SCRIPT END === > > > > /tmp/qemu-test/src/hw/net/virtio-net.c:173: undefined reference to > > `vhost_dev_set_config' > > /usr/lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld: > > hw/net/virtio-net.o: in function `virtio_net_get_config': > > /tmp/qemu-test/src/hw/net/virtio-net.c:149: undefined reference to > > `vhost_dev_get_config' > > collect2: error: ld returned 1 exit status > > make[1]: *** [Makefile:208: qemu-system-x86_64w.exe] Error 1 > > make: *** [Makefile:527: x86_64-softmmu/all] Error 2 > > make: *** Waiting for unfinished jobs > >LINKaarch64-softmmu/qemu-system-aarch64w.exe > > /usr/lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld: > > hw/net/virtio-net.o: in function `virtio_net_set_config': > > /tmp/qemu-test/src/hw/net/virtio-net.c:173: undefined reference to > > `vhost_dev_set_config' > > /usr/lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld: > > hw/net/virtio-net.o: in function `virtio_net_get_config': > > /tmp/qemu-test/src/hw/net/virtio-net.c:149: undefined reference to > > `vhost_dev_get_config' > > collect2: error: ld returned 1 exit status > > make[1]: *** [Makefile:208: qemu-system-aarch64w.exe] Error 1 > > make: *** [Makefile:527: aarch64-softmmu/all] Error 2 > > Traceback (most recent call last): > >File "./tests/docker/docker.py", line 669, in > > sys.exit(main()) > > --- > > raise CalledProcessError(retcode, cmd) > > subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', > > '--label', 'com.qemu.instance.uuid=9f5def1ac1a840deb219e8827020f24d', '-u', > > '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', > > 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', > > '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', > > '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', > > '/var/tmp/patchew-tester-tmp-lwyumgcs/src/docker-src.2020-06-30-14.01.04.32102:/var/tmp/qemu:z,ro', > > 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit > > status 2. > > filter=--filter=label=com.qemu.instance.uuid=9f5def1ac1a840deb219e8827020f24d > > make[1]: *** [docker-run] Error 1 > > make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-lwyumgcs/src' > > make: *** [docker-run-test-mingw@fedora] Error 2 > > > > real5m52.723s > > user0m8.824s > > > > > > The full log is available at > > http://patchew.org/logs/20200630174937.25560-1-l...@redhat.com/testing.docker-mingw@fedora/?type=message. > > --- > > Email generated automatically by Patchew [https://patchew.org/]. > > Please send your feedback to patchew-de...@redhat.com >
[PATCH v2 12/12] vhost-vdpa: introduce vhost-vdpa net client
This patch set introduces a new net client type: vhost-vdpa. vhost-vdpa net client will set up a vDPA device which is specified by a "vhostdev" parameter. Signed-off-by: Lingshan Zhu Signed-off-by: Tiwei Bie Signed-off-by: Cindy Lu --- include/net/vhost-vdpa.h | 22 net/Makefile.objs| 2 +- net/clients.h| 2 + net/net.c| 3 + net/vhost-vdpa.c | 228 +++ qapi/net.json| 28 - 6 files changed, 281 insertions(+), 4 deletions(-) create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h new file mode 100644 index 00..45e34b7cfc --- /dev/null +++ b/include/net/vhost-vdpa.h @@ -0,0 +1,22 @@ +/* + * vhost-vdpa.h + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef VHOST_VDPA_H +#define VHOST_VDPA_H + +#define TYPE_VHOST_VDPA "vhost-vdpa" + +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); + +extern const int vdpa_feature_bits[]; + +#endif /* VHOST_VDPA_H */ diff --git a/net/Makefile.objs b/net/Makefile.objs index c5d076d19c..5ab45545db 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -26,7 +26,7 @@ tap-obj-$(CONFIG_SOLARIS) = tap-solaris.o tap-obj-y ?= tap-stub.o common-obj-$(CONFIG_POSIX) += tap.o $(tap-obj-y) common-obj-$(CONFIG_WIN32) += tap-win32.o - +common-obj-$(CONFIG_VHOST_NET_VDPA) += vhost-vdpa.o vde.o-libs = $(VDE_LIBS) common-obj-$(CONFIG_CAN_BUS) += can/ diff --git a/net/clients.h b/net/clients.h index a6ef267e19..92f9b59aed 100644 --- a/net/clients.h +++ b/net/clients.h @@ -61,4 +61,6 @@ int net_init_netmap(const Netdev *netdev, const char *name, int net_init_vhost_user(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, +NetClientState *peer, Error **errp); #endif /* QEMU_NET_CLIENTS_H */ diff --git a/net/net.c b/net/net.c index 9099a327dd..94dc546fb2 100644 --- a/net/net.c +++ b/net/net.c @@ -966,6 +966,9 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])( #ifdef CONFIG_VHOST_NET_USER [NET_CLIENT_DRIVER_VHOST_USER] = net_init_vhost_user, #endif +#ifdef CONFIG_VHOST_NET_VDPA +[NET_CLIENT_DRIVER_VHOST_VDPA] = net_init_vhost_vdpa, +#endif #ifdef CONFIG_L2TPV3 [NET_CLIENT_DRIVER_L2TPV3]= net_init_l2tpv3, #endif diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c new file mode 100644 index 00..bc0e0d2d35 --- /dev/null +++ b/net/vhost-vdpa.c @@ -0,0 +1,228 @@ +/* + * vhost-vdpa.c + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "clients.h" +#include "net/vhost_net.h" +#include "net/vhost-vdpa.h" +#include "hw/virtio/vhost-vdpa.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "qemu/option.h" +#include "qapi/error.h" +#include +#include +#include "standard-headers/linux/virtio_net.h" +#include "monitor/monitor.h" +#include "hw/virtio/vhost.h" + +/* Todo:need to add the multiqueue support here */ +typedef struct VhostVDPAState { +NetClientState nc; +struct vhost_vdpa vhost_vdpa; +VHostNetState *vhost_net; +uint64_t acked_features; +bool started; +} VhostVDPAState; + +const int vdpa_feature_bits[] = { +VIRTIO_F_NOTIFY_ON_EMPTY, +VIRTIO_RING_F_INDIRECT_DESC, +VIRTIO_RING_F_EVENT_IDX, +VIRTIO_F_ANY_LAYOUT, +VIRTIO_F_VERSION_1, +VIRTIO_NET_F_CSUM, +VIRTIO_NET_F_GUEST_CSUM, +VIRTIO_NET_F_GSO, +VIRTIO_NET_F_GUEST_TSO4, +VIRTIO_NET_F_GUEST_TSO6, +VIRTIO_NET_F_GUEST_ECN, +VIRTIO_NET_F_GUEST_UFO, +VIRTIO_NET_F_HOST_TSO4, +VIRTIO_NET_F_HOST_TSO6, +VIRTIO_NET_F_HOST_ECN, +VIRTIO_NET_F_HOST_UFO, +VIRTIO_NET_F_MRG_RXBUF, +VIRTIO_NET_F_MTU, +VIRTIO_F_IOMMU_PLATFORM, +VIRTIO_F_RING_PACKED, +VIRTIO_NET_F_GUEST_ANNOUNCE, +VHOST_INVALID_FEATURE_BIT +}; + +VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) +{ +VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); +assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); +return s->vhost_net; +} + +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc) +{ +VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); +assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_V
[PATCH v2 11/12] vhost-vdpa: introduce vhost-vdpa backend
Currently we have 2 types of vhost backends in QEMU: vhost kernel and vhost-user. The above patch provides a generic device for vDPA purpose, this vDPA device exposes to user space a non-vendor-specific configuration interface for setting up a vhost HW accelerator, this patch set introduces a third vhost backend called vhost-vdpa based on the vDPA interface. Vhost-vdpa usage: qemu-system-x86_64 -cpu host -enable-kvm \ .. -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ Signed-off-by: Lingshan zhu Signed-off-by: Tiwei Bie Signed-off-by: Cindy Lu --- configure | 21 ++ docs/interop/index.rst| 1 + docs/interop/vhost-vdpa.rst | 17 ++ hw/net/vhost_net.c| 19 +- hw/net/virtio-net.c | 22 +- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 7 +- hw/virtio/vhost-vdpa.c| 469 ++ hw/virtio/vhost.c | 7 +- include/hw/virtio/vhost-backend.h | 4 +- include/hw/virtio/vhost-vdpa.h| 26 ++ include/hw/virtio/vhost.h | 7 + qemu-options.hx | 12 + 13 files changed, 601 insertions(+), 12 deletions(-) create mode 100644 docs/interop/vhost-vdpa.rst create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h diff --git a/configure b/configure index 4a22dcd563..3db7f20185 100755 --- a/configure +++ b/configure @@ -1575,6 +1575,10 @@ for opt do ;; --enable-vhost-user) vhost_user="yes" ;; + --disable-vhost-vdpa) vhost_vdpa="no" + ;; + --enable-vhost-vdpa) vhost_vdpa="yes" + ;; --disable-vhost-kernel) vhost_kernel="no" ;; --enable-vhost-kernel) vhost_kernel="yes" @@ -1883,6 +1887,7 @@ disabled with --disable-FEATURE, default is enabled if available: vhost-cryptovhost-user-crypto backend support vhost-kernelvhost kernel backend support vhost-user vhost-user backend support + vhost-vdpa vhost-vdpa kernel backend support spice spice rbd rados block device (rbd) libiscsiiscsi support @@ -2394,6 +2399,10 @@ test "$vhost_user" = "" && vhost_user=yes if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then error_exit "vhost-user isn't available on win32" fi +test "$vhost_vdpa" = "" && vhost_vdpa=$linux +if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then + error_exit "vhost-vdpa is only available on Linux" +fi test "$vhost_kernel" = "" && vhost_kernel=$linux if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then error_exit "vhost-kernel is only available on Linux" @@ -2422,6 +2431,11 @@ test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then error_exit "--enable-vhost-user-fs requires --enable-vhost-user" fi +#vhost-vdpa backends +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" +fi # OR the vhost-kernel and vhost-user values for simplicity if test "$vhost_net" = ""; then @@ -6936,6 +6950,7 @@ echo "vhost-scsi support $vhost_scsi" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" echo "vhost-user-fs support $vhost_user_fs" +echo "vhost-vdpa support $vhost_vdpa" echo "Trace backends$trace_backends" if have_backend "simple"; then echo "Trace output file $trace_file-" @@ -7437,6 +7452,9 @@ fi if test "$vhost_net_user" = "yes" ; then echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak fi +if test "$vhost_net_vdpa" = "yes" ; then + echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak +fi if test "$vhost_crypto" = "yes" ; then echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak fi @@ -7452,6 +7470,9 @@ fi if test "$vhost_user" = "yes" ; then echo "CONFIG_VHOST_USER=y" >> $config_host_mak fi +if test "$vhost_vdpa" = "yes" ; then + echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak +fi if test "$vhost_user_fs" = "yes" ; then echo "CONFIG_VHOST
[PATCH v2 10/12] vhost: introduce new VhostOps vhost_get_device_id
This patch introduces new VhostOps vhost_get_device_id callback which can get the device id from backend Signed-off-by: Cindy Lu --- include/hw/virtio/vhost-backend.h | 4 1 file changed, 4 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index fa84abac97..bfc24207e2 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -118,6 +118,9 @@ typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); typedef int (*vhost_vq_get_addr_op)(struct vhost_dev *dev, struct vhost_vring_addr *addr, struct vhost_virtqueue *vq); + +typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id); + typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -160,6 +163,7 @@ typedef struct VhostOps { vhost_set_inflight_fd_op vhost_set_inflight_fd; vhost_dev_start_op vhost_dev_start; vhost_vq_get_addr_op vhost_vq_get_addr; +vhost_get_device_id_op vhost_get_device_id; } VhostOps; extern const VhostOps user_ops; -- 2.21.1
[PATCH v2 09/12] vhost: implement vhost_vq_get_addr method
use vhost_vq_get_addr callback to get the vq address from backend Signed-off-by: Cindy Lu --- hw/virtio/vhost.c | 28 +++- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 32809e54b5..1e083a8976 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -773,15 +773,25 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev, struct vhost_virtqueue *vq, unsigned idx, bool enable_log) { -struct vhost_vring_addr addr = { -.index = idx, -.desc_user_addr = (uint64_t)(unsigned long)vq->desc, -.avail_user_addr = (uint64_t)(unsigned long)vq->avail, -.used_user_addr = (uint64_t)(unsigned long)vq->used, -.log_guest_addr = vq->used_phys, -.flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0, -}; -int r = dev->vhost_ops->vhost_set_vring_addr(dev, ); +struct vhost_vring_addr addr; +int r; +memset(, 0, sizeof(struct vhost_vring_addr)); + +if (dev->vhost_ops->vhost_vq_get_addr) { +r = dev->vhost_ops->vhost_vq_get_addr(dev, , vq); +if (r < 0) { +VHOST_OPS_DEBUG("vhost_vq_get_addr failed"); +return -errno; +} +} else { +addr.desc_user_addr = (uint64_t)(unsigned long)vq->desc; +addr.avail_user_addr = (uint64_t)(unsigned long)vq->avail; +addr.used_user_addr = (uint64_t)(unsigned long)vq->used; +} +addr.index = idx; +addr.log_guest_addr = vq->used_phys; +addr.flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0; +r = dev->vhost_ops->vhost_set_vring_addr(dev, ); if (r < 0) { VHOST_OPS_DEBUG("vhost_set_vring_addr failed"); return -errno; -- 2.21.1
[PATCH v2 07/12] vhost: implement vhost_dev_start method
use the vhost_dev_start callback to send the status to backend Signed-off-by: Cindy Lu --- hw/virtio/vhost.c | 10 +- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 10304b583e..32809e54b5 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1685,7 +1685,12 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) goto fail_log; } } - +if (hdev->vhost_ops->vhost_dev_start) { +r = hdev->vhost_ops->vhost_dev_start(hdev, true); +if (r) { +goto fail_log; +} +} if (vhost_dev_has_iommu(hdev) && hdev->vhost_ops->vhost_set_iotlb_callback) { hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); @@ -1723,6 +1728,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) /* should only be called after backend is connected */ assert(hdev->vhost_ops); +if (hdev->vhost_ops->vhost_dev_start) { +hdev->vhost_ops->vhost_dev_start(hdev, false); +} for (i = 0; i < hdev->nvqs; ++i) { vhost_virtqueue_stop(hdev, vdev, -- 2.21.1
[PATCH v2 05/12] vhost: check the existence of vhost_set_iotlb_callback
From: Jason Wang Add the check of vhost_set_iotlb_callback before calling Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/vhost.c | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 5fd25fe520..10304b583e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1686,8 +1686,9 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) } } -if (vhost_dev_has_iommu(hdev)) { -hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); +if (vhost_dev_has_iommu(hdev) && +hdev->vhost_ops->vhost_set_iotlb_callback) { +hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); /* Update used ring information for IOTLB to work correctly, * vhost-kernel code requires for this.*/ @@ -1730,7 +1731,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) } if (vhost_dev_has_iommu(hdev)) { -hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false); +if (hdev->vhost_ops->vhost_set_iotlb_callback) { +hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false); +} memory_listener_unregister(>iommu_listener); } vhost_log_put(hdev, true); -- 2.21.1
[PATCH v2 08/12] vhost: introduce new VhostOps vhost_vq_get_addr
This patch introduces new VhostOps vhost_vq_get_addr_op callback to get the vring addr from the backend Signed-off-by: Cindy Lu --- include/hw/virtio/vhost-backend.h | 6 ++ 1 file changed, 6 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index b80f344cd6..fa84abac97 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -34,6 +34,7 @@ struct vhost_vring_state; struct vhost_vring_addr; struct vhost_scsi_target; struct vhost_iotlb_msg; +struct vhost_virtqueue; typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque); typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); @@ -113,6 +114,10 @@ typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, struct vhost_inflight *inflight); typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); + +typedef int (*vhost_vq_get_addr_op)(struct vhost_dev *dev, +struct vhost_vring_addr *addr, +struct vhost_virtqueue *vq); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -154,6 +159,7 @@ typedef struct VhostOps { vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; vhost_dev_start_op vhost_dev_start; +vhost_vq_get_addr_op vhost_vq_get_addr; } VhostOps; extern const VhostOps user_ops; -- 2.21.1
[PATCH v2 06/12] vhost: introduce new VhostOps vhost_dev_start
This patch introduces new VhostOps vhost_dev_start callback which allows the vhost_net set the start/stop status to backend Signed-off-by: Cindy Lu --- include/hw/virtio/vhost-backend.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 6f6670783f..b80f344cd6 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -112,6 +112,7 @@ typedef int (*vhost_get_inflight_fd_op)(struct vhost_dev *dev, typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, struct vhost_inflight *inflight); +typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -152,6 +153,7 @@ typedef struct VhostOps { vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter; vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; +vhost_dev_start_op vhost_dev_start; } VhostOps; extern const VhostOps user_ops; -- 2.21.1
[PATCH v2 03/12] virtio-bus: introduce queue_enabled method
From: Jason Wang This patch introduces queue_enabled() method which allows the transport to implement its own way to report whether or not a queue is enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/virtio.c | 6 ++ include/hw/virtio/virtio-bus.h | 4 2 files changed, 10 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index cc9c9dc162..5bd2a2f621 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3286,6 +3286,12 @@ hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n) bool virtio_queue_enabled(VirtIODevice *vdev, int n) { +BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); +VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + +if (k->queue_enabled) { +return k->queue_enabled(qbus->parent, n); +} return virtio_queue_get_desc_addr(vdev, n) != 0; } diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index 38c9399cd4..0f6f215925 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -83,6 +83,10 @@ typedef struct VirtioBusClass { */ int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier, int n, bool assign); +/* + * Whether queue number n is enabled. + */ +bool (*queue_enabled)(DeviceState *d, int n); /* * Does the transport have variable vring alignment? * (ie can it ever call virtio_queue_set_align()?) -- 2.21.1
[PATCH v2 04/12] virtio-pci: implement queue_enabled method
From: Jason Wang With version 1, we can detect whether a queue is enabled via queue_enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 13 + 1 file changed, 13 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 7bc8c1c056..8554cf2a03 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1107,6 +1107,18 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d) return pci_get_address_space(dev); } +static bool virtio_pci_queue_enabled(DeviceState *d, int n) +{ +VirtIOPCIProxy *proxy = VIRTIO_PCI(d); +VirtIODevice *vdev = virtio_bus_get_device(>bus); + +if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { +return proxy->vqs[vdev->queue_sel].enabled; +} + +return virtio_queue_enabled(vdev, n); +} + static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, struct virtio_pci_cap *cap) { @@ -2064,6 +2076,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; k->ioeventfd_assign = virtio_pci_ioeventfd_assign; k->get_dma_as = virtio_pci_get_dma_as; +k->queue_enabled = virtio_pci_queue_enabled; } static const TypeInfo virtio_pci_bus_info = { -- 2.21.1
[PATCH v2 02/12] vhost_net: use the function qemu_get_peer
user the qemu_get_peer to replace the old process Signed-off-by: Cindy Lu Reviewed-by: Laurent Vivier --- hw/net/vhost_net.c | 16 ++-- 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6b82803fa7..4096d64aaf 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -306,7 +306,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus = VIRTIO_BUS(qbus); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); +struct vhost_net *net; int r, e, i; +NetClientState *peer; if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); @@ -314,9 +316,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -struct vhost_net *net; -net = get_vhost_net(ncs[i].peer); +peer = qemu_get_peer(ncs, i); +net = get_vhost_net(peer); vhost_net_set_vq_index(net, i * 2); /* Suppress the masking guest notifiers on vhost user @@ -335,15 +337,16 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs, i); +r = vhost_net_start_one(get_vhost_net(peer), dev); if (r < 0) { goto err_start; } -if (ncs[i].peer->vring_enable) { +if (peer->vring_enable) { /* restore vring enable state */ -r = vhost_set_vring_enable(ncs[i].peer, ncs[i].peer->vring_enable); +r = vhost_set_vring_enable(peer, peer->vring_enable); if (r < 0) { goto err_start; @@ -355,7 +358,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, err_start: while (--i >= 0) { -vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs , i); +vhost_net_stop_one(get_vhost_net(peer), dev); } e = k->set_guest_notifiers(qbus->parent, total_queues * 2, false); if (e < 0) { -- 2.21.1
[PATCH v2 01/12] net: introduce qemu_get_peer
This is a small function that can get the peer from given NetClientState and queue_index Signed-off-by: Cindy Lu --- include/net/net.h | 1 + net/net.c | 7 +++ 2 files changed, 8 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 39085d9444..e7ef42d62b 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -176,6 +176,7 @@ void hmp_info_network(Monitor *mon, const QDict *qdict); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, bool vnet_hdr); +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); /* NIC info */ diff --git a/net/net.c b/net/net.c index d1130296e1..9099a327dd 100644 --- a/net/net.c +++ b/net/net.c @@ -325,6 +325,13 @@ void *qemu_get_nic_opaque(NetClientState *nc) return nic->opaque; } +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) +{ +assert(nc != NULL); +NetClientState *ncs = nc + queue_index; +return ncs->peer; +} + static void qemu_cleanup_net_client(NetClientState *nc) { QTAILQ_REMOVE(_clients, nc, next); -- 2.21.1
[PATCH v2 00/12] vDPA support in qemu
vDPA device is a device that uses a datapath which complies with the virtio specifications with vendor specific control path. vDPA devices can be both physically located on the hardware or emulated by software. This PATCH introduce the vDPA support in qemu TODO 1) vIOMMU support 2) live migration support 3) docs for vhost-vdpa 4) config interrupt support change from v1 separate the patch of vhost_vq_get_addr separate the patch of vhost_dev_start introduce the docmation for vhost-vdpa.rst other comments form last version github address https://github.com/lulu-github-name/qemutmp.git PATCHV2 Cindy Lu (9): net: introduce qemu_get_peer vhost_net: use the function qemu_get_peer vhost: introduce new VhostOps vhost_dev_start vhost: implement vhost_dev_start method vhost: introduce new VhostOps vhost_vq_get_addr vhost: implement vhost_vq_get_addr method vhost: introduce new VhostOps vhost_get_device_id vhost-vdpa: introduce vhost-vdpa backend vhost-vdpa: introduce vhost-vdpa net client Jason Wang (3): virtio-bus: introduce queue_enabled method virtio-pci: implement queue_enabled method vhost: check the existence of vhost_set_iotlb_callback configure | 21 ++ docs/interop/index.rst| 1 + docs/interop/vhost-vdpa.rst | 17 ++ hw/net/vhost_net.c| 35 ++- hw/net/virtio-net.c | 22 +- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 7 +- hw/virtio/vhost-vdpa.c| 469 ++ hw/virtio/vhost.c | 48 ++- hw/virtio/virtio-pci.c| 13 + hw/virtio/virtio.c| 6 + include/hw/virtio/vhost-backend.h | 16 +- include/hw/virtio/vhost-vdpa.h| 26 ++ include/hw/virtio/vhost.h | 7 + include/hw/virtio/virtio-bus.h| 4 + include/net/net.h | 1 + include/net/vhost-vdpa.h | 22 ++ net/Makefile.objs | 2 +- net/clients.h | 2 + net/net.c | 10 + net/vhost-vdpa.c | 228 +++ qapi/net.json | 28 +- qemu-options.hx | 12 + 23 files changed, 966 insertions(+), 32 deletions(-) create mode 100644 docs/interop/vhost-vdpa.rst create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c -- 2.21.1
Re: [PATCH v1 09/10] vhost-vdpa: introduce vhost-vdpa backend
On Tue, Jun 30, 2020 at 3:19 PM Maxime Coquelin wrote: > > > > On 6/22/20 5:37 PM, Cindy Lu wrote: > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > > qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > > -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > > -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Signed-off-by: Lingshan zhu > > Signed-off-by: Tiwei Bie > > Signed-off-by: Cindy Lu > > --- > > configure | 21 ++ > > hw/net/vhost_net.c| 19 +- > > hw/net/virtio-net.c | 19 +- > > hw/virtio/Makefile.objs | 1 + > > hw/virtio/vhost-backend.c | 22 +- > > hw/virtio/vhost-vdpa.c| 406 ++ > > hw/virtio/vhost.c | 42 +++- > > include/hw/virtio/vhost-backend.h | 6 +- > > include/hw/virtio/vhost-vdpa.h| 26 ++ > > include/hw/virtio/vhost.h | 6 + > > qemu-options.hx | 12 + > > 11 files changed, 555 insertions(+), 25 deletions(-) > > create mode 100644 hw/virtio/vhost-vdpa.c > > create mode 100644 include/hw/virtio/vhost-vdpa.h > > > > diff --git a/configure b/configure > > index 23b5e93752..53679ee57f 100755 > > --- a/configure > > +++ b/configure > > @@ -1557,6 +1557,10 @@ for opt do > >;; > >--enable-vhost-user) vhost_user="yes" > >;; > > + --disable-vhost-vdpa) vhost_vdpa="no" > > + ;; > > + --enable-vhost-vdpa) vhost_vdpa="yes" > > + ;; > >--disable-vhost-kernel) vhost_kernel="no" > >;; > >--enable-vhost-kernel) vhost_kernel="yes" > > @@ -1846,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled > > if available: > >vhost-cryptovhost-user-crypto backend support > >vhost-kernelvhost kernel backend support > >vhost-user vhost-user backend support > > + vhost-vdpa vhost-vdpa kernel backend support > >spice spice > >rbd rados block device (rbd) > >libiscsiiscsi support > > @@ -2336,6 +2341,10 @@ test "$vhost_user" = "" && vhost_user=yes > > if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then > >error_exit "vhost-user isn't available on win32" > > fi > > +test "$vhost_vdpa" = "" && vhost_vdpa=$linux > > +if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then > > + error_exit "vhost-vdpa is only available on Linux" > > +fi > > test "$vhost_kernel" = "" && vhost_kernel=$linux > > if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then > >error_exit "vhost-kernel is only available on Linux" > > @@ -2364,6 +2373,11 @@ test "$vhost_user_fs" = "" && > > vhost_user_fs=$vhost_user > > if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then > >error_exit "--enable-vhost-user-fs requires --enable-vhost-user" > > fi > > +#vhost-vdpa backends > > +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa > > +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then > > + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" > > +fi > > > > # OR the vhost-kernel and vhost-user values for simplicity > > if test "$vhost_net" = ""; then > > @@ -6673,6 +6687,7 @@ echo "vhost-scsi support $vhost_scsi" > > echo "vhost-vsock support $vhost_vsock" > > echo "vhost-user support $vhost_user" > > echo "vhost-user-fs support $vhost_user_fs" > > +echo "vhost-vdpa support $vhost_vdpa" > > echo "Trace backends$trace_backends" > > if have_backend "simple"; the
Re: [PATCH v1 05/10] vhost-backend: export the vhost backend helper
On Thu, Jun 25, 2020 at 11:07 PM Laurent Vivier wrote: > > On 22/06/2020 17:37, Cindy Lu wrote: > > export the helper then we can reuse them in other backend > > > > Signed-off-by: Cindy Lu > > --- > > hw/virtio/vhost-backend.c | 18 +- > > include/hw/virtio/vhost-backend.h | 28 > > 2 files changed, 37 insertions(+), 9 deletions(-) > > > > This looks weird to export all these functions whereas they are all > already exported by the vhost_ops structure. > > So if vhost-vdpa is not a subset of vhost-kernel and if these functions > will diverge from vhost-backend.c definition in the future, perhaps it > is wise to already copy their definitions right now in vhost-vdpa.c > rather than exporting them now and to have to copy them in the future in > vhost-vdpa.c to modify them. > > It will also simplify the definition of vhost_kernel_call(). > > Thanks, > Laurent > Thanks Laurent, will fix this > > diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c > > index 48905383f8..660e9e8588 100644 > > --- a/hw/virtio/vhost-backend.c > > +++ b/hw/virtio/vhost-backend.c > > @@ -89,7 +89,7 @@ static int vhost_kernel_scsi_get_abi_version(struct > > vhost_dev *dev, int *version > > return vhost_kernel_call(dev, VHOST_SCSI_GET_ABI_VERSION, version); > > } > > > > -static int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, > > +int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, > > struct vhost_log *log) > > { > > return vhost_kernel_call(dev, VHOST_SET_LOG_BASE, ); > > @@ -101,7 +101,7 @@ static int vhost_kernel_set_mem_table(struct vhost_dev > > *dev, > > return vhost_kernel_call(dev, VHOST_SET_MEM_TABLE, mem); > > } > > > > -static int vhost_kernel_set_vring_addr(struct vhost_dev *dev, > > +int vhost_kernel_set_vring_addr(struct vhost_dev *dev, > > struct vhost_vring_addr *addr) > > { > > return vhost_kernel_call(dev, VHOST_SET_VRING_ADDR, addr); > > @@ -113,31 +113,31 @@ static int vhost_kernel_set_vring_endian(struct > > vhost_dev *dev, > > return vhost_kernel_call(dev, VHOST_SET_VRING_ENDIAN, ring); > > } > > > > -static int vhost_kernel_set_vring_num(struct vhost_dev *dev, > > +int vhost_kernel_set_vring_num(struct vhost_dev *dev, > >struct vhost_vring_state *ring) > > { > > return vhost_kernel_call(dev, VHOST_SET_VRING_NUM, ring); > > } > > > > -static int vhost_kernel_set_vring_base(struct vhost_dev *dev, > > +int vhost_kernel_set_vring_base(struct vhost_dev *dev, > > struct vhost_vring_state *ring) > > { > > return vhost_kernel_call(dev, VHOST_SET_VRING_BASE, ring); > > } > > > > -static int vhost_kernel_get_vring_base(struct vhost_dev *dev, > > +int vhost_kernel_get_vring_base(struct vhost_dev *dev, > > struct vhost_vring_state *ring) > > { > > return vhost_kernel_call(dev, VHOST_GET_VRING_BASE, ring); > > } > > > > -static int vhost_kernel_set_vring_kick(struct vhost_dev *dev, > > +int vhost_kernel_set_vring_kick(struct vhost_dev *dev, > > struct vhost_vring_file *file) > > { > > return vhost_kernel_call(dev, VHOST_SET_VRING_KICK, file); > > } > > > > -static int vhost_kernel_set_vring_call(struct vhost_dev *dev, > > +int vhost_kernel_set_vring_call(struct vhost_dev *dev, > > struct vhost_vring_file *file) > > { > > return vhost_kernel_call(dev, VHOST_SET_VRING_CALL, file); > > @@ -155,13 +155,13 @@ static int vhost_kernel_set_features(struct vhost_dev > > *dev, > > return vhost_kernel_call(dev, VHOST_SET_FEATURES, ); > > } > > > > -static int vhost_kernel_get_features(struct vhost_dev *dev, > > +int vhost_kernel_get_features(struct vhost_dev *dev, > > uint64_t *features) > > { > > return vhost_kernel_call(dev, VHOST_GET_FEATURES, features); > > } > > > > -static int vhost_kernel_set_owner(struct vhost_dev *dev) > > +int vhost_kernel_set_owner(struct vhost_dev *dev) > > { > > return vhost_kernel_call(dev, VHOST_SET_OWNER, NULL); > > } > > diff --git a/include/hw/virtio/vhost-backend.h > > b/include/hw/virtio/vhost-backend.h > &g
Re: [PATCH v1 04/10] virtio-pci: implement queue_enabled method
On Wed, Jun 24, 2020 at 9:25 PM Laurent Vivier wrote: > > On 22/06/2020 17:37, Cindy Lu wrote: > > From: Jason Wang > > > > With version 1, we can detect whether a queue is enabled via > > queue_enabled. > > > > Signed-off-by: Jason Wang > > Signed-off-by: Cindy Lu > > --- > > hw/virtio/virtio-pci.c | 18 ++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > > index 4cb784389c..3918aa9f6c 100644 > > --- a/hw/virtio/virtio-pci.c > > +++ b/hw/virtio/virtio-pci.c > > @@ -1107,6 +1107,23 @@ static AddressSpace > > *virtio_pci_get_dma_as(DeviceState *d) > > return pci_get_address_space(dev); > > } > > > > +static bool virtio_queue_check_enabled(VirtIODevice *vdev, int n) > > +{ > > +return virtio_queue_get_desc_addr(vdev, n) != 0; > > +} > > This function is already defined under a different name in > hw/virtio/virtio.c: > > >3287 bool virtio_queue_enabled(VirtIODevice *vdev, int n) >3288 { >3289 return virtio_queue_get_desc_addr(vdev, n) != 0; >3290 } > > As this file includes "hw/virtio/virtio.h" you can use it directly. > Thanks Laurent, Will fix this > Thanks, > Laurent >
Re: [PATCH v1 08/10] vhost: implement vhost_dev_start method
On Thu, Jun 25, 2020 at 10:35 PM Laurent Vivier wrote: > > On 22/06/2020 17:37, Cindy Lu wrote: > > use the vhost_dev_start callback to send the status to backend > > I agree with Jason, squash this patch with the previous one. > will fix this > > Signed-off-by: Cindy Lu > > --- > > hw/virtio/vhost.c | 17 + > > include/hw/virtio/vhost.h | 2 ++ > > 2 files changed, 19 insertions(+) > > > > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c > > index 01ebe12f28..bfd7f9ce1f 100644 > > --- a/hw/virtio/vhost.c > > +++ b/hw/virtio/vhost.c > > @@ -744,6 +744,7 @@ static void vhost_iommu_region_del(MemoryListener > > *listener, > > } > > } > > > > + > > static int vhost_virtqueue_set_addr(struct vhost_dev *dev, > > struct vhost_virtqueue *vq, > > unsigned idx, bool enable_log) > > @@ -1661,6 +1662,11 @@ int vhost_dev_start(struct vhost_dev *hdev, > > VirtIODevice *vdev) > > } > > } > > > > +r = vhost_set_start(hdev, true); > > Perhaps you can use the same kind of name we have for the queue > (queue_set_started()) and use something like vhost_dev_set_started()? > sure, will fix this > > +if (r) { > > +goto fail_log; > > +} > > + > > if (vhost_dev_has_iommu(hdev)) { > > hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); > > > > @@ -1697,6 +1703,8 @@ void vhost_dev_stop(struct vhost_dev *hdev, > > VirtIODevice *vdev) > > /* should only be called after backend is connected */ > > assert(hdev->vhost_ops); > > > > +vhost_set_start(hdev, false); > > + > > for (i = 0; i < hdev->nvqs; ++i) { > > vhost_virtqueue_stop(hdev, > > vdev, > > @@ -1722,3 +1730,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev, > > > > return -1; > > } > > + > > +int vhost_set_start(struct vhost_dev *hdev, bool started) > > +{ > > + > > +if (hdev->vhost_ops->vhost_dev_start) { > > +hdev->vhost_ops->vhost_dev_start(hdev, started); > > The "return" is missing. > > And generally a function that only embeds a call to a hook has the same > as the hook. > > > +} > > +return 0; > > +} > > so something like: > > int vhost_dev_set_started(struct vhost_dev *hdev, bool started) > { > if (hdev->vhost_ops->dev_set_started) { > return hdev->vhost_ops->dev_set_started(hdev, started); > } > return 0; > } > > thanks will fix this > > diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h > > index 085450c6f8..59ea53f8c2 100644 > > --- a/include/hw/virtio/vhost.h > > +++ b/include/hw/virtio/vhost.h > > @@ -92,6 +92,7 @@ struct vhost_dev { > > const VhostDevConfigOps *config_ops; > > }; > > > > + > > int vhost_dev_init(struct vhost_dev *hdev, void *opaque, > > VhostBackendType backend_type, > > uint32_t busyloop_timeout); > > @@ -137,4 +138,5 @@ int vhost_dev_set_inflight(struct vhost_dev *dev, > > struct vhost_inflight *inflight); > > int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size, > > struct vhost_inflight *inflight); > > +int vhost_set_start(struct vhost_dev *dev, bool started); > > There is no need to export it, so set it "static" in hw/virtio/vhost.c > and move the definition before the use. > thanks will fix this > Thanks, > Laurent >
Re: [PATCH v1 00/10] vDPA support in qemu
On Sun, Jun 28, 2020 at 3:07 PM Jason Wang wrote: > > > On 2020/6/22 下午11:37, Cindy Lu wrote: > > vDPA device is a device that uses a datapath which complies with the > > virtio specifications with vendor specific control path. vDPA devices > > can be both physically located on the hardware or emulated by software. > > This RFC introduce the vDPA support in qemu > > TODO > > 1) vIOMMU support > > 2) live migration support > > > Jut notice that the config interrupt [1] looks missed in this series. > > Please add them in next version. > > Thanks > > [1] > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=776f395004d829bbbf18c159ed9beb517a208c71 > sure will add this part
Re: [PATCH v1 00/10] vDPA support in qemu
On Thu, Jun 25, 2020 at 12:48 PM Markus Armbruster wrote: > > Cindy Lu writes: > > > On Tue, Jun 23, 2020 at 5:43 PM Jason Wang wrote: > >> > >> > >> On 2020/6/23 下午5:16, Cindy Lu wrote: > >> > On Tue, Jun 23, 2020 at 3:07 PM Markus Armbruster > >> > wrote: > >> >> Cindy Lu writes: > >> >> > >> >>> vDPA device is a device that uses a datapath which complies with the > >> >>> virtio specifications with vendor specific control path. vDPA devices > >> >>> can be both physically located on the hardware or emulated by software. > >> >>> This RFC introduce the vDPA support in qemu > >> >>> TODO > >> >>> 1) vIOMMU support > >> >>> 2) live migration support > >> >> This gives me the foggiest of ideas on what vDPA is. Could we use > >> >> docs/interop/vhost-vdpa.rst? > >> >> > >> > Sure will add this > >> > > >> > > >> > >> Not sure it's the best place since vhost-vdpa is kernel specific. > >> > >> Maybe kernel docs (TBD) is a better place and we can refer it this file > >> in the future. > >> > >> But it doesn't harm if you said something more here and refer the kernel > >> commit here: > >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4c8cf31885f69e86be0b5b9e6677a26797365e1d > >> > >> Thanks > >> > >> > > Hi Markus, > > I think I agree with Jason's opinion, kernel docs is a better place. > > Maybe we can keep what it is now, and do this job in the future. > > I think a super-short description of vDPA here (one sentence?) together > with a link to complete information would be helpful. If the link's > target doesn't yet exist, adding the link later is okay. > sure thanks Markus, will do
Re: [PATCH v1 09/10] vhost-vdpa: introduce vhost-vdpa backend
On Thu, Jun 25, 2020 at 8:37 PM Laurent Vivier wrote: > > On 22/06/2020 17:37, Cindy Lu wrote: > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > > qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > > -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > > -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Signed-off-by: Lingshan zhu > > Signed-off-by: Tiwei Bie > > Signed-off-by: Cindy Lu > > --- > > configure | 21 ++ > > hw/net/vhost_net.c| 19 +- > > hw/net/virtio-net.c | 19 +- > > hw/virtio/Makefile.objs | 1 + > > hw/virtio/vhost-backend.c | 22 +- > > hw/virtio/vhost-vdpa.c| 406 ++ > > hw/virtio/vhost.c | 42 +++- > > include/hw/virtio/vhost-backend.h | 6 +- > > include/hw/virtio/vhost-vdpa.h| 26 ++ > > include/hw/virtio/vhost.h | 6 + > > qemu-options.hx | 12 + > > 11 files changed, 555 insertions(+), 25 deletions(-) > > create mode 100644 hw/virtio/vhost-vdpa.c > > create mode 100644 include/hw/virtio/vhost-vdpa.h > > > ... > > diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c > > index 660e9e8588..84e5b1a833 100644 > > --- a/hw/virtio/vhost-backend.c > > +++ b/hw/virtio/vhost-backend.c > > @@ -14,7 +14,7 @@ > > #include "qemu/error-report.h" > > #include "qemu/main-loop.h" > > #include "standard-headers/linux/vhost_types.h" > > - > > +#include "hw/virtio/vhost-vdpa.h" > > #ifdef CONFIG_VHOST_KERNEL > > #include > > #include > > @@ -22,10 +22,19 @@ > > static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int > > request, > > void *arg) > > { > > -int fd = (uintptr_t) dev->opaque; > > - > > -assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL); > > +int fd = -1; > > You don't need to initialize fd before the switch() because all cases > will set a value to it or assert. > > > +switch (dev->vhost_ops->backend_type) { > > +case VHOST_BACKEND_TYPE_KERNEL: > > +fd = (uintptr_t)dev->opaque; > > +break; > > +case VHOST_BACKEND_TYPE_VDPA: > > +fd = ((struct vhost_vdpa *)dev->opaque)->device_fd; > > +break; > > +default: > > +g_assert_not_reached(); > > +} > > > > +assert(fd != -1); > > Perhaps this assert is not needed: > Unitialized value will be catched by "default:", and there was no such > kind of check on "(uintptr_t)dev->opaque" before. > sure, thanks will fix this > Thanks, > Laurent >
Re: [PATCH v1 00/10] vDPA support in qemu
On Tue, Jun 23, 2020 at 5:43 PM Jason Wang wrote: > > > On 2020/6/23 下午5:16, Cindy Lu wrote: > > On Tue, Jun 23, 2020 at 3:07 PM Markus Armbruster wrote: > >> Cindy Lu writes: > >> > >>> vDPA device is a device that uses a datapath which complies with the > >>> virtio specifications with vendor specific control path. vDPA devices > >>> can be both physically located on the hardware or emulated by software. > >>> This RFC introduce the vDPA support in qemu > >>> TODO > >>> 1) vIOMMU support > >>> 2) live migration support > >> This gives me the foggiest of ideas on what vDPA is. Could we use > >> docs/interop/vhost-vdpa.rst? > >> > > Sure will add this > > > > > > Not sure it's the best place since vhost-vdpa is kernel specific. > > Maybe kernel docs (TBD) is a better place and we can refer it this file > in the future. > > But it doesn't harm if you said something more here and refer the kernel > commit here: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4c8cf31885f69e86be0b5b9e6677a26797365e1d > > Thanks > > Hi Markus, I think I agree with Jason's opinion, kernel docs is a better place. Maybe we can keep what it is now, and do this job in the future. Thanks Cindy
Re: [PATCH v1 10/10] vhost-vdpa: introduce vhost-vdpa net client
On Tue, Jun 23, 2020 at 4:57 PM Jason Wang wrote: > > > On 2020/6/22 下午11:37, Cindy Lu wrote: > > This patch set introduces a new net client type: vhost-vdpa. > > vhost-vdpa net client will set up a vDPA device which is specified > > by a "vhostdev" parameter. > > > > Signed-off-by: Lingshan Zhu > > Signed-off-by: Tiwei Bie > > Signed-off-by: Cindy Lu > > --- > > include/net/vhost-vdpa.h | 21 > > include/net/vhost_net.h | 1 - > > net/Makefile.objs| 2 +- > > net/clients.h| 2 + > > net/net.c| 3 + > > net/vhost-vdpa.c | 230 +++ > > qapi/net.json| 23 +++- > > 7 files changed, 278 insertions(+), 4 deletions(-) > > create mode 100644 include/net/vhost-vdpa.h > > create mode 100644 net/vhost-vdpa.c > > > > diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h > > new file mode 100644 > > index 00..725c8b1c81 > > --- /dev/null > > +++ b/include/net/vhost-vdpa.h > > @@ -0,0 +1,21 @@ > > +/* > > + * vhost-vdpa.h > > + * > > + * Copyright(c) 2017-2018 Intel Corporation. > > + * Copyright(c) 2020 Red Hat, Inc. > > + * > > + * This work is licensed under the terms of the GNU GPL, version 2 or > > later. > > + * See the COPYING file in the top-level directory. > > + * > > + */ > > + > > +#ifndef VHOST_VDPA_H > > +#define VHOST_VDPA_H > > + > > +struct vhost_net; > > +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); > > +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); > > + > > +extern const int vdpa_feature_bits[]; > > + > > +#endif /* VHOST_VDPA_H */ > > diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h > > index abfb0e8e68..4843cdb36f 100644 > > --- a/include/net/vhost_net.h > > +++ b/include/net/vhost_net.h > > @@ -44,5 +44,4 @@ int vhost_set_vring_enable(NetClientState * nc, int > > enable); > > uint64_t vhost_net_get_acked_features(VHostNetState *net); > > > > int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); > > - > > > Let's keep this newline. > > > > #endif > > diff --git a/net/Makefile.objs b/net/Makefile.objs > > index c5d076d19c..5ab45545db 100644 > > --- a/net/Makefile.objs > > +++ b/net/Makefile.objs > > @@ -26,7 +26,7 @@ tap-obj-$(CONFIG_SOLARIS) = tap-solaris.o > > tap-obj-y ?= tap-stub.o > > common-obj-$(CONFIG_POSIX) += tap.o $(tap-obj-y) > > common-obj-$(CONFIG_WIN32) += tap-win32.o > > - > > > And this. > > Sure will do, I will double check these issue next time > > +common-obj-$(CONFIG_VHOST_NET_VDPA) += vhost-vdpa.o > > vde.o-libs = $(VDE_LIBS) > > > > common-obj-$(CONFIG_CAN_BUS) += can/ > > diff --git a/net/clients.h b/net/clients.h > > index a6ef267e19..92f9b59aed 100644 > > --- a/net/clients.h > > +++ b/net/clients.h > > @@ -61,4 +61,6 @@ int net_init_netmap(const Netdev *netdev, const char > > *name, > > int net_init_vhost_user(const Netdev *netdev, const char *name, > > NetClientState *peer, Error **errp); > > > > +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, > > +NetClientState *peer, Error **errp); > > #endif /* QEMU_NET_CLIENTS_H */ > > diff --git a/net/net.c b/net/net.c > > index 599fb61028..82624ea9ac 100644 > > --- a/net/net.c > > +++ b/net/net.c > > @@ -965,6 +965,9 @@ static int (* const > > net_client_init_fun[NET_CLIENT_DRIVER__MAX])( > > #ifdef CONFIG_VHOST_NET_USER > > [NET_CLIENT_DRIVER_VHOST_USER] = net_init_vhost_user, > > #endif > > +#ifdef CONFIG_VHOST_NET_VDPA > > +[NET_CLIENT_DRIVER_VHOST_VDPA] = net_init_vhost_vdpa, > > +#endif > > #ifdef CONFIG_L2TPV3 > > [NET_CLIENT_DRIVER_L2TPV3]= net_init_l2tpv3, > > #endif > > diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c > > new file mode 100644 > > index 00..34858a6ea3 > > --- /dev/null > > +++ b/net/vhost-vdpa.c > > @@ -0,0 +1,230 @@ > > +/* > > + * vhost-vdpa.c > > + * > > + * Copyright(c) 2017-2018 Intel Corporation. > > + * Copyright(c) 2020 Red Hat, Inc. > > + * > > + * This work is licensed under the terms of the GNU GPL, version 2 or > > later. > > + * See the COPYING file in the top-level directory. > > + * > > + */ > > + > > +#i
Re: [PATCH v1 09/10] vhost-vdpa: introduce vhost-vdpa backend
On Tue, Jun 23, 2020 at 3:31 PM Jason Wang wrote: > > > On 2020/6/22 下午11:37, Cindy Lu wrote: > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > > qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > > -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > > -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Signed-off-by: Lingshan zhu > > Signed-off-by: Tiwei Bie > > Signed-off-by: Cindy Lu > > --- > > configure | 21 ++ > > hw/net/vhost_net.c| 19 +- > > hw/net/virtio-net.c | 19 +- > > hw/virtio/Makefile.objs | 1 + > > hw/virtio/vhost-backend.c | 22 +- > > hw/virtio/vhost-vdpa.c| 406 ++ > > hw/virtio/vhost.c | 42 +++- > > include/hw/virtio/vhost-backend.h | 6 +- > > include/hw/virtio/vhost-vdpa.h| 26 ++ > > include/hw/virtio/vhost.h | 6 + > > qemu-options.hx | 12 + > > 11 files changed, 555 insertions(+), 25 deletions(-) > > create mode 100644 hw/virtio/vhost-vdpa.c > > create mode 100644 include/hw/virtio/vhost-vdpa.h > > > > diff --git a/configure b/configure > > index 23b5e93752..53679ee57f 100755 > > --- a/configure > > +++ b/configure > > @@ -1557,6 +1557,10 @@ for opt do > > ;; > > --enable-vhost-user) vhost_user="yes" > > ;; > > + --disable-vhost-vdpa) vhost_vdpa="no" > > + ;; > > + --enable-vhost-vdpa) vhost_vdpa="yes" > > + ;; > > --disable-vhost-kernel) vhost_kernel="no" > > ;; > > --enable-vhost-kernel) vhost_kernel="yes" > > @@ -1846,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled > > if available: > > vhost-cryptovhost-user-crypto backend support > > vhost-kernelvhost kernel backend support > > vhost-user vhost-user backend support > > + vhost-vdpa vhost-vdpa kernel backend support > > spice spice > > rbd rados block device (rbd) > > libiscsiiscsi support > > @@ -2336,6 +2341,10 @@ test "$vhost_user" = "" && vhost_user=yes > > if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then > > error_exit "vhost-user isn't available on win32" > > fi > > +test "$vhost_vdpa" = "" && vhost_vdpa=$linux > > +if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then > > + error_exit "vhost-vdpa is only available on Linux" > > +fi > > test "$vhost_kernel" = "" && vhost_kernel=$linux > > if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then > > error_exit "vhost-kernel is only available on Linux" > > @@ -2364,6 +2373,11 @@ test "$vhost_user_fs" = "" && > > vhost_user_fs=$vhost_user > > if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then > > error_exit "--enable-vhost-user-fs requires --enable-vhost-user" > > fi > > +#vhost-vdpa backends > > +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa > > +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then > > + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" > > +fi > > > > # OR the vhost-kernel and vhost-user values for simplicity > > if test "$vhost_net" = ""; then > > @@ -6673,6 +6687,7 @@ echo "vhost-scsi support $vhost_scsi" > > echo "vhost-vsock support $vhost_vsock" > > echo "vhost-user support $vhost_user" > > echo "vhost-user-fs support $vhost_user_fs" > > +echo "vhost-vdpa support $vhost_vdpa" > > echo "Trace backends$trace_backends" > > i
Re: [PATCH v1 08/10] vhost: implement vhost_dev_start method
On Tue, Jun 23, 2020 at 5:38 PM Jason Wang wrote: > > > On 2020/6/23 下午5:34, Cindy Lu wrote: > > On Tue, Jun 23, 2020 at 3:21 PM Jason Wang wrote: > >> On 2020/6/22 下午11:37, Cindy Lu wrote: > >>> use the vhost_dev_start callback to send the status to backend > >> I suggest to squash this into previous patch. > >> > > Sure will do > >>> Signed-off-by: Cindy Lu > >>> --- > >>>hw/virtio/vhost.c | 17 + > >>>include/hw/virtio/vhost.h | 2 ++ > >>>2 files changed, 19 insertions(+) > >>> > >>> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c > >>> index 01ebe12f28..bfd7f9ce1f 100644 > >>> --- a/hw/virtio/vhost.c > >>> +++ b/hw/virtio/vhost.c > >>> @@ -744,6 +744,7 @@ static void vhost_iommu_region_del(MemoryListener > >>> *listener, > >>>} > >>>} > >>> > >>> + > >>>static int vhost_virtqueue_set_addr(struct vhost_dev *dev, > >>>struct vhost_virtqueue *vq, > >>>unsigned idx, bool enable_log) > >>> @@ -1661,6 +1662,11 @@ int vhost_dev_start(struct vhost_dev *hdev, > >>> VirtIODevice *vdev) > >>>} > >>>} > >>> > >>> +r = vhost_set_start(hdev, true); > >> I think we need a better name for this function. > >> > > Shall we change it to vhost_set_device_start ? Since the > > vhost_dev_start was occupied by other function > > > Or maybe just open code the vhost_set_start here since there's no other > users. > > Thanks > Sure will do >
Re: [PATCH v1 08/10] vhost: implement vhost_dev_start method
On Tue, Jun 23, 2020 at 3:21 PM Jason Wang wrote: > > > On 2020/6/22 下午11:37, Cindy Lu wrote: > > use the vhost_dev_start callback to send the status to backend > > > I suggest to squash this into previous patch. > Sure will do > > > > > Signed-off-by: Cindy Lu > > --- > > hw/virtio/vhost.c | 17 + > > include/hw/virtio/vhost.h | 2 ++ > > 2 files changed, 19 insertions(+) > > > > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c > > index 01ebe12f28..bfd7f9ce1f 100644 > > --- a/hw/virtio/vhost.c > > +++ b/hw/virtio/vhost.c > > @@ -744,6 +744,7 @@ static void vhost_iommu_region_del(MemoryListener > > *listener, > > } > > } > > > > + > > static int vhost_virtqueue_set_addr(struct vhost_dev *dev, > > struct vhost_virtqueue *vq, > > unsigned idx, bool enable_log) > > @@ -1661,6 +1662,11 @@ int vhost_dev_start(struct vhost_dev *hdev, > > VirtIODevice *vdev) > > } > > } > > > > +r = vhost_set_start(hdev, true); > > > I think we need a better name for this function. > Shall we change it to vhost_set_device_start ? Since the vhost_dev_start was occupied by other function > > > +if (r) { > > +goto fail_log; > > +} > > + > > if (vhost_dev_has_iommu(hdev)) { > > hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); > > > > @@ -1697,6 +1703,8 @@ void vhost_dev_stop(struct vhost_dev *hdev, > > VirtIODevice *vdev) > > /* should only be called after backend is connected */ > > assert(hdev->vhost_ops); > > > > +vhost_set_start(hdev, false); > > + > > for (i = 0; i < hdev->nvqs; ++i) { > > vhost_virtqueue_stop(hdev, > >vdev, > > @@ -1722,3 +1730,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev, > > > > return -1; > > } > > + > > +int vhost_set_start(struct vhost_dev *hdev, bool started) > > +{ > > + > > +if (hdev->vhost_ops->vhost_dev_start) { > > +hdev->vhost_ops->vhost_dev_start(hdev, started); > > +} > > +return 0; > > +} > > diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h > > index 085450c6f8..59ea53f8c2 100644 > > --- a/include/hw/virtio/vhost.h > > +++ b/include/hw/virtio/vhost.h > > @@ -92,6 +92,7 @@ struct vhost_dev { > > const VhostDevConfigOps *config_ops; > > }; > > > > + > > int vhost_dev_init(struct vhost_dev *hdev, void *opaque, > > VhostBackendType backend_type, > > uint32_t busyloop_timeout); > > @@ -137,4 +138,5 @@ int vhost_dev_set_inflight(struct vhost_dev *dev, > > struct vhost_inflight *inflight); > > int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size, > > struct vhost_inflight *inflight); > > +int vhost_set_start(struct vhost_dev *dev, bool started); > > > Any reason for exporting this? It looks to me there's no real user out > this file. > > Thanks > Sure will fix this > > > #endif >
Re: [PATCH v1 06/10] vhsot_net: introduce set_config & get_config function
On Tue, Jun 23, 2020 at 3:18 PM Jason Wang wrote: > > > On 2020/6/22 下午11:37, Cindy Lu wrote: > > This patch introduces set_config & get_config method which allows > > > One space is sufficient between get_config and method. > > > > vhost_net set/get the config to backend > > > Typo in the subject. > > thanks jason, I will correct this > > > > Signed-off-by: Cindy Lu > > --- > > hw/net/vhost_net.c | 11 +++ > > include/net/vhost_net.h | 5 + > > 2 files changed, 16 insertions(+) > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index 4096d64aaf..04cc3db264 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > Is there any reason that making this net specific? I guess it could be > used by other vhost devices as well. > > Thanks > Thanks jason I will correct this > > > @@ -111,6 +111,17 @@ uint64_t vhost_net_get_features(struct vhost_net *net, > > uint64_t features) > > features); > > } > > > > +int vhost_net_get_config(struct vhost_net *net, uint8_t *config, > > + uint32_t config_len) > > +{ > > +return vhost_dev_get_config(>dev, config, config_len); > > +} > > +int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, > > + uint32_t offset, uint32_t size, uint32_t flags) > > +{ > > +return vhost_dev_set_config(>dev, data, offset, size, flags); > > +} > > + > > void vhost_net_ack_features(struct vhost_net *net, uint64_t features) > > { > > net->dev.acked_features = net->dev.backend_features; > > diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h > > index 77e47398c4..abfb0e8e68 100644 > > --- a/include/net/vhost_net.h > > +++ b/include/net/vhost_net.h > > @@ -27,6 +27,11 @@ void vhost_net_cleanup(VHostNetState *net); > > > > uint64_t vhost_net_get_features(VHostNetState *net, uint64_t features); > > void vhost_net_ack_features(VHostNetState *net, uint64_t features); > > +int vhost_net_get_config(struct vhost_net *net, uint8_t *config, > > + uint32_t config_len); > > + > > +int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, > > + uint32_t offset, uint32_t size, uint32_t flags); > > > > bool vhost_net_virtqueue_pending(VHostNetState *net, int n); > > void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, >
Re: [PATCH v1 04/10] virtio-pci: implement queue_enabled method
On Tue, Jun 23, 2020 at 3:13 PM Jason Wang wrote: > > > On 2020/6/22 下午11:37, Cindy Lu wrote: > > From: Jason Wang > > > > With version 1, we can detect whether a queue is enabled via > > queue_enabled. > > > > Signed-off-by: Jason Wang > > Signed-off-by: Cindy Lu > > --- > > hw/virtio/virtio-pci.c | 18 ++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > > index 4cb784389c..3918aa9f6c 100644 > > --- a/hw/virtio/virtio-pci.c > > +++ b/hw/virtio/virtio-pci.c > > @@ -1107,6 +1107,23 @@ static AddressSpace > > *virtio_pci_get_dma_as(DeviceState *d) > > return pci_get_address_space(dev); > > } > > > > +static bool virtio_queue_check_enabled(VirtIODevice *vdev, int n) > > > One space is sufficient between bool and virtio_queue_check_enabled. > > > > +{ > > +return virtio_queue_get_desc_addr(vdev, n) != 0; > > +} > > + > > +static bool virtio_pci_queue_enabled(DeviceState *d, int n) > > +{ > > +VirtIOPCIProxy *proxy = VIRTIO_PCI(d); > > +VirtIODevice *vdev = virtio_bus_get_device(>bus); > > + > > +if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { > > +return proxy->vqs[vdev->queue_sel].enabled; > > +} > > + > > +return virtio_queue_check_enabled(vdev, n); > > > Similar issue here. > > Thanks > Thanks, I will correct this > > > +} > > + > > static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, > > struct virtio_pci_cap *cap) > > { > > @@ -2059,6 +2076,7 @@ static void virtio_pci_bus_class_init(ObjectClass > > *klass, void *data) > > k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; > > k->ioeventfd_assign = virtio_pci_ioeventfd_assign; > > k->get_dma_as = virtio_pci_get_dma_as; > > +k->queue_enabled = virtio_pci_queue_enabled; > > } > > > > static const TypeInfo virtio_pci_bus_info = { >
Re: [PATCH v1 10/10] vhost-vdpa: introduce vhost-vdpa net client
On Tue, Jun 23, 2020 at 3:13 PM Markus Armbruster wrote: > > QAPI schema review only. > > Cindy Lu writes: > > > This patch set introduces a new net client type: vhost-vdpa. > > vhost-vdpa net client will set up a vDPA device which is specified > > by a "vhostdev" parameter. > > > > Signed-off-by: Lingshan Zhu > > Signed-off-by: Tiwei Bie > > Signed-off-by: Cindy Lu > [...] > > diff --git a/qapi/net.json b/qapi/net.json > > index cebb1b52e3..03aad67693 100644 > > --- a/qapi/net.json > > +++ b/qapi/net.json > > @@ -428,6 +428,24 @@ > > '*vhostforce':'bool', > > '*queues':'int' } } > > > > +## > > +# @NetdevVhostVDPAOptions: > > +# > > +# Vhost-vdpa network backend > > Considering this ends up in QMP reference documentation, could you add a > hint on what "Vhost-vdpa" is? > > > +# > > +# @vhostdev: name of a vdpa dev path in sysfs > > How is this thing to be spelled in text, vdpa, VDPA or vDPA? > > Avoid unnecessary abbreviations in doc text, please: write "device > path", not "dev path". > > > +#(default path:/dev/vhost-vdpa-$ID) > > What's $ID? > Thanks, I will rewrite this part and make it clear > > +# > > +# @queues: number of queues to be created for multiqueue vhost-vdpa > > +# (default: 1) > > +# > > +# Since: 5.1 > > +## > > +{ 'struct': 'NetdevVhostVDPAOptions', > > + 'data': { > > +'*vhostdev': 'str', > > +'*queues': 'int' } } > > + > > ## > > # @NetClientDriver: > > # > > @@ -437,7 +455,7 @@ > > ## > > { 'enum': 'NetClientDriver', > >'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', > > -'bridge', 'hubport', 'netmap', 'vhost-user' ] } > > +'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa' ] } > > > > ## > > # @Netdev: > > @@ -465,7 +483,8 @@ > > 'bridge': 'NetdevBridgeOptions', > > 'hubport': 'NetdevHubPortOptions', > > 'netmap': 'NetdevNetmapOptions', > > -'vhost-user': 'NetdevVhostUserOptions' } } > > +'vhost-user': 'NetdevVhostUserOptions', > > +'vhost-vdpa': 'NetdevVhostVDPAOptions' } } > > > > ## > > # @NetLegacy: >
Re: [PATCH v1 01/10] net: introduce qemu_get_peer
On Tue, Jun 23, 2020 at 3:10 PM Jason Wang wrote: > > > On 2020/6/22 下午11:37, Cindy Lu wrote: > > This is a small function that can get the peer > > from given NetClientState and queue_index > > > > Signed-off-by: Cindy Lu > > --- > > include/net/net.h | 1 + > > net/net.c | 6 ++ > > 2 files changed, 7 insertions(+) > > > > diff --git a/include/net/net.h b/include/net/net.h > > index 39085d9444..e7ef42d62b 100644 > > --- a/include/net/net.h > > +++ b/include/net/net.h > > @@ -176,6 +176,7 @@ void hmp_info_network(Monitor *mon, const QDict *qdict); > > void net_socket_rs_init(SocketReadState *rs, > > SocketReadStateFinalize *finalize, > > bool vnet_hdr); > > +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); > > > > /* NIC info */ > > > > diff --git a/net/net.c b/net/net.c > > index 38778e831d..599fb61028 100644 > > --- a/net/net.c > > +++ b/net/net.c > > @@ -324,6 +324,12 @@ void *qemu_get_nic_opaque(NetClientState *nc) > > > > return nic->opaque; > > } > > > newline please. > > Thanks > will add this > > > +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) > > +{ > > +assert(nc != NULL); > > +NetClientState *ncs = nc + queue_index; > > +return ncs->peer; > > +} > > > > static void qemu_cleanup_net_client(NetClientState *nc) > > { >
Re: [PATCH v1 00/10] vDPA support in qemu
On Tue, Jun 23, 2020 at 3:07 PM Markus Armbruster wrote: > > Cindy Lu writes: > > > vDPA device is a device that uses a datapath which complies with the > > virtio specifications with vendor specific control path. vDPA devices > > can be both physically located on the hardware or emulated by software. > > This RFC introduce the vDPA support in qemu > > TODO > > 1) vIOMMU support > > 2) live migration support > > This gives me the foggiest of ideas on what vDPA is. Could we use > docs/interop/vhost-vdpa.rst? > Sure will add this
[PATCH v1 10/10] vhost-vdpa: introduce vhost-vdpa net client
This patch set introduces a new net client type: vhost-vdpa. vhost-vdpa net client will set up a vDPA device which is specified by a "vhostdev" parameter. Signed-off-by: Lingshan Zhu Signed-off-by: Tiwei Bie Signed-off-by: Cindy Lu --- include/net/vhost-vdpa.h | 21 include/net/vhost_net.h | 1 - net/Makefile.objs| 2 +- net/clients.h| 2 + net/net.c| 3 + net/vhost-vdpa.c | 230 +++ qapi/net.json| 23 +++- 7 files changed, 278 insertions(+), 4 deletions(-) create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h new file mode 100644 index 00..725c8b1c81 --- /dev/null +++ b/include/net/vhost-vdpa.h @@ -0,0 +1,21 @@ +/* + * vhost-vdpa.h + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef VHOST_VDPA_H +#define VHOST_VDPA_H + +struct vhost_net; +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); + +extern const int vdpa_feature_bits[]; + +#endif /* VHOST_VDPA_H */ diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index abfb0e8e68..4843cdb36f 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -44,5 +44,4 @@ int vhost_set_vring_enable(NetClientState * nc, int enable); uint64_t vhost_net_get_acked_features(VHostNetState *net); int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); - #endif diff --git a/net/Makefile.objs b/net/Makefile.objs index c5d076d19c..5ab45545db 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -26,7 +26,7 @@ tap-obj-$(CONFIG_SOLARIS) = tap-solaris.o tap-obj-y ?= tap-stub.o common-obj-$(CONFIG_POSIX) += tap.o $(tap-obj-y) common-obj-$(CONFIG_WIN32) += tap-win32.o - +common-obj-$(CONFIG_VHOST_NET_VDPA) += vhost-vdpa.o vde.o-libs = $(VDE_LIBS) common-obj-$(CONFIG_CAN_BUS) += can/ diff --git a/net/clients.h b/net/clients.h index a6ef267e19..92f9b59aed 100644 --- a/net/clients.h +++ b/net/clients.h @@ -61,4 +61,6 @@ int net_init_netmap(const Netdev *netdev, const char *name, int net_init_vhost_user(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, +NetClientState *peer, Error **errp); #endif /* QEMU_NET_CLIENTS_H */ diff --git a/net/net.c b/net/net.c index 599fb61028..82624ea9ac 100644 --- a/net/net.c +++ b/net/net.c @@ -965,6 +965,9 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])( #ifdef CONFIG_VHOST_NET_USER [NET_CLIENT_DRIVER_VHOST_USER] = net_init_vhost_user, #endif +#ifdef CONFIG_VHOST_NET_VDPA +[NET_CLIENT_DRIVER_VHOST_VDPA] = net_init_vhost_vdpa, +#endif #ifdef CONFIG_L2TPV3 [NET_CLIENT_DRIVER_L2TPV3]= net_init_l2tpv3, #endif diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c new file mode 100644 index 00..34858a6ea3 --- /dev/null +++ b/net/vhost-vdpa.c @@ -0,0 +1,230 @@ +/* + * vhost-vdpa.c + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "clients.h" +#include "net/vhost_net.h" +#include "net/vhost-vdpa.h" +#include "hw/virtio/vhost-vdpa.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "qemu/option.h" +#include "qapi/error.h" +#include +#include +#include "standard-headers/linux/virtio_net.h" +#include "monitor/monitor.h" +#include "hw/virtio/vhost.h" + +/* Todo:need to add the multiqueue support here */ +typedef struct VhostVDPAState { +NetClientState nc; +struct vhost_vdpa vhost_vdpa; +VHostNetState *vhost_net; +uint64_t acked_features; +bool started; +} VhostVDPAState; + +const int vdpa_feature_bits[] = { +VIRTIO_F_NOTIFY_ON_EMPTY, +VIRTIO_RING_F_INDIRECT_DESC, +VIRTIO_RING_F_EVENT_IDX, +VIRTIO_F_ANY_LAYOUT, +VIRTIO_F_VERSION_1, +VIRTIO_NET_F_CSUM, +VIRTIO_NET_F_GUEST_CSUM, +VIRTIO_NET_F_GSO, +VIRTIO_NET_F_GUEST_TSO4, +VIRTIO_NET_F_GUEST_TSO6, +VIRTIO_NET_F_GUEST_ECN, +VIRTIO_NET_F_GUEST_UFO, +VIRTIO_NET_F_HOST_TSO4, +VIRTIO_NET_F_HOST_TSO6, +VIRTIO_NET_F_HOST_ECN, +VIRTIO_NET_F_HOST_UFO, +VIRTIO_NET_F_MRG_RXBUF, +VIRTIO_NET_F_MTU, +VIRTIO_F_IOMMU_PLATFORM, +VIRTIO_F_RING_PACKED, +VIRTIO_NET_F_GUEST_ANNOUNCE, +VHOST_INVALID_FEATURE_BIT +}; + +VHostNetState *vhos
[PATCH v1 06/10] vhsot_net: introduce set_config & get_config function
This patch introduces set_config & get_config method which allows vhost_net set/get the config to backend Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 11 +++ include/net/vhost_net.h | 5 + 2 files changed, 16 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 4096d64aaf..04cc3db264 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -111,6 +111,17 @@ uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) features); } +int vhost_net_get_config(struct vhost_net *net, uint8_t *config, + uint32_t config_len) +{ +return vhost_dev_get_config(>dev, config, config_len); +} +int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, + uint32_t offset, uint32_t size, uint32_t flags) +{ +return vhost_dev_set_config(>dev, data, offset, size, flags); +} + void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { net->dev.acked_features = net->dev.backend_features; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 77e47398c4..abfb0e8e68 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -27,6 +27,11 @@ void vhost_net_cleanup(VHostNetState *net); uint64_t vhost_net_get_features(VHostNetState *net, uint64_t features); void vhost_net_ack_features(VHostNetState *net, uint64_t features); +int vhost_net_get_config(struct vhost_net *net, uint8_t *config, + uint32_t config_len); + +int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, + uint32_t offset, uint32_t size, uint32_t flags); bool vhost_net_virtqueue_pending(VHostNetState *net, int n); void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, -- 2.21.1
[PATCH v1 09/10] vhost-vdpa: introduce vhost-vdpa backend
Currently we have 2 types of vhost backends in QEMU: vhost kernel and vhost-user. The above patch provides a generic device for vDPA purpose, this vDPA device exposes to user space a non-vendor-specific configuration interface for setting up a vhost HW accelerator, this patch set introduces a third vhost backend called vhost-vdpa based on the vDPA interface. Vhost-vdpa usage: qemu-system-x86_64 -cpu host -enable-kvm \ .. -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ Signed-off-by: Lingshan zhu Signed-off-by: Tiwei Bie Signed-off-by: Cindy Lu --- configure | 21 ++ hw/net/vhost_net.c| 19 +- hw/net/virtio-net.c | 19 +- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 22 +- hw/virtio/vhost-vdpa.c| 406 ++ hw/virtio/vhost.c | 42 +++- include/hw/virtio/vhost-backend.h | 6 +- include/hw/virtio/vhost-vdpa.h| 26 ++ include/hw/virtio/vhost.h | 6 + qemu-options.hx | 12 + 11 files changed, 555 insertions(+), 25 deletions(-) create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h diff --git a/configure b/configure index 23b5e93752..53679ee57f 100755 --- a/configure +++ b/configure @@ -1557,6 +1557,10 @@ for opt do ;; --enable-vhost-user) vhost_user="yes" ;; + --disable-vhost-vdpa) vhost_vdpa="no" + ;; + --enable-vhost-vdpa) vhost_vdpa="yes" + ;; --disable-vhost-kernel) vhost_kernel="no" ;; --enable-vhost-kernel) vhost_kernel="yes" @@ -1846,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available: vhost-cryptovhost-user-crypto backend support vhost-kernelvhost kernel backend support vhost-user vhost-user backend support + vhost-vdpa vhost-vdpa kernel backend support spice spice rbd rados block device (rbd) libiscsiiscsi support @@ -2336,6 +2341,10 @@ test "$vhost_user" = "" && vhost_user=yes if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then error_exit "vhost-user isn't available on win32" fi +test "$vhost_vdpa" = "" && vhost_vdpa=$linux +if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then + error_exit "vhost-vdpa is only available on Linux" +fi test "$vhost_kernel" = "" && vhost_kernel=$linux if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then error_exit "vhost-kernel is only available on Linux" @@ -2364,6 +2373,11 @@ test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then error_exit "--enable-vhost-user-fs requires --enable-vhost-user" fi +#vhost-vdpa backends +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" +fi # OR the vhost-kernel and vhost-user values for simplicity if test "$vhost_net" = ""; then @@ -6673,6 +6687,7 @@ echo "vhost-scsi support $vhost_scsi" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" echo "vhost-user-fs support $vhost_user_fs" +echo "vhost-vdpa support $vhost_vdpa" echo "Trace backends$trace_backends" if have_backend "simple"; then echo "Trace output file $trace_file-" @@ -7170,6 +7185,9 @@ fi if test "$vhost_net_user" = "yes" ; then echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak fi +if test "$vhost_net_vdpa" = "yes" ; then + echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak +fi if test "$vhost_crypto" = "yes" ; then echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak fi @@ -7182,6 +7200,9 @@ fi if test "$vhost_user" = "yes" ; then echo "CONFIG_VHOST_USER=y" >> $config_host_mak fi +if test "$vhost_vdpa" = "yes" ; then + echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak +fi if test "$vhost_user_fs" = "yes" ; then echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak fi diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 04cc3db264
[PATCH v1 07/10] vhost: introduce new VhostOps vhost_dev_start
This patch introduces vhost_dev_start() callback which allows the vhost_net set the start/stop status to backend Signed-off-by: Cindy Lu --- include/hw/virtio/vhost-backend.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 300b59c172..c1384bd2c7 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -112,6 +112,7 @@ typedef int (*vhost_get_inflight_fd_op)(struct vhost_dev *dev, typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, struct vhost_inflight *inflight); +typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -152,6 +153,7 @@ typedef struct VhostOps { vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter; vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; +vhost_dev_start_op vhost_dev_start; } VhostOps; extern const VhostOps user_ops; -- 2.21.1
[PATCH v1 08/10] vhost: implement vhost_dev_start method
use the vhost_dev_start callback to send the status to backend Signed-off-by: Cindy Lu --- hw/virtio/vhost.c | 17 + include/hw/virtio/vhost.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 01ebe12f28..bfd7f9ce1f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -744,6 +744,7 @@ static void vhost_iommu_region_del(MemoryListener *listener, } } + static int vhost_virtqueue_set_addr(struct vhost_dev *dev, struct vhost_virtqueue *vq, unsigned idx, bool enable_log) @@ -1661,6 +1662,11 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) } } +r = vhost_set_start(hdev, true); +if (r) { +goto fail_log; +} + if (vhost_dev_has_iommu(hdev)) { hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true); @@ -1697,6 +1703,8 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) /* should only be called after backend is connected */ assert(hdev->vhost_ops); +vhost_set_start(hdev, false); + for (i = 0; i < hdev->nvqs; ++i) { vhost_virtqueue_stop(hdev, vdev, @@ -1722,3 +1730,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev, return -1; } + +int vhost_set_start(struct vhost_dev *hdev, bool started) +{ + +if (hdev->vhost_ops->vhost_dev_start) { +hdev->vhost_ops->vhost_dev_start(hdev, started); +} +return 0; +} diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 085450c6f8..59ea53f8c2 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -92,6 +92,7 @@ struct vhost_dev { const VhostDevConfigOps *config_ops; }; + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeout); @@ -137,4 +138,5 @@ int vhost_dev_set_inflight(struct vhost_dev *dev, struct vhost_inflight *inflight); int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size, struct vhost_inflight *inflight); +int vhost_set_start(struct vhost_dev *dev, bool started); #endif -- 2.21.1
[PATCH v1 04/10] virtio-pci: implement queue_enabled method
From: Jason Wang With version 1, we can detect whether a queue is enabled via queue_enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 4cb784389c..3918aa9f6c 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1107,6 +1107,23 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d) return pci_get_address_space(dev); } +static bool virtio_queue_check_enabled(VirtIODevice *vdev, int n) +{ +return virtio_queue_get_desc_addr(vdev, n) != 0; +} + +static bool virtio_pci_queue_enabled(DeviceState *d, int n) +{ +VirtIOPCIProxy *proxy = VIRTIO_PCI(d); +VirtIODevice *vdev = virtio_bus_get_device(>bus); + +if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { +return proxy->vqs[vdev->queue_sel].enabled; +} + +return virtio_queue_check_enabled(vdev, n); +} + static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, struct virtio_pci_cap *cap) { @@ -2059,6 +2076,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; k->ioeventfd_assign = virtio_pci_ioeventfd_assign; k->get_dma_as = virtio_pci_get_dma_as; +k->queue_enabled = virtio_pci_queue_enabled; } static const TypeInfo virtio_pci_bus_info = { -- 2.21.1
[PATCH v1 03/10] virtio-bus: introduce queue_enabled method
From: Jason Wang This patch introduces queue_enabled() method which allows the transport to implement its own way to report whether or not a queue is enabled. Signed-off-by: Jason Wang Signed-off-by: Cindy Lu --- hw/virtio/virtio.c | 6 ++ include/hw/virtio/virtio-bus.h | 4 2 files changed, 10 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b6c8ef5bc0..445a4ed760 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3285,6 +3285,12 @@ hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n) bool virtio_queue_enabled(VirtIODevice *vdev, int n) { +BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); +VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + +if (k->queue_enabled) { +return k->queue_enabled(qbus->parent, n); +} return virtio_queue_get_desc_addr(vdev, n) != 0; } diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index 38c9399cd4..0f6f215925 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -83,6 +83,10 @@ typedef struct VirtioBusClass { */ int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier, int n, bool assign); +/* + * Whether queue number n is enabled. + */ +bool (*queue_enabled)(DeviceState *d, int n); /* * Does the transport have variable vring alignment? * (ie can it ever call virtio_queue_set_align()?) -- 2.21.1
[PATCH v1 05/10] vhost-backend: export the vhost backend helper
export the helper then we can reuse them in other backend Signed-off-by: Cindy Lu --- hw/virtio/vhost-backend.c | 18 +- include/hw/virtio/vhost-backend.h | 28 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 48905383f8..660e9e8588 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -89,7 +89,7 @@ static int vhost_kernel_scsi_get_abi_version(struct vhost_dev *dev, int *version return vhost_kernel_call(dev, VHOST_SCSI_GET_ABI_VERSION, version); } -static int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, +int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, struct vhost_log *log) { return vhost_kernel_call(dev, VHOST_SET_LOG_BASE, ); @@ -101,7 +101,7 @@ static int vhost_kernel_set_mem_table(struct vhost_dev *dev, return vhost_kernel_call(dev, VHOST_SET_MEM_TABLE, mem); } -static int vhost_kernel_set_vring_addr(struct vhost_dev *dev, +int vhost_kernel_set_vring_addr(struct vhost_dev *dev, struct vhost_vring_addr *addr) { return vhost_kernel_call(dev, VHOST_SET_VRING_ADDR, addr); @@ -113,31 +113,31 @@ static int vhost_kernel_set_vring_endian(struct vhost_dev *dev, return vhost_kernel_call(dev, VHOST_SET_VRING_ENDIAN, ring); } -static int vhost_kernel_set_vring_num(struct vhost_dev *dev, +int vhost_kernel_set_vring_num(struct vhost_dev *dev, struct vhost_vring_state *ring) { return vhost_kernel_call(dev, VHOST_SET_VRING_NUM, ring); } -static int vhost_kernel_set_vring_base(struct vhost_dev *dev, +int vhost_kernel_set_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { return vhost_kernel_call(dev, VHOST_SET_VRING_BASE, ring); } -static int vhost_kernel_get_vring_base(struct vhost_dev *dev, +int vhost_kernel_get_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { return vhost_kernel_call(dev, VHOST_GET_VRING_BASE, ring); } -static int vhost_kernel_set_vring_kick(struct vhost_dev *dev, +int vhost_kernel_set_vring_kick(struct vhost_dev *dev, struct vhost_vring_file *file) { return vhost_kernel_call(dev, VHOST_SET_VRING_KICK, file); } -static int vhost_kernel_set_vring_call(struct vhost_dev *dev, +int vhost_kernel_set_vring_call(struct vhost_dev *dev, struct vhost_vring_file *file) { return vhost_kernel_call(dev, VHOST_SET_VRING_CALL, file); @@ -155,13 +155,13 @@ static int vhost_kernel_set_features(struct vhost_dev *dev, return vhost_kernel_call(dev, VHOST_SET_FEATURES, ); } -static int vhost_kernel_get_features(struct vhost_dev *dev, +int vhost_kernel_get_features(struct vhost_dev *dev, uint64_t *features) { return vhost_kernel_call(dev, VHOST_GET_FEATURES, features); } -static int vhost_kernel_set_owner(struct vhost_dev *dev) +int vhost_kernel_set_owner(struct vhost_dev *dev) { return vhost_kernel_call(dev, VHOST_SET_OWNER, NULL); } diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 6f6670783f..300b59c172 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -172,4 +172,32 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd); + +int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log); + +int vhost_kernel_set_vring_addr(struct vhost_dev *dev, + struct vhost_vring_addr *addr); + +int vhost_kernel_set_vring_num(struct vhost_dev *dev, + struct vhost_vring_state *ring); + +int vhost_kernel_set_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring); + +int vhost_kernel_get_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring); + +int vhost_kernel_set_vring_kick(struct vhost_dev *dev, + struct vhost_vring_file *file); + +int vhost_kernel_set_vring_call(struct vhost_dev *dev, + struct vhost_vring_file *file); + +int vhost_kernel_set_owner(struct vhost_dev *dev); + +int vhost_kernel_get_features(struct vhost_dev *dev, + uint64_t *features); + + #endif /* VHOST_BACKEND_H */ -- 2.21.1
[PATCH v1 02/10] vhost_net: use the function qemu_get_peer
user the qemu_get_peer to replace the old process Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 16 ++-- 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6b82803fa7..4096d64aaf 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -306,7 +306,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus = VIRTIO_BUS(qbus); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); +struct vhost_net *net; int r, e, i; +NetClientState *peer; if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); @@ -314,9 +316,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -struct vhost_net *net; -net = get_vhost_net(ncs[i].peer); +peer = qemu_get_peer(ncs, i); +net = get_vhost_net(peer); vhost_net_set_vq_index(net, i * 2); /* Suppress the masking guest notifiers on vhost user @@ -335,15 +337,16 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs, i); +r = vhost_net_start_one(get_vhost_net(peer), dev); if (r < 0) { goto err_start; } -if (ncs[i].peer->vring_enable) { +if (peer->vring_enable) { /* restore vring enable state */ -r = vhost_set_vring_enable(ncs[i].peer, ncs[i].peer->vring_enable); +r = vhost_set_vring_enable(peer, peer->vring_enable); if (r < 0) { goto err_start; @@ -355,7 +358,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, err_start: while (--i >= 0) { -vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs , i); +vhost_net_stop_one(get_vhost_net(peer), dev); } e = k->set_guest_notifiers(qbus->parent, total_queues * 2, false); if (e < 0) { -- 2.21.1
[PATCH v1 01/10] net: introduce qemu_get_peer
This is a small function that can get the peer from given NetClientState and queue_index Signed-off-by: Cindy Lu --- include/net/net.h | 1 + net/net.c | 6 ++ 2 files changed, 7 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 39085d9444..e7ef42d62b 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -176,6 +176,7 @@ void hmp_info_network(Monitor *mon, const QDict *qdict); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, bool vnet_hdr); +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); /* NIC info */ diff --git a/net/net.c b/net/net.c index 38778e831d..599fb61028 100644 --- a/net/net.c +++ b/net/net.c @@ -324,6 +324,12 @@ void *qemu_get_nic_opaque(NetClientState *nc) return nic->opaque; } +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) +{ +assert(nc != NULL); +NetClientState *ncs = nc + queue_index; +return ncs->peer; +} static void qemu_cleanup_net_client(NetClientState *nc) { -- 2.21.1
[PATCH v1 00/10] vDPA support in qemu
vDPA device is a device that uses a datapath which complies with the virtio specifications with vendor specific control path. vDPA devices can be both physically located on the hardware or emulated by software. This RFC introduce the vDPA support in qemu TODO 1) vIOMMU support 2) live migration support Cindy Lu (8): net: introduce qemu_get_peer vhost_net: use the function qemu_get_peer vhost-backend: export the vhost backend helper vhsot_net: introduce set_config & get_config function vhost: introduce new VhostOps vhost_dev_start vhost: implement vhost_dev_start method vhost-vdpa: introduce vhost-vdpa backend vhost-vdpa: introduce vhost-vdpa net client Jason Wang (2): virtio-bus: introduce queue_enabled method virtio-pci: implement queue_enabled method configure | 21 ++ hw/net/vhost_net.c| 46 +++- hw/net/virtio-net.c | 19 +- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 40 ++- hw/virtio/vhost-vdpa.c| 406 ++ hw/virtio/vhost.c | 59 - hw/virtio/virtio-pci.c| 18 ++ hw/virtio/virtio.c| 6 + include/hw/virtio/vhost-backend.h | 36 ++- include/hw/virtio/vhost-vdpa.h| 26 ++ include/hw/virtio/vhost.h | 8 + include/hw/virtio/virtio-bus.h| 4 + include/net/net.h | 1 + include/net/vhost-vdpa.h | 21 ++ include/net/vhost_net.h | 6 +- net/Makefile.objs | 2 +- net/clients.h | 2 + net/net.c | 9 + net/vhost-vdpa.c | 230 + qapi/net.json | 23 +- qemu-options.hx | 12 + 22 files changed, 952 insertions(+), 44 deletions(-) create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c -- 2.21.1
Re: [RFC v3 6/8] vhost-backend: export the vhost backend helper
On Tue, Jun 16, 2020 at 4:17 PM Laurent Vivier wrote: > > On 29/05/2020 16:06, Cindy Lu wrote: > > export the helper then we can reuse some of them in vhost-vdpa > > > > Signed-off-by: Cindy Lu > > --- > > hw/virtio/vhost-backend.c | 34 ++- > > include/hw/virtio/vhost-backend.h | 28 + > > 2 files changed, 48 insertions(+), 14 deletions(-) > > > > diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c > > index 48905383f8..42efb4967b 100644 > > --- a/hw/virtio/vhost-backend.c > > +++ b/hw/virtio/vhost-backend.c > > @@ -14,7 +14,7 @@ > > #include "qemu/error-report.h" > > #include "qemu/main-loop.h" > > #include "standard-headers/linux/vhost_types.h" > > - > > +#include "hw/virtio/vhost-vdpa.h" > > You can't include this file because it is created in the next patch. > > > #ifdef CONFIG_VHOST_KERNEL > > #include > > #include > > @@ -22,10 +22,16 @@ > > static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int > > request, > > void *arg) > > { > > -int fd = (uintptr_t) dev->opaque; > > - > > -assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL); > > - > > +int fd = -1; > > +struct vhost_vdpa *v = NULL; > > +if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL) { > > +fd = (uintptr_t) dev->opaque; > > +} > > +if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA) { > > +v = dev->opaque; > > +fd = v->device_fd; > > +} > > +assert(fd != -1); > > A switch would be cleaner: > > switch (dev->vhost_ops->backend_type) { > case VHOST_BACKEND_TYPE_KERNEL: > fd = (uintptr_t)dev->opaque; > break; > case VHOST_BACKEND_TYPE_VDPA: > fd = ((struct vhost_vdpa *)dev->opaque)->device_fd; > break; > default: > g_assert_not_reached() > } > > > return ioctl(fd, request, arg); > > } > > > Thanks Laurent , will fix this > Thanks, > Laurent >
Re: [RFC v3 3/8] virtio-bus: introduce queue_enabled method
On Tue, Jun 16, 2020 at 3:50 PM Laurent Vivier wrote: > > On 29/05/2020 16:06, Cindy Lu wrote: > > From: Jason Wang > > > > This patch introduces queue_enabled() method which allows the > > transport to implement its own way to report whether or not a queue is > > enabled. > > > > Signed-off-by: Jason Wang > > Cindy, you must add your signed-off-by on all the patch you send, after > all the existing S-o-b. > sure will fix this > > > > 0005-virtio-bus-introduce-queue_enabled-method.patch > will remove this part > bad cut? > > Thanks, > Laurent >
Re: [RFC v3 5/8] vhost: introduce vhost_set_vring_ready method
On Tue, Jun 16, 2020 at 4:04 PM Laurent Vivier wrote: > > On 29/05/2020 16:06, Cindy Lu wrote: > > From: Jason Wang > > > > Vhost-vdpa introduces VHOST_VDPA_SET_VRING_ENABLE which complies the > > semantic of queue_enable defined in virtio spec. This method can be > > used for preventing device from executing request for a specific > > virtqueue. This patch introduces the vhost_ops for this. > > > > Note that, we've already had vhost_set_vring_enable which has different > > semantic which allows to enable or disable a specific virtqueue for > > some kinds of vhost backends. E.g vhost-user use this to changes the > > number of active queue pairs. > > > > Signed-off-by: Jason Wang > > Add your S-o-b. > will fix this > > --- > > hw/net/vhost_net-stub.c | 4 > > hw/net/vhost_net.c | 11 ++- > > include/net/vhost_net.h | 1 + > > 3 files changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c > > index aac0e98228..43e93e1a9a 100644 > > --- a/hw/net/vhost_net-stub.c > > +++ b/hw/net/vhost_net-stub.c > > @@ -86,6 +86,10 @@ int vhost_set_vring_enable(NetClientState *nc, int > > enable) > > return 0; > > } > > > > +int vhost_set_vring_ready(NetClientState *nc) > > +{ > > +return 0; > > +} > > Add a blank line here. > will fix this > > int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) > > { > > return 0; > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index d1d421e3d9..e2bc7de2eb 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -344,7 +344,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState > > *ncs, > > goto err_start; > > } > > > > -if (ncs[i].peer->vring_enable) { > > +if (peer->vring_enable) { > > /* restore vring enable state */ > > r = vhost_set_vring_enable(peer, peer->vring_enable); > > Move this part to PATCH 2/8 > will fix this > > @@ -455,6 +455,15 @@ int vhost_set_vring_enable(NetClientState *nc, int > > enable) > > return 0; > > } > > > > +int vhost_set_vring_ready(NetClientState *nc) > > +{ > > +VHostNetState *net = get_vhost_net(nc); > > +const VhostOps *vhost_ops = net->dev.vhost_ops; > > +if (vhost_ops && vhost_ops->vhost_set_vring_ready) { > > The structure VhostOps doesn't declare the vhost_set_vring_ready field. > Your patch is missing something and it could be not built. > > It is defined in PATCH 7/8. If you want to keep this patch you should > move the declaration of "vhost_set_vring_ready_op vhost_set_vring_ready" > (and related) to this patch. > Thanks Laurent, I will fix this > > +return vhost_ops->vhost_set_vring_ready(>dev); > > +} > > +return 0; > > +} > > Add a blank line. > sure will fix this > > int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) > > { > > const VhostOps *vhost_ops = net->dev.vhost_ops; > > diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h > > index 77e47398c4..8a6f208189 100644 > > --- a/include/net/vhost_net.h > > +++ b/include/net/vhost_net.h > > @@ -35,6 +35,7 @@ int vhost_net_notify_migration_done(VHostNetState *net, > > char* mac_addr); > > VHostNetState *get_vhost_net(NetClientState *nc); > > > > int vhost_set_vring_enable(NetClientState * nc, int enable); > > +int vhost_set_vring_ready(NetClientState *nc); > > > > uint64_t vhost_net_get_acked_features(VHostNetState *net); > > > > > > Thanks, > Laurent >
Re: [RFC v3 7/8] vhost-vdpa: introduce vhost-vdpa backend
On Mon, Jun 15, 2020 at 10:44 PM Laurent Vivier wrote: > > On 08/06/2020 22:14, Eric Blake wrote: > > On 5/29/20 9:06 AM, Cindy Lu wrote: > >> From: Tiwei Bie > > > > The original author is Tiwei Bie... > > > >> > >> Currently we have 2 types of vhost backends in QEMU: vhost kernel and > >> vhost-user. The above patch provides a generic device for vDPA purpose, > >> this vDPA device exposes to user space a non-vendor-specific > >> configuration > >> interface for setting up a vhost HW accelerator, this patch set > >> introduces > >> a third vhost backend called vhost-vdpa based on the vDPA interface. > >> > >> Vhost-vdpa usage: > >> > >>qemu-system-x86_64 -cpu host -enable-kvm \ > >> .. > >>-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > >>-device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > >> > >> Co-Authored-By: Lingshan zhu > >> Signed-off-by: Cindy Lu > >> --- > > > > ...but there is no S-o-b here. Also, Co-Authored-By is an unusual tag; > > it's just as easy to spell it Signed-off-by even for co-authors. > > > > Normally the tag to use in this case is "Co-developed-by". > > https://www.kernel.org/doc/html/v4.17/process/submitting-patches.html#when-to-use-acked-by-cc-and-co-developed-by > > "A Co-Developed-by: states that the patch was also created by another > developer along with the original author. This is useful at times when > multiple people work on a single patch. Note, this person also needs to > have a Signed-off-by: line in the patch as well." > > Thanks, > Laurent > Thanks Laurent,I will fix this
Re: [RFC v3 1/8] net: introduce qemu_get_peer
On Thu, Jun 11, 2020 at 5:08 PM Laurent Vivier wrote: > > On 29/05/2020 16:06, Cindy Lu wrote: > > This is a small function that can get the peer from given NetClientState > > and queue_index > > > > Signed-off-by: Cindy Lu > > --- > > include/net/net.h | 1 + > > net/net.c | 6 ++ > > 2 files changed, 7 insertions(+) > > > > diff --git a/include/net/net.h b/include/net/net.h > > index 39085d9444..e7ef42d62b 100644 > > --- a/include/net/net.h > > +++ b/include/net/net.h > > @@ -176,6 +176,7 @@ void hmp_info_network(Monitor *mon, const QDict *qdict); > > void net_socket_rs_init(SocketReadState *rs, > > SocketReadStateFinalize *finalize, > > bool vnet_hdr); > > +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); > > > > /* NIC info */ > > > > diff --git a/net/net.c b/net/net.c > > index 38778e831d..599fb61028 100644 > > --- a/net/net.c > > +++ b/net/net.c > > @@ -324,6 +324,12 @@ void *qemu_get_nic_opaque(NetClientState *nc) > > > > return nic->opaque; > > } > > To be consistent with the style of the file, you should add a blank line > here. > Thanks Laurent, I will fix this > > +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) > > +{ > > +assert(nc != NULL); > > +NetClientState *ncs = nc + queue_index; > > +return ncs->peer; > > +} > > > > static void qemu_cleanup_net_client(NetClientState *nc) > > { > > > > Thanks, > Laurent >
Re: [RFC v3 7/8] vhost-vdpa: introduce vhost-vdpa backend
On Tue, Jun 9, 2020 at 4:14 AM Eric Blake wrote: > > On 5/29/20 9:06 AM, Cindy Lu wrote: > > From: Tiwei Bie > > The original author is Tiwei Bie... > > > > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > >qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > >-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > >-device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Co-Authored-By: Lingshan zhu > > Signed-off-by: Cindy Lu > > --- > > ...but there is no S-o-b here. Also, Co-Authored-By is an unusual tag; > it's just as easy to spell it Signed-off-by even for co-authors. > > [Pardon my delicacy in wording my response; I unfortunately lack enough > cultural context to know a preferred name or even gender-correct > pronouns for referring to the authors in shorthand] > Thanks Eric for pointing that out :-), I will fix this soon. Thanks Cindy > -- > Eric Blake, Principal Software Engineer > Red Hat, Inc. +1-919-301-3226 > Virtualization: qemu.org | libvirt.org >
Re: [RFC v3 7/8] vhost-vdpa: introduce vhost-vdpa backend
On Thu, Jun 4, 2020 at 7:34 PM Michael S. Tsirkin wrote: > > On Thu, Jun 04, 2020 at 12:39:34PM +0200, Eugenio Perez Martin wrote: > > > +static int vhost_vdpa_set_config(struct vhost_dev *dev, const uint8_t > > > *data, > > > + uint32_t offset, uint32_t size, > > > + uint32_t flags) > > > +{ > > > +struct vhost_vdpa_config config; > > > +int ret; > > > +if ((size > VHOST_VDPA_MAX_CONFIG_SIZE) || (data == NULL)) { > > > > VHOST_VDPA_MAX_CONFIG_SIZE is currently undefined. > > > > If we want to maintain this as a stack allocation (as proposed in > > https://www.mail-archive.com/qemu-devel@nongnu.org/msg701744.html) I > > think that the best option is to decide which is the maximum value buf > > can hold, and set it in vhost_vdpa_config.buf declaration. > > That depends on device features. qemu has logic to figure out > config size based on that and set config_size accordingly. > Why not reuse it? Sending more should be ok and extra > data just ignored. > > -- > MST > Thanks Michael and Eugenio for your suggestion,I‘m rewriting this part
Re: [RFC v3 8/8] vhost-vdpa: introduce vhost-vdpa net client
Hi Jason, On Wed, Jun 3, 2020 at 4:43 PM Jason Wang wrote: > > > On 2020/6/3 下午4:19, Cindy Lu wrote: > >>> +static void vhost_vdpa_cleanup(NetClientState *nc) > >>> +{ > >>> +VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); > >>> + > >>> +if (s->vhost_net) { > >>> +vhost_net_cleanup(s->vhost_net); > >>> +g_free(s->vhost_net); > >>> +s->vhost_net = NULL; > >>> +} > >>> + > >>> +qemu_purge_queued_packets(nc); > >> Why this is needed? > >> > >> Thanks > >> > > This is to clean the packet in the queue while the vdpa remove, I > > will double check this part > > > Note we don't have a software backup driver for qemu currently (we > probably need one in the future). > > So we can't fallback into userspace which means the packet can not be > queued by qemu. > Got it, Thanks Jason, I will remove this part > Thanks >
Re: [RFC v3 7/8] vhost-vdpa: introduce vhost-vdpa backend
On Wed, Jun 3, 2020 at 2:43 PM Jason Wang wrote: > > > On 2020/5/29 下午10:06, Cindy Lu wrote: > > From: Tiwei Bie > > > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > >qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > >-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > >-device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Co-Authored-By: Lingshan zhu > > Signed-off-by: Cindy Lu > > --- > > > Btw, I don't see the how to connect the vhost_set/get_config() with the > virtio_net_set/get_config(). > Sure, I will add this part > Thanks > >
Re: [RFC v3 8/8] vhost-vdpa: introduce vhost-vdpa net client
Hi Jason, On Wed, Jun 3, 2020 at 2:39 PM Jason Wang wrote: > > > On 2020/5/29 下午10:06, Cindy Lu wrote: > > From: Tiwei Bie > > > Similar for this patch, you can change the git author and keep sobs for > both Tiwei and Ling Shan. > > Will Fix this > > > > This patch set introduces a new net client type: vhost-vdpa. > > vhost-vdpa net client will set up a vDPA device which is specified > > by a "vhostdev" parameter. > > > > Co-authored-by: Lingshan Zhu > > Signed-off-by: Cindy Lu > > --- > > include/net/vhost-vdpa.h | 19 > > include/net/vhost_net.h | 2 +- > > net/Makefile.objs| 2 +- > > net/clients.h| 2 + > > net/net.c| 3 + > > net/vhost-vdpa.c | 235 +++ > > qapi/net.json| 26 - > > 7 files changed, 285 insertions(+), 4 deletions(-) > > create mode 100644 include/net/vhost-vdpa.h > > create mode 100644 net/vhost-vdpa.c > > > > diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h > > new file mode 100644 > > index 00..6ce0d04f72 > > --- /dev/null > > +++ b/include/net/vhost-vdpa.h > > @@ -0,0 +1,19 @@ > > +/* > > + * vhost-vdpa.h > > + * > > + * Copyright(c) 2017-2018 Intel Corporation. > > + * Copyright(c) 2020 Red Hat, Inc. > > + * > > + * This work is licensed under the terms of the GNU GPL, version 2 or > > later. > > + * See the COPYING file in the top-level directory. > > + * > > + */ > > + > > +#ifndef VHOST_VDPA_H > > +#define VHOST_VDPA_H > > + > > +struct vhost_net; > > +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); > > +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); > > + > > +#endif /* VHOST_VDPA_H */ > > diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h > > index 56e67fe164..0b87d3c6e9 100644 > > --- a/include/net/vhost_net.h > > +++ b/include/net/vhost_net.h > > @@ -41,4 +41,4 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net); > > > > int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); > > int vhost_net_get_device_id(struct vhost_net *net, uint32_t *device_id); > > -endif > > +#endif > > diff --git a/net/Makefile.objs b/net/Makefile.objs > > index c5d076d19c..5ab45545db 100644 > > --- a/net/Makefile.objs > > +++ b/net/Makefile.objs > > @@ -26,7 +26,7 @@ tap-obj-$(CONFIG_SOLARIS) = tap-solaris.o > > tap-obj-y ?= tap-stub.o > > common-obj-$(CONFIG_POSIX) += tap.o $(tap-obj-y) > > common-obj-$(CONFIG_WIN32) += tap-win32.o > > - > > +common-obj-$(CONFIG_VHOST_NET_VDPA) += vhost-vdpa.o > > vde.o-libs = $(VDE_LIBS) > > > > common-obj-$(CONFIG_CAN_BUS) += can/ > > diff --git a/net/clients.h b/net/clients.h > > index a6ef267e19..92f9b59aed 100644 > > --- a/net/clients.h > > +++ b/net/clients.h > > @@ -61,4 +61,6 @@ int net_init_netmap(const Netdev *netdev, const char > > *name, > > int net_init_vhost_user(const Netdev *netdev, const char *name, > > NetClientState *peer, Error **errp); > > > > +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, > > +NetClientState *peer, Error **errp); > > #endif /* QEMU_NET_CLIENTS_H */ > > diff --git a/net/net.c b/net/net.c > > index 599fb61028..82624ea9ac 100644 > > --- a/net/net.c > > +++ b/net/net.c > > @@ -965,6 +965,9 @@ static int (* const > > net_client_init_fun[NET_CLIENT_DRIVER__MAX])( > > #ifdef CONFIG_VHOST_NET_USER > > [NET_CLIENT_DRIVER_VHOST_USER] = net_init_vhost_user, > > #endif > > +#ifdef CONFIG_VHOST_NET_VDPA > > +[NET_CLIENT_DRIVER_VHOST_VDPA] = net_init_vhost_vdpa, > > +#endif > > #ifdef CONFIG_L2TPV3 > > [NET_CLIENT_DRIVER_L2TPV3]= net_init_l2tpv3, > > #endif > > diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c > > new file mode 100644 > > index 00..7b98c142b5 > > --- /dev/null > > +++ b/net/vhost-vdpa.c > > @@ -0,0 +1,235 @@ > > +/* > > + * vhost-vdpa.c > > + * > > + * Copyright(c) 2017-2018 Intel Corporation. > > + * Copyright(c) 2020 Red Hat, Inc. > > + * > > + * This work is licensed under the terms of the GNU GPL, version 2 or > > later. > > + * See the COPYING file in the top-level directory. > > + * > > + */ > > + > > +#include "qemu/osdep.h" > > +#include &qu
Re: [RFC v3 7/8] vhost-vdpa: introduce vhost-vdpa backend
On Wed, Jun 3, 2020 at 10:54 AM Jason Wang wrote: > > > On 2020/5/29 下午10:06, Cindy Lu wrote: > > From: Tiwei Bie > > > Consider the significant modification based on the original patch. > > I think you may change the other to yourslef and keep the sobs for both > Tiwei and Lingshan. > > Thanks > > Sure, Will change this > > > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > >qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > >-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > > -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Co-Authored-By: Lingshan zhu > > Signed-off-by: Cindy Lu >
Re: [RFC v3 7/8] vhost-vdpa: introduce vhost-vdpa backend
Hi Jason, On Wed, Jun 3, 2020 at 10:52 AM Jason Wang wrote: > > > On 2020/5/29 下午10:06, Cindy Lu wrote: > > From: Tiwei Bie > > > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > >qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > >-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > >-device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Co-Authored-By: Lingshan zhu > > Signed-off-by: Cindy Lu > > --- > > configure | 21 ++ > > hw/net/vhost_net-stub.c | 5 + > > hw/net/vhost_net.c| 47 +++- > > hw/virtio/Makefile.objs | 1 + > > hw/virtio/vhost-backend.c | 5 + > > hw/virtio/vhost-vdpa.c| 399 ++ > > hw/virtio/vhost.c | 37 ++- > > include/hw/virtio/vhost-backend.h | 10 +- > > include/hw/virtio/vhost-vdpa.h| 26 ++ > > include/hw/virtio/vhost.h | 2 + > > include/net/vhost_net.h | 4 +- > > qemu-options.hx | 15 ++ > > 12 files changed, 566 insertions(+), 6 deletions(-) > > create mode 100644 hw/virtio/vhost-vdpa.c > > create mode 100644 include/hw/virtio/vhost-vdpa.h > > > > diff --git a/configure b/configure > > index 23b5e93752..53679ee57f 100755 > > --- a/configure > > +++ b/configure > > @@ -1557,6 +1557,10 @@ for opt do > > ;; > > --enable-vhost-user) vhost_user="yes" > > ;; > > + --disable-vhost-vdpa) vhost_vdpa="no" > > + ;; > > + --enable-vhost-vdpa) vhost_vdpa="yes" > > + ;; > > --disable-vhost-kernel) vhost_kernel="no" > > ;; > > --enable-vhost-kernel) vhost_kernel="yes" > > @@ -1846,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled > > if available: > > vhost-cryptovhost-user-crypto backend support > > vhost-kernelvhost kernel backend support > > vhost-user vhost-user backend support > > + vhost-vdpa vhost-vdpa kernel backend support > > spice spice > > rbd rados block device (rbd) > > libiscsiiscsi support > > @@ -2336,6 +2341,10 @@ test "$vhost_user" = "" && vhost_user=yes > > if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then > > error_exit "vhost-user isn't available on win32" > > fi > > +test "$vhost_vdpa" = "" && vhost_vdpa=$linux > > +if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then > > + error_exit "vhost-vdpa is only available on Linux" > > +fi > > test "$vhost_kernel" = "" && vhost_kernel=$linux > > if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then > > error_exit "vhost-kernel is only available on Linux" > > @@ -2364,6 +2373,11 @@ test "$vhost_user_fs" = "" && > > vhost_user_fs=$vhost_user > > if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then > > error_exit "--enable-vhost-user-fs requires --enable-vhost-user" > > fi > > +#vhost-vdpa backends > > +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa > > +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then > > + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" > > +fi > > > > # OR the vhost-kernel and vhost-user values for simplicity > > if test "$vhost_net" = ""; then > > @@ -6673,6 +6687,7 @@ echo "vhost-scsi support $vhost_scsi" > > echo "vhost-vsock support $vhost_vsock" > > echo "vhost-user support $vhost_user" > > echo "vhost-user-fs support $vhost_user_fs" > > +echo "vhost-vdpa support $vhost_vdpa" > > echo
Re: [RFC v3 8/8] vhost-vdpa: introduce vhost-vdpa net client
On Fri, May 29, 2020 at 10:23 PM Eric Blake wrote: > > On 5/29/20 9:06 AM, Cindy Lu wrote: > > From: Tiwei Bie > > > > This patch set introduces a new net client type: vhost-vdpa. > > vhost-vdpa net client will set up a vDPA device which is specified > > by a "vhostdev" parameter. > > > > Co-authored-by: Lingshan Zhu > > Signed-off-by: Cindy Lu > > --- > > > +static int net_vhost_vdpa_init(NetClientState *peer, const char *device, > > + const char *name, const char *vhostdev, > > + bool has_fd, char *fd) > > +{ > > fd is usually an int, not a string. > will fix this > > +NetClientState *nc = NULL; > > +VhostVDPAState *s; > > +int vdpa_device_fd = -1; > > +Error *err = NULL; > > +int ret = 0; > > +assert(name); > > + > > +nc = qemu_new_net_client(_vhost_vdpa_info, peer, device, name); > > +snprintf(nc->info_str, sizeof(nc->info_str), "vhost-vdpa"); > > +nc->queue_index = 0; > > + > > +s = DO_UPCAST(VhostVDPAState, nc, nc); > > + > > +if (has_fd) { > > +vdpa_device_fd = monitor_fd_param(cur_mon, fd, ); > > +} else{ > > +vdpa_device_fd = open(vhostdev, O_RDWR); > > +} > > Oh, you're trying to use the old way for passing in fds. The preferred > way is to use qemu_open(), at which point you can pass in fds via the > add-fd QMP command, and then pass the string "/dev/fdset/NNN" as > vhostdev. Then you don't need a special fd parameter here. > Thanks Eric, I will try this. > > +++ b/qapi/net.json > > @@ -428,6 +428,27 @@ > > '*vhostforce':'bool', > > '*queues':'int' } } > > > > +## > > +# @NetdevVhostVDPAOptions: > > +# > > +# Vhost-vdpa network backend > > +# > > +# @vhostdev: name of a vdpa dev path in sysfs > > +#(default path:/dev/vhost-vdpa-$ID) > > +# > > +# @fd: file descriptor of an already opened vdpa device > > +# > > +# @queues: number of queues to be created for multiqueue vhost-vdpa > > +# (default: 1) > > +# > > +# Since: 5.1 > > +## > > +{ 'struct': 'NetdevVhostVDPAOptions', > > + 'data': { > > +'*vhostdev': 'str', > > +'*fd': 'str', > > +'*queues': 'int' } } > > Instead of having vhostdev and fd both be optional (but where the user > has to specify exactly one of them), you should only have vhostdev be > mandatory, and rely on the /dev/fdset/NNN string as a way to get > vhostdev to point to a previously-passed fd. > will fix this > -- > Eric Blake, Principal Software Engineer > Red Hat, Inc. +1-919-301-3226 > Virtualization: qemu.org | libvirt.org >
[RFC v3 8/8] vhost-vdpa: introduce vhost-vdpa net client
From: Tiwei Bie This patch set introduces a new net client type: vhost-vdpa. vhost-vdpa net client will set up a vDPA device which is specified by a "vhostdev" parameter. Co-authored-by: Lingshan Zhu Signed-off-by: Cindy Lu --- include/net/vhost-vdpa.h | 19 include/net/vhost_net.h | 2 +- net/Makefile.objs| 2 +- net/clients.h| 2 + net/net.c| 3 + net/vhost-vdpa.c | 235 +++ qapi/net.json| 26 - 7 files changed, 285 insertions(+), 4 deletions(-) create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h new file mode 100644 index 00..6ce0d04f72 --- /dev/null +++ b/include/net/vhost-vdpa.h @@ -0,0 +1,19 @@ +/* + * vhost-vdpa.h + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef VHOST_VDPA_H +#define VHOST_VDPA_H + +struct vhost_net; +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); + +#endif /* VHOST_VDPA_H */ diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 56e67fe164..0b87d3c6e9 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -41,4 +41,4 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net); int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); int vhost_net_get_device_id(struct vhost_net *net, uint32_t *device_id); -endif +#endif diff --git a/net/Makefile.objs b/net/Makefile.objs index c5d076d19c..5ab45545db 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -26,7 +26,7 @@ tap-obj-$(CONFIG_SOLARIS) = tap-solaris.o tap-obj-y ?= tap-stub.o common-obj-$(CONFIG_POSIX) += tap.o $(tap-obj-y) common-obj-$(CONFIG_WIN32) += tap-win32.o - +common-obj-$(CONFIG_VHOST_NET_VDPA) += vhost-vdpa.o vde.o-libs = $(VDE_LIBS) common-obj-$(CONFIG_CAN_BUS) += can/ diff --git a/net/clients.h b/net/clients.h index a6ef267e19..92f9b59aed 100644 --- a/net/clients.h +++ b/net/clients.h @@ -61,4 +61,6 @@ int net_init_netmap(const Netdev *netdev, const char *name, int net_init_vhost_user(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp); +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, +NetClientState *peer, Error **errp); #endif /* QEMU_NET_CLIENTS_H */ diff --git a/net/net.c b/net/net.c index 599fb61028..82624ea9ac 100644 --- a/net/net.c +++ b/net/net.c @@ -965,6 +965,9 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])( #ifdef CONFIG_VHOST_NET_USER [NET_CLIENT_DRIVER_VHOST_USER] = net_init_vhost_user, #endif +#ifdef CONFIG_VHOST_NET_VDPA +[NET_CLIENT_DRIVER_VHOST_VDPA] = net_init_vhost_vdpa, +#endif #ifdef CONFIG_L2TPV3 [NET_CLIENT_DRIVER_L2TPV3]= net_init_l2tpv3, #endif diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c new file mode 100644 index 00..7b98c142b5 --- /dev/null +++ b/net/vhost-vdpa.c @@ -0,0 +1,235 @@ +/* + * vhost-vdpa.c + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "clients.h" +#include "net/vhost_net.h" +#include "net/vhost-vdpa.h" +#include "hw/virtio/vhost-vdpa.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "qemu/option.h" +#include "qapi/error.h" +#include +#include +#include "standard-headers/linux/virtio_net.h" +#include "monitor/monitor.h" +#include "hw/virtio/vhost.h" + +/* Todo:need to add the multiqueue support here */ +typedef struct VhostVDPAState { +NetClientState nc; +struct vhost_vdpa vhost_vdpa; +VHostNetState *vhost_net; +uint64_t acked_features; +bool started; +} VhostVDPAState; + +VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) +{ +VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); +assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); +return s->vhost_net; +} + +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc) +{ +VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); +assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); +return s->acked_features; +} + +static int vhost_vdpa_check_device_id(NetClientState *nc) +{ +uint32_t device_id; +int ret; +assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); +VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); +/* Get the device id from hw*/ +ret = vhost_net_g
[RFC v3 7/8] vhost-vdpa: introduce vhost-vdpa backend
From: Tiwei Bie Currently we have 2 types of vhost backends in QEMU: vhost kernel and vhost-user. The above patch provides a generic device for vDPA purpose, this vDPA device exposes to user space a non-vendor-specific configuration interface for setting up a vhost HW accelerator, this patch set introduces a third vhost backend called vhost-vdpa based on the vDPA interface. Vhost-vdpa usage: qemu-system-x86_64 -cpu host -enable-kvm \ .. -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ Co-Authored-By: Lingshan zhu Signed-off-by: Cindy Lu --- configure | 21 ++ hw/net/vhost_net-stub.c | 5 + hw/net/vhost_net.c| 47 +++- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 5 + hw/virtio/vhost-vdpa.c| 399 ++ hw/virtio/vhost.c | 37 ++- include/hw/virtio/vhost-backend.h | 10 +- include/hw/virtio/vhost-vdpa.h| 26 ++ include/hw/virtio/vhost.h | 2 + include/net/vhost_net.h | 4 +- qemu-options.hx | 15 ++ 12 files changed, 566 insertions(+), 6 deletions(-) create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h diff --git a/configure b/configure index 23b5e93752..53679ee57f 100755 --- a/configure +++ b/configure @@ -1557,6 +1557,10 @@ for opt do ;; --enable-vhost-user) vhost_user="yes" ;; + --disable-vhost-vdpa) vhost_vdpa="no" + ;; + --enable-vhost-vdpa) vhost_vdpa="yes" + ;; --disable-vhost-kernel) vhost_kernel="no" ;; --enable-vhost-kernel) vhost_kernel="yes" @@ -1846,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available: vhost-cryptovhost-user-crypto backend support vhost-kernelvhost kernel backend support vhost-user vhost-user backend support + vhost-vdpa vhost-vdpa kernel backend support spice spice rbd rados block device (rbd) libiscsiiscsi support @@ -2336,6 +2341,10 @@ test "$vhost_user" = "" && vhost_user=yes if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then error_exit "vhost-user isn't available on win32" fi +test "$vhost_vdpa" = "" && vhost_vdpa=$linux +if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then + error_exit "vhost-vdpa is only available on Linux" +fi test "$vhost_kernel" = "" && vhost_kernel=$linux if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then error_exit "vhost-kernel is only available on Linux" @@ -2364,6 +2373,11 @@ test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then error_exit "--enable-vhost-user-fs requires --enable-vhost-user" fi +#vhost-vdpa backends +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" +fi # OR the vhost-kernel and vhost-user values for simplicity if test "$vhost_net" = ""; then @@ -6673,6 +6687,7 @@ echo "vhost-scsi support $vhost_scsi" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" echo "vhost-user-fs support $vhost_user_fs" +echo "vhost-vdpa support $vhost_vdpa" echo "Trace backends$trace_backends" if have_backend "simple"; then echo "Trace output file $trace_file-" @@ -7170,6 +7185,9 @@ fi if test "$vhost_net_user" = "yes" ; then echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak fi +if test "$vhost_net_vdpa" = "yes" ; then + echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak +fi if test "$vhost_crypto" = "yes" ; then echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak fi @@ -7182,6 +7200,9 @@ fi if test "$vhost_user" = "yes" ; then echo "CONFIG_VHOST_USER=y" >> $config_host_mak fi +if test "$vhost_vdpa" = "yes" ; then + echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak +fi if test "$vhost_user_fs" = "yes" ; then echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak fi diff --git a/hw/net/vhost_net-stub.c b/
[RFC v3 5/8] vhost: introduce vhost_set_vring_ready method
From: Jason Wang Vhost-vdpa introduces VHOST_VDPA_SET_VRING_ENABLE which complies the semantic of queue_enable defined in virtio spec. This method can be used for preventing device from executing request for a specific virtqueue. This patch introduces the vhost_ops for this. Note that, we've already had vhost_set_vring_enable which has different semantic which allows to enable or disable a specific virtqueue for some kinds of vhost backends. E.g vhost-user use this to changes the number of active queue pairs. Signed-off-by: Jason Wang --- hw/net/vhost_net-stub.c | 4 hw/net/vhost_net.c | 11 ++- include/net/vhost_net.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index aac0e98228..43e93e1a9a 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -86,6 +86,10 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) return 0; } +int vhost_set_vring_ready(NetClientState *nc) +{ +return 0; +} int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) { return 0; diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index d1d421e3d9..e2bc7de2eb 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -344,7 +344,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, goto err_start; } -if (ncs[i].peer->vring_enable) { +if (peer->vring_enable) { /* restore vring enable state */ r = vhost_set_vring_enable(peer, peer->vring_enable); @@ -455,6 +455,15 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) return 0; } +int vhost_set_vring_ready(NetClientState *nc) +{ +VHostNetState *net = get_vhost_net(nc); +const VhostOps *vhost_ops = net->dev.vhost_ops; +if (vhost_ops && vhost_ops->vhost_set_vring_ready) { +return vhost_ops->vhost_set_vring_ready(>dev); +} +return 0; +} int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) { const VhostOps *vhost_ops = net->dev.vhost_ops; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 77e47398c4..8a6f208189 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -35,6 +35,7 @@ int vhost_net_notify_migration_done(VHostNetState *net, char* mac_addr); VHostNetState *get_vhost_net(NetClientState *nc); int vhost_set_vring_enable(NetClientState * nc, int enable); +int vhost_set_vring_ready(NetClientState *nc); uint64_t vhost_net_get_acked_features(VHostNetState *net); -- 2.21.1
[RFC v3 4/8] virtio-pci: implement queue_enabled method
From: Jason Wang With version 1, we can detect whether a queue is enabled via queue_enabled. Signed-off-by: Jason Wang --- hw/virtio/virtio-pci.c | 13 + 1 file changed, 13 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 4cb784389c..2c82ed5246 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1107,6 +1107,18 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d) return pci_get_address_space(dev); } +static bool virtio_pci_queue_enabled(DeviceState *d, int n) +{ +VirtIOPCIProxy *proxy = VIRTIO_PCI(d); +VirtIODevice *vdev = virtio_bus_get_device(>bus); + +if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { +return proxy->vqs[vdev->queue_sel].enabled; +} + +return virtio_queue_get_desc_addr(vdev, n) != 0; +} + static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, struct virtio_pci_cap *cap) { @@ -2059,6 +2071,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; k->ioeventfd_assign = virtio_pci_ioeventfd_assign; k->get_dma_as = virtio_pci_get_dma_as; +k->queue_enabled = virtio_pci_queue_enabled; } static const TypeInfo virtio_pci_bus_info = { -- 2.21.1
[RFC v3 3/8] virtio-bus: introduce queue_enabled method
From: Jason Wang This patch introduces queue_enabled() method which allows the transport to implement its own way to report whether or not a queue is enabled. Signed-off-by: Jason Wang 0005-virtio-bus-introduce-queue_enabled-method.patch --- hw/virtio/virtio.c | 6 ++ include/hw/virtio/virtio-bus.h | 4 2 files changed, 10 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index b6c8ef5bc0..445a4ed760 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3285,6 +3285,12 @@ hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n) bool virtio_queue_enabled(VirtIODevice *vdev, int n) { +BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); +VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + +if (k->queue_enabled) { +return k->queue_enabled(qbus->parent, n); +} return virtio_queue_get_desc_addr(vdev, n) != 0; } diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index 38c9399cd4..0f6f215925 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -83,6 +83,10 @@ typedef struct VirtioBusClass { */ int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier, int n, bool assign); +/* + * Whether queue number n is enabled. + */ +bool (*queue_enabled)(DeviceState *d, int n); /* * Does the transport have variable vring alignment? * (ie can it ever call virtio_queue_set_align()?) -- 2.21.1
[RFC v3 2/8] vhost_net: use the function qemu_get_peer
user the qemu_get_peer to replace the old process Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 14 +- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6b82803fa7..d1d421e3d9 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -306,7 +306,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus = VIRTIO_BUS(qbus); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); +struct vhost_net *net; int r, e, i; +NetClientState *peer; if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); @@ -314,9 +316,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -struct vhost_net *net; -net = get_vhost_net(ncs[i].peer); +peer = qemu_get_peer(ncs, i); +net = get_vhost_net(peer); vhost_net_set_vq_index(net, i * 2); /* Suppress the masking guest notifiers on vhost user @@ -335,7 +337,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs, i); +r = vhost_net_start_one(get_vhost_net(peer), dev); if (r < 0) { goto err_start; @@ -343,7 +346,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, if (ncs[i].peer->vring_enable) { /* restore vring enable state */ -r = vhost_set_vring_enable(ncs[i].peer, ncs[i].peer->vring_enable); +r = vhost_set_vring_enable(peer, peer->vring_enable); if (r < 0) { goto err_start; @@ -355,7 +358,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, err_start: while (--i >= 0) { -vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs , i); +vhost_net_stop_one(get_vhost_net(peer), dev); } e = k->set_guest_notifiers(qbus->parent, total_queues * 2, false); if (e < 0) { -- 2.21.1
[RFC v3 1/8] net: introduce qemu_get_peer
This is a small function that can get the peer from given NetClientState and queue_index Signed-off-by: Cindy Lu --- include/net/net.h | 1 + net/net.c | 6 ++ 2 files changed, 7 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 39085d9444..e7ef42d62b 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -176,6 +176,7 @@ void hmp_info_network(Monitor *mon, const QDict *qdict); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, bool vnet_hdr); +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); /* NIC info */ diff --git a/net/net.c b/net/net.c index 38778e831d..599fb61028 100644 --- a/net/net.c +++ b/net/net.c @@ -324,6 +324,12 @@ void *qemu_get_nic_opaque(NetClientState *nc) return nic->opaque; } +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) +{ +assert(nc != NULL); +NetClientState *ncs = nc + queue_index; +return ncs->peer; +} static void qemu_cleanup_net_client(NetClientState *nc) { -- 2.21.1
[RFC v3 6/8] vhost-backend: export the vhost backend helper
export the helper then we can reuse some of them in vhost-vdpa Signed-off-by: Cindy Lu --- hw/virtio/vhost-backend.c | 34 ++- include/hw/virtio/vhost-backend.h | 28 + 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 48905383f8..42efb4967b 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -14,7 +14,7 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "standard-headers/linux/vhost_types.h" - +#include "hw/virtio/vhost-vdpa.h" #ifdef CONFIG_VHOST_KERNEL #include #include @@ -22,10 +22,16 @@ static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int request, void *arg) { -int fd = (uintptr_t) dev->opaque; - -assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL); - +int fd = -1; +struct vhost_vdpa *v = NULL; +if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL) { +fd = (uintptr_t) dev->opaque; +} +if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA) { +v = dev->opaque; +fd = v->device_fd; +} +assert(fd != -1); return ioctl(fd, request, arg); } @@ -89,7 +95,7 @@ static int vhost_kernel_scsi_get_abi_version(struct vhost_dev *dev, int *version return vhost_kernel_call(dev, VHOST_SCSI_GET_ABI_VERSION, version); } -static int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, +int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, struct vhost_log *log) { return vhost_kernel_call(dev, VHOST_SET_LOG_BASE, ); @@ -101,7 +107,7 @@ static int vhost_kernel_set_mem_table(struct vhost_dev *dev, return vhost_kernel_call(dev, VHOST_SET_MEM_TABLE, mem); } -static int vhost_kernel_set_vring_addr(struct vhost_dev *dev, +int vhost_kernel_set_vring_addr(struct vhost_dev *dev, struct vhost_vring_addr *addr) { return vhost_kernel_call(dev, VHOST_SET_VRING_ADDR, addr); @@ -113,31 +119,31 @@ static int vhost_kernel_set_vring_endian(struct vhost_dev *dev, return vhost_kernel_call(dev, VHOST_SET_VRING_ENDIAN, ring); } -static int vhost_kernel_set_vring_num(struct vhost_dev *dev, +int vhost_kernel_set_vring_num(struct vhost_dev *dev, struct vhost_vring_state *ring) { return vhost_kernel_call(dev, VHOST_SET_VRING_NUM, ring); } -static int vhost_kernel_set_vring_base(struct vhost_dev *dev, +int vhost_kernel_set_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { return vhost_kernel_call(dev, VHOST_SET_VRING_BASE, ring); } -static int vhost_kernel_get_vring_base(struct vhost_dev *dev, +int vhost_kernel_get_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { return vhost_kernel_call(dev, VHOST_GET_VRING_BASE, ring); } -static int vhost_kernel_set_vring_kick(struct vhost_dev *dev, +int vhost_kernel_set_vring_kick(struct vhost_dev *dev, struct vhost_vring_file *file) { return vhost_kernel_call(dev, VHOST_SET_VRING_KICK, file); } -static int vhost_kernel_set_vring_call(struct vhost_dev *dev, +int vhost_kernel_set_vring_call(struct vhost_dev *dev, struct vhost_vring_file *file) { return vhost_kernel_call(dev, VHOST_SET_VRING_CALL, file); @@ -155,13 +161,13 @@ static int vhost_kernel_set_features(struct vhost_dev *dev, return vhost_kernel_call(dev, VHOST_SET_FEATURES, ); } -static int vhost_kernel_get_features(struct vhost_dev *dev, +int vhost_kernel_get_features(struct vhost_dev *dev, uint64_t *features) { return vhost_kernel_call(dev, VHOST_GET_FEATURES, features); } -static int vhost_kernel_set_owner(struct vhost_dev *dev) +int vhost_kernel_set_owner(struct vhost_dev *dev) { return vhost_kernel_call(dev, VHOST_SET_OWNER, NULL); } diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 6f6670783f..300b59c172 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -172,4 +172,32 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd); + +int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log); + +int vhost_kernel_set_vring_addr(struct vhost_dev *dev, + struct vhost_vring_addr *addr); + +int vhost_kernel_set_vring_num(struct vhost_dev *dev, + struct vhost_vring_
[RFC v3 0/8] vDPA support in qemu
vDPA device is a device that uses a datapath which complies with the virtio specifications with vendor specific control path. vDPA devices can be both physically located on the hardware or emulated by software. This RFC introduce the vDPA support in qemu TODO: 1) vIOMMU support 2) live migration support change from v1 separate the patch of introduce vhost_set_vring_ready method separate the patch of qemu_get_peer separate the patch of vhost_set_state introduce the new macro specific for vDPA in configure introduce the function to pass the fd from cmdline introduce the docmation in qemu-options.hx the other comments form last version change from v2 change the work process of vhost set status introduce vhost_get_device_id test based on qemu v5.0.0-rc4 the other comments from last version Cindy Lu (3): net: introduce qemu_get_peer vhost_net: use the function qemu_get_peer vhost-backend: export the vhost backend helper Jason Wang (3): virtio-bus: introduce queue_enabled method virtio-pci: implement queue_enabled method vhost: introduce vhost_set_vring_ready method Tiwei Bie (2): vhost-vdpa: introduce vhost-vdpa backend vhost-vdpa: introduce vhost-vdpa net client configure | 21 ++ hw/net/vhost_net-stub.c | 9 + hw/net/vhost_net.c| 72 +- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 39 +-- hw/virtio/vhost-vdpa.c| 399 ++ hw/virtio/vhost.c | 37 ++- hw/virtio/virtio-pci.c| 13 + hw/virtio/virtio.c| 6 + include/hw/virtio/vhost-backend.h | 38 ++- include/hw/virtio/vhost-vdpa.h| 26 ++ include/hw/virtio/vhost.h | 2 + include/hw/virtio/virtio-bus.h| 4 + include/net/net.h | 1 + include/net/vhost-vdpa.h | 19 ++ include/net/vhost_net.h | 3 +- net/Makefile.objs | 2 +- net/clients.h | 2 + net/net.c | 9 + net/vhost-vdpa.c | 235 ++ qapi/net.json | 26 +- qemu-options.hx | 15 ++ 22 files changed, 951 insertions(+), 28 deletions(-) create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c -- 2.21.1
Re: [RFC v2 5/9] vhost-vdpa: implement vhost-vdpa backend
On Thu, May 21, 2020 at 8:40 PM Stefan Hajnoczi wrote: > > On Sat, May 09, 2020 at 12:32:14AM +0800, Cindy Lu wrote: > > From: Tiwei Bie > > > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > > qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > > -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > > -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > I haven't looked at vDPA in depth. What is different here compared to > the existing vhost-backend.c kernel backend? > > It seems to be making the same ioctls calls so I wonder if it makes > sense to share the vhost-backend.c kernel code? > > Stefan Hi Stefan, Sorry for the late reply and Thanks for these suggestions. I think the most difference between vhost kernel and vdpa is vdpa depends on a real hardware. The point is that vDPA devices work as a virtio device, but vhost-vdpa qemu must present a vhost-like device in qemu vhost layer. The ioctl calls are similar with vhost-backend.c now, but after more and more NIC support vdpa. The difference between vhost-backend.c and vpda will become more and more big. It will make the code complicated to share the code with kernel code. Thanks Cindy
Re: [RFC v2 7/9] virito-pci: implement queue_enabled method
On Sat, May 9, 2020 at 8:02 PM Philippe Mathieu-Daudé wrote: > > Typo "virtio-pci" in patch subject. > Thanks Philippe, I will fix this > On 5/8/20 6:32 PM, Cindy Lu wrote: > > From: Jason Wang > > > > With version 1, we can detect whether a queue is enabled via > > queue_enabled. > > > > Signed-off-by: Jason Wang > > --- > > hw/virtio/virtio-pci.c | 13 + > > 1 file changed, 13 insertions(+) > > > > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > > index c6b47a9c73..4aaf5d953e 100644 > > --- a/hw/virtio/virtio-pci.c > > +++ b/hw/virtio/virtio-pci.c > > @@ -1103,6 +1103,18 @@ static AddressSpace > > *virtio_pci_get_dma_as(DeviceState *d) > > return pci_get_address_space(dev); > > } > > > > +static bool virtio_pci_queue_enabled(DeviceState *d, int n) > > +{ > > +VirtIOPCIProxy *proxy = VIRTIO_PCI(d); > > +VirtIODevice *vdev = virtio_bus_get_device(>bus); > > + > > +if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { > > +return proxy->vqs[vdev->queue_sel].enabled; > > +} > > + > > +return virtio_queue_get_desc_addr(vdev, n) != 0; > > +} > > + > > static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, > > struct virtio_pci_cap *cap) > > { > > @@ -2053,6 +2065,7 @@ static void virtio_pci_bus_class_init(ObjectClass > > *klass, void *data) > > k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; > > k->ioeventfd_assign = virtio_pci_ioeventfd_assign; > > k->get_dma_as = virtio_pci_get_dma_as; > > +k->queue_enabled = virtio_pci_queue_enabled; > > } > > > > static const TypeInfo virtio_pci_bus_info = { > > >
Re: [RFC v2 5/9] vhost-vdpa: implement vhost-vdpa backend
On Sat, May 9, 2020 at 11:00 AM Jason Wang wrote: > > > On 2020/5/9 上午12:32, Cindy Lu wrote: > > From: Tiwei Bie > > > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > >qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > >-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > >-device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Co-Authored-By: Lingshan zhu > > Signed-off-by: Cindy Lu > > > Signed-off-by: Jason Wang > > > > --- > > hw/net/vhost_net.c| 39 ++- > > hw/virtio/Makefile.objs | 1 + > > hw/virtio/vhost-backend.c | 5 + > > hw/virtio/vhost-vdpa.c| 447 ++ > > hw/virtio/vhost.c | 14 + > > include/hw/virtio/vhost-backend.h | 8 +- > > include/hw/virtio/vhost-vdpa.h| 25 ++ > > include/hw/virtio/vhost.h | 1 + > > 8 files changed, 538 insertions(+), 2 deletions(-) > > create mode 100644 hw/virtio/vhost-vdpa.c > > create mode 100644 include/hw/virtio/vhost-vdpa.h > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index 63b2a85d6e..1af39abaf3 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -17,8 +17,10 @@ > > #include "net/net.h" > > #include "net/tap.h" > > #include "net/vhost-user.h" > > +#include "net/vhost-vdpa.h" > > > > #include "standard-headers/linux/vhost_types.h" > > +#include "linux-headers/linux/vhost.h" > > #include "hw/virtio/virtio-net.h" > > #include "net/vhost_net.h" > > #include "qemu/error-report.h" > > @@ -85,6 +87,29 @@ static const int user_feature_bits[] = { > > VHOST_INVALID_FEATURE_BIT > > }; > > > > +static const int vdpa_feature_bits[] = { > > +VIRTIO_F_NOTIFY_ON_EMPTY, > > +VIRTIO_RING_F_INDIRECT_DESC, > > +VIRTIO_RING_F_EVENT_IDX, > > +VIRTIO_F_ANY_LAYOUT, > > +VIRTIO_F_VERSION_1, > > +VIRTIO_NET_F_CSUM, > > +VIRTIO_NET_F_GUEST_CSUM, > > +VIRTIO_NET_F_GSO, > > +VIRTIO_NET_F_GUEST_TSO4, > > +VIRTIO_NET_F_GUEST_TSO6, > > +VIRTIO_NET_F_GUEST_ECN, > > +VIRTIO_NET_F_GUEST_UFO, > > +VIRTIO_NET_F_HOST_TSO4, > > +VIRTIO_NET_F_HOST_TSO6, > > +VIRTIO_NET_F_HOST_ECN, > > +VIRTIO_NET_F_HOST_UFO, > > +VIRTIO_NET_F_MRG_RXBUF, > > +VIRTIO_NET_F_MTU, > > +VIRTIO_F_IOMMU_PLATFORM, > > +VIRTIO_NET_F_GUEST_ANNOUNCE, > > +VHOST_INVALID_FEATURE_BIT > > +}; > > > The framework should be ready for packed ring, let's add that. > Will fix this > > > static const int *vhost_net_get_feature_bits(struct vhost_net *net) > > { > > const int *feature_bits = 0; > > @@ -96,6 +121,9 @@ static const int *vhost_net_get_feature_bits(struct > > vhost_net *net) > > case NET_CLIENT_DRIVER_VHOST_USER: > > feature_bits = user_feature_bits; > > break; > > +case NET_CLIENT_DRIVER_VHOST_VDPA: > > +feature_bits = vdpa_feature_bits; > > +break; > > default: > > error_report("Feature bits not defined for this type: %d", > > net->nc->info->type); > > @@ -110,7 +138,10 @@ uint64_t vhost_net_get_features(struct vhost_net *net, > > uint64_t features) > > return vhost_get_features(>dev, vhost_net_get_feature_bits(net), > > features); > > } > > - > > +int vhost_net_get_device_id(struct vhost_net *net, uint32_t * device_id) > > +{ > > +return vhost_dev_get_device_id(>dev, device_id); > > +} > > void vhost_net_ack_features(struct vhost_net *net, uint64_t features) > > { > > net->dev.acked_features = net->dev.backend_features; > > @@ -433,6 +464,12 @@ VHostNetState *get_vhost_net(NetClientState *nc) > > vhost_net = vhost_user_get_vhost_net(nc); > > assert(vhost_net); > > break; > > +#endif > > +#ifdef CONFIG_VHOST_NET_
Re: [RFC v2 4/9] vhost-vdpa: introduce vhost-vdpa net client
On Sat, May 9, 2020 at 10:40 AM Jason Wang wrote: > > > On 2020/5/9 上午12:32, Cindy Lu wrote: > > From: Tiwei Bie > > > If you think you've done a huge refactor on the code, you can change the > author but need to keep the sob of Tiwei. > > > > > > This patch set introduces a new net client type: vhost-vdpa. > > vhost-vdpa net client will set up a vDPA device which is specified > > by a "vhostdev" parameter. > > > > Co-authored-by: Lingshan Zhu > > Signed-off-by: Cindy Lu > > --- > > configure| 21 > > include/net/vhost-vdpa.h | 19 > > include/net/vhost_net.h | 1 + > > > Patch 5 which is the infrastructure of vhost-vpda should come first. > Please re-order the patch in next version. > Sure, Will fix this > > > net/Makefile.objs| 2 +- > > net/clients.h| 2 + > > net/net.c| 3 + > > net/vhost-vdpa.c | 227 +++ > > qapi/net.json| 22 +++- > > qemu-options.hx | 19 > > 9 files changed, 313 insertions(+), 3 deletions(-) > > create mode 100644 include/net/vhost-vdpa.h > > create mode 100644 net/vhost-vdpa.c > > > > diff --git a/configure b/configure > > index 6099be1d84..bdd732e3bb 100755 > > --- a/configure > > +++ b/configure > > @@ -1505,6 +1505,10 @@ for opt do > > ;; > > --enable-vhost-user) vhost_user="yes" > > ;; > > + --disable-vhost-vdpa) vhost_vdpa="no" > > + ;; > > + --enable-vhost-vdpa) vhost_vdpa="yes" > > + ;; > > --disable-vhost-kernel) vhost_kernel="no" > > ;; > > --enable-vhost-kernel) vhost_kernel="yes" > > @@ -1780,6 +1784,7 @@ disabled with --disable-FEATURE, default is enabled > > if available: > > vhost-cryptovhost-user-crypto backend support > > vhost-kernelvhost kernel backend support > > vhost-user vhost-user backend support > > + vhost-vdpa vhost-vdpa backend support > > > Maybe "vhost-vdpa kernel backend support" is better. > > Will fix this > > spice spice > > rbd rados block device (rbd) > > libiscsiiscsi support > > @@ -2241,6 +2246,10 @@ test "$vhost_user" = "" && vhost_user=yes > > if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then > > error_exit "vhost-user isn't available on win32" > > fi > > +test "$vhost_vdpa" = "" && vhost_vdpa=yes > > +if test "$vhost_vdpa" = "yes" && test "$mingw32" = "yes"; then > > + error_exit "vhost-vdpa isn't available on win32" > > +fi > > > Let's add a check for Linux like vhost kernel below. > Will fix this > > > test "$vhost_kernel" = "" && vhost_kernel=$linux > > if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then > > error_exit "vhost-kernel is only available on Linux" > > @@ -2269,6 +2278,11 @@ test "$vhost_user_fs" = "" && > > vhost_user_fs=$vhost_user > > if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then > > error_exit "--enable-vhost-user-fs requires --enable-vhost-user" > > fi > > +#vhost-vdpa backends > > +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa > > +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then > > + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" > > +fi > > > > # OR the vhost-kernel and vhost-user values for simplicity > > if test "$vhost_net" = ""; then > > @@ -6543,6 +6557,7 @@ echo "vhost-scsi support $vhost_scsi" > > echo "vhost-vsock support $vhost_vsock" > > echo "vhost-user support $vhost_user" > > echo "vhost-user-fs support $vhost_user_fs" > > +echo "vhost-vdpa support $vhost_vdpa" > > echo "Trace backends$trace_backends" > > if have_backend "simple"; then > > echo "Trace output file $trace_file-" > > @@ -7031,6 +7046,9 @@ fi > > if test "$vhost_net_user" = "y
Re: [RFC v2 4/9] vhost-vdpa: introduce vhost-vdpa net client
On Sat, May 9, 2020 at 12:42 AM Eric Blake wrote: > > On 5/8/20 11:32 AM, Cindy Lu wrote: > > From: Tiwei Bie > > > > This patch set introduces a new net client type: vhost-vdpa. > > vhost-vdpa net client will set up a vDPA device which is specified > > by a "vhostdev" parameter. > > > > Co-authored-by: Lingshan Zhu > > Signed-off-by: Cindy Lu > > --- > > Just looking at UI: > > > > +++ b/qapi/net.json > > @@ -441,6 +441,23 @@ > > '*queues':'int' } } > > > > ## > > +# @NetdevVhostVDPAOptions: > > +# > > +# Vhost-vdpa network backend > > +# > > +# @vhostdev: name of a vdpa dev path in sysfs > > +# > > +# @queues: number of queues to be created for multiqueue vhost-vdpa > > +# (default: 1) (Since 5.1) > > No need to mark a 'since' tag on a member introduced at the same time as > the overall struct itself. > Will fix this > > +# > > +# Since: 5.1 > > +## > > +{ 'struct': 'NetdevVhostVDPAOptions', > > + 'data': { > > +'*vhostdev': 'str', > > What does this default to if omitted? > > > +'*fd': 'str', > > Not documented above. > > > +'*queues': 'int' } } > > +## > > Missing blank line separator. > Thanks Eric, Will fix these all > > # @NetClientDriver: > > # > > # Available netdev drivers. > > @@ -451,7 +468,7 @@ > > ## > > { 'enum': 'NetClientDriver', > > 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', > > -'bridge', 'hubport', 'netmap', 'vhost-user' ] } > > +'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa' ] } > > Missing a line above that 'vhost-vdpa' is new to 5.1. > > Will fix this > > @@ -2749,6 +2756,18 @@ qemu -m 512 -object > > memory-backend-file,id=mem,size=512M,mem-path=/hugetlbfs,sha > >-device virtio-net-pci,netdev=net0 > > @end example > > > > +@item -netdev vhost-vdpa,vhostdev=/path/to/dev > > +Establish a vhost-vdpa netdev, backed by a vhostdev. The chardev should > > +be a unix domain socket backed one. The vhost-vdpa uses a specifically > > defined > > +protocol to pass vhost ioctl replacement messages to an application on the > > other > > +end of the socket. > > +Example: > > +@example > > +qemu -m 512 -object > > memory-backend-file,id=mem,size=512M,mem-path=/hugetlbfs,share=on \ > > + -numa node,memdev=mem \ > > + -netdev type=vhost-vdpa,id=net0,vhostdev=/path/to/dev \ > > + -device virtio-net-pci,netdev=net0 > > +@end example > > @item -netdev hubport,id=@var{id},hubid=@var{hubid}[,netdev=@var{nd}] > > > > Create a hub port on the emulated hub with ID @var{hubid}. > > > > -- > Eric Blake, Principal Software Engineer > Red Hat, Inc. +1-919-301-3226 > Virtualization: qemu.org | libvirt.org >
Re: [RFC v2 3/9] virtio_net: introduce vhost_set_state
On Sat, May 9, 2020 at 10:25 AM Jason Wang wrote: > > > On 2020/5/9 上午12:32, Cindy Lu wrote: > > Introduce a function to set the state to the vhost driver. > > vDPA need to sync the driver's state to NIC > > > Let's split this patch into two. > > 1) introduce vhost_set_state > 2) make virtio-net use of vhost_set_state > Sure, Will fix this > > > > Signed-off-by: Cindy Lu > > --- > > hw/net/vhost_net.c| 9 + > > hw/net/virtio-net.c | 9 + > > include/hw/virtio/vhost-backend.h | 2 ++ > > include/net/vhost_net.h | 2 +- > > 4 files changed, 21 insertions(+), 1 deletion(-) > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index d1d421e3d9..63b2a85d6e 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -465,3 +465,12 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t > > mtu) > > > > return vhost_ops->vhost_net_set_mtu(>dev, mtu); > > } > > +int vhost_set_state(NetClientState *nc, uint8_t state) > > +{ > > +struct vhost_net *net = get_vhost_net(nc); > > +struct vhost_dev *hdev = >dev; > > +if (hdev->vhost_ops->vhost_set_state) { > > > Indentation looks wrong. > Will fix this > > > +return hdev->vhost_ops->vhost_set_state(hdev, state); > > +} > > +return 0; > > +} > > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c > > index db3d7c38e6..1bddb4b4af 100644 > > --- a/hw/net/virtio-net.c > > +++ b/hw/net/virtio-net.c > > @@ -206,6 +206,9 @@ static void virtio_net_vhost_status(VirtIONet *n, > > uint8_t status) > > VirtIODevice *vdev = VIRTIO_DEVICE(n); > > NetClientState *nc = qemu_get_queue(n->nic); > > int queues = n->multiqueue ? n->max_queues : 1; > > +NetClientState *peer = qemu_get_peer(nc, 0); > > +uint8_t status_set = vdev->status ; > > +uint8_t vhost_started_pre = n->vhost_started; > > > > if (!get_vhost_net(nc->peer)) { > > return; > > @@ -245,6 +248,7 @@ static void virtio_net_vhost_status(VirtIONet *n, > > uint8_t status) > > return; > > } > > } > > +status_set = status_set | VIRTIO_CONFIG_S_DRIVER_OK; > > > > n->vhost_started = 1; > > r = vhost_net_start(vdev, n->nic->ncs, queues); > > @@ -252,11 +256,16 @@ static void virtio_net_vhost_status(VirtIONet *n, > > uint8_t status) > > error_report("unable to start vhost net: %d: " > >"falling back on userspace virtio", -r); > > n->vhost_started = 0; > > +status_set = status_set & ~VIRTIO_CONFIG_S_DRIVER_OK; > > } > > } else { > > vhost_net_stop(vdev, n->nic->ncs, queues); > > +status_set = status_set & ~VIRTIO_CONFIG_S_DRIVER_OK; > > n->vhost_started = 0; > > } > > +if (vhost_started_pre != n->vhost_started) { > > +vhost_set_state(peer, status_set); > > > Any reason why not just passing virtio device status to vhost-vdpa? > I will double check and fix this > > > +} > > } > > > > static int virtio_net_set_vnet_endian_one(VirtIODevice *vdev, > > diff --git a/include/hw/virtio/vhost-backend.h > > b/include/hw/virtio/vhost-backend.h > > index 6f6670783f..f823055167 100644 > > --- a/include/hw/virtio/vhost-backend.h > > +++ b/include/hw/virtio/vhost-backend.h > > @@ -112,6 +112,7 @@ typedef int (*vhost_get_inflight_fd_op)(struct > > vhost_dev *dev, > > typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, > > struct vhost_inflight *inflight); > > > > +typedef int (*vhost_set_state_op)(struct vhost_dev *dev, uint8_t state); > > > Need document what's the meaning of state here, is it e.g virtio device > status? If yes, is it better to rename it to vhost_set_status()? > > Thanks > sure will fix this > > > typedef struct VhostOps { > > VhostBackendType backend_type; > > vhost_backend_init vhost_backend_init; > > @@ -152,6 +153,7 @@ typedef struct VhostOps { > > vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter; > > vhost_get_inflight_fd_op vhost_get_inflight_fd; > > vhost_set_inflight_fd_op vhost_set_inflight_fd; > > +vhost_set_state_op vhost_set_state; > > } VhostOps; > > > > extern const VhostOps user_ops; > > diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h > > index 77e47398c4..6548a5a105 100644 > > --- a/include/net/vhost_net.h > > +++ b/include/net/vhost_net.h > > @@ -39,5 +39,5 @@ int vhost_set_vring_enable(NetClientState * nc, int > > enable); > > uint64_t vhost_net_get_acked_features(VHostNetState *net); > > > > int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); > > - > > +int vhost_set_state(NetClientState *nc, uint8_t state); > > #endif >
Re: [RFC v2 6/9] virtio-bus: introduce queue_enabled method
On Sat, May 9, 2020 at 11:02 AM Jason Wang wrote: > > > On 2020/5/9 上午12:32, Cindy Lu wrote: > > From: Jason Wang > > > > This patch introduces queue_enabled() method which allows the > > transport to implement its own way to report whether or not a queue is > > enabled. > > > > Signed-off-by: Jason Wang > > > This patch should come before any of the vhost-vpda patch. > > Thanks > Sure, Will fix this > > > --- > > hw/virtio/virtio.c | 6 ++ > > include/hw/virtio/virtio-bus.h | 4 > > 2 files changed, 10 insertions(+) > > > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > > index 04716b5f6c..09732a8836 100644 > > --- a/hw/virtio/virtio.c > > +++ b/hw/virtio/virtio.c > > @@ -3169,6 +3169,12 @@ hwaddr virtio_queue_get_desc_addr(VirtIODevice > > *vdev, int n) > > > > bool virtio_queue_enabled(VirtIODevice *vdev, int n) > > { > > +BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); > > +VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); > > + > > +if (k->queue_enabled) > > +return k->queue_enabled(qbus->parent, n); > > + > > return virtio_queue_get_desc_addr(vdev, n) != 0; > > } > > > > diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h > > index 38c9399cd4..0f6f215925 100644 > > --- a/include/hw/virtio/virtio-bus.h > > +++ b/include/hw/virtio/virtio-bus.h > > @@ -83,6 +83,10 @@ typedef struct VirtioBusClass { > >*/ > > int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier, > > int n, bool assign); > > +/* > > + * Whether queue number n is enabled. > > + */ > > +bool (*queue_enabled)(DeviceState *d, int n); > > /* > >* Does the transport have variable vring alignment? > >* (ie can it ever call virtio_queue_set_align()?) >
Re: [RFC v2 8/9] vhost_net: set vq ready during start if necessary
On Sat, May 9, 2020 at 11:04 AM Jason Wang wrote: > > > On 2020/5/9 上午12:32, Cindy Lu wrote: > > From: Jason Wang > > > > Signed-off-by: Jason Wang > > --- > > hw/net/vhost_net.c | 4 > > 1 file changed, 4 insertions(+) > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index 1af39abaf3..eff9ec9177 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -383,6 +383,10 @@ int vhost_net_start(VirtIODevice *dev, NetClientState > > *ncs, > > goto err_start; > > } > > } > > + > > +if (virtio_queue_enabled(dev, i)) { > > +vhost_set_vring_ready(peer); > > +} > > } > > > > return 0; > > > Please place the patch before vhost-vdpa. > > Thanks > Sure will fix this
Re: [RFC v2 2/9] net: use the function qemu_get_peer
On Sat, May 9, 2020 at 10:20 AM Jason Wang wrote: > > > On 2020/5/9 上午12:32, Cindy Lu wrote: > > user the qemu_get_peer to replace the old process > > > The title should be "vhost_net: use the function qemu_get_peer". > > Thanks > Sure, I will fix this > > > > > Signed-off-by: Cindy Lu > > --- > > hw/net/vhost_net.c | 14 +- > > 1 file changed, 9 insertions(+), 5 deletions(-) > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index 6b82803fa7..d1d421e3d9 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -306,7 +306,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState > > *ncs, > > BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev))); > > VirtioBusState *vbus = VIRTIO_BUS(qbus); > > VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); > > +struct vhost_net *net; > > int r, e, i; > > +NetClientState *peer; > > > > if (!k->set_guest_notifiers) { > > error_report("binding does not support guest notifiers"); > > @@ -314,9 +316,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState > > *ncs, > > } > > > > for (i = 0; i < total_queues; i++) { > > -struct vhost_net *net; > > > > -net = get_vhost_net(ncs[i].peer); > > +peer = qemu_get_peer(ncs, i); > > +net = get_vhost_net(peer); > > vhost_net_set_vq_index(net, i * 2); > > > > /* Suppress the masking guest notifiers on vhost user > > @@ -335,7 +337,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState > > *ncs, > > } > > > > for (i = 0; i < total_queues; i++) { > > -r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev); > > +peer = qemu_get_peer(ncs, i); > > +r = vhost_net_start_one(get_vhost_net(peer), dev); > > > > if (r < 0) { > > goto err_start; > > @@ -343,7 +346,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState > > *ncs, > > > > if (ncs[i].peer->vring_enable) { > > /* restore vring enable state */ > > -r = vhost_set_vring_enable(ncs[i].peer, > > ncs[i].peer->vring_enable); > > +r = vhost_set_vring_enable(peer, peer->vring_enable); > > > > if (r < 0) { > > goto err_start; > > @@ -355,7 +358,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState > > *ncs, > > > > err_start: > > while (--i >= 0) { > > -vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); > > +peer = qemu_get_peer(ncs , i); > > +vhost_net_stop_one(get_vhost_net(peer), dev); > > } > > e = k->set_guest_notifiers(qbus->parent, total_queues * 2, false); > > if (e < 0) { >
[RFC v2 7/9] virito-pci: implement queue_enabled method
From: Jason Wang With version 1, we can detect whether a queue is enabled via queue_enabled. Signed-off-by: Jason Wang --- hw/virtio/virtio-pci.c | 13 + 1 file changed, 13 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index c6b47a9c73..4aaf5d953e 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1103,6 +1103,18 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d) return pci_get_address_space(dev); } +static bool virtio_pci_queue_enabled(DeviceState *d, int n) +{ +VirtIOPCIProxy *proxy = VIRTIO_PCI(d); +VirtIODevice *vdev = virtio_bus_get_device(>bus); + +if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { +return proxy->vqs[vdev->queue_sel].enabled; +} + +return virtio_queue_get_desc_addr(vdev, n) != 0; +} + static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, struct virtio_pci_cap *cap) { @@ -2053,6 +2065,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; k->ioeventfd_assign = virtio_pci_ioeventfd_assign; k->get_dma_as = virtio_pci_get_dma_as; +k->queue_enabled = virtio_pci_queue_enabled; } static const TypeInfo virtio_pci_bus_info = { -- 2.21.1
[RFC v2 8/9] vhost_net: set vq ready during start if necessary
From: Jason Wang Signed-off-by: Jason Wang --- hw/net/vhost_net.c | 4 1 file changed, 4 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 1af39abaf3..eff9ec9177 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -383,6 +383,10 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, goto err_start; } } + +if (virtio_queue_enabled(dev, i)) { +vhost_set_vring_ready(peer); +} } return 0; -- 2.21.1
[RFC v2 5/9] vhost-vdpa: implement vhost-vdpa backend
From: Tiwei Bie Currently we have 2 types of vhost backends in QEMU: vhost kernel and vhost-user. The above patch provides a generic device for vDPA purpose, this vDPA device exposes to user space a non-vendor-specific configuration interface for setting up a vhost HW accelerator, this patch set introduces a third vhost backend called vhost-vdpa based on the vDPA interface. Vhost-vdpa usage: qemu-system-x86_64 -cpu host -enable-kvm \ .. -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ Co-Authored-By: Lingshan zhu Signed-off-by: Cindy Lu --- hw/net/vhost_net.c| 39 ++- hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 5 + hw/virtio/vhost-vdpa.c| 447 ++ hw/virtio/vhost.c | 14 + include/hw/virtio/vhost-backend.h | 8 +- include/hw/virtio/vhost-vdpa.h| 25 ++ include/hw/virtio/vhost.h | 1 + 8 files changed, 538 insertions(+), 2 deletions(-) create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 63b2a85d6e..1af39abaf3 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -17,8 +17,10 @@ #include "net/net.h" #include "net/tap.h" #include "net/vhost-user.h" +#include "net/vhost-vdpa.h" #include "standard-headers/linux/vhost_types.h" +#include "linux-headers/linux/vhost.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "qemu/error-report.h" @@ -85,6 +87,29 @@ static const int user_feature_bits[] = { VHOST_INVALID_FEATURE_BIT }; +static const int vdpa_feature_bits[] = { +VIRTIO_F_NOTIFY_ON_EMPTY, +VIRTIO_RING_F_INDIRECT_DESC, +VIRTIO_RING_F_EVENT_IDX, +VIRTIO_F_ANY_LAYOUT, +VIRTIO_F_VERSION_1, +VIRTIO_NET_F_CSUM, +VIRTIO_NET_F_GUEST_CSUM, +VIRTIO_NET_F_GSO, +VIRTIO_NET_F_GUEST_TSO4, +VIRTIO_NET_F_GUEST_TSO6, +VIRTIO_NET_F_GUEST_ECN, +VIRTIO_NET_F_GUEST_UFO, +VIRTIO_NET_F_HOST_TSO4, +VIRTIO_NET_F_HOST_TSO6, +VIRTIO_NET_F_HOST_ECN, +VIRTIO_NET_F_HOST_UFO, +VIRTIO_NET_F_MRG_RXBUF, +VIRTIO_NET_F_MTU, +VIRTIO_F_IOMMU_PLATFORM, +VIRTIO_NET_F_GUEST_ANNOUNCE, +VHOST_INVALID_FEATURE_BIT +}; static const int *vhost_net_get_feature_bits(struct vhost_net *net) { const int *feature_bits = 0; @@ -96,6 +121,9 @@ static const int *vhost_net_get_feature_bits(struct vhost_net *net) case NET_CLIENT_DRIVER_VHOST_USER: feature_bits = user_feature_bits; break; +case NET_CLIENT_DRIVER_VHOST_VDPA: +feature_bits = vdpa_feature_bits; +break; default: error_report("Feature bits not defined for this type: %d", net->nc->info->type); @@ -110,7 +138,10 @@ uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) return vhost_get_features(>dev, vhost_net_get_feature_bits(net), features); } - +int vhost_net_get_device_id(struct vhost_net *net, uint32_t * device_id) +{ +return vhost_dev_get_device_id(>dev, device_id); +} void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { net->dev.acked_features = net->dev.backend_features; @@ -433,6 +464,12 @@ VHostNetState *get_vhost_net(NetClientState *nc) vhost_net = vhost_user_get_vhost_net(nc); assert(vhost_net); break; +#endif +#ifdef CONFIG_VHOST_NET_VDPA +case NET_CLIENT_DRIVER_VHOST_VDPA: +vhost_net = vhost_vdpa_get_vhost_net(nc); +assert(vhost_net); +break; #endif default: break; diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index e2f70fbb89..e7c5d4a862 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -5,6 +5,7 @@ obj-y += virtio.o obj-$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_VHOST_KERNEL)) += vhost.o vhost-backend.o common-obj-$(call lnot,$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_VHOST_KERNEL))) += vhost-stub.o obj-$(CONFIG_VHOST_USER) += vhost-user.o +obj-$(CONFIG_VHOST_VDPA) += vhost-vdpa.o common-obj-$(CONFIG_VIRTIO_RNG) += virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 48905383f8..069ddb423d 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -285,6 +285,11 @@ int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type) case VHOST_BACKEND_TYPE_USER: dev->vhost_ops = _ops; break; +#endif +#ifdef CONFIG_VHOST_VDPA +case VHOST_BACKEND_TYPE_VDPA: +dev->vhost_ops = _ops; +break; #endif default: error_report("Unknown vhost backend type"); diff --git a/hw/virtio/vhost-vd
[RFC v2 6/9] virtio-bus: introduce queue_enabled method
From: Jason Wang This patch introduces queue_enabled() method which allows the transport to implement its own way to report whether or not a queue is enabled. Signed-off-by: Jason Wang --- hw/virtio/virtio.c | 6 ++ include/hw/virtio/virtio-bus.h | 4 2 files changed, 10 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 04716b5f6c..09732a8836 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3169,6 +3169,12 @@ hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n) bool virtio_queue_enabled(VirtIODevice *vdev, int n) { +BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); +VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + +if (k->queue_enabled) +return k->queue_enabled(qbus->parent, n); + return virtio_queue_get_desc_addr(vdev, n) != 0; } diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index 38c9399cd4..0f6f215925 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -83,6 +83,10 @@ typedef struct VirtioBusClass { */ int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier, int n, bool assign); +/* + * Whether queue number n is enabled. + */ +bool (*queue_enabled)(DeviceState *d, int n); /* * Does the transport have variable vring alignment? * (ie can it ever call virtio_queue_set_align()?) -- 2.21.1
[RFC v2 9/9] vhost: introduce vhost_set_vring_ready method
From: Jason Wang Vhost-vdpa introduces VHOST_VDPA_SET_VRING_ENABLE which complies the semantic of queue_enable defined in virtio spec. This method can be used for preventing device from executing request for a specific virtqueue. This patch introduces the vhost_ops for this. Note that, we've already had vhost_set_vring_enable which has different semantic which allows to enable or disable a specific virtqueue for some kinds of vhost backends. E.g vhost-user use this to changes the number of active queue pairs. Signed-off-by: Jason Wang --- hw/net/vhost_net-stub.c | 4 hw/net/vhost_net.c | 11 ++- include/net/vhost_net.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index aac0e98228..43e93e1a9a 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -86,6 +86,10 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) return 0; } +int vhost_set_vring_ready(NetClientState *nc) +{ +return 0; +} int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) { return 0; diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index eff9ec9177..6911282a0a 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -375,7 +375,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, goto err_start; } -if (ncs[i].peer->vring_enable) { +if (peer->vring_enable) { /* restore vring enable state */ r = vhost_set_vring_enable(peer, peer->vring_enable); @@ -496,6 +496,15 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) return 0; } +int vhost_set_vring_ready(NetClientState *nc) +{ +VHostNetState *net = get_vhost_net(nc); +const VhostOps *vhost_ops = net->dev.vhost_ops; +if (vhost_ops && vhost_ops->vhost_set_vring_ready) { +return vhost_ops->vhost_set_vring_ready(>dev); +} +return 0; +} int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) { const VhostOps *vhost_ops = net->dev.vhost_ops; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index b47844bf29..247432a3b2 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -35,6 +35,7 @@ int vhost_net_notify_migration_done(VHostNetState *net, char* mac_addr); VHostNetState *get_vhost_net(NetClientState *nc); int vhost_set_vring_enable(NetClientState * nc, int enable); +int vhost_set_vring_ready(NetClientState *nc); uint64_t vhost_net_get_acked_features(VHostNetState *net); -- 2.21.1
[RFC v2 3/9] virtio_net: introduce vhost_set_state
Introduce a function to set the state to the vhost driver. vDPA need to sync the driver's state to NIC Signed-off-by: Cindy Lu --- hw/net/vhost_net.c| 9 + hw/net/virtio-net.c | 9 + include/hw/virtio/vhost-backend.h | 2 ++ include/net/vhost_net.h | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index d1d421e3d9..63b2a85d6e 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -465,3 +465,12 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) return vhost_ops->vhost_net_set_mtu(>dev, mtu); } +int vhost_set_state(NetClientState *nc, uint8_t state) +{ +struct vhost_net *net = get_vhost_net(nc); +struct vhost_dev *hdev = >dev; +if (hdev->vhost_ops->vhost_set_state) { +return hdev->vhost_ops->vhost_set_state(hdev, state); +} +return 0; +} diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index db3d7c38e6..1bddb4b4af 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -206,6 +206,9 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) VirtIODevice *vdev = VIRTIO_DEVICE(n); NetClientState *nc = qemu_get_queue(n->nic); int queues = n->multiqueue ? n->max_queues : 1; +NetClientState *peer = qemu_get_peer(nc, 0); +uint8_t status_set = vdev->status ; +uint8_t vhost_started_pre = n->vhost_started; if (!get_vhost_net(nc->peer)) { return; @@ -245,6 +248,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) return; } } +status_set = status_set | VIRTIO_CONFIG_S_DRIVER_OK; n->vhost_started = 1; r = vhost_net_start(vdev, n->nic->ncs, queues); @@ -252,11 +256,16 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) error_report("unable to start vhost net: %d: " "falling back on userspace virtio", -r); n->vhost_started = 0; +status_set = status_set & ~VIRTIO_CONFIG_S_DRIVER_OK; } } else { vhost_net_stop(vdev, n->nic->ncs, queues); +status_set = status_set & ~VIRTIO_CONFIG_S_DRIVER_OK; n->vhost_started = 0; } +if (vhost_started_pre != n->vhost_started) { +vhost_set_state(peer, status_set); +} } static int virtio_net_set_vnet_endian_one(VirtIODevice *vdev, diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 6f6670783f..f823055167 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -112,6 +112,7 @@ typedef int (*vhost_get_inflight_fd_op)(struct vhost_dev *dev, typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, struct vhost_inflight *inflight); +typedef int (*vhost_set_state_op)(struct vhost_dev *dev, uint8_t state); typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -152,6 +153,7 @@ typedef struct VhostOps { vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter; vhost_get_inflight_fd_op vhost_get_inflight_fd; vhost_set_inflight_fd_op vhost_set_inflight_fd; +vhost_set_state_op vhost_set_state; } VhostOps; extern const VhostOps user_ops; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 77e47398c4..6548a5a105 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -39,5 +39,5 @@ int vhost_set_vring_enable(NetClientState * nc, int enable); uint64_t vhost_net_get_acked_features(VHostNetState *net); int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); - +int vhost_set_state(NetClientState *nc, uint8_t state); #endif -- 2.21.1
[RFC v2 4/9] vhost-vdpa: introduce vhost-vdpa net client
From: Tiwei Bie This patch set introduces a new net client type: vhost-vdpa. vhost-vdpa net client will set up a vDPA device which is specified by a "vhostdev" parameter. Co-authored-by: Lingshan Zhu Signed-off-by: Cindy Lu --- configure| 21 include/net/vhost-vdpa.h | 19 include/net/vhost_net.h | 1 + net/Makefile.objs| 2 +- net/clients.h| 2 + net/net.c| 3 + net/vhost-vdpa.c | 227 +++ qapi/net.json| 22 +++- qemu-options.hx | 19 9 files changed, 313 insertions(+), 3 deletions(-) create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c diff --git a/configure b/configure index 6099be1d84..bdd732e3bb 100755 --- a/configure +++ b/configure @@ -1505,6 +1505,10 @@ for opt do ;; --enable-vhost-user) vhost_user="yes" ;; + --disable-vhost-vdpa) vhost_vdpa="no" + ;; + --enable-vhost-vdpa) vhost_vdpa="yes" + ;; --disable-vhost-kernel) vhost_kernel="no" ;; --enable-vhost-kernel) vhost_kernel="yes" @@ -1780,6 +1784,7 @@ disabled with --disable-FEATURE, default is enabled if available: vhost-cryptovhost-user-crypto backend support vhost-kernelvhost kernel backend support vhost-user vhost-user backend support + vhost-vdpa vhost-vdpa backend support spice spice rbd rados block device (rbd) libiscsiiscsi support @@ -2241,6 +2246,10 @@ test "$vhost_user" = "" && vhost_user=yes if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then error_exit "vhost-user isn't available on win32" fi +test "$vhost_vdpa" = "" && vhost_vdpa=yes +if test "$vhost_vdpa" = "yes" && test "$mingw32" = "yes"; then + error_exit "vhost-vdpa isn't available on win32" +fi test "$vhost_kernel" = "" && vhost_kernel=$linux if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then error_exit "vhost-kernel is only available on Linux" @@ -2269,6 +2278,11 @@ test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then error_exit "--enable-vhost-user-fs requires --enable-vhost-user" fi +#vhost-vdpa backends +test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa +if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then + error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa" +fi # OR the vhost-kernel and vhost-user values for simplicity if test "$vhost_net" = ""; then @@ -6543,6 +6557,7 @@ echo "vhost-scsi support $vhost_scsi" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" echo "vhost-user-fs support $vhost_user_fs" +echo "vhost-vdpa support $vhost_vdpa" echo "Trace backends$trace_backends" if have_backend "simple"; then echo "Trace output file $trace_file-" @@ -7031,6 +7046,9 @@ fi if test "$vhost_net_user" = "yes" ; then echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak fi +if test "$vhost_net_vdpa" = "yes" ; then + echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak +fi if test "$vhost_crypto" = "yes" ; then echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak fi @@ -7043,6 +7061,9 @@ fi if test "$vhost_user" = "yes" ; then echo "CONFIG_VHOST_USER=y" >> $config_host_mak fi +if test "$vhost_vdpa" = "yes" ; then + echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak +fi if test "$vhost_user_fs" = "yes" ; then echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak fi diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h new file mode 100644 index 00..6ce0d04f72 --- /dev/null +++ b/include/net/vhost-vdpa.h @@ -0,0 +1,19 @@ +/* + * vhost-vdpa.h + * + * Copyright(c) 2017-2018 Intel Corporation. + * Copyright(c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef VHOST_VDPA_H +#define VHOST_VDPA_H + +struct vhost_net; +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); + +#endif /* VHOST_VDPA_H */ diff --git a/include/net
[RFC v2 2/9] net: use the function qemu_get_peer
user the qemu_get_peer to replace the old process Signed-off-by: Cindy Lu --- hw/net/vhost_net.c | 14 +- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6b82803fa7..d1d421e3d9 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -306,7 +306,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev))); VirtioBusState *vbus = VIRTIO_BUS(qbus); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); +struct vhost_net *net; int r, e, i; +NetClientState *peer; if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); @@ -314,9 +316,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -struct vhost_net *net; -net = get_vhost_net(ncs[i].peer); +peer = qemu_get_peer(ncs, i); +net = get_vhost_net(peer); vhost_net_set_vq_index(net, i * 2); /* Suppress the masking guest notifiers on vhost user @@ -335,7 +337,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, } for (i = 0; i < total_queues; i++) { -r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs, i); +r = vhost_net_start_one(get_vhost_net(peer), dev); if (r < 0) { goto err_start; @@ -343,7 +346,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, if (ncs[i].peer->vring_enable) { /* restore vring enable state */ -r = vhost_set_vring_enable(ncs[i].peer, ncs[i].peer->vring_enable); +r = vhost_set_vring_enable(peer, peer->vring_enable); if (r < 0) { goto err_start; @@ -355,7 +358,8 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, err_start: while (--i >= 0) { -vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); +peer = qemu_get_peer(ncs , i); +vhost_net_stop_one(get_vhost_net(peer), dev); } e = k->set_guest_notifiers(qbus->parent, total_queues * 2, false); if (e < 0) { -- 2.21.1
[RFC v2 1/9] net: introduce qemu_get_peer
This is a small function that can get the peer from given NetClientState and queue_index Signed-off-by: Cindy Lu --- include/net/net.h | 1 + net/net.c | 6 ++ 2 files changed, 7 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index e175ba9677..0a74324ccd 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -175,6 +175,7 @@ void hmp_info_network(Monitor *mon, const QDict *qdict); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, bool vnet_hdr); +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); /* NIC info */ diff --git a/net/net.c b/net/net.c index 84aa6d8d00..b3192deaf1 100644 --- a/net/net.c +++ b/net/net.c @@ -324,6 +324,12 @@ void *qemu_get_nic_opaque(NetClientState *nc) return nic->opaque; } +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) +{ +assert(nc != NULL); +NetClientState *ncs = nc + queue_index; +return ncs->peer; +} static void qemu_cleanup_net_client(NetClientState *nc) { -- 2.21.1
[RFC v2 0/9] vDPA support in qemu
vDPA device is a device that uses a datapath which complies with the virtio specifications with vendor specific control path. vDPA devices can be both physically located on the hardware or emulated by software. This RFC introduce the vDPA support in qemu change from v1 separe the patch of introduce vhost_set_vring_ready method separe the patch of qemu_get_peer separe the patch of vhost_set_state intorduce the new macro specific for vDPA in configure intorduce the fuction to pass the fd from cmdline introduce the docmation in qemu-options.hx the other comments form last version Cindy Lu (3): net: introduce qemu_get_peer net: use the function qemu_get_peer virtio_net: introduce vhost_set_state Jason Wang (4): virtio-bus: introduce queue_enabled method virito-pci: implement queue_enabled method vhost_net: set vq ready during start if necessary vhost: introduce vhost_set_vring_ready method Tiwei Bie (2): vhost-vdpa: introduce vhost-vdpa net client vhost-vdpa: implement vhost-vdpa backend configure | 21 ++ hw/net/vhost_net-stub.c | 4 + hw/net/vhost_net.c| 77 - hw/net/virtio-net.c | 9 + hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-backend.c | 5 + hw/virtio/vhost-vdpa.c| 447 ++ hw/virtio/vhost.c | 14 + hw/virtio/virtio-pci.c| 13 + hw/virtio/virtio.c| 6 + include/hw/virtio/vhost-backend.h | 10 +- include/hw/virtio/vhost-vdpa.h| 25 ++ include/hw/virtio/vhost.h | 1 + include/hw/virtio/virtio-bus.h| 4 + include/net/net.h | 1 + include/net/vhost-vdpa.h | 19 ++ include/net/vhost_net.h | 4 +- net/Makefile.objs | 2 +- net/clients.h | 2 + net/net.c | 9 + net/vhost-vdpa.c | 227 +++ qapi/net.json | 22 +- qemu-options.hx | 19 ++ 23 files changed, 930 insertions(+), 12 deletions(-) create mode 100644 hw/virtio/vhost-vdpa.c create mode 100644 include/hw/virtio/vhost-vdpa.h create mode 100644 include/net/vhost-vdpa.h create mode 100644 net/vhost-vdpa.c -- 2.21.1
Re: [RFC v1 3/4] vhost-vdpa: implement vhost-vdpa backend
On Thu, May 7, 2020 at 11:30 PM Maxime Coquelin wrote: > > > > On 4/20/20 11:32 AM, Cindy Lu wrote: > > diff --git a/include/hw/virtio/vhost-backend.h > > b/include/hw/virtio/vhost-backend.h > > index 6f6670783f..d81bd9885f 100644 > > --- a/include/hw/virtio/vhost-backend.h > > +++ b/include/hw/virtio/vhost-backend.h > > @@ -17,7 +17,8 @@ typedef enum VhostBackendType { > > VHOST_BACKEND_TYPE_NONE = 0, > > VHOST_BACKEND_TYPE_KERNEL = 1, > > VHOST_BACKEND_TYPE_USER = 2, > > -VHOST_BACKEND_TYPE_MAX = 3, > > +VHOST_BACKEND_TYPE_VDPA = 3, > > +VHOST_BACKEND_TYPE_MAX = 4, > > } VhostBackendType; > > > > typedef enum VhostSetConfigType { > > @@ -112,6 +113,7 @@ typedef int (*vhost_get_inflight_fd_op)(struct > > vhost_dev *dev, > > typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev, > > struct vhost_inflight *inflight); > > > > +typedef int (*vhost_set_state_op)(struct vhost_dev *dev, int state); > > I think state should be of type uint8_t. > ok, I will change this to uint8_t
Re: [RFC v1 3/4] vhost-vdpa: implement vhost-vdpa backend
On Thu, May 7, 2020 at 11:13 PM Maxime Coquelin wrote: > > > > On 4/20/20 11:32 AM, Cindy Lu wrote: > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > > qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > > -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > > -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Author: Tiwei Bie > > Signed-off-by: Cindy Lu > > --- > > hw/net/vhost_net.c| 43 > > hw/net/virtio-net.c | 9 + > > hw/virtio/Makefile.objs | 2 +- > > hw/virtio/vhost-backend.c | 3 + > > hw/virtio/vhost-vdpa.c| 379 ++ > > hw/virtio/vhost.c | 5 + > > include/hw/virtio/vhost-backend.h | 6 +- > > include/hw/virtio/vhost-vdpa.h| 14 ++ > > 8 files changed, 459 insertions(+), 2 deletions(-) > > create mode 100644 hw/virtio/vhost-vdpa.c > > create mode 100644 include/hw/virtio/vhost-vdpa.h > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index 4096d64aaf..0d13fda2fc 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -17,8 +17,10 @@ > > #include "net/net.h" > > #include "net/tap.h" > > #include "net/vhost-user.h" > > +#include "net/vhost-vdpa.h" > > > > #include "standard-headers/linux/vhost_types.h" > > +#include "linux-headers/linux/vhost.h" > > #include "hw/virtio/virtio-net.h" > > #include "net/vhost_net.h" > > #include "qemu/error-report.h" > > @@ -85,6 +87,29 @@ static const int user_feature_bits[] = { > > VHOST_INVALID_FEATURE_BIT > > }; > > > > +static const int vdpa_feature_bits[] = { > > +VIRTIO_F_NOTIFY_ON_EMPTY, > > +VIRTIO_RING_F_INDIRECT_DESC, > > +VIRTIO_RING_F_EVENT_IDX, > > +VIRTIO_F_ANY_LAYOUT, > > +VIRTIO_F_VERSION_1, > > +VIRTIO_NET_F_CSUM, > > +VIRTIO_NET_F_GUEST_CSUM, > > +VIRTIO_NET_F_GSO, > > +VIRTIO_NET_F_GUEST_TSO4, > > +VIRTIO_NET_F_GUEST_TSO6, > > +VIRTIO_NET_F_GUEST_ECN, > > +VIRTIO_NET_F_GUEST_UFO, > > +VIRTIO_NET_F_HOST_TSO4, > > +VIRTIO_NET_F_HOST_TSO6, > > +VIRTIO_NET_F_HOST_ECN, > > +VIRTIO_NET_F_HOST_UFO, > > +VIRTIO_NET_F_MRG_RXBUF, > > +VIRTIO_NET_F_MTU, > > +VIRTIO_F_IOMMU_PLATFORM, > > +VIRTIO_NET_F_GUEST_ANNOUNCE, > > +VHOST_INVALID_FEATURE_BIT > > +}; > > static const int *vhost_net_get_feature_bits(struct vhost_net *net) > > { > > const int *feature_bits = 0; > > @@ -96,6 +121,9 @@ static const int *vhost_net_get_feature_bits(struct > > vhost_net *net) > > case NET_CLIENT_DRIVER_VHOST_USER: > > feature_bits = user_feature_bits; > > break; > > +case NET_CLIENT_DRIVER_VHOST_VDPA: > > +feature_bits = vdpa_feature_bits; > > +break; > > default: > > error_report("Feature bits not defined for this type: %d", > > net->nc->info->type); > > @@ -434,6 +462,10 @@ VHostNetState *get_vhost_net(NetClientState *nc) > > assert(vhost_net); > > break; > > #endif > > +case NET_CLIENT_DRIVER_VHOST_VDPA: > > +vhost_net = vhost_vdpa_get_vhost_net(nc); > > +assert(vhost_net); > > +break; > > default: > > break; > > } > > @@ -465,3 +497,14 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t > > mtu) > > > > return vhost_ops->vhost_net_set_mtu(>dev, mtu); > > } > > +int vhost_set_state(NetClientState *nc, int state) > > +{ > > +struct vhost_net *net = get_vhost_net(nc); > > +struct vhost_dev *hdev = >dev; > > +if (nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { > > Maybe checking the vhost_set_state callback is implemented is enough, > and it is not need to restrict that to Vhost-vDPA? Sure, Will remove this > > +if (hdev->vhost_ops->vhost_set_state) { > > +return hdev->vhost_ops->vhost_set_state(hdev, state); > > + } > > +} > > +return 0; > > +} >
Re: [RFC v1 3/4] vhost-vdpa: implement vhost-vdpa backend
On Tue, Apr 21, 2020 at 11:54 PM Laurent Vivier wrote: > > On 20/04/2020 11:32, Cindy Lu wrote: > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific configuration > > interface for setting up a vhost HW accelerator, this patch set introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > > qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > > -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > > -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > > Author: Tiwei Bie > > Use "git commit --author" to set that. Thanks, I will fix this > > Signed-off-by: Cindy Lu > > --- > > hw/net/vhost_net.c| 43 > > hw/net/virtio-net.c | 9 + > > hw/virtio/Makefile.objs | 2 +- > > hw/virtio/vhost-backend.c | 3 + > > hw/virtio/vhost-vdpa.c| 379 ++ > > hw/virtio/vhost.c | 5 + > > include/hw/virtio/vhost-backend.h | 6 +- > > include/hw/virtio/vhost-vdpa.h| 14 ++ > > 8 files changed, 459 insertions(+), 2 deletions(-) > > create mode 100644 hw/virtio/vhost-vdpa.c > > create mode 100644 include/hw/virtio/vhost-vdpa.h > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index 4096d64aaf..0d13fda2fc 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > ... > > @@ -434,6 +462,10 @@ VHostNetState *get_vhost_net(NetClientState *nc) > > assert(vhost_net); > > break; > > #endif > > +case NET_CLIENT_DRIVER_VHOST_VDPA: > > +vhost_net = vhost_vdpa_get_vhost_net(nc); > > +assert(vhost_net); > > +break; > > This should be inside a "#ifdef". > Thanks Laurent, I will add a new macro for vDPA > Thanks, > Laurent >
Re: [RFC v1 2/4] vhost-vdpa: introduce vhost-vdpa net client
On Tue, Apr 21, 2020 at 11:47 PM Laurent Vivier wrote: > > On 20/04/2020 11:32, Cindy Lu wrote: > > This patch set introduces a new net client type: vhost-vdpa. > > vhost-vdpa net client will set up a vDPA device which is svhostdevpecified > > by a "vhostdev" parameter. > > > > Author: Tiwei Bie > > Signed-off-by: Cindy Lu > > --- > > include/net/vhost-vdpa.h | 18 > > include/net/vhost_net.h | 1 + > > net/Makefile.objs| 2 +- > > net/clients.h| 2 + > > net/net.c| 1 + > > net/vhost-vdpa.c | 211 +++ > > qapi/net.json| 21 +++- > > 7 files changed, 253 insertions(+), 3 deletions(-) > > create mode 100644 include/net/vhost-vdpa.h > > create mode 100644 net/vhost-vdpa.c > > > > diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h > > new file mode 100644 > > index 00..9ddd538dad > > --- /dev/null > > +++ b/include/net/vhost-vdpa.h > > @@ -0,0 +1,18 @@ > > +/* > > + * vhost-vdpa.h > > + * > > + * Copyright(c) 2017 Intel Corporation. All rights reserved. > > + * > > + * This work is licensed under the terms of the GNU GPL, version 2 or > > later. > > + * See the COPYING file in the top-level directory. > > + * > > + */ > > + > > +#ifndef VHOST_VDPA_H > > +#define VHOST_VDPA_H > > + > > +struct vhost_net; > > +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); > > +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); > > + > > +#endif /* VHOST_VDPA_H */ > > diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h > > index 77e47398c4..6f3a624cf7 100644 > > --- a/include/net/vhost_net.h > > +++ b/include/net/vhost_net.h > > @@ -39,5 +39,6 @@ int vhost_set_vring_enable(NetClientState * nc, int > > enable); > > uint64_t vhost_net_get_acked_features(VHostNetState *net); > > > > int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); > > +int vhost_set_state(NetClientState *nc, int state); > > > > #endif > > diff --git a/net/Makefile.objs b/net/Makefile.objs > > index c5d076d19c..da459cfc19 100644 > > --- a/net/Makefile.objs > > +++ b/net/Makefile.objs > > @@ -26,7 +26,7 @@ tap-obj-$(CONFIG_SOLARIS) = tap-solaris.o > > tap-obj-y ?= tap-stub.o > > common-obj-$(CONFIG_POSIX) += tap.o $(tap-obj-y) > > common-obj-$(CONFIG_WIN32) += tap-win32.o > > - > > +common-obj-$(CONFIG_VHOST_KERNEL) += vhost-vdpa.o > > should it be CONFIG_VHOST_NET_USER as you use net_init_vhost_vdpa() > below inside a "#ifdef CONFIG_VHOST_NET_USER"? > > Why don't you define a CONFIG_VHOST_VDPA? > Thanks Laurent for point it out, There is no dependence between CONFIG_VHOST_NET_USER and vDPA, So I will implement a new macro specific for vDPA > > vde.o-libs = $(VDE_LIBS) > > > > common-obj-$(CONFIG_CAN_BUS) += can/ > > diff --git a/net/clients.h b/net/clients.h > > index a6ef267e19..92f9b59aed 100644 > > --- a/net/clients.h > > +++ b/net/clients.h > > @@ -61,4 +61,6 @@ int net_init_netmap(const Netdev *netdev, const char > > *name, > > int net_init_vhost_user(const Netdev *netdev, const char *name, > > NetClientState *peer, Error **errp); > > > > +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, > > +NetClientState *peer, Error **errp); > > #endif /* QEMU_NET_CLIENTS_H */ > > diff --git a/net/net.c b/net/net.c > > index ac5080dda1..2beb95388a 100644 > > --- a/net/net.c > > +++ b/net/net.c > > @@ -964,6 +964,7 @@ static int (* const > > net_client_init_fun[NET_CLIENT_DRIVER__MAX])( > > [NET_CLIENT_DRIVER_HUBPORT] = net_init_hubport, > > #ifdef CONFIG_VHOST_NET_USER ^ >here > > > [NET_CLIENT_DRIVER_VHOST_USER] = net_init_vhost_user, > > +[NET_CLIENT_DRIVER_VHOST_VDPA] = net_init_vhost_vdpa, > > #endif > > #ifdef CONFIG_L2TPV3 > > [NET_CLIENT_DRIVER_L2TPV3]= net_init_l2tpv3, > > diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c > > new file mode 100644 > > index 00..5daeba0b76 > > --- /dev/null > > +++ b/net/vhost-vdpa.c > ... > > +static int net_vhost_check_net(void *opaque, QemuOpts *opts, Error **errp) > > +{ > > +const char *name = opaque; > > +const char *driver, *netdev; > > + > > +driver = qemu_opt_get(opts, "driver"); > > +netdev = qemu_opt_get(opts, "netdev"); > > + > > +if (!driver || !netdev) { > > +return 0; > > +} > > + > > +if (strcmp(netdev, name) == 0 && > > +!g_str_has_prefix(driver, "virtio-net-")) { > > +error_setg(errp, "vhost-vdpa requires frontend driver > > virtio-net-*"); > > +return -1; > > +} > > > > So perhaps you can build the file only if CONFIG_VIRTIO_NET is set? > > Thanks, > Laurent > Thanks, There will be a new macro specific for vDPA
Re: [RFC v1 0/4] vDPA support in qemu
Thanks Jason, I will fix these problems and send new version soon On Tue, Apr 21, 2020 at 12:05 PM Jason Wang wrote: > > On 2020/4/20 下午5:32, Cindy Lu wrote: > > vDPA device is a device that uses a datapath which complies with the > > virtio specifications with vendor specific control path. vDPA devices > > can be both physically located on the hardware or emulated by software. > > This RFC introduce the vDPA support in qemu > > > And please mention the TODO list. E.g: > > 1) vIOMMU support > 2) software assisted live migration > > Thanks > >
Re: [RFC v1 2/4] vhost-vdpa: introduce vhost-vdpa net client
On Tue, Apr 21, 2020 at 11:40 AM Jason Wang wrote: > > On 2020/4/20 下午5:32, Cindy Lu wrote: > > This patch set introduces a new net client type: vhost-vdpa. > > vhost-vdpa net client will set up a vDPA device which is > svhostdevpecified > > > typo. > > Will fix this > > > by a "vhostdev" parameter. > > > > Author: Tiwei Bie > > > Please keep the sobs from the original patch. > > > Will fix this > > Signed-off-by: Cindy Lu > > --- > > include/net/vhost-vdpa.h | 18 > > include/net/vhost_net.h | 1 + > > net/Makefile.objs| 2 +- > > net/clients.h| 2 + > > net/net.c| 1 + > > net/vhost-vdpa.c | 211 +++ > > qapi/net.json| 21 +++- > > 7 files changed, 253 insertions(+), 3 deletions(-) > > create mode 100644 include/net/vhost-vdpa.h > > create mode 100644 net/vhost-vdpa.c > > > I think this patch should come after patch 3. > > And it's better to make this as a module like vhost-user. > > Got it, Will fix this > > > > > diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h > > new file mode 100644 > > index 00..9ddd538dad > > --- /dev/null > > +++ b/include/net/vhost-vdpa.h > > @@ -0,0 +1,18 @@ > > +/* > > + * vhost-vdpa.h > > + * > > + * Copyright(c) 2017 Intel Corporation. All rights reserved. > > > 2020 and please add Red Hat here as well. > > > Will fix this > > + * > > + * This work is licensed under the terms of the GNU GPL, version 2 or > later. > > + * See the COPYING file in the top-level directory. > > + * > > + */ > > + > > +#ifndef VHOST_VDPA_H > > +#define VHOST_VDPA_H > > + > > +struct vhost_net; > > +struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); > > +uint64_t vhost_vdpa_get_acked_features(NetClientState *nc); > > + > > +#endif /* VHOST_VDPA_H */ > > diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h > > index 77e47398c4..6f3a624cf7 100644 > > --- a/include/net/vhost_net.h > > +++ b/include/net/vhost_net.h > > @@ -39,5 +39,6 @@ int vhost_set_vring_enable(NetClientState * nc, int > enable); > > uint64_t vhost_net_get_acked_features(VHostNetState *net); > > > > int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); > > +int vhost_set_state(NetClientState *nc, int state); > > > This function is not used in this patch. > > Will fix this > > > > > #endif > > diff --git a/net/Makefile.objs b/net/Makefile.objs > > index c5d076d19c..da459cfc19 100644 > > --- a/net/Makefile.objs > > +++ b/net/Makefile.objs > > @@ -26,7 +26,7 @@ tap-obj-$(CONFIG_SOLARIS) = tap-solaris.o > > tap-obj-y ?= tap-stub.o > > common-obj-$(CONFIG_POSIX) += tap.o $(tap-obj-y) > > common-obj-$(CONFIG_WIN32) += tap-win32.o > > - > > +common-obj-$(CONFIG_VHOST_KERNEL) += vhost-vdpa.o > > vde.o-libs = $(VDE_LIBS) > > > > common-obj-$(CONFIG_CAN_BUS) += can/ > > diff --git a/net/clients.h b/net/clients.h > > index a6ef267e19..92f9b59aed 100644 > > --- a/net/clients.h > > +++ b/net/clients.h > > @@ -61,4 +61,6 @@ int net_init_netmap(const Netdev *netdev, const char > *name, > > int net_init_vhost_user(const Netdev *netdev, const char *name, > > NetClientState *peer, Error **errp); > > > > +int net_init_vhost_vdpa(const Netdev *netdev, const char *name, > > +NetClientState *peer, Error **errp); > > #endif /* QEMU_NET_CLIENTS_H */ > > diff --git a/net/net.c b/net/net.c > > index ac5080dda1..2beb95388a 100644 > > --- a/net/net.c > > +++ b/net/net.c > > @@ -964,6 +964,7 @@ static int (* const > net_client_init_fun[NET_CLIENT_DRIVER__MAX])( > > [NET_CLIENT_DRIVER_HUBPORT] = net_init_hubport, > > #ifdef CONFIG_VHOST_NET_USER > > [NET_CLIENT_DRIVER_VHOST_USER] = net_init_vhost_user, > > +[NET_CLIENT_DRIVER_VHOST_VDPA] = net_init_vhost_vdpa, > > #endif > > #ifdef CONFIG_L2TPV3 > > [NET_CLIENT_DRIVER_L2TPV3]= net_init_l2tpv3, > > diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c > > new file mode 100644 > > index 00..5daeba0b76 > > --- /dev/null > > +++ b/net/vhost-vdpa.c > > @@ -0,0 +1,211 @@ > > +/* > > + * vhost-vdpa.c > > + * > > + * Copyright(c) 2017-2018 Intel Corporation. All rights reserved. > > + * Copy
Re: [RFC v1 3/4] vhost-vdpa: implement vhost-vdpa backend
On Tue, Apr 21, 2020 at 11:57 AM Jason Wang wrote: > > On 2020/4/20 下午5:32, Cindy Lu wrote: > > Currently we have 2 types of vhost backends in QEMU: vhost kernel and > > vhost-user. The above patch provides a generic device for vDPA purpose, > > this vDPA device exposes to user space a non-vendor-specific > configuration > > interface for setting up a vhost HW accelerator, this patch set > introduces > > a third vhost backend called vhost-vdpa based on the vDPA interface. > > > > Vhost-vdpa usage: > > > >qemu-system-x86_64 -cpu host -enable-kvm \ > > .. > >-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \ > >-device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \ > > > Actually, this part should belongs to patch 2. > > And we probably need to add a comment that vIOMMU is not supported right > now. > > > Will fix this problem > > > > Author: Tiwei Bie > > Signed-off-by: Cindy Lu > > --- > > hw/net/vhost_net.c| 43 > > hw/net/virtio-net.c | 9 + > > hw/virtio/Makefile.objs | 2 +- > > hw/virtio/vhost-backend.c | 3 + > > hw/virtio/vhost-vdpa.c| 379 ++ > > hw/virtio/vhost.c | 5 + > > include/hw/virtio/vhost-backend.h | 6 +- > > include/hw/virtio/vhost-vdpa.h| 14 ++ > > 8 files changed, 459 insertions(+), 2 deletions(-) > > create mode 100644 hw/virtio/vhost-vdpa.c > > create mode 100644 include/hw/virtio/vhost-vdpa.h > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index 4096d64aaf..0d13fda2fc 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -17,8 +17,10 @@ > > #include "net/net.h" > > #include "net/tap.h" > > #include "net/vhost-user.h" > > +#include "net/vhost-vdpa.h" > > > > #include "standard-headers/linux/vhost_types.h" > > +#include "linux-headers/linux/vhost.h" > > #include "hw/virtio/virtio-net.h" > > #include "net/vhost_net.h" > > #include "qemu/error-report.h" > > @@ -85,6 +87,29 @@ static const int user_feature_bits[] = { > > VHOST_INVALID_FEATURE_BIT > > }; > > > > +static const int vdpa_feature_bits[] = { > > +VIRTIO_F_NOTIFY_ON_EMPTY, > > +VIRTIO_RING_F_INDIRECT_DESC, > > +VIRTIO_RING_F_EVENT_IDX, > > +VIRTIO_F_ANY_LAYOUT, > > +VIRTIO_F_VERSION_1, > > +VIRTIO_NET_F_CSUM, > > +VIRTIO_NET_F_GUEST_CSUM, > > +VIRTIO_NET_F_GSO, > > +VIRTIO_NET_F_GUEST_TSO4, > > +VIRTIO_NET_F_GUEST_TSO6, > > +VIRTIO_NET_F_GUEST_ECN, > > +VIRTIO_NET_F_GUEST_UFO, > > +VIRTIO_NET_F_HOST_TSO4, > > +VIRTIO_NET_F_HOST_TSO6, > > +VIRTIO_NET_F_HOST_ECN, > > +VIRTIO_NET_F_HOST_UFO, > > +VIRTIO_NET_F_MRG_RXBUF, > > +VIRTIO_NET_F_MTU, > > +VIRTIO_F_IOMMU_PLATFORM, > > +VIRTIO_NET_F_GUEST_ANNOUNCE, > > +VHOST_INVALID_FEATURE_BIT > > +}; > > static const int *vhost_net_get_feature_bits(struct vhost_net *net) > > { > > const int *feature_bits = 0; > > @@ -96,6 +121,9 @@ static const int *vhost_net_get_feature_bits(struct > vhost_net *net) > > case NET_CLIENT_DRIVER_VHOST_USER: > > feature_bits = user_feature_bits; > > break; > > +case NET_CLIENT_DRIVER_VHOST_VDPA: > > +feature_bits = vdpa_feature_bits; > > +break; > > default: > > error_report("Feature bits not defined for this type: %d", > > net->nc->info->type); > > @@ -434,6 +462,10 @@ VHostNetState *get_vhost_net(NetClientState *nc) > > assert(vhost_net); > > break; > > #endif > > +case NET_CLIENT_DRIVER_VHOST_VDPA: > > +vhost_net = vhost_vdpa_get_vhost_net(nc); > > +assert(vhost_net); > > +break; > > default: > > break; > > } > > @@ -465,3 +497,14 @@ int vhost_net_set_mtu(struct vhost_net *net, > uint16_t mtu) > > > > return vhost_ops->vhost_net_set_mtu(>dev, mtu); > > } > > +int vhost_set_state(NetClientState *nc, int state) > > +{ > > +struct vhost_net *net = get_vhost_net(nc); > > +struct vhost_dev *hdev = >dev; > > +if (nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA)
Re: [RFC v1 4/4] vhost: introduce vhost_set_vring_ready method
On Tue, Apr 21, 2020 at 12:00 PM Jason Wang wrote: > > On 2020/4/20 下午5:32, Cindy Lu wrote: > > From: Jason Wang > > > > Vhost-vdpa introduces VHOST_VDPA_SET_VRING_ENABLE which complies the > > semantic of queue_enable defined in virtio spec. This method can be > > used for preventing device from executing request for a specific > > virtqueue. This patch introduces the vhost_ops for this. > > > > Note that, we've already had vhost_set_vring_enable which has different > > semantic which allows to enable or disable a specific virtqueue for > > some kinds of vhost backends. E.g vhost-user use this to changes the > > number of active queue pairs. > > > This patch seems to mix fours things, please use dedicated patches for: > > 1) introduce queue_enabled method for virtio-bus > 2) implement queue_enabled for virtio-pci > 3) introduce vhost_set_vring_ready method for vhost ops > 4) implement vhost_set_vring_ready for vdpa (need to be squashed into > the patch of vhost-vdpa). > > Thanks > > Sure, Will fix this > > > > > Author: Jason Wang > > Signed-off-by: Jason Wang > > --- > > hw/net/vhost_net-stub.c | 5 + > > hw/net/vhost_net.c| 16 > > hw/virtio/vhost-vdpa.c| 9 +++-- > > hw/virtio/virtio-pci.c| 13 + > > hw/virtio/virtio.c| 6 ++ > > include/hw/virtio/vhost-backend.h | 2 ++ > > include/hw/virtio/virtio-bus.h| 4 > > include/net/vhost_net.h | 1 + > > 8 files changed, 50 insertions(+), 6 deletions(-) > > > > diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c > > index aac0e98228..f5ef1e3055 100644 > > --- a/hw/net/vhost_net-stub.c > > +++ b/hw/net/vhost_net-stub.c > > @@ -86,6 +86,11 @@ int vhost_set_vring_enable(NetClientState *nc, int > enable) > > return 0; > > } > > > > +int vhost_set_vring_ready(NetClientState *nc) > > +{ > > +return 0; > > +} > > + > > int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) > > { > > return 0; > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index 0d13fda2fc..463e333531 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -380,6 +380,10 @@ int vhost_net_start(VirtIODevice *dev, > NetClientState *ncs, > > goto err_start; > > } > > } > > + > > +if (virtio_queue_enabled(dev, i)) { > > +vhost_set_vring_ready(peer); > > +} > > } > > > > return 0; > > @@ -487,6 +491,18 @@ int vhost_set_vring_enable(NetClientState *nc, int > enable) > > return 0; > > } > > > > +int vhost_set_vring_ready(NetClientState *nc) > > +{ > > +VHostNetState *net = get_vhost_net(nc); > > +const VhostOps *vhost_ops = net->dev.vhost_ops; > > + > > +if (vhost_ops && vhost_ops->vhost_set_vring_ready) { > > +return vhost_ops->vhost_set_vring_ready(>dev); > > +} > > + > > +return 0; > > +} > > + > > int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) > > { > > const VhostOps *vhost_ops = net->dev.vhost_ops; > > diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c > > index 213b327600..49224ef9f8 100644 > > --- a/hw/virtio/vhost-vdpa.c > > +++ b/hw/virtio/vhost-vdpa.c > > @@ -325,18 +325,15 @@ static int vhost_vdpa_get_vq_index(struct > vhost_dev *dev, int idx) > > return idx - dev->vq_index; > > } > > > > -static int vhost_vdpa_set_vring_enable(struct vhost_dev *dev, int > enable) > > +static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev) > > { > > int i; > > > > for (i = 0; i < dev->nvqs; ++i) { > > struct vhost_vring_state state = { > > .index = dev->vq_index + i, > > -.num = enable, > > +.num = 1, > > }; > > - > > -state.num = 1; > > - > > vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, ); > > } > > > > @@ -368,7 +365,7 @@ const VhostOps vdpa_ops = { > > .vhost_set_owner = vhost_vdpa_set_owner, > > .vhost_reset_device = vhost_vdpa_reset_device, > > .vhost_get_vq_index = vhost_vdpa_get_vq_index, > > -.vhost_set_vring_enable = vhost_vdpa_set_vring_enable, > > +
Re: [RFC v1 1/4] net: Introduce qemu_get_peer
On Tue, Apr 21, 2020 at 11:23 AM Jason Wang wrote: > > On 2020/4/20 下午5:32, Cindy Lu wrote: > > This is a small function that can get the peer from given > NetClientState and queue_index > > > Unnecessary space between 'function' and 'that'. > > > > > > Signed-off-by: Cindy Lu > > > Please split this patch into two parts: > > 1) introduce the function > 2) the actual user for this fucntion > > > sure, I will fix this problem. > > --- > > hw/net/vhost_net.c | 16 ++-- > > include/net/net.h | 1 + > > net/net.c | 6 ++ > > 3 files changed, 17 insertions(+), 6 deletions(-) > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > index 6b82803fa7..4096d64aaf 100644 > > --- a/hw/net/vhost_net.c > > +++ b/hw/net/vhost_net.c > > @@ -306,7 +306,9 @@ int vhost_net_start(VirtIODevice *dev, > NetClientState *ncs, > > BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev))); > > VirtioBusState *vbus = VIRTIO_BUS(qbus); > > VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); > > +struct vhost_net *net; > > int r, e, i; > > +NetClientState *peer; > > > > if (!k->set_guest_notifiers) { > > error_report("binding does not support guest notifiers"); > > @@ -314,9 +316,9 @@ int vhost_net_start(VirtIODevice *dev, > NetClientState *ncs, > > } > > > > for (i = 0; i < total_queues; i++) { > > -struct vhost_net *net; > > > > -net = get_vhost_net(ncs[i].peer); > > +peer = qemu_get_peer(ncs, i); > > +net = get_vhost_net(peer); > > vhost_net_set_vq_index(net, i * 2); > > > > /* Suppress the masking guest notifiers on vhost user > > @@ -335,15 +337,16 @@ int vhost_net_start(VirtIODevice *dev, > NetClientState *ncs, > > } > > > > for (i = 0; i < total_queues; i++) { > > -r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev); > > +peer = qemu_get_peer(ncs, i); > > +r = vhost_net_start_one(get_vhost_net(peer), dev); > > > > if (r < 0) { > > goto err_start; > > } > > > > -if (ncs[i].peer->vring_enable) { > > +if (peer->vring_enable) { > > /* restore vring enable state */ > > -r = vhost_set_vring_enable(ncs[i].peer, > ncs[i].peer->vring_enable); > > +r = vhost_set_vring_enable(peer, peer->vring_enable); > > > > if (r < 0) { > > goto err_start; > > @@ -355,7 +358,8 @@ int vhost_net_start(VirtIODevice *dev, > NetClientState *ncs, > > > > err_start: > > while (--i >= 0) { > > -vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev); > > +peer = qemu_get_peer(ncs , i); > > +vhost_net_stop_one(get_vhost_net(peer), dev); > > } > > e = k->set_guest_notifiers(qbus->parent, total_queues * 2, false); > > if (e < 0) { > > diff --git a/include/net/net.h b/include/net/net.h > > index e175ba9677..0a74324ccd 100644 > > --- a/include/net/net.h > > +++ b/include/net/net.h > > @@ -175,6 +175,7 @@ void hmp_info_network(Monitor *mon, const QDict > *qdict); > > void net_socket_rs_init(SocketReadState *rs, > > SocketReadStateFinalize *finalize, > > bool vnet_hdr); > > +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); > > > > /* NIC info */ > > > > diff --git a/net/net.c b/net/net.c > > index 84aa6d8d00..ac5080dda1 100644 > > --- a/net/net.c > > +++ b/net/net.c > > @@ -324,6 +324,12 @@ void *qemu_get_nic_opaque(NetClientState *nc) > > > > return nic->opaque; > > } > > +NetClientState *qemu_get_peer(NetClientState *nc, int queue_index) > > +{ > > +NetClientState *ncs = nc + queue_index; > > > Unnecessary space around '='. > > Thanks > > > Will correct this > +assert(ncs != NULL); > > +return ncs->peer; > > +} > > > > static void qemu_cleanup_net_client(NetClientState *nc) > > { > >