Skip to content

Commit 108a648

Browse files
lulu-github-namemstsirkin
authored andcommitted
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 <[email protected]> Signed-off-by: Tiwei Bie <[email protected]> Signed-off-by: Cindy Lu <[email protected]> Signed-off-by: Jason Wang <[email protected]> Message-Id: <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent 38140cc commit 108a648

File tree

12 files changed

+600
-7
lines changed

12 files changed

+600
-7
lines changed

configure

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,10 @@ for opt do
15751575
;;
15761576
--enable-vhost-user) vhost_user="yes"
15771577
;;
1578+
--disable-vhost-vdpa) vhost_vdpa="no"
1579+
;;
1580+
--enable-vhost-vdpa) vhost_vdpa="yes"
1581+
;;
15781582
--disable-vhost-kernel) vhost_kernel="no"
15791583
;;
15801584
--enable-vhost-kernel) vhost_kernel="yes"
@@ -1883,6 +1887,7 @@ disabled with --disable-FEATURE, default is enabled if available:
18831887
vhost-crypto vhost-user-crypto backend support
18841888
vhost-kernel vhost kernel backend support
18851889
vhost-user vhost-user backend support
1890+
vhost-vdpa vhost-vdpa kernel backend support
18861891
spice spice
18871892
rbd rados block device (rbd)
18881893
libiscsi iscsi support
@@ -2394,6 +2399,10 @@ test "$vhost_user" = "" && vhost_user=yes
23942399
if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then
23952400
error_exit "vhost-user isn't available on win32"
23962401
fi
2402+
test "$vhost_vdpa" = "" && vhost_vdpa=$linux
2403+
if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
2404+
error_exit "vhost-vdpa is only available on Linux"
2405+
fi
23972406
test "$vhost_kernel" = "" && vhost_kernel=$linux
23982407
if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
23992408
error_exit "vhost-kernel is only available on Linux"
@@ -2422,6 +2431,11 @@ test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
24222431
if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
24232432
error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
24242433
fi
2434+
#vhost-vdpa backends
2435+
test "$vhost_net_vdpa" = "" && vhost_net_vdpa=$vhost_vdpa
2436+
if test "$vhost_net_vdpa" = "yes" && test "$vhost_vdpa" = "no"; then
2437+
error_exit "--enable-vhost-net-vdpa requires --enable-vhost-vdpa"
2438+
fi
24252439

24262440
# OR the vhost-kernel and vhost-user values for simplicity
24272441
if test "$vhost_net" = ""; then
@@ -6936,6 +6950,7 @@ echo "vhost-scsi support $vhost_scsi"
69366950
echo "vhost-vsock support $vhost_vsock"
69376951
echo "vhost-user support $vhost_user"
69386952
echo "vhost-user-fs support $vhost_user_fs"
6953+
echo "vhost-vdpa support $vhost_vdpa"
69396954
echo "Trace backends $trace_backends"
69406955
if have_backend "simple"; then
69416956
echo "Trace output file $trace_file-<pid>"
@@ -7437,6 +7452,9 @@ fi
74377452
if test "$vhost_net_user" = "yes" ; then
74387453
echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
74397454
fi
7455+
if test "$vhost_net_vdpa" = "yes" ; then
7456+
echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
7457+
fi
74407458
if test "$vhost_crypto" = "yes" ; then
74417459
echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
74427460
fi
@@ -7452,6 +7470,9 @@ fi
74527470
if test "$vhost_user" = "yes" ; then
74537471
echo "CONFIG_VHOST_USER=y" >> $config_host_mak
74547472
fi
7473+
if test "$vhost_vdpa" = "yes" ; then
7474+
echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
7475+
fi
74557476
if test "$vhost_user_fs" = "yes" ; then
74567477
echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
74577478
fi

docs/interop/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ Contents:
2020
qemu-ga
2121
vhost-user
2222
vhost-user-gpu
23+
vhost-vdpa

docs/interop/vhost-vdpa.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=====================
2+
Vhost-vdpa Protocol
3+
=====================
4+
5+
Introduction
6+
=============
7+
vDPA(Virtual data path acceleration) device is a device that uses
8+
a datapath which complies with the virtio specifications with vendor
9+
specific control path. vDPA devices can be both physically located on
10+
the hardware or emulated by software.
11+
12+
This document describes the vDPA support in qemu
13+
14+
Here is the kernel commit here
15+
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4c8cf31885f69e86be0b5b9e6677a26797365e1d
16+
17+
TODO : More information will add later

hw/net/vhost_net.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "net/net.h"
1818
#include "net/tap.h"
1919
#include "net/vhost-user.h"
20+
#include "net/vhost-vdpa.h"
2021

