From patchwork Fri Apr 7 00:26:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagar Abhang X-Patchwork-Id: 23308 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 [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id BD33E326C; Fri, 7 Apr 2017 02:26:47 +0200 (CEST) Received: from mx0a-000f0801.pphosted.com (mx0a-000f0801.pphosted.com [67.231.144.122]) by dpdk.org (Postfix) with ESMTP id 5A659326B for ; Fri, 7 Apr 2017 02:26:45 +0200 (CEST) Received: from pps.filterd (m0000542.ppops.net [127.0.0.1]) by mx0a-000f0801.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v370KUEu006064; Thu, 6 Apr 2017 17:26:44 -0700 Received: from hq1wp-exmb12.corp.brocade.com ([144.49.131.13]) by mx0a-000f0801.pphosted.com with ESMTP id 29ndqb3y22-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 06 Apr 2017 17:26:44 -0700 Received: from debian.brocade.com (10.120.21.4) by HQ1WP-EXMB12.corp.brocade.com (10.70.20.186) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Thu, 6 Apr 2017 17:26:43 -0700 From: Sagar Abhang To: CC: , , Sagar Abhang Date: Thu, 6 Apr 2017 17:26:37 -0700 Message-ID: <1491524797-27299-1-git-send-email-sabhang@brocade.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <20170406055112.GQ18844@yliu-dev.sh.intel.com> References: <20170406055112.GQ18844@yliu-dev.sh.intel.com> MIME-Version: 1.0 X-Originating-IP: [10.120.21.4] X-ClientProxiedBy: hq1wp-excas14.corp.brocade.com (10.70.38.103) To HQ1WP-EXMB12.corp.brocade.com (10.70.20.186) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-06_19:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704060193 Subject: [dpdk-dev] [PATCH v2] net/vhost: stop dev in close and address mem leak 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" Move the call to stop the device inside the close routine because close needs to stop the device if it isn't stopped. Free the allocated queue buffers in close instead of doing so in remove. Original code had these clean ups in remove which was causing memory leak. Signed-off-by: Sagar Abhang --- v2: - Modified the log message as requested. drivers/net/vhost/rte_eth_vhost.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 41ce5fc..b6fc94a 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -791,11 +791,14 @@ eth_dev_close(struct rte_eth_dev *dev) { struct pmd_internal *internal; struct internal_list *list; + unsigned int i; internal = dev->data->dev_private; if (!internal) return; + eth_dev_stop(dev); + rte_vhost_driver_unregister(internal->iface_name); list = find_internal_resource(internal->iface_name); @@ -807,9 +810,17 @@ eth_dev_close(struct rte_eth_dev *dev) pthread_mutex_unlock(&internal_list_lock); rte_free(list); + for (i = 0; i < dev->data->nb_rx_queues; i++) + rte_free(dev->data->rx_queues[i]); + for (i = 0; i < dev->data->nb_tx_queues; i++) + rte_free(dev->data->tx_queues[i]); + + rte_free(dev->data->mac_addrs); free(internal->dev_name); free(internal->iface_name); rte_free(internal); + + dev->data->dev_private = NULL; } static int @@ -1198,7 +1209,6 @@ static int rte_pmd_vhost_remove(const char *name) { struct rte_eth_dev *eth_dev = NULL; - unsigned int i; RTE_LOG(INFO, PMD, "Un-Initializing pmd_vhost for %s\n", name); @@ -1207,19 +1217,11 @@ rte_pmd_vhost_remove(const char *name) if (eth_dev == NULL) return -ENODEV; - eth_dev_stop(eth_dev); - eth_dev_close(eth_dev); rte_free(vring_states[eth_dev->data->port_id]); vring_states[eth_dev->data->port_id] = NULL; - for (i = 0; i < eth_dev->data->nb_rx_queues; i++) - rte_free(eth_dev->data->rx_queues[i]); - for (i = 0; i < eth_dev->data->nb_tx_queues; i++) - rte_free(eth_dev->data->tx_queues[i]); - - rte_free(eth_dev->data->mac_addrs); rte_free(eth_dev->data); rte_eth_dev_release_port(eth_dev);