From patchwork Fri Sep 30 16:05:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101727 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp373672qgf; Fri, 30 Sep 2016 09:08:19 -0700 (PDT) X-Received: by 10.66.158.200 with SMTP id ww8mr6742021pab.116.1475251699236; Fri, 30 Sep 2016 09:08:19 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u23si20660931pfa.234.2016.09.30.09.08.18; Fri, 30 Sep 2016 09:08:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933842AbcI3QIR (ORCPT + 27 others); Fri, 30 Sep 2016 12:08:17 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:62006 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933296AbcI3QIH (ORCPT ); Fri, 30 Sep 2016 12:08:07 -0400 Received: from wuerfel.lan. ([78.43.20.153]) by mrelayeu.kundenserver.de (mreue101) with ESMTPA (Nemesis) id 0MYNd3-1bUOrv0KTR-00V8ju; Fri, 30 Sep 2016 18:07:58 +0200 From: Arnd Bergmann To: Pablo Neira Ayuso Cc: Arnd Bergmann , Patrick McHardy , Jozsef Kadlecsik , "David S. Miller" , Joshua Hunt , Vishwanath Pai , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] netfilter: xt_hashlimit: uses div_u64 for division Date: Fri, 30 Sep 2016 18:05:36 +0200 Message-Id: <20160930160559.4102745-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160930160559.4102745-1-arnd@arndb.de> References: <20160930160559.4102745-1-arnd@arndb.de> X-Provags-ID: V03:K0:sWtNZd45SMsy4L1SQe8Oz85YdCuM5iQNChR4S9s4CPGseDhFQ7a MS9ljvmzxuRolFoaRN5C+ZBBSe4Mz95Sjx4y4g2E3yToiImgbRtpMRo8k6rI1vSHfIKN3bz 2NYsmPl/1ZJOTFA1bMqA3pI1UjMM8LEXPT+hpkMYvG8lByMQ6E1c6C+ljWKMuC6hP3UdAso 6pO8jjefXtd3ugPat5CYw== X-UI-Out-Filterresults: notjunk:1; V01:K0:9JZzylGP5hE=:WUXCMFmAQA19cUMKTE+R1p rq/2OY36o4ZOCzRl3gznjVdkdR1DcJUUbZcfTBmjFKarnyTMIDfeeS8aG7YkaOnrDH9ubsQnv PVnS4PwdA01aM2nt5MBjh2AffmQQtm/gjKxC5C3tBewnyPyZJpzi1wjDMY8abgm9hvuKx2w49 chp8HyHEEuKVO7Jd6JPZFJmCTh3KCLqzJAFZcuTscavnMZUHvgZI4S4ancjGzc5BMFNlwkGVl B924sfUhbhkywWhXS6KKXiSBHV02GyWbaHiAUXeXCDrr7YuIxJwW/2gibNdDEFKoWQ55BGGcd MHg6gE0Q2TbqSb1wWtwHrYdbnBk1oozpngcilmq0r4Ra+8SetNoNhfb47pO7ejCXk6uNaDLLg j3BgJ1ZAKINQOtHSeoXz7KibTPkWr/dvACEvaGUAjGsw+zjZxwqtPmgHtAxdK5XMSMZPqIeL6 liA2uiyM8fij/u4+JrfXImyHkHLOa6lbbzxd2Zc8NqCcsnIE4PQDY1vHU7kCzTHZ70aaQIpix 6FhCf1/3QwuguMUVmzWRszcrmOzT8EgBv4+KciJF/dnEkWxDISxzGiVU8DAS4K0Zak8eVzPaw VsJhzMe5W0kjTRyCVXFyPXExccljwBzBXql3d+3jYu8qT77nru6Lk0a5Fh+nkrHhl2jEL8Teb D3bln24pWB/St99JJU7sI667TeX7ioXpEGitLSALtjRGO5bNK8fLQRD6qzFAqVXwrOeA= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The newly added support for high-resolution pps rates introduced multiple 64-bit division operations in one function, which fails on all 32-bit architectures: net/netfilter/xt_hashlimit.o: In function `user2credits': xt_hashlimit.c:(.text.user2credits+0x3c): undefined reference to `__aeabi_uldivmod' xt_hashlimit.c:(.text.user2credits+0x68): undefined reference to `__aeabi_uldivmod' xt_hashlimit.c:(.text.user2credits+0x88): undefined reference to `__aeabi_uldivmod' This replaces the division with an explicit call to div_u64 for version 2 to documents that this is a slow operation, and reverts back to 32-bit arguments for the version 1 data to restore the original faster 32-bit division. With both changes combined, we no longer get a link error. Fixes: 11d5f15723c9 ("netfilter: xt_hashlimit: Create revision 2 to support higher pps rates") Signed-off-by: Arnd Bergmann --- Vishwanath Pai already sent a patch for this, and I did my version independently. The difference is that his version also the more expensive division for the version 1 variant that doesn't need it. See also http://patchwork.ozlabs.org/patch/676713/ --- net/netfilter/xt_hashlimit.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) -- 2.9.0 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c index 44a095ecc7b7..3d5525df6eb3 100644 --- a/net/netfilter/xt_hashlimit.c +++ b/net/netfilter/xt_hashlimit.c @@ -464,20 +464,23 @@ static u32 xt_hashlimit_len_to_chunks(u32 len) static u64 user2credits(u64 user, int revision) { if (revision == 1) { + u32 user32 = user; /* use 32-bit division */ + /* If multiplying would overflow... */ - if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY_v1)) + if (user32 > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY_v1)) /* Divide first. */ - return (user / XT_HASHLIMIT_SCALE) *\ + return (user32 / XT_HASHLIMIT_SCALE) * HZ * CREDITS_PER_JIFFY_v1; - return (user * HZ * CREDITS_PER_JIFFY_v1) \ - / XT_HASHLIMIT_SCALE; + return (user32 * HZ * CREDITS_PER_JIFFY_v1) / + XT_HASHLIMIT_SCALE; } else { if (user > 0xFFFFFFFFFFFFFFFF / (HZ*CREDITS_PER_JIFFY)) - return (user / XT_HASHLIMIT_SCALE_v2) *\ - HZ * CREDITS_PER_JIFFY; + return div_u64_u64(user, XT_HASHLIMIT_SCALE_v2) * + HZ * CREDITS_PER_JIFFY; - return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE_v2; + return div_u64_u64(user * HZ * CREDITS_PER_JIFFY, + XT_HASHLIMIT_SCALE_v2); } }