2122
#include "standard-headers/linux/vhost_types.h"
2223
#include "hw/virtio/virtio-net.h"
@@ -33,12 +34,6 @@
3334
#include "hw/virtio/vhost.h"
3435
#include "hw/virtio/virtio-bus.h"
3536

36-
struct vhost_net {
37-
struct vhost_dev dev;
38-
struct vhost_virtqueue vqs[2];
39-
int backend;
40-
NetClientState *nc;
41-
};
4237

4338
/* Features supported by host kernel. */
4439
static const int kernel_feature_bits[] = {
@@ -96,6 +91,11 @@ static const int *vhost_net_get_feature_bits(struct vhost_net *net)
9691
case NET_CLIENT_DRIVER_VHOST_USER:
9792
feature_bits = user_feature_bits;
9893
break;
94+
#ifdef CONFIG_VHOST_NET_VDPA
95+
case NET_CLIENT_DRIVER_VHOST_VDPA:
96+
feature_bits = vdpa_feature_bits;
97+
break;
98+
#endif
9999
default:
100100
error_report("Feature bits not defined for this type: %d",
101101
net->nc->info->type);
@@ -443,6 +443,12 @@ VHostNetState *get_vhost_net(NetClientState *nc)
443443
vhost_net = vhost_user_get_vhost_net(nc);
444444
assert(vhost_net);
445445
break;
446+
#endif
447+
#ifdef CONFIG_VHOST_NET_VDPA
448+
case NET_CLIENT_DRIVER_VHOST_VDPA:
449+
vhost_net = vhost_vdpa_get_vhost_net(nc);
450+
assert(vhost_net);
451+
break;
446452
#endif
447453
default:
448454
break;

hw/net/virtio-net.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "monitor/qdev.h"
4444
#include "hw/pci/pci.h"
4545
#include "net_rx_pkt.h"
46+
#include "hw/virtio/vhost.h"
4647

4748
#define VIRTIO_NET_VM_VERSION 11
4849

@@ -125,6 +126,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
125126
VirtIONet *n = VIRTIO_NET(vdev);
126127
struct virtio_net_config netcfg;
127128

129+
int ret = 0;
130+
memset(&netcfg, 0 , sizeof(struct virtio_net_config));
128131
virtio_stw_p(vdev, &netcfg.status, n->status);
129132
virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues);
130133
virtio_stw_p(vdev, &netcfg.mtu, n->net_conf.mtu);
@@ -138,6 +141,15 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
138141
virtio_stl_p(vdev, &netcfg.supported_hash_types,
139142
VIRTIO_NET_RSS_SUPPORTED_HASHES);
140143
memcpy(config, &netcfg, n->config_size);
144+
145+
NetClientState *nc = qemu_get_queue(n->nic);
146+
if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
147+
ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg,
148+
n->config_size);
149+
if (ret != -1) {
150+
memcpy(config, &netcfg, n->config_size);
151+
}
152+
}
141153
}
142154

143155
static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
@@ -153,6 +165,13 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
153165
memcpy(n->mac, netcfg.mac, ETH_ALEN);
154166
qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
155167
}
168+
169+
NetClientState *nc = qemu_get_queue(n->nic);
170+
if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
171+
vhost_net_set_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg,
172+
0, n->config_size,
173+
VHOST_SET_CONFIG_TYPE_MASTER);
174+
}
156175
}
157176

158177
static bool virtio_net_started(VirtIONet *n, uint8_t status)

hw/virtio/Makefile.objs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ obj-y += virtio.o
55
obj-$(CONFIG_VHOST) += vhost.o vhost-backend.o
66
common-obj-$(call lnot,$(CONFIG_VHOST)) += vhost-stub.o
77
obj-$(CONFIG_VHOST_USER) += vhost-user.o
8+
obj-$(CONFIG_VHOST_VDPA) += vhost-vdpa.o
89

910
common-obj-$(CONFIG_VIRTIO_RNG) += virtio-rng.o
1011
common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o

hw/virtio/vhost-backend.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "qemu/main-loop.h"
1616
#include "standard-headers/linux/vhost_types.h"
1717

18+
#include "hw/virtio/vhost-vdpa.h"
1819
#ifdef CONFIG_VHOST_KERNEL
1920
#include <linux/vhost.h>
2021
#include <sys/ioctl.h>
@@ -285,6 +286,11 @@ int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type)
285286
case VHOST_BACKEND_TYPE_USER:
286287
dev->vhost_ops = &user_ops;
287288
break;
289+
#endif
290+
#ifdef CONFIG_VHOST_VDPA
291+
case VHOST_BACKEND_TYPE_VDPA:
292+
dev->vhost_ops = &vdpa_ops;
293+
break;
288294
#endif
289295
default:
290296
error_report("Unknown vhost backend type");

0 commit comments

Comments
 (0)