From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
kernel-team@lists.ubuntu.com
Cc: Eric Dumazet <edumazet@google.com>,
Andy Gospodarek <gospo@cumulusnetworks.com>,
Jay Vosburgh <j.vosburgh@gmail.com>,
Veaceslav Falico <vfalico@gmail.com>,
"David S . Miller" <davem@davemloft.net>,
Kamal Mostafa <kamal@canonical.com>
Subject: [PATCH 4.2.y-ckt 16/93] bonding: fix bond_get_stats()
Date: Tue, 26 Apr 2016 11:16:16 -0700 [thread overview]
Message-ID: <1461694653-29506-17-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1461694653-29506-1-git-send-email-kamal@canonical.com>
4.2.8-ckt9 -stable review patch. If anyone has any objections, please let me know.
---8<------------------------------------------------------------
From: Eric Dumazet <edumazet@google.com>
[ Upstream commit fe30937b65354c7fec244caebbdaae68e28ca797 ]
bond_get_stats() can be called from rtnetlink (with RTNL held)
or from /proc/net/dev seq handler (with RCU held)
The logic added in commit 5f0c5f73e5ef ("bonding: make global bonding
stats more reliable") kind of assumed only one cpu could run there.
If multiple threads are reading /proc/net/dev, stats can be really
messed up after a while.
A second problem is that some fields are 32bit, so we need to properly
handle the wrap around problem.
Given that RTNL is not always held, we need to use
bond_for_each_slave_rcu().
Fixes: 5f0c5f73e5ef ("bonding: make global bonding stats more reliable")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Andy Gospodarek <gospo@cumulusnetworks.com>
Cc: Jay Vosburgh <j.vosburgh@gmail.com>
Cc: Veaceslav Falico <vfalico@gmail.com>
Reviewed-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
drivers/net/bonding/bond_main.c | 65 ++++++++++++++++++++++-------------------
include/net/bonding.h | 1 +
2 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 197ee34..6a64c35 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3269,6 +3269,30 @@ static int bond_close(struct net_device *bond_dev)
return 0;
}
+/* fold stats, assuming all rtnl_link_stats64 fields are u64, but
+ * that some drivers can provide 32bit values only.
+ */
+static void bond_fold_stats(struct rtnl_link_stats64 *_res,
+ const struct rtnl_link_stats64 *_new,
+ const struct rtnl_link_stats64 *_old)
+{
+ const u64 *new = (const u64 *)_new;
+ const u64 *old = (const u64 *)_old;
+ u64 *res = (u64 *)_res;
+ int i;
+
+ for (i = 0; i < sizeof(*_res) / sizeof(u64); i++) {
+ u64 nv = new[i];
+ u64 ov = old[i];
+
+ /* detects if this particular field is 32bit only */
+ if (((nv | ov) >> 32) == 0)
+ res[i] += (u32)nv - (u32)ov;
+ else
+ res[i] += nv - ov;
+ }
+}
+
static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
struct rtnl_link_stats64 *stats)
{
@@ -3277,43 +3301,23 @@ static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
struct list_head *iter;
struct slave *slave;
+ spin_lock(&bond->stats_lock);
memcpy(stats, &bond->bond_stats, sizeof(*stats));
- bond_for_each_slave(bond, slave, iter) {
- const struct rtnl_link_stats64 *sstats =
+ rcu_read_lock();
+ bond_for_each_slave_rcu(bond, slave, iter) {
+ const struct rtnl_link_stats64 *new =
dev_get_stats(slave->dev, &temp);
- struct rtnl_link_stats64 *pstats = &slave->slave_stats;
-
- stats->rx_packets += sstats->rx_packets - pstats->rx_packets;
- stats->rx_bytes += sstats->rx_bytes - pstats->rx_bytes;
- stats->rx_errors += sstats->rx_errors - pstats->rx_errors;
- stats->rx_dropped += sstats->rx_dropped - pstats->rx_dropped;
-
- stats->tx_packets += sstats->tx_packets - pstats->tx_packets;;
- stats->tx_bytes += sstats->tx_bytes - pstats->tx_bytes;
- stats->tx_errors += sstats->tx_errors - pstats->tx_errors;
- stats->tx_dropped += sstats->tx_dropped - pstats->tx_dropped;
-
- stats->multicast += sstats->multicast - pstats->multicast;
- stats->collisions += sstats->collisions - pstats->collisions;
-
- stats->rx_length_errors += sstats->rx_length_errors - pstats->rx_length_errors;
- stats->rx_over_errors += sstats->rx_over_errors - pstats->rx_over_errors;
- stats->rx_crc_errors += sstats->rx_crc_errors - pstats->rx_crc_errors;
- stats->rx_frame_errors += sstats->rx_frame_errors - pstats->rx_frame_errors;
- stats->rx_fifo_errors += sstats->rx_fifo_errors - pstats->rx_fifo_errors;
- stats->rx_missed_errors += sstats->rx_missed_errors - pstats->rx_missed_errors;
-
- stats->tx_aborted_errors += sstats->tx_aborted_errors - pstats->tx_aborted_errors;
- stats->tx_carrier_errors += sstats->tx_carrier_errors - pstats->tx_carrier_errors;
- stats->tx_fifo_errors += sstats->tx_fifo_errors - pstats->tx_fifo_errors;
- stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors - pstats->tx_heartbeat_errors;
- stats->tx_window_errors += sstats->tx_window_errors - pstats->tx_window_errors;
+
+ bond_fold_stats(stats, new, &slave->slave_stats);
/* save off the slave stats for the next run */
- memcpy(pstats, sstats, sizeof(*sstats));
+ memcpy(&slave->slave_stats, new, sizeof(*new));
}
+ rcu_read_unlock();
+
memcpy(&bond->bond_stats, stats, sizeof(*stats));
+ spin_unlock(&bond->stats_lock);
return stats;
}
@@ -4129,6 +4133,7 @@ void bond_setup(struct net_device *bond_dev)
struct bonding *bond = netdev_priv(bond_dev);
spin_lock_init(&bond->mode_lock);
+ spin_lock_init(&bond->stats_lock);
bond->params = bonding_defaults;
/* Initialize pointers */
diff --git a/include/net/bonding.h b/include/net/bonding.h
index 20defc0..c87fa4f 100644
--- a/include/net/bonding.h
+++ b/include/net/bonding.h
@@ -214,6 +214,7 @@ struct bonding {
* ALB mode (6) - to sync the use and modifications of its hash table
*/
spinlock_t mode_lock;
+ spinlock_t stats_lock;
u8 send_peer_notif;
u8 igmp_retrans;
#ifdef CONFIG_PROC_FS
--
2.7.4
next prev parent reply other threads:[~2016-04-26 18:45 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-26 18:16 [4.2.y-ckt stable] Linux 4.2.8-ckt9 stable review Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 01/93] usbnet: cleanup after bind() in probe() Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 02/93] tunnel: Clear IPCB(skb)->opt before dst_link_failure called Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 03/93] net: jme: fix suspend/resume on JMC260 Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 04/93] net: qca_spi: clear IFF_TX_SKB_SHARING Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 05/93] sctp: lack the check for ports in sctp_v6_cmp_addr Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 06/93] qmi_wwan: add Sierra Wireless EM74xx device ID Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 07/93] cdc_ncm: toggle altsetting to force reset before setup Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 08/93] udp6: fix UDP/IPv6 encap resubmit path Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 09/93] net: validate variable length ll headers Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 10/93] ax25: add link layer header validation function Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 11/93] packet: validate variable length ll headers Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 12/93] sh_eth: fix NULL pointer dereference in sh_eth_ring_format() Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 13/93] macvtap: always pass ethernet header in linear Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 14/93] farsync: fix off-by-one bug in fst_add_one Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 15/93] qlge: Fix receive packets drop Kamal Mostafa
2016-04-26 18:16 ` Kamal Mostafa [this message]
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 17/93] xfrm: Fix crash observed during device unregistration and decryption Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 18/93] qmi_wwan: add "D-Link DWM-221 B1" device id Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 19/93] rtnl: fix msg size calculation in if_nlmsg_size() Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 20/93] tun, bpf: fix suspicious RCU usage in tun_{attach, detach}_filter Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 21/93] ipv4: l2tp: fix a potential issue in l2tp_ip_recv Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 22/93] ipv6: l2tp: fix a potential issue in l2tp_ip6_recv Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 23/93] ipv6: Count in extension headers in skb->network_header Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 24/93] iwlwifi: pcie: lower the debug level for RSA semaphore access Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 25/93] HID: usbhid: fix inconsistent reset/resume/reset-resume behavior Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 26/93] ARM: OMAP2+: hwmod: Fix updating of sysconfig register Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 27/93] ARM: mvebu: Correct unit address for linksys Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 28/93] drm/qxl: fix cursor position with non-zero hotspot Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 29/93] Input: gtco - fix crash on detecting device without endpoints Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 30/93] s390/pci: add extra padding to function measurement block Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 31/93] ALSA: usb-audio: Add a sample rate quirk for Phoenix Audio TMX320 Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 32/93] dmaengine: hsu: correct use of channel status register Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 33/93] ALSA: usb-audio: Add a quirk for Plantronics BT300 Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 34/93] assoc_array: don't call compare_object() on a node Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 35/93] kvm: x86: do not leak guest xcr0 into host interrupt handlers Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 36/93] netlink: don't send NETLINK_URELEASE for unbound sockets Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 37/93] ALSA: hda/realtek - Enable the ALC292 dock fixup on the Thinkpad T460s Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 38/93] ALSA: usb-audio: Skip volume controls triggers hangup on Dell USB Dock Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 39/93] nl80211: check netlink protocol in socket release notification Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 40/93] debugfs: Make automount point inodes permanently empty Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 41/93] ALSA: hda - Fix regression of monitor_present flag in eld proc file Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 42/93] dmaengine: dw: fix master selection Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 43/93] lib: lz4: fixed zram with lz4 on big endian machines Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 44/93] usb: xhci: applying XHCI_PME_STUCK_QUIRK to Intel BXT B0 host Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 45/93] xhci: resume USB 3 roothub first Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 46/93] usb: host: xhci: add a new quirk XHCI_NO_64BIT_SUPPORT Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 47/93] usb: xhci: fix wild pointers in xhci_mem_cleanup Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 48/93] xhci: fix 10 second timeout on removal of PCI hotpluggable xhci controllers Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 49/93] USB: uas: Add a new NO_REPORT_LUNS quirk Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 50/93] usb: hcd: out of bounds access in for_each_companion Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 51/93] drm/radeon: fix initial connector audio value Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 52/93] drm/amdgpu: when suspending, if uvd/vce was running. need to cancel delay work Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 53/93] dm cache metadata: fix READ_LOCK macros and cleanup WRITE_LOCK macros Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 54/93] pinctrl: mediatek: correct debounce time unit in mtk_gpio_set_debounce Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 55/93] crypto: sha1-mb - use corrcet pointer while completing jobs Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 56/93] crypto: ccp - Prevent information leakage on export Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 57/93] dm cache metadata: fix cmd_read_lock() acquiring write lock Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 58/93] video: ARM CLCD: runtime check for Versatile Kamal Mostafa
2016-04-26 18:16 ` [PATCH 4.2.y-ckt 59/93] drm/i915/userptr: Hold mmref whilst calling get-user-pages Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 60/93] drm/i915: Use fw_domains_put_with_fifo() on HSW Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 61/93] ALSA: hda/realtek - Add ALC3234 headset mode for Optiplex 9020m Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 62/93] powerpc: scan_features() updates incorrect bits for REAL_LE Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 63/93] powerpc: Update cpu_user_features2 in scan_features() Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 64/93] powerpc: Update TM user feature bits " Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 65/93] drm/radeon: add a quirk for a XFX R9 270X Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 66/93] usb: gadget: f_fs: Fix use-after-free Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 67/93] futex: Handle unlock_pi race gracefully Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 68/93] futex: Acknowledge a new waiter in counter before plist Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 69/93] asm-generic/futex: Re-enable preemption in futex_atomic_cmpxchg_inatomic() Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 70/93] ALSA: pcxhr: Fix missing mutex unlock Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 71/93] drm/dp/mst: Validate port in drm_dp_payload_send_msg() Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 72/93] drm/amdgpu: use defines for CRTCs and AMFT blocks Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 73/93] drm/amdgpu: bump the afmt limit for CZ, ST, Polaris Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 74/93] drm/radeon: forbid mapping of userptr bo through radeon device file Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 75/93] amdgpu/uvd: add uvd fw version for amdgpu Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 76/93] drm: Loongson-3 doesn't fully support wc memory Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 77/93] x86/mm/xen: Suppress hugetlbfs in PV guests Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 78/93] x86 EDAC, sb_edac.c: Repair damage introduced when "fixing" channel address Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 79/93] x86 EDAC, sb_edac.c: Take account of channel hashing when needed Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 80/93] s390/scm_blk: fix deadlock for requests != REQ_TYPE_FS Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 81/93] packet: fix heap info leak in PACKET_DIAG_MCLIST sock_diag interface Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 82/93] net: sched: do not requeue a NULL skb Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 83/93] bpf/verifier: reject invalid LD_ABS | BPF_DW instruction Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 84/93] pinctrl: single: Fix pcs_parse_bits_in_pinctrl_entry to use __ffs than ffs Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 85/93] s390/spinlock: avoid yield to non existent cpu Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 86/93] net: bcmgenet: device stats are unsigned long Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 87/93] Input: pmic8xxx-pwrkey - fix algorithm for converting trigger delay Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 88/93] net: ethernet: davinci_emac: Fix Unbalanced pm_runtime_enable Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 89/93] net: ethernet: davinci_emac: Fix platform_data overwrite Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 90/93] net/mlx4_core: Implement pci_resume callback Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 91/93] net/mlx4_core: Avoid repeated calls to pci enable/disable Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 92/93] atl2: Disable unimplemented scatter/gather feature Kamal Mostafa
2016-04-26 18:17 ` [PATCH 4.2.y-ckt 93/93] openvswitch: use flow protocol when recalculating ipv6 checksums Kamal Mostafa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461694653-29506-17-git-send-email-kamal@canonical.com \
--to=kamal@canonical.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gospo@cumulusnetworks.com \
--cc=j.vosburgh@gmail.com \
--cc=kernel-team@lists.ubuntu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=vfalico@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®