From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bn3nam01on0124.outbound.protection.outlook.com ([104.47.33.124]:4000 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754393AbeDIAVN (ORCPT ); Sun, 8 Apr 2018 20:21:13 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: "Md. Islam" , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 165/189] sch_netem: Bug fixing in calculating Netem interval Date: Mon, 9 Apr 2018 00:19:00 +0000 Message-ID: <20180409001637.162453-165-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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: "Md. Islam" [ Upstream commit 043e337f555e610ad8237fd23522d97c968d72b9 ] In Kernel 4.15.0+, Netem does not work properly. Netem setup: tc qdisc add dev h1-eth0 root handle 1: netem delay 10ms 2ms Result: PING 172.16.101.2 (172.16.101.2) 56(84) bytes of data. 64 bytes from 172.16.101.2: icmp_seq=3D1 ttl=3D64 time=3D22.8 ms 64 bytes from 172.16.101.2: icmp_seq=3D2 ttl=3D64 time=3D10.9 ms 64 bytes from 172.16.101.2: icmp_seq=3D3 ttl=3D64 time=3D10.9 ms 64 bytes from 172.16.101.2: icmp_seq=3D5 ttl=3D64 time=3D11.4 ms 64 bytes from 172.16.101.2: icmp_seq=3D6 ttl=3D64 time=3D11.8 ms 64 bytes from 172.16.101.2: icmp_seq=3D4 ttl=3D64 time=3D4303 ms 64 bytes from 172.16.101.2: icmp_seq=3D10 ttl=3D64 time=3D11.2 ms 64 bytes from 172.16.101.2: icmp_seq=3D11 ttl=3D64 time=3D10.3 ms 64 bytes from 172.16.101.2: icmp_seq=3D7 ttl=3D64 time=3D4304 ms 64 bytes from 172.16.101.2: icmp_seq=3D8 ttl=3D64 time=3D4303 ms Patch: (rnd % (2 * sigma)) - sigma was overflowing s32. After applying the patch, I found following output which is desirable. PING 172.16.101.2 (172.16.101.2) 56(84) bytes of data. 64 bytes from 172.16.101.2: icmp_seq=3D1 ttl=3D64 time=3D21.1 ms 64 bytes from 172.16.101.2: icmp_seq=3D2 ttl=3D64 time=3D8.46 ms 64 bytes from 172.16.101.2: icmp_seq=3D3 ttl=3D64 time=3D9.00 ms 64 bytes from 172.16.101.2: icmp_seq=3D4 ttl=3D64 time=3D11.8 ms 64 bytes from 172.16.101.2: icmp_seq=3D5 ttl=3D64 time=3D8.36 ms 64 bytes from 172.16.101.2: icmp_seq=3D6 ttl=3D64 time=3D11.8 ms 64 bytes from 172.16.101.2: icmp_seq=3D7 ttl=3D64 time=3D8.11 ms 64 bytes from 172.16.101.2: icmp_seq=3D8 ttl=3D64 time=3D10.0 ms 64 bytes from 172.16.101.2: icmp_seq=3D9 ttl=3D64 time=3D11.3 ms 64 bytes from 172.16.101.2: icmp_seq=3D10 ttl=3D64 time=3D11.5 ms 64 bytes from 172.16.101.2: icmp_seq=3D11 ttl=3D64 time=3D10.2 ms Reviewed-by: Stephen Hemminger Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sched/sch_netem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index 2aeca57f9bd0..73c4bea821cb 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -327,7 +327,7 @@ static s64 tabledist(s64 mu, s32 sigma, =20 /* default uniform distribution */ if (dist =3D=3D NULL) - return (rnd % (2 * sigma)) - sigma + mu; + return ((rnd % (2 * sigma)) + mu) - sigma; =20 t =3D dist->table[rnd % dist->size]; x =3D (sigma % NETEM_DIST_SCALE) * t; --=20 2.15.1