Return-Path: Received: from mail-by2nam01on0118.outbound.protection.outlook.com ([104.47.34.118]:24760 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934016AbeCCWdV (ORCPT ); Sat, 3 Mar 2018 17:33:21 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Eric Dumazet , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 087/219] bonding: refine bond_fold_stats() wrap detection Date: Sat, 3 Mar 2018 22:28:46 +0000 Message-ID: <20180303222716.26640-87-alexander.levin@microsoft.com> References: <20180303222716.26640-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222716.26640-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Eric Dumazet [ Upstream commit 142c6594acbcc32391af9c15f8cd65c6c177698f ] Some device drivers reset their stats at down/up events, possibly fooling bonding stats, since they operate with relative deltas. It is nearly not possible to fix drivers, since some of them compute the tx/rx counters based on per rx/tx queue stats, and the queues can be reconfigured (ethtool -L) between the down/up sequence. Lets avoid accumulating 'negative' values that render bonding stats useless. It is better to lose small deltas, assuming the bonding stats are fetched at a reasonable frequency. Fixes: 5f0c5f73e5ef ("bonding: make global bonding stats more reliable") Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/bonding/bond_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_mai= n.c index 6b4b43319ffa..c3f3096b24ae 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -3331,12 +3331,17 @@ static void bond_fold_stats(struct rtnl_link_stats6= 4 *_res, for (i =3D 0; i < sizeof(*_res) / sizeof(u64); i++) { u64 nv =3D new[i]; u64 ov =3D old[i]; + s64 delta =3D nv - ov; =20 /* detects if this particular field is 32bit only */ if (((nv | ov) >> 32) =3D=3D 0) - res[i] +=3D (u32)nv - (u32)ov; - else - res[i] +=3D nv - ov; + delta =3D (s64)(s32)((u32)nv - (u32)ov); + + /* filter anomalies, some drivers reset their stats + * at down/up events. + */ + if (delta > 0) + res[i] +=3D delta; } } =20 --=20 2.14.1