lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1617359240-16609-1-git-send-email-yangtiezhu@loongson.cn>
Date:   Fri,  2 Apr 2021 18:27:20 +0800
From:   Tiezhu Yang <yangtiezhu@...ngson.cn>
To:     Thomas Bogendoerfer <tsbogend@...ha.franken.de>
Cc:     linux-mips@...r.kernel.org, linux-kernel@...r.kernel.org,
        "Maciej W. Rozycki" <macro@...am.me.uk>,
        Xuefeng Li <lixuefeng@...ngson.cn>
Subject: [PATCH v3] MIPS: Check __clang__ to avoid performance influence with GCC in csum_tcpudp_nofold()

The asm code in csum_tcpudp_nofold() is performance critical, I am sorry
for the poorly considered implementation about the performance influence
with GCC in the commit 198688edbf77 ("MIPS: Fix inline asm input/output
type mismatch in checksum.h used with Clang").

Using __clang__ instead of CC_IS_CLANG as check condition, because it
still occurs build error under CC_IS_GCC when make M=samples/bpf which
used with Clang compiler.

With this patch, we can build successfully by both GCC and Clang,
at the same time, the logic is much clear to avoid the potential
performance influence with GCC.

Here are some test data, the config file is loongson3_defconfig, the gcc
version is 10.2.1, we can see that the size has no differences between (1)
and (3).

(1) linux-5.12-rc5.nopatch:
without commit 198688edbf77 ("MIPS: Fix inline asm input/output type
mismatch in checksum.h used with Clang").

(2) linux-5.12-rc5:
with commit 198688edbf77 ("MIPS: Fix inline asm input/output type
mismatch in checksum.h used with Clang").

(3) linux-5.12-rc5.newpatch:
with this patch based on linux-5.12-rc5.

loongson@...ux:~$ size --format=GNU linux-5.12-rc5.nopatch/vmlinux
      text       data        bss      total filename
  10273312    3489518   17865568   31628398 linux-5.12-rc5.nopatch/vmlinux

loongson@...ux:~$ size --format=GNU linux-5.12-rc5/vmlinux
      text       data        bss      total filename
  10273536    3489550   17865568   31628654 linux-5.12-rc5/vmlinux

loongson@...ux:~$ size --format=GNU linux-5.12-rc5.newpatch/vmlinux
      text       data        bss      total filename
  10273312    3489518   17865568   31628398 linux-5.12-rc5.newpatch/vmlinux

As far as I can tell, the differences between (1) and (2) is due to the
following affected objects:

loongson@...ux:~$ size --format=GNU linux-5.12-rc5.nopatch/net/ipv4/tcp_ipv4.o
      text       data        bss      total filename
     20684       2268        576      23528 linux-5.12-rc5.nopatch/net/ipv4/tcp_ipv4.o
loongson@...ux:~$ size --format=GNU linux-5.12-rc5/net/ipv4/tcp_ipv4.o
      text       data        bss      total filename
     20700       2268        576      23544 linux-5.12-rc5/net/ipv4/tcp_ipv4.o

loongson@...ux:~$ size --format=GNU linux-5.12-rc5.nopatch/net/ipv4/tcp_offload.o
      text       data        bss      total filename
      3584        167          0       3751 linux-5.12-rc5.nopatch/net/ipv4/tcp_offload.o
loongson@...ux:~$ size --format=GNU linux-5.12-rc5/net/ipv4/tcp_offload.o
      text       data        bss      total filename
      3600        167          0       3767 linux-5.12-rc5/net/ipv4/tcp_offload.o

loongson@...ux:~$ size --format=GNU linux-5.12-rc5.nopatch/net/ipv4/udp.o
      text       data        bss      total filename
     30068       3018         32      33118 linux-5.12-rc5.nopatch/net/ipv4/udp.o
loongson@...ux:~$ size --format=GNU linux-5.12-rc5/net/ipv4/udp.o
      text       data        bss      total filename
     30100       3018         32      33150 linux-5.12-rc5/net/ipv4/udp.o

loongson@...ux:~$ size --format=GNU linux-5.12-rc5.nopatch/net/ipv4/udp_offload.o
      text       data        bss      total filename
      6624        311          0       6935 linux-5.12-rc5.nopatch/net/ipv4/udp_offload.o
loongson@...ux:~$ size --format=GNU linux-5.12-rc5/net/ipv4/udp_offload.o
      text       data        bss      total filename
      6640        311          0       6951 linux-5.12-rc5/net/ipv4/udp_offload.o

loongson@...ux:~$ size --format=GNU linux-5.12-rc5.nopatch/net/netfilter/nf_nat.o
      text       data        bss      total filename
     20804       2102       4112      27018 linux-5.12-rc5.nopatch/net/netfilter/nf_nat.o
loongson@...ux:~$ size --format=GNU linux-5.12-rc5/net/netfilter/nf_nat.o
      text       data        bss      total filename
     20820       2102       4112      27034 linux-5.12-rc5/net/netfilter/nf_nat.o

loongson@...ux:~$ size --format=GNU linux-5.12-rc5.nopatch/net/netfilter/nf_nat_proto.o
      text       data        bss      total filename
      7392        770          0       8162 linux-5.12-rc5.nopatch/net/netfilter/nf_nat_proto.o
loongson@...ux:~$ size --format=GNU linux-5.12-rc5/net/netfilter/nf_nat_proto.o
      text       data        bss      total filename
      7408        770          0       8178 linux-5.12-rc5/net/netfilter/nf_nat_proto.o

loongson@...ux:~$ size --format=GNU linux-5.12-rc5.nopatch/net/ipv4/netfilter/nf_reject_ipv4.o
      text       data        bss      total filename
      3776        429          0       4205 linux-5.12-rc5.nopatch/net/ipv4/netfilter/nf_reject_ipv4.o
loongson@...ux:~$ size --format=GNU linux-5.12-rc5/net/ipv4/netfilter/nf_reject_ipv4.o
      text       data        bss      total filename
      3792        429          0       4221 linux-5.12-rc5/net/ipv4/netfilter/nf_reject_ipv4.o

Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
---
 arch/mips/include/asm/checksum.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/mips/include/asm/checksum.h b/arch/mips/include/asm/checksum.h
index 1e6c135..e1f80407 100644
--- a/arch/mips/include/asm/checksum.h
+++ b/arch/mips/include/asm/checksum.h
@@ -130,7 +130,11 @@ static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
 					__u32 len, __u8 proto,
 					__wsum sum)
 {
+#ifdef __clang__
 	unsigned long tmp = (__force unsigned long)sum;
+#else
+	__wsum tmp = sum;
+#endif
 
 	__asm__(
 	"	.set	push		# csum_tcpudp_nofold\n"
-- 
2.1.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