|
|
a6040a |
From 8db980965f3d8cde1abbdb89eaecbc829460133e Mon Sep 17 00:00:00 2001
|
|
|
a6040a |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
a6040a |
Date: Wed, 31 Jan 2018 17:46:50 +0000
|
|
|
a6040a |
Subject: [PATCH 5/6] vhost: add flag for built-in virtio driver
|
|
|
a6040a |
|
|
|
a6040a |
The librte_vhost API is used in two ways:
|
|
|
a6040a |
1. As a vhost net device backend via rte_vhost_enqueue/dequeue_burst().
|
|
|
a6040a |
2. As a library for implementing vhost device backends.
|
|
|
a6040a |
|
|
|
a6040a |
There is no distinction between the two at the API level or in the
|
|
|
a6040a |
librte_vhost implementation. For example, device state is kept in
|
|
|
a6040a |
"struct virtio_net" regardless of whether this is actually a net device
|
|
|
a6040a |
backend or whether the built-in virtio_net.c driver is in use.
|
|
|
a6040a |
|
|
|
a6040a |
The virtio_net.c driver should be a librte_vhost API client just like
|
|
|
a6040a |
the vhost-scsi code and have no special access to vhost.h internals.
|
|
|
a6040a |
Unfortunately, fixing this requires significant librte_vhost API
|
|
|
a6040a |
changes.
|
|
|
a6040a |
|
|
|
a6040a |
This patch takes a different approach: keep the librte_vhost API
|
|
|
a6040a |
unchanged but track whether the built-in virtio_net.c driver is in use.
|
|
|
a6040a |
See the next patch for a bug fix that requires knowledge of whether
|
|
|
a6040a |
virtio_net.c is in use.
|
|
|
a6040a |
|
|
|
a6040a |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
a6040a |
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
|
|
|
a6040a |
Acked-by: Yuanhan Liu <yliu@fridaylinux.org>
|
|
|
a6040a |
(cherry picked from commit 1c717af4c699e60081feb1d645f86189551f9a9c)
|
|
|
a6040a |
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
|
|
|
a6040a |
---
|
|
|
a6040a |
dpdk-17.11/lib/librte_vhost/socket.c | 15 +++++++++++++++
|
|
|
a6040a |
dpdk-17.11/lib/librte_vhost/vhost.c | 17 ++++++++++++++++-
|
|
|
a6040a |
dpdk-17.11/lib/librte_vhost/vhost.h | 3 +++
|
|
|
a6040a |
dpdk-17.11/lib/librte_vhost/virtio_net.c | 14 ++++++++++++++
|
|
|
a6040a |
4 files changed, 48 insertions(+), 1 deletion(-)
|
|
|
a6040a |
|
|
|
a6040a |
diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
|
|
|
a6040a |
index 422da002f..ceecc6149 100644
|
|
|
a6040a |
--- a/lib/librte_vhost/socket.c
|
|
|
a6040a |
+++ b/lib/librte_vhost/socket.c
|
|
|
a6040a |
@@ -69,6 +69,7 @@ struct vhost_user_socket {
|
|
|
a6040a |
bool reconnect;
|
|
|
a6040a |
bool dequeue_zero_copy;
|
|
|
a6040a |
bool iommu_support;
|
|
|
a6040a |
+ bool use_builtin_virtio_net;
|
|
|
a6040a |
|
|
|
a6040a |
/*
|
|
|
a6040a |
* The "supported_features" indicates the feature bits the
|
|
|
a6040a |
@@ -224,6 +225,8 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
|
|
|
a6040a |
size = strnlen(vsocket->path, PATH_MAX);
|
|
|
a6040a |
vhost_set_ifname(vid, vsocket->path, size);
|
|
|
a6040a |
|
|
|
a6040a |
+ vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net);
|
|
|
a6040a |
+
|
|
|
a6040a |
if (vsocket->dequeue_zero_copy)
|
|
|
a6040a |
vhost_enable_dequeue_zero_copy(vid);
|
|
|
a6040a |
|
|
|
a6040a |
@@ -547,6 +550,12 @@ rte_vhost_driver_disable_features(const char *path, uint64_t features)
|
|
|
a6040a |
|
|
|
a6040a |
pthread_mutex_lock(&vhost_user.mutex);
|
|
|
a6040a |
vsocket = find_vhost_user_socket(path);
|
|
|
a6040a |
+
|
|
|
a6040a |
+ /* Note that use_builtin_virtio_net is not affected by this function
|
|
|
a6040a |
+ * since callers may want to selectively disable features of the
|
|
|
a6040a |
+ * built-in vhost net device backend.
|
|
|
a6040a |
+ */
|
|
|
a6040a |
+
|
|
|
a6040a |
if (vsocket)
|
|
|
a6040a |
vsocket->features &= ~features;
|
|
|
a6040a |
pthread_mutex_unlock(&vhost_user.mutex);
|
|
|
a6040a |
@@ -587,6 +596,11 @@ rte_vhost_driver_set_features(const char *path, uint64_t features)
|
|
|
a6040a |
if (vsocket) {
|
|
|
a6040a |
vsocket->supported_features = features;
|
|
|
a6040a |
vsocket->features = features;
|
|
|
a6040a |
+
|
|
|
a6040a |
+ /* Anyone setting feature bits is implementing their own vhost
|
|
|
a6040a |
+ * device backend.
|
|
|
a6040a |
+ */
|
|
|
a6040a |
+ vsocket->use_builtin_virtio_net = false;
|
|
|
a6040a |
}
|
|
|
a6040a |
pthread_mutex_unlock(&vhost_user.mutex);
|
|
|
a6040a |
|
|
|
a6040a |
@@ -667,6 +681,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
|
|
|
a6040a |
* rte_vhost_driver_set_features(), which will overwrite following
|
|
|
a6040a |
* two values.
|
|
|
a6040a |
*/
|
|
|
a6040a |
+ vsocket->use_builtin_virtio_net = true;
|
|
|
a6040a |
vsocket->supported_features = VIRTIO_NET_SUPPORTED_FEATURES;
|
|
|
a6040a |
vsocket->features = VIRTIO_NET_SUPPORTED_FEATURES;
|
|
|
a6040a |
|
|
|
a6040a |
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
|
|
|
a6040a |
index df528a4ea..75deaa877 100644
|
|
|
a6040a |
--- a/lib/librte_vhost/vhost.c
|
|
|
a6040a |
+++ b/lib/librte_vhost/vhost.c
|
|
|
a6040a |
@@ -279,7 +279,7 @@ reset_device(struct virtio_net *dev)
|
|
|
a6040a |
|
|
|
a6040a |
dev->features = 0;
|
|
|
a6040a |
dev->protocol_features = 0;
|
|
|
a6040a |
- dev->flags = 0;
|
|
|
a6040a |
+ dev->flags &= VIRTIO_DEV_BUILTIN_VIRTIO_NET;
|
|
|
a6040a |
|
|
|
a6040a |
for (i = 0; i < dev->nr_vring; i++)
|
|
|
a6040a |
reset_vring_queue(dev, i);
|
|
|
a6040a |
@@ -315,6 +315,7 @@ vhost_new_device(void)
|
|
|
a6040a |
|
|
|
a6040a |
vhost_devices[i] = dev;
|
|
|
a6040a |
dev->vid = i;
|
|
|
a6040a |
+ dev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET;
|
|
|
a6040a |
dev->slave_req_fd = -1;
|
|
|
a6040a |
|
|
|
a6040a |
return i;
|
|
|
a6040a |
@@ -371,6 +372,20 @@ vhost_enable_dequeue_zero_copy(int vid)
|
|
|
a6040a |
dev->dequeue_zero_copy = 1;
|
|
|
a6040a |
}
|
|
|
a6040a |
|
|
|
a6040a |
+void
|
|
|
a6040a |
+vhost_set_builtin_virtio_net(int vid, bool enable)
|
|
|
a6040a |
+{
|
|
|
a6040a |
+ struct virtio_net *dev = get_device(vid);
|
|
|
a6040a |
+
|
|
|
a6040a |
+ if (dev == NULL)
|
|
|
a6040a |
+ return;
|
|
|
a6040a |
+
|
|
|
a6040a |
+ if (enable)
|
|
|
a6040a |
+ dev->flags |= VIRTIO_DEV_BUILTIN_VIRTIO_NET;
|
|
|
a6040a |
+ else
|
|
|
a6040a |
+ dev->flags &= ~VIRTIO_DEV_BUILTIN_VIRTIO_NET;
|
|
|
a6040a |
+}
|
|
|
a6040a |
+
|
|
|
a6040a |
int
|
|
|
a6040a |
rte_vhost_get_mtu(int vid, uint16_t *mtu)
|
|
|
a6040a |
{
|
|
|
a6040a |
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
|
|
|
a6040a |
index 9cad1bb3c..e06531e6b 100644
|
|
|
a6040a |
--- a/lib/librte_vhost/vhost.h
|
|
|
a6040a |
+++ b/lib/librte_vhost/vhost.h
|
|
|
a6040a |
@@ -53,6 +53,8 @@
|
|
|
a6040a |
#define VIRTIO_DEV_RUNNING 1
|
|
|
a6040a |
/* Used to indicate that the device is ready to operate */
|
|
|
a6040a |
#define VIRTIO_DEV_READY 2
|
|
|
a6040a |
+/* Used to indicate that the built-in vhost net device backend is enabled */
|
|
|
a6040a |
+#define VIRTIO_DEV_BUILTIN_VIRTIO_NET 4
|
|
|
a6040a |
|
|
|
a6040a |
/* Backend value set by guest. */
|
|
|
a6040a |
#define VIRTIO_DEV_STOPPED -1
|
|
|
a6040a |
@@ -371,6 +373,7 @@ int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);
|
|
|
a6040a |
|
|
|
a6040a |
void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
|
|
|
a6040a |
void vhost_enable_dequeue_zero_copy(int vid);
|
|
|
a6040a |
+void vhost_set_builtin_virtio_net(int vid, bool enable);
|
|
|
a6040a |
|
|
|
a6040a |
struct vhost_device_ops const *vhost_driver_callback_get(const char *path);
|
|
|
a6040a |
|
|
|
a6040a |
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
|
|
|
a6040a |
index 6fee16e55..3bfd71945 100644
|
|
|
a6040a |
--- a/lib/librte_vhost/virtio_net.c
|
|
|
a6040a |
+++ b/lib/librte_vhost/virtio_net.c
|
|
|
a6040a |
@@ -727,6 +727,13 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
|
|
|
a6040a |
if (!dev)
|
|
|
a6040a |
return 0;
|
|
|
a6040a |
|
|
|
a6040a |
+ if (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {
|
|
|
a6040a |
+ RTE_LOG(ERR, VHOST_DATA,
|
|
|
a6040a |
+ "(%d) %s: built-in vhost net backend is disabled.\n",
|
|
|
a6040a |
+ dev->vid, __func__);
|
|
|
a6040a |
+ return 0;
|
|
|
a6040a |
+ }
|
|
|
a6040a |
+
|
|
|
a6040a |
if (dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF))
|
|
|
a6040a |
return virtio_dev_merge_rx(dev, queue_id, pkts, count);
|
|
|
a6040a |
else
|
|
|
a6040a |
@@ -1173,6 +1180,13 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
|
|
|
a6040a |
if (!dev)
|
|
|
a6040a |
return 0;
|
|
|
a6040a |
|
|
|
a6040a |
+ if (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {
|
|
|
a6040a |
+ RTE_LOG(ERR, VHOST_DATA,
|
|
|
a6040a |
+ "(%d) %s: built-in vhost net backend is disabled.\n",
|
|
|
a6040a |
+ dev->vid, __func__);
|
|
|
a6040a |
+ return 0;
|
|
|
a6040a |
+ }
|
|
|
a6040a |
+
|
|
|
a6040a |
if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->nr_vring))) {
|
|
|
a6040a |
RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
|
|
|
a6040a |
dev->vid, __func__, queue_id);
|
|
|
a6040a |
--
|
|
|
a6040a |
2.14.3
|
|
|
a6040a |
|