* [PATCH] Fix link error in 32bit arch because of 64bit division
@ 2016-09-27 7:42 Vishwanath Pai
2016-09-27 10:23 ` Liping Zhang
2016-09-27 13:32 ` Eric Dumazet
0 siblings, 2 replies; 3+ messages in thread
From: Vishwanath Pai @ 2016-09-27 7:42 UTC (permalink / raw)
To: pablo
Cc: kaber, kadlec, johunt, netfilter-devel, coreteam, netdev,
pai.vishwain, zlpnobody
Fix link error in 32bit arch because of 64bit division
Division of 64bit integers will cause linker error undefined reference
to `__udivdi3'. Fix this by replacing divisions with div64_64
Signed-off-by: Vishwanath Pai <vpai@akamai.com>
---
net/netfilter/xt_hashlimit.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 44a095e..7fc694e 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -465,19 +465,20 @@ static u64 user2credits(u64 user, int revision)
{
if (revision == 1) {
/* If multiplying would overflow... */
- if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY_v1))
+ if (user > div64_u64(0xFFFFFFFF, (HZ*CREDITS_PER_JIFFY_v1)))
/* Divide first. */
- return (user / XT_HASHLIMIT_SCALE) *\
+ return div64_u64(user, XT_HASHLIMIT_SCALE) *\
HZ * CREDITS_PER_JIFFY_v1;
- return (user * HZ * CREDITS_PER_JIFFY_v1) \
- / XT_HASHLIMIT_SCALE;
+ return div64_u64((user * HZ * CREDITS_PER_JIFFY_v1),
+ XT_HASHLIMIT_SCALE);
} else {
- if (user > 0xFFFFFFFFFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
- return (user / XT_HASHLIMIT_SCALE_v2) *\
+ if (user > div64_u64(0xFFFFFFFFFFFFFFFF, (HZ*CREDITS_PER_JIFFY)))
+ return div64_u64(user, XT_HASHLIMIT_SCALE_v2) *\
HZ * CREDITS_PER_JIFFY;
- return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE_v2;
+ return div64_u64((user * HZ * CREDITS_PER_JIFFY),
+ XT_HASHLIMIT_SCALE_v2);
}
}
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix link error in 32bit arch because of 64bit division
2016-09-27 7:42 [PATCH] Fix link error in 32bit arch because of 64bit division Vishwanath Pai
@ 2016-09-27 10:23 ` Liping Zhang
2016-09-27 13:32 ` Eric Dumazet
1 sibling, 0 replies; 3+ messages in thread
From: Liping Zhang @ 2016-09-27 10:23 UTC (permalink / raw)
To: Vishwanath Pai
Cc: Pablo Neira Ayuso, Patrick McHardy, Jozsef Kadlecsik, johunt,
Netfilter Developer Mailing List, coreteam,
Linux Kernel Network Developers, Vishwanath Pai
Hi Vishwanath Pai,
2016-09-27 15:42 GMT+08:00 Vishwanath Pai <vpai@akamai.com>:
> Fix link error in 32bit arch because of 64bit division
This should be "netfilter: xt_hashlimit: fix ... "
>
> --- a/net/netfilter/xt_hashlimit.c
> +++ b/net/netfilter/xt_hashlimit.c
> @@ -465,19 +465,20 @@ static u64 user2credits(u64 user, int revision)
> {
> if (revision == 1) {
> /* If multiplying would overflow... */
> - if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY_v1))
> + if (user > div64_u64(0xFFFFFFFF, (HZ*CREDITS_PER_JIFFY_v1)))
Here divisor and dividend are all 32-bit integer, so covert "/" to div64_u64
seems unnecessary.
> /* Divide first. */
> - return (user / XT_HASHLIMIT_SCALE) *\
> + return div64_u64(user, XT_HASHLIMIT_SCALE) *\
> HZ * CREDITS_PER_JIFFY_v1;
>
> - return (user * HZ * CREDITS_PER_JIFFY_v1) \
> - / XT_HASHLIMIT_SCALE;
> + return div64_u64((user * HZ * CREDITS_PER_JIFFY_v1),
> + XT_HASHLIMIT_SCALE);
> } else {
> - if (user > 0xFFFFFFFFFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
> - return (user / XT_HASHLIMIT_SCALE_v2) *\
> + if (user > div64_u64(0xFFFFFFFFFFFFFFFF, (HZ*CREDITS_PER_JIFFY)))
0xFFFFFFFFFFFFFFFF and "HZ*CREDITS_PER_JIFFY" are both
constant, and GCC will do constant folding optimization, so I think
convert "/" to div64_u64 here is also unnecessary.
> + return div64_u64(user, XT_HASHLIMIT_SCALE_v2) *\
> HZ * CREDITS_PER_JIFFY;
>
> - return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE_v2;
> + return div64_u64((user * HZ * CREDITS_PER_JIFFY),
> + XT_HASHLIMIT_SCALE_v2);
> }
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix link error in 32bit arch because of 64bit division
2016-09-27 7:42 [PATCH] Fix link error in 32bit arch because of 64bit division Vishwanath Pai
2016-09-27 10:23 ` Liping Zhang
@ 2016-09-27 13:32 ` Eric Dumazet
1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2016-09-27 13:32 UTC (permalink / raw)
To: Vishwanath Pai
Cc: pablo, kaber, kadlec, johunt, netfilter-devel, coreteam, netdev,
pai.vishwain, zlpnobody
On Tue, 2016-09-27 at 03:42 -0400, Vishwanath Pai wrote:
> Fix link error in 32bit arch because of 64bit division
>
> Division of 64bit integers will cause linker error undefined reference
> to `__udivdi3'. Fix this by replacing divisions with div64_64
>
> Signed-off-by: Vishwanath Pai <vpai@akamai.com>
>
> ---
> net/netfilter/xt_hashlimit.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
> index 44a095e..7fc694e 100644
> --- a/net/netfilter/xt_hashlimit.c
> +++ b/net/netfilter/xt_hashlimit.c
> @@ -465,19 +465,20 @@ static u64 user2credits(u64 user, int revision)
> {
> if (revision == 1) {
> /* If multiplying would overflow... */
> - if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY_v1))
> + if (user > div64_u64(0xFFFFFFFF, (HZ*CREDITS_PER_JIFFY_v1)))
How can this be needed ? 0xFFFFFFFF is 32bits, compiler knows how to
compute 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY_v1) itself, without using a
64 bit divide !
Please be selective.
> /* Divide first. */
> - return (user / XT_HASHLIMIT_SCALE) *\
> + return div64_u64(user, XT_HASHLIMIT_SCALE) *\
> HZ * CREDITS_PER_JIFFY_v1;
>
> - return (user * HZ * CREDITS_PER_JIFFY_v1) \
> - / XT_HASHLIMIT_SCALE;
> + return div64_u64((user * HZ * CREDITS_PER_JIFFY_v1),
> + XT_HASHLIMIT_SCALE);
> } else {
> - if (user > 0xFFFFFFFFFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
> - return (user / XT_HASHLIMIT_SCALE_v2) *\
Probably same remark here.
> + if (user > div64_u64(0xFFFFFFFFFFFFFFFF, (HZ*CREDITS_PER_JIFFY)))
> + return div64_u64(user, XT_HASHLIMIT_SCALE_v2) *\
> HZ * CREDITS_PER_JIFFY;
>
> - return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE_v2;
> + return div64_u64((user * HZ * CREDITS_PER_JIFFY),
> + XT_HASHLIMIT_SCALE_v2);
> }
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-27 13:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-27 7:42 [PATCH] Fix link error in 32bit arch because of 64bit division Vishwanath Pai
2016-09-27 10:23 ` Liping Zhang
2016-09-27 13:32 ` Eric Dumazet
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.