netfilter: xt_hashlimit: avoid 64-bit division
Subsystems (3)
PATCH 1/1 netfilter: xt_hashlimit: avoid 64-bit division
64-bit division is expensive on 32-bit architectures, and requires a special function call to avoid a link error like:
net/netfilter/xt_hashlimit.o: In function `hashlimit_mt_common':
xt_hashlimit.c:(.text+0x1328): undefined reference to `__aeabi_uldivmod'
In the case of hashlimit_mt_common, we don't actually need a 64-bit operation, we can simply rewrite the function slightly to make that clear to the compiler.
--- net/netfilter/xt_hashlimit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/xt_hashlimit.c +4 -1
@@ -531,7 +531,10 @@ static u64 user2rate_bytes(u64 user) {u64 r; - r = user ?0xFFFFFFFFULL / user :0xFFFFFFFFULL ; +if (user >0xFFFFFFFFULL ) +return 0 ; + + r = user ?0xFFFFFFFFULL / (u32 )user :0xFFFFFFFFULL ; r = (r -1 ) <<4 ;return r; }
Signature · 1 line
2.9.0
Quoted 23 lines · Arnd Bergmann
64-bit division is expensive on 32-bit architectures, and requires a special function call to avoid a link error like:
net/netfilter/xt_hashlimit.o: In function `hashlimit_mt_common':
xt_hashlimit.c:(.text+0x1328): undefined reference to `__aeabi_uldivmod'In the case of
hashlimit_mt_common, we don't actually need a 64-bit operation, we can simply rewrite the function slightly to make that clear to the compiler.Fixes bea74641e378 ("netfilter: xt_hashlimit: add rate match mode")Signed-off-by Arnd Bergmann <[email protected]>--- net/netfilter/xt_hashlimit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/netfilter/xt_hashlimit.c +0
-0@@ -531,7 +531,10 @@ static u64 user2rate_bytes(u64 user) {
net/netfilter/xt_hashlimit.c static u64 user2rate_bytes(u64 user) · line 540
Quoted 10 lines
net/netfilter/xt_hashlimit.c +4
-1u64 r; - r = user ?0xFFFFFFFFULL / user :0xFFFFFFFFULL ; +if (user >0xFFFFFFFFULL ) +return 0 ; + + r = user ?0xFFFFFFFFULL / (u32 )user :0xFFFFFFFFULL ; r = (r -1 ) <<4 ;return r; }
I have submitted another patch to fix this:
https://patchwork.ozlabs.org/patch/809881/
We have seen this problem before, I was careful not to introduce this again in the new patch but clearly I overlooked this particular line :(
In the other cases we fixed it by replacing division with div64_u64().
-Vishwanath
Quoted 38 lines · Vishwanath Pai
Quoted 23 lines · Arnd Bergmann
64-bit division is expensive on 32-bit architectures, and requires a special function call to avoid a link error like:
net/netfilter/xt_hashlimit.o: In function `hashlimit_mt_common':
xt_hashlimit.c:(.text+0x1328): undefined reference to `__aeabi_uldivmod'In the case of
hashlimit_mt_common, we don't actually need a 64-bit operation, we can simply rewrite the function slightly to make that clear to the compiler.Fixes bea74641e378 ("netfilter: xt_hashlimit: add rate match mode")Signed-off-by Arnd Bergmann <[email protected]>--- net/netfilter/xt_hashlimit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/netfilter/xt_hashlimit.c +0
-0@@ -531,7 +531,10 @@ static u64 user2rate_bytes(u64 user) {net/netfilter/xt_hashlimit.c static u64 user2rate_bytes(u64 user) · line 540
Quoted 10 lines
net/netfilter/xt_hashlimit.c +4
-1u64 r; - r = user ?0xFFFFFFFFULL / user :0xFFFFFFFFULL ; +if (user >0xFFFFFFFFULL ) +return 0 ; + + r = user ?0xFFFFFFFFULL / (u32 )user :0xFFFFFFFFULL ; r = (r -1 ) <<4 ;return r; }I have submitted another patch to fix this:
https://patchwork.ozlabs.org/patch/809881/
Quoted 4 lines
We have seen this problem before, I was careful not to introduce this again in the new patch but clearly I overlooked this particular line :(
In the other cases we fixed it by replacing division with
div64_u64().
div64_u64() seems needlessly expensive here since the dividend is known to be a 32-bit number. I guess the function is not called frequently though, so it doesn't matter much.
Arnd
Pablo Neira Ayuso
maintainerQuoted 39 lines · Arnd Bergmann
Quoted 38 lines · Vishwanath Pai
Quoted 23 lines · Arnd Bergmann
64-bit division is expensive on 32-bit architectures, and requires a special function call to avoid a link error like:
net/netfilter/xt_hashlimit.o: In function `hashlimit_mt_common':
xt_hashlimit.c:(.text+0x1328): undefined reference to `__aeabi_uldivmod'In the case of
hashlimit_mt_common, we don't actually need a 64-bit operation, we can simply rewrite the function slightly to make that clear to the compiler.Fixes bea74641e378 ("netfilter: xt_hashlimit: add rate match mode")Signed-off-by Arnd Bergmann <[email protected]>--- net/netfilter/xt_hashlimit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/netfilter/xt_hashlimit.c +0
-0@@ -531,7 +531,10 @@ static u64 user2rate_bytes(u64 user) {net/netfilter/xt_hashlimit.c static u64 user2rate_bytes(u64 user) · line 540
Quoted 10 lines
net/netfilter/xt_hashlimit.c +4
-1u64 r; - r = user ?0xFFFFFFFFULL / user :0xFFFFFFFFULL ; +if (user >0xFFFFFFFFULL ) +return 0 ; + + r = user ?0xFFFFFFFFULL / (u32 )user :0xFFFFFFFFULL ; r = (r -1 ) <<4 ;return r; }I have submitted another patch to fix this:
https://patchwork.ozlabs.org/patch/809881/
Quoted 8 lines
Quoted 4 lines
We have seen this problem before, I was careful not to introduce this again in the new patch but clearly I overlooked this particular line :(
In the other cases we fixed it by replacing division with
div64_u64().
div64_u64()seems needlessly expensive here since the dividend is known to be a 32-bit number. I guess the function is not called frequently though, so it doesn't matter much.
This is called from the packet path, only for the first packet for each new destination IP entry in the hashtable, still from the datapath. So if we can take something faster (for 32 bit arches) that is correct, I think it's sensible to take.
Let me know in any case.
Quoted 49 lines · Pablo Neira Ayuso
Quoted 39 lines · Arnd Bergmann
Quoted 38 lines · Vishwanath Pai
Quoted 23 lines · Arnd Bergmann
64-bit division is expensive on 32-bit architectures, and requires a special function call to avoid a link error like:
net/netfilter/xt_hashlimit.o: In function `hashlimit_mt_common':
xt_hashlimit.c:(.text+0x1328): undefined reference to `__aeabi_uldivmod'In the case of
hashlimit_mt_common, we don't actually need a 64-bit operation, we can simply rewrite the function slightly to make that clear to the compiler.Fixes bea74641e378 ("netfilter: xt_hashlimit: add rate match mode")Signed-off-by Arnd Bergmann <[email protected]>--- net/netfilter/xt_hashlimit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/netfilter/xt_hashlimit.c +0
-0@@ -531,7 +531,10 @@ static u64 user2rate_bytes(u64 user) {net/netfilter/xt_hashlimit.c static u64 user2rate_bytes(u64 user) · line 540
Quoted 10 lines
net/netfilter/xt_hashlimit.c +4
-1u64 r; - r = user ?0xFFFFFFFFULL / user :0xFFFFFFFFULL ; +if (user >0xFFFFFFFFULL ) +return 0 ; + + r = user ?0xFFFFFFFFULL / (u32 )user :0xFFFFFFFFULL ; r = (r -1 ) <<4 ;return r; }I have submitted another patch to fix this:
https://patchwork.ozlabs.org/patch/809881/Quoted 8 lines
Quoted 4 lines
We have seen this problem before, I was careful not to introduce this again in the new patch but clearly I overlooked this particular line :(
In the other cases we fixed it by replacing division with
div64_u64().
div64_u64()seems needlessly expensive here since the dividend is known to be a 32-bit number. I guess the function is not called frequently though, so it doesn't matter much.
Quoted 6 lines
This is called from the packet path, only for the first packet for each new destination IP entry in the hashtable, still from the datapath. So if we can take something faster (for 32 bit arches) that is correct, I think it's sensible to take.
Let me know in any case.
I think my version should be slightly better then, unless someone finds something wrong with it.
Arnd
Hi Arnd,
Quoted 6 lines · Arnd Bergmann
64-bit division is expensive on 32-bit architectures, and requires a special function call to avoid a link error like:
net/netfilter/xt_hashlimit.o: In function `hashlimit_mt_common':
xt_hashlimit.c:(.text+0x1328): undefined reference to `__aeabi_uldivmod'
Quoted 6 lines
In the case of
hashlimit_mt_common, we don't actually need a 64-bit operation, we can simply rewrite the function slightly to make that clear to the compiler.Fixes bea74641e378 ("netfilter: xt_hashlimit: add rate match mode")Signed-off-by Arnd Bergmann <[email protected]>
Thanks, this fixes a similar issue (__udivdi3 undefined) on m68k.
Gr{oetje,eeting}s,
Geert