From patchwork Tue Jan 17 20:49:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Druzhinin X-Patchwork-Id: 9521915 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 22F0860244 for ; Tue, 17 Jan 2017 20:51:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C7DA26E64 for ; Tue, 17 Jan 2017 20:51:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1165A285B8; Tue, 17 Jan 2017 20:51:38 +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 BE76026E64 for ; Tue, 17 Jan 2017 20:51:37 +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 1cTahQ-0007mj-PZ; Tue, 17 Jan 2017 20:49:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cTahP-0007mF-Kt for xen-devel@lists.xenproject.org; Tue, 17 Jan 2017 20:49:47 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 50/02-27165-B638E785; Tue, 17 Jan 2017 20:49:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXjeruS7 CYPZxOYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPP/U0sBZMEKuZP+cPSwPiGt4uRk0NCwF/i Td93VhCbTcBA4tSmRSwgtoiApMTVDU/Yuxi5OJgFljNK7Fh/FCwhLBAsMbvjHTuIzSKgKjFl5 TPmLkYODl4BT4k375whZipITHn4nhnE5hTwkvg6dwcbiC0EVDJrWzMrhK0mcbRrF9hIXgFBiZ Mzn4DZzAISEgdfvGCewMg7C0lqFpLUAkamVYwaxalFZalFuoYGeklFmekZJbmJmTlAnplebmp xcWJ6ak5iUrFecn7uJkZg8DAAwQ7Ge8sCDjFKcjApifJ2PK6NEOJLyk+pzEgszogvKs1JLT7E KMPBoSTBm9tUFyEkWJSanlqRlpkDDGOYtAQHj5IIbzVImre4IDG3ODMdInWKUVFKnNcKJCEAk sgozYNrg8XOJUZZKWFeRqBDhHgKUotyM0tQ5V8xinMwKgnzVoBM4cnMK4Gb/gpoMRPQ4us61S CLSxIRUlINjFqLltXVWrt9nz/17bXEuJqcqGrNlowt/Npbzp/a3Z4cqXqkyVFwxWMTl+v8TFZ P95XHvSrpfc5yU/F1YMT8ihnTTibX/9w18Y/Hpu8Mv2rCL92YeSH1jE5zx+ILzzYuPK6T+0vp qJTrFvUkUbaDiaKXvj52v7+y6pd6SbyF0RS3eyHNKUl90kosxRmJhlrMRcWJAEpuqCCYAgAA X-Env-Sender: prvs=183722f83=igor.druzhinin@citrix.com X-Msg-Ref: server-16.tower-21.messagelabs.com!1484686184!48677905!2 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 12052 invoked from network); 17 Jan 2017 20:49:46 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-16.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 17 Jan 2017 20:49:46 -0000 X-IronPort-AV: E=Sophos;i="5.33,246,1477958400"; d="scan'208";a="409157738" From: Igor Druzhinin To: Date: Tue, 17 Jan 2017 20:49:38 +0000 Message-ID: <1484686178-76959-3-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1484686178-76959-1-git-send-email-igor.druzhinin@citrix.com> References: <1484686178-76959-1-git-send-email-igor.druzhinin@citrix.com> MIME-Version: 1.0 Cc: xen-devel@lists.xenproject.org, Igor Druzhinin , Paul.Durrant@citrix.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [Xen-devel] [PATCH v2 2/2] xen-netback: protect resource cleaning 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 vif->lock is used to protect statistics gathering agents from using the queue structure during cleaning. Signed-off-by: Igor Druzhinin Acked-by: Wei Liu Reviewed-by: Paul Durrant --- drivers/net/xen-netback/interface.c | 6 ++++-- drivers/net/xen-netback/xenbus.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c index 41c69b3..c48252a 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c @@ -230,18 +230,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; @@ -250,6 +250,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 3e99071..d82cd71 100644 --- a/drivers/net/xen-netback/xenbus.c +++ b/drivers/net/xen-netback/xenbus.c @@ -503,9 +503,11 @@ static void backend_disconnect(struct backend_info *be) 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); }