From patchwork Fri Jan 19 15:55:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 34127 X-Patchwork-Delegate: yuanhan.liu@linux.intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B6F931B389; Fri, 19 Jan 2018 16:56:20 +0100 (CET) Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id EA5241B348; Fri, 19 Jan 2018 16:56:11 +0100 (CET) Received: from glumotte.dev.6wind.com. (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 862D81245C3; Fri, 19 Jan 2018 16:54:35 +0100 (CET) From: Olivier Matz To: dev@dpdk.org, Yuanhan Liu , Maxime Coquelin , Tiwei Bie Cc: stable@dpdk.org, Zijie Pan Date: Fri, 19 Jan 2018 16:55:54 +0100 Message-Id: <20180119155556.32597-3-olivier.matz@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180119155556.32597-1-olivier.matz@6wind.com> References: <20180118090733.12728-1-olivier.matz@6wind.com> <20180119155556.32597-1-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v2 2/4] net/virtio: fix memory leak when reinitializing device X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Free the previous queues and the attached mbufs before initializing new ones. The function virtio_dev_free_mbufs() is now called when reconfiguring the device, so we also need to add a check to ensure that it won't crash for uninitialized queues. Cc: stable@dpdk.org Fixes: 60e6f4707ef2 ("net/virtio: reinitialize device when configuring") Signed-off-by: Zijie Pan Signed-off-by: Olivier Matz --- drivers/net/virtio/virtio_ethdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 2c7f902e7..a8adf0037 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -1368,6 +1368,11 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) /* Reset the device although not necessary at startup */ vtpci_reset(hw); + if (hw->vqs) { + virtio_dev_free_mbufs(eth_dev); + virtio_free_queues(hw); + } + /* Tell the host we've noticed this device. */ vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_ACK); @@ -1863,6 +1868,9 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev) for (i = 0; i < dev->data->nb_rx_queues; i++) { struct virtnet_rx *rxvq = dev->data->rx_queues[i]; + if (rxvq == NULL || rxvq->vq == NULL) + continue; + PMD_INIT_LOG(DEBUG, "Before freeing rxq[%d] used and unused buf", i); VIRTQUEUE_DUMP(rxvq->vq); @@ -1882,6 +1890,9 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev) for (i = 0; i < dev->data->nb_tx_queues; i++) { struct virtnet_tx *txvq = dev->data->tx_queues[i]; + if (txvq == NULL || txvq->vq == NULL) + continue; + PMD_INIT_LOG(DEBUG, "Before freeing txq[%d] used and unused bufs", i);