From patchwork Mon Mar 18 18:13:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pravin B Shelar X-Patchwork-Id: 228760 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A8AF02C0099 for ; Tue, 19 Mar 2013 05:14:36 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754193Ab3CRSO3 (ORCPT ); Mon, 18 Mar 2013 14:14:29 -0400 Received: from na3sys009aog126.obsmtp.com ([74.125.149.155]:59783 "HELO na3sys009aog126.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753389Ab3CRSOY (ORCPT ); Mon, 18 Mar 2013 14:14:24 -0400 Received: from mail-da0-f70.google.com ([209.85.210.70]) (using TLSv1) by na3sys009aob126.postini.com ([74.125.148.12]) with SMTP ID DSNKUUdZfFHSxsw8I85Quqa73L19oIxk5swm@postini.com; Mon, 18 Mar 2013 11:14:24 PDT Received: by mail-da0-f70.google.com with SMTP id i30so3137707dad.9 for ; Mon, 18 Mar 2013 11:14:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=D/0ESxRWTgo6JJW+rNXhFgDLmN5wybMaq8WkGZv3G0I=; b=PbfpdgEMg62b95HQt4Kqgq1C2ij6ETckh8mexv1chfuIwQOFgEHDcy2LAPbwRuv4bU kGyNgPhoDe+fv1u6wLfKQz0eiqs+QyDgHj9o2PaI6k9PpGrsaDBd3278tpbM6qZ9/5HU Mwdk5xxV31Mbzo2/Uu1UcHSnsMQ+6LhhWJkVjMi9XP05oq4ANqTdbvxtkg7sqyM+idmu 8rZTdryzN3LBlOEOAeP91P3tX7I/ePaE9BLbrW3KbkzirmYpYSn+CprYyyHWiM9d5Zg4 N4oTrpXMaWyA6oLExov62xZzTGtGK6s1sDYULwKM/7iTsJgkXgvm3yAjN2QHPaTQ0Ao+ pfgw== X-Received: by 10.66.170.44 with SMTP id aj12mr11695076pac.31.1363630460722; Mon, 18 Mar 2013 11:14:20 -0700 (PDT) X-Received: by 10.66.170.44 with SMTP id aj12mr11695058pac.31.1363630460584; Mon, 18 Mar 2013 11:14:20 -0700 (PDT) Received: from localhost (c-76-126-241-147.hsd1.ca.comcast.net. [76.126.241.147]) by mx.google.com with ESMTPS id 1sm20973155pba.32.2013.03.18.11.14.19 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Mon, 18 Mar 2013 11:14:19 -0700 (PDT) From: Pravin B Shelar To: davem@davemloft.net Cc: stephen@networkplumber.org, xiyou.wangcong@gmail.com, netdev@vger.kernel.org, jesse@nicira.com, Pravin B Shelar Subject: [PATCH v2 net-next 3/5] VXLAN: Fix vxlan stats handling. Date: Mon, 18 Mar 2013 11:13:33 -0700 Message-Id: <1363630413-1736-1-git-send-email-pshelar@nicira.com> X-Mailer: git-send-email 1.7.12.315.g682ce8b X-Gm-Message-State: ALoCoQnSm5cEwl6eRfmL03Bgz0Dk8YaWxOkMdvB+v/vbJzzpPkPPvh83C4FIvOHBfxMtHXMJAhX+CTPuavpiko0mkkclAjsYykgKSAsDtNHsUkSibLyu4sk1L7lNypieQ8Oh6b0p9lVSBXunUF3jRSuPdMDif1ipWPytRcN1MyIEczkKejoAa7g= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Fixes bug in VXLAN code where is iptunnel_xmit() called with NULL dev->tstats. This bug was introduced in commit 6aed0c8bf7d2f389b (tunnel: use iptunnel_xmit() again). Following patch fixes bug by setting dev->tstats. It uses ip_tunnel module code to share stats function. CC: Cong Wang Signed-off-by: Pravin B Shelar Acked-by: Stephen Hemminger --- drivers/net/vxlan.c | 72 +++++---------------------------------------------- 1 files changed, 7 insertions(+), 65 deletions(-) diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index fe9ea7d..e532b2a 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -101,20 +101,10 @@ struct vxlan_fdb { u8 eth_addr[ETH_ALEN]; }; -/* Per-cpu network traffic stats */ -struct vxlan_stats { - u64 rx_packets; - u64 rx_bytes; - u64 tx_packets; - u64 tx_bytes; - struct u64_stats_sync syncp; -}; - /* Pseudo network device */ struct vxlan_dev { struct hlist_node hlist; struct net_device *dev; - struct vxlan_stats __percpu *stats; __u32 vni; /* virtual network id */ __be32 gaddr; /* multicast group */ __be32 saddr; /* source address */ @@ -667,7 +657,7 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb) struct iphdr *oip; struct vxlanhdr *vxh; struct vxlan_dev *vxlan; - struct vxlan_stats *stats; + struct pcpu_tstats *stats; __u32 vni; int err; @@ -743,7 +733,7 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb) } } - stats = this_cpu_ptr(vxlan->stats); + stats = this_cpu_ptr(vxlan->dev->tstats); u64_stats_update_begin(&stats->syncp); stats->rx_packets++; stats->rx_bytes += skb->len; @@ -974,8 +964,7 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, /* short-circuited back to local bridge */ if (netif_rx(skb) == NET_RX_SUCCESS) { - struct vxlan_stats *stats = - this_cpu_ptr(vxlan->stats); + struct pcpu_tstats *stats = this_cpu_ptr(dev->tstats); u64_stats_update_begin(&stats->syncp); stats->tx_packets++; @@ -1183,10 +1172,8 @@ static void vxlan_cleanup(unsigned long arg) /* Setup stats when device is created */ static int vxlan_init(struct net_device *dev) { - struct vxlan_dev *vxlan = netdev_priv(dev); - - vxlan->stats = alloc_percpu(struct vxlan_stats); - if (!vxlan->stats) + dev->tstats = alloc_percpu(struct pcpu_tstats); + if (!dev->tstats) return -ENOMEM; return 0; @@ -1242,49 +1229,6 @@ static int vxlan_stop(struct net_device *dev) return 0; } -/* Merge per-cpu statistics */ -static struct rtnl_link_stats64 *vxlan_stats64(struct net_device *dev, - struct rtnl_link_stats64 *stats) -{ - struct vxlan_dev *vxlan = netdev_priv(dev); - struct vxlan_stats tmp, sum = { 0 }; - unsigned int cpu; - - for_each_possible_cpu(cpu) { - unsigned int start; - const struct vxlan_stats *stats - = per_cpu_ptr(vxlan->stats, cpu); - - do { - start = u64_stats_fetch_begin_bh(&stats->syncp); - memcpy(&tmp, stats, sizeof(tmp)); - } while (u64_stats_fetch_retry_bh(&stats->syncp, start)); - - sum.tx_bytes += tmp.tx_bytes; - sum.tx_packets += tmp.tx_packets; - sum.rx_bytes += tmp.rx_bytes; - sum.rx_packets += tmp.rx_packets; - } - - stats->tx_bytes = sum.tx_bytes; - stats->tx_packets = sum.tx_packets; - stats->rx_bytes = sum.rx_bytes; - stats->rx_packets = sum.rx_packets; - - stats->multicast = dev->stats.multicast; - stats->rx_length_errors = dev->stats.rx_length_errors; - stats->rx_frame_errors = dev->stats.rx_frame_errors; - stats->rx_errors = dev->stats.rx_errors; - - stats->tx_dropped = dev->stats.tx_dropped; - stats->tx_carrier_errors = dev->stats.tx_carrier_errors; - stats->tx_aborted_errors = dev->stats.tx_aborted_errors; - stats->collisions = dev->stats.collisions; - stats->tx_errors = dev->stats.tx_errors; - - return stats; -} - /* Stub, nothing needs to be done. */ static void vxlan_set_multicast_list(struct net_device *dev) { @@ -1295,7 +1239,7 @@ static const struct net_device_ops vxlan_netdev_ops = { .ndo_open = vxlan_open, .ndo_stop = vxlan_stop, .ndo_start_xmit = vxlan_xmit, - .ndo_get_stats64 = vxlan_stats64, + .ndo_get_stats64 = ip_tunnel_get_stats64, .ndo_set_rx_mode = vxlan_set_multicast_list, .ndo_change_mtu = eth_change_mtu, .ndo_validate_addr = eth_validate_addr, @@ -1312,9 +1256,7 @@ static struct device_type vxlan_type = { static void vxlan_free(struct net_device *dev) { - struct vxlan_dev *vxlan = netdev_priv(dev); - - free_percpu(vxlan->stats); + free_percpu(dev->tstats); free_netdev(dev); }