From: Jianfeng Tan <jianfeng.tan@intel.com>
To: dev@dpdk.org
Cc: huawei.xie@intel.com, yuanhan.liu@linux.intel.com,
Jianfeng Tan <jianfeng.tan@intel.com>
Subject: [dpdk-dev] [PATCH v2 2/2] virtio: fix memory leak of virtqueue memzones
Date: Thu, 28 Apr 2016 19:04:01 +0000 [thread overview]
Message-ID: <1461870241-83333-3-git-send-email-jianfeng.tan@intel.com> (raw)
In-Reply-To: <1461870241-83333-1-git-send-email-jianfeng.tan@intel.com>
Issue: When virtio was proposed in DPDK, there is no API to free memzones.
But this has changed since rte_memzone_free() has been implemented by
commit ff909fe21f0a ("mem: introduce memzone freeing").
This patch is to make sure memzones in struct virtqueue, like mz and
virtio_net_hdr_mz, are freed when queue is released or setup fails.
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
drivers/net/virtio/virtio_ethdev.c | 21 ++++++++++++++-------
drivers/net/virtio/virtqueue.h | 2 ++
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 0553b67..a14cc88 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -260,12 +260,18 @@ virtio_set_multiple_queues(struct rte_eth_dev *dev, uint16_t nb_queues)
}
void
-virtio_dev_queue_release(struct virtqueue *vq) {
+virtio_dev_queue_release(struct virtqueue *vq)
+{
struct virtio_hw *hw;
if (vq) {
hw = vq->hw;
- hw->vtpci_ops->del_queue(hw, vq);
+ if (vq->started)
+ hw->vtpci_ops->del_queue(hw, vq);
+
+ rte_memzone_free(vq->mz);
+ if (vq->virtio_net_hdr_mz)
+ rte_memzone_free(vq->virtio_net_hdr_mz);
rte_free(vq->sw_ring);
rte_free(vq);
@@ -330,7 +336,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
socket_id);
if (!vq->sw_ring) {
PMD_INIT_LOG(ERR, "Can not allocate RX soft ring");
- rte_free(vq);
+ virtio_dev_queue_release(vq);
return -ENOMEM;
}
}
@@ -358,7 +364,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
if (rte_errno == EEXIST)
mz = rte_memzone_lookup(vq_name);
if (mz == NULL) {
- rte_free(vq);
+ virtio_dev_queue_release(vq);
return -ENOMEM;
}
}
@@ -370,7 +376,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
*/
if ((mz->phys_addr + vq->vq_ring_size - 1) >> (VIRTIO_PCI_QUEUE_ADDR_SHIFT + 32)) {
PMD_INIT_LOG(ERR, "vring address shouldn't be above 16TB!");
- rte_free(vq);
+ virtio_dev_queue_release(vq);
return -ENOMEM;
}
@@ -402,7 +408,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
if (rte_errno == EEXIST)
hdr_mz = rte_memzone_lookup(vq_name);
if (hdr_mz == NULL) {
- rte_free(vq);
+ virtio_dev_queue_release(vq);
return -ENOMEM;
}
}
@@ -436,7 +442,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
vq->virtio_net_hdr_mz =
rte_memzone_lookup(vq_name);
if (vq->virtio_net_hdr_mz == NULL) {
- rte_free(vq);
+ virtio_dev_queue_release(vq);
return -ENOMEM;
}
}
@@ -447,6 +453,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
hw->vtpci_ops->setup_queue(hw, vq);
+ vq->started = 1;
*pvq = vq;
return 0;
}
diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
index 4e9239e..83d89ca 100644
--- a/drivers/net/virtio/virtqueue.h
+++ b/drivers/net/virtio/virtqueue.h
@@ -201,6 +201,8 @@ struct virtqueue {
uint16_t *notify_addr;
+ int started;
+
struct vq_desc_extra {
void *cookie;
uint16_t ndescs;
--
2.1.4
next prev parent reply other threads:[~2016-04-28 19:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-26 12:32 [dpdk-dev] [PATCH] " Jianfeng Tan
2016-04-27 22:37 ` Yuanhan Liu
2016-04-28 2:01 ` Tan, Jianfeng
2016-04-28 3:29 ` Yuanhan Liu
2016-04-28 19:03 ` [dpdk-dev] [PATCH v2 0/2] " Jianfeng Tan
2016-04-28 19:04 ` [dpdk-dev] [PATCH v2 1/2] virtio: cleanup virtio_dev_queue_setup() Jianfeng Tan
2016-04-28 19:04 ` Jianfeng Tan [this message]
2016-04-28 19:05 ` [dpdk-dev] [PATCH v2 0/2] virtio: fix memory leak of virtqueue memzones Tan, Jianfeng
2016-04-28 19:08 ` Tan, Jianfeng
2016-04-29 0:48 ` [dpdk-dev] [PATCH v3 " Jianfeng Tan
2016-04-29 0:48 ` [dpdk-dev] [PATCH v3 1/2] virtio: cleanup virtio_dev_queue_setup() Jianfeng Tan
2016-05-05 3:19 ` Yuanhan Liu
2016-05-09 7:58 ` Tan, Jianfeng
2016-05-09 18:04 ` Yuanhan Liu
2016-04-29 0:48 ` [dpdk-dev] [PATCH v3 2/2] virtio: fix memory leak of virtqueue memzones Jianfeng Tan
2016-04-29 5:33 ` Yuanhan Liu
2016-05-05 3:27 ` Yuanhan Liu
2016-05-05 4:51 ` Tan, Jianfeng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461870241-83333-3-git-send-email-jianfeng.tan@intel.com \
--to=jianfeng.tan@intel.com \
--cc=dev@dpdk.org \
--cc=huawei.xie@intel.com \
--cc=yuanhan.liu@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).