From patchwork Thu Jan 12 17:51:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Druzhinin X-Patchwork-Id: 9513753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 36962601E7 for ; Thu, 12 Jan 2017 17:54:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DF83286DB for ; Thu, 12 Jan 2017 17:54:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22C1E286F3; Thu, 12 Jan 2017 17:54:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 04243286DB for ; Thu, 12 Jan 2017 17:54:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRjXp-0004Me-00; Thu, 12 Jan 2017 17:52:12 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRjXn-0004MT-Nv for xen-devel@lists.xenproject.org; Thu, 12 Jan 2017 17:52:11 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id A4/F2-23854-B42C7785; Thu, 12 Jan 2017 17:52:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsXitHSDva7HofI Ig5UXhS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyun88YC96KVfS8XsPUwHhZuIuRk0NCwF9i U+sFZhCbTcBA4tSmRSwgtohAuMS+HztZQWxmgSiJddfugtnCAs4S32ffB6tnEVCV+PtkEhOIz SvgJXF0w0E2iJkKElMevgerERJQkzjatYsFokZQ4uTMJywQMyUkDr54wTyBkXsWktQsJKkFjE yrGDWKU4vKUot0jSz1kooy0zNKchMzc3QNDYz1clOLixPTU3MSk4r1kvNzNzECg6GegYFxB2P TXr9DjJIcTEqivDJbyiOE+JLyUyozEosz4otKc1KLDzHKcHAoSfBGHwDKCRalpqdWpGXmAMMS Ji3BwaMkwhsHkuYtLkjMLc5Mh0idYtTlOHXj9EsmIZa8/LxUKXHelSBFAiBFGaV5cCNgMXKJU VZKmJeRgYFBiKcgtSg3swRV/hWjOAejkjDvTZApPJl5JXCbXgEdwQR0xEUbsCNKEhFSUg2Mi4 73Z8S8CPywzD+x93Zbeaf4sX+T1A/N38pTkTjJQsGnpitIQj35zhpNlxBF19cigXu9RWQfZwt 79PFIax8WSygT7zE3nXkzMmjnuiX+R177TYp+7auvniz5Z2OW5OPXBl13VhSfC2ZMuXp6qU/g xsn3vy/j2i4XKvmm79PJzkclp9P7GpiVWIozEg21mIuKEwH3GEqzjAIAAA== X-Env-Sender: prvs=1781eed2f=igor.druzhinin@citrix.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1484243526!68625326!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 47977 invoked from network); 12 Jan 2017 17:52:08 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-2.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 12 Jan 2017 17:52:08 -0000 X-IronPort-AV: E=Sophos;i="5.33,219,1477958400"; d="scan'208";a="408366617" From: Igor Druzhinin To: , , Date: Thu, 12 Jan 2017 17:51:56 +0000 Message-ID: <1484243516-141100-1-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, igor.druzhinin@citrix.com Subject: [Xen-devel] [PATCH] xen-netback: fix memory leaks on XenBus disconnect X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Eliminate memory leaks introduced several years ago by cleaning the queue resources which are allocated on XenBus connection event. Namely, queue structure array and pages used for IO rings. vif->lock is used to protect statistics gathering agents from using the queue structure during cleaning. Signed-off-by: Igor Druzhinin Reviewed-by: Paul Durrant --- drivers/net/xen-netback/interface.c | 6 ++++-- drivers/net/xen-netback/xenbus.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c index e30ffd2..5795213 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c @@ -221,18 +221,18 @@ static struct net_device_stats *xenvif_get_stats(struct net_device *dev) { struct xenvif *vif = netdev_priv(dev); struct xenvif_queue *queue = NULL; - unsigned int num_queues = vif->num_queues; unsigned long rx_bytes = 0; unsigned long rx_packets = 0; unsigned long tx_bytes = 0; unsigned long tx_packets = 0; unsigned int index; + spin_lock(&vif->lock); if (vif->queues == NULL) goto out; /* Aggregate tx and rx stats from each queue */ - for (index = 0; index < num_queues; ++index) { + for (index = 0; index < vif->num_queues; ++index) { queue = &vif->queues[index]; rx_bytes += queue->stats.rx_bytes; rx_packets += queue->stats.rx_packets; @@ -241,6 +241,8 @@ static struct net_device_stats *xenvif_get_stats(struct net_device *dev) } out: + spin_unlock(&vif->lock); + vif->dev->stats.rx_bytes = rx_bytes; vif->dev->stats.rx_packets = rx_packets; vif->dev->stats.tx_bytes = tx_bytes; diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c index 3124eae..85b742e 100644 --- a/drivers/net/xen-netback/xenbus.c +++ b/drivers/net/xen-netback/xenbus.c @@ -493,11 +493,22 @@ static int backend_create_xenvif(struct backend_info *be) static void backend_disconnect(struct backend_info *be) { if (be->vif) { + unsigned int queue_index; + xen_unregister_watchers(be->vif); #ifdef CONFIG_DEBUG_FS xenvif_debugfs_delif(be->vif); #endif /* CONFIG_DEBUG_FS */ xenvif_disconnect_data(be->vif); + for (queue_index = 0; queue_index < be->vif->num_queues; ++queue_index) + xenvif_deinit_queue(&be->vif->queues[queue_index]); + + spin_lock(&be->vif->lock); + vfree(be->vif->queues); + be->vif->num_queues = 0; + be->vif->queues = NULL; + spin_unlock(&be->vif->lock); + xenvif_disconnect_ctrl(be->vif); } } @@ -1034,6 +1045,8 @@ static void connect(struct backend_info *be) err: if (be->vif->num_queues > 0) xenvif_disconnect_data(be->vif); /* Clean up existing queues */ + for (queue_index = 0; queue_index < be->vif->num_queues; ++queue_index) + xenvif_deinit_queue(&be->vif->queues[queue_index]); vfree(be->vif->queues); be->vif->queues = NULL; be->vif->num_queues = 0;