d761fec5f6
- Applied all the fixes recommended by upstream for v2.2 stable release(bsc#981996). [+0008-app-testpmd-handle-SIGINT-and-SIGTERM.patch, +0009-bonding-copy-entire-config-structure-in-mode-4.patch, +0010-bonding-fix-active-slaves-with-no-primary.patch, +0011-bonding-do-not-ignore-multicast-in-mode-4.patch, +0012-bonding-do-not-activate-slave-twice.patch, +0013-bonding-fix-crash-when-no-slave-device.patch, +0014-bonding-fix-detach-of-bonded-device.patch, +0015-bonding-fix-detach-of-slave-devices.patch, +0016-eal-linux-support-built-in-kernel-modules.patch, +0017-examples-l3fwd-handle-SIGINT-and-SIGTERM.patch, +0018-fm10k-fix-VLAN-flag-in-scattered-Rx.patch, +0019-i40e-base-fix-driver-load-failure.patch, +0020-i40e-base-fix-missing-check-for-stopped-admin-queue.patch, +0021-i40e-fix-inverted-check-for-no-refcount.patch, +0022-i40e-fix-overflow.patch, +0023-i40e-fix-VLAN-filtering.patch, +0024-mempool-fix-leak-when-creation-fails.patch, +0025-pcap-fix-captured-frame-length.patch, +0026-port-fix-crash-for-ethdev-writer-nodrop.patch, +0027-port-fix-crash-for-ring-writer-nodrop.patch, +0028-tools-fix-unbinding-failure-handling.patch, +0029-tools-support-Python-3-in-bind-script.patch, +0030-tools-support-binding-to-built-in-kernel-modules.patch, +0031-vhost-fix-leak-of-fds-and-mmaps.patch, +0032-virtio-fix-crash-in-statistics-functions.patch, +0033-virtio-fix-descriptors-pointing-to-the-same-buffer.patch, +0034-virtio-fix-restart.patch] OBS-URL: https://build.opensuse.org/request/show/399089 OBS-URL: https://build.opensuse.org/package/show/network/dpdk?expand=0&rev=3
152 lines
4.9 KiB
Diff
152 lines
4.9 KiB
Diff
From ca67ed289a76f38d6c4a4021985a36eaf1d77e28 Mon Sep 17 00:00:00 2001
|
|
From: Rich Lane <rich.lane@bigswitch.com>
|
|
Date: Wed, 10 Feb 2016 10:40:55 -0800
|
|
Subject: [PATCH] vhost: fix leak of fds and mmaps
|
|
|
|
The common vhost code only supported a single mmap per device. vhost-user
|
|
worked around this by saving the address/length/fd of each mmap after the end
|
|
of the rte_virtio_memory struct. This only works if the vhost-user code frees
|
|
dev->mem, since the common code is unaware of the extra info. The
|
|
VHOST_USER_RESET_OWNER message is one situation where the common code frees
|
|
dev->mem and leaks the fds and mappings. This happens every time I shut down a
|
|
VM.
|
|
|
|
The new code calls back into the implementation (vhost-user or vhost-cuse) to
|
|
clean up these resources.
|
|
|
|
The vhost-cuse changes are only compile tested.
|
|
|
|
Signed-off-by: Rich Lane <rich.lane@bigswitch.com>
|
|
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
|
|
---
|
|
lib/librte_vhost/vhost-net.h | 6 ++++++
|
|
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 12 ++++++++++++
|
|
lib/librte_vhost/vhost_user/vhost-net-user.c | 1 -
|
|
lib/librte_vhost/vhost_user/virtio-net-user.c | 25 ++++++++++---------------
|
|
lib/librte_vhost/vhost_user/virtio-net-user.h | 1 -
|
|
lib/librte_vhost/virtio-net.c | 8 +-------
|
|
6 files changed, 29 insertions(+), 24 deletions(-)
|
|
|
|
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
|
|
index c69b60b..affbd1a 100644
|
|
--- a/lib/librte_vhost/vhost-net.h
|
|
+++ b/lib/librte_vhost/vhost-net.h
|
|
@@ -115,4 +115,10 @@ struct vhost_net_device_ops {
|
|
|
|
|
|
struct vhost_net_device_ops const *get_virtio_net_callbacks(void);
|
|
+
|
|
+/*
|
|
+ * Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
|
|
+ */
|
|
+void vhost_backend_cleanup(struct virtio_net *dev);
|
|
+
|
|
#endif /* _VHOST_NET_CDEV_H_ */
|
|
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
|
|
index ae2c3fa..374c884 100644
|
|
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
|
|
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
|
|
@@ -421,3 +421,15 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
|
|
|
|
return ops->set_backend(ctx, file);
|
|
}
|
|
+
|
|
+void
|
|
+vhost_backend_cleanup(struct virtio_net *dev)
|
|
+{
|
|
+ /* Unmap QEMU memory file if mapped. */
|
|
+ if (dev->mem) {
|
|
+ munmap((void *)(uintptr_t)dev->mem->mapped_address,
|
|
+ (size_t)dev->mem->mapped_size);
|
|
+ free(dev->mem);
|
|
+ dev->mem = NULL;
|
|
+ }
|
|
+}
|
|
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
|
|
index cb18396..6ed7669 100644
|
|
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
|
|
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
|
|
@@ -348,7 +348,6 @@ vserver_message_handler(int connfd, void *dat, int *remove)
|
|
close(connfd);
|
|
*remove = 1;
|
|
free(cfd_ctx);
|
|
- user_destroy_device(ctx);
|
|
ops->destroy_device(ctx);
|
|
|
|
return;
|
|
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
|
|
index 4270c98..ffce0d6 100644
|
|
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
|
|
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
|
|
@@ -94,6 +94,16 @@ free_mem_region(struct virtio_net *dev)
|
|
}
|
|
}
|
|
|
|
+void
|
|
+vhost_backend_cleanup(struct virtio_net *dev)
|
|
+{
|
|
+ if (dev->mem) {
|
|
+ free_mem_region(dev);
|
|
+ free(dev->mem);
|
|
+ dev->mem = NULL;
|
|
+ }
|
|
+}
|
|
+
|
|
int
|
|
user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
|
|
{
|
|
@@ -345,21 +355,6 @@ user_set_vring_enable(struct vhost_device_ctx ctx,
|
|
}
|
|
|
|
void
|
|
-user_destroy_device(struct vhost_device_ctx ctx)
|
|
-{
|
|
- struct virtio_net *dev = get_device(ctx);
|
|
-
|
|
- if (dev && (dev->flags & VIRTIO_DEV_RUNNING))
|
|
- notify_ops->destroy_device(dev);
|
|
-
|
|
- if (dev && dev->mem) {
|
|
- free_mem_region(dev);
|
|
- free(dev->mem);
|
|
- dev->mem = NULL;
|
|
- }
|
|
-}
|
|
-
|
|
-void
|
|
user_set_protocol_features(struct vhost_device_ctx ctx,
|
|
uint64_t protocol_features)
|
|
{
|
|
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.h b/lib/librte_vhost/vhost_user/virtio-net-user.h
|
|
index 28213f3..559bb46 100644
|
|
--- a/lib/librte_vhost/vhost_user/virtio-net-user.h
|
|
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.h
|
|
@@ -61,5 +61,4 @@ int user_get_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
|
|
int user_set_vring_enable(struct vhost_device_ctx ctx,
|
|
struct vhost_vring_state *state);
|
|
|
|
-void user_destroy_device(struct vhost_device_ctx);
|
|
#endif
|
|
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
|
|
index 9059b11..196e1cf 100644
|
|
--- a/lib/librte_vhost/virtio-net.c
|
|
+++ b/lib/librte_vhost/virtio-net.c
|
|
@@ -207,13 +207,7 @@ cleanup_device(struct virtio_net *dev, int destroy)
|
|
{
|
|
uint32_t i;
|
|
|
|
- /* Unmap QEMU memory file if mapped. */
|
|
- if (dev->mem) {
|
|
- munmap((void *)(uintptr_t)dev->mem->mapped_address,
|
|
- (size_t)dev->mem->mapped_size);
|
|
- free(dev->mem);
|
|
- dev->mem = NULL;
|
|
- }
|
|
+ vhost_backend_cleanup(dev);
|
|
|
|
for (i = 0; i < dev->virt_qp_nb; i++) {
|
|
cleanup_vq(dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_RXQ], destroy);
|
|
--
|
|
2.6.2
|
|
|