From 428261b4615ecc69672b19df8b0e535a380c04d1 Mon Sep 17 00:00:00 2001 From: Ilya Maximets Date: Thu, 16 Jun 2016 12:16:37 +0300 Subject: [PATCH] vhost: unmap log memory on cleanup Fixes memory leak on QEMU migration. Fixes: 54f9e32305d4 ("vhost: handle dirty pages logging request") Signed-off-by: Ilya Maximets Acked-by: Yuanhan Liu --- lib/librte_vhost/vhost-net.h | 1 + lib/librte_vhost/vhost_user/virtio-net-user.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h index ec8f964b8c..38593a2974 100644 --- a/lib/librte_vhost/vhost-net.h +++ b/lib/librte_vhost/vhost-net.h @@ -134,6 +134,7 @@ struct virtio_net { char ifname[IF_NAME_SZ]; uint64_t log_size; uint64_t log_base; + uint64_t log_addr; struct ether_addr mac; } __rte_cache_aligned; diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c index e6a2aeddac..a867a43606 100644 --- a/lib/librte_vhost/vhost_user/virtio-net-user.c +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c @@ -95,6 +95,10 @@ vhost_backend_cleanup(struct virtio_net *dev) free(dev->mem); dev->mem = NULL; } + if (dev->log_addr) { + munmap((void *)(uintptr_t)dev->log_addr, dev->log_size); + dev->log_addr = 0; + } } int @@ -407,8 +411,15 @@ user_set_log_base(int vid, struct VhostUserMsg *msg) return -1; } - /* TODO: unmap on stop */ - dev->log_base = (uint64_t)(uintptr_t)addr + off; + /* + * Free previously mapped log memory on occasionally + * multiple VHOST_USER_SET_LOG_BASE. + */ + if (dev->log_addr) { + munmap((void *)(uintptr_t)dev->log_addr, dev->log_size); + } + dev->log_addr = (uint64_t)(uintptr_t)addr; + dev->log_base = dev->log_addr + off; dev->log_size = size; return 0; -- 2.20.1