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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240820123731.31568-2-yangtiezhu@loongson.cn>
Date: Tue, 20 Aug 2024 20:37:30 +0800
From: Tiezhu Yang <yangtiezhu@...ngson.cn>
To: Huacai Chen <chenhuacai@...nel.org>
Cc: Arnd Bergmann <arnd@...db.de>,
	loongarch@...ts.linux.dev,
	linux-kernel@...r.kernel.org
Subject: [PATCH v1 1/2] LoongArch: Define barrier_before_unreachable() as empty

When building kernel with -Os (CONFIG_CC_OPTIMIZE_FOR_SIZE=y) rather
than the default -O2 (CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE is not set),
there exist many objtool warnings "unreachable instruction", this is
because objtool couldn't find a code path to reach the instruction,
objdump shows that the unreachable instruction is related with BUG()
or unreachable().

In include/linux/compiler-gcc.h, there is an empty inline assembly

  #define barrier_before_unreachable() asm volatile("")

in the definition of unreachable() to work around GCC 7.0 after the
commit 173a3efd3edb ("bug.h: work around GCC PR82365 in BUG()") in
the year of 2018, the unreachable instruction is generated by it.

As far as I can see, this workaround is to fix warnings of frame sizes,
the default CONFIG_FRAME_WARN is 2048 on 64 bit system now, it seems
that there are no -Wframe-larger-than warnings in the current kernel
without this workaround.

I am not sure whether the GCC bug has been fixed, I can not find the
fixup in the link https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365
and in the GCC repo. So I am not sure whether it is time and proper
to remove this workaround in the common header totally, just remove
it in the arch specified header when compiling kernel with a newer
GCC version (for example GCC 12.1 or higher on LoongArch) at least.

For example:
arch/loongarch/kernel/cpu-probe.o: warning: objtool: cpu_probe+0x664: unreachable instruction

objdump -M no-aliases -D arch/loongarch/kernel/cpu-probe.o

Without this patch:

0000000000000000 <cpu_probe>:
 ...
 65c:   44000d80        bnez            $t0, 12 # 668 <.L345^B1+0x4>

0000000000000660 <.L10001^B2>:
 660:   002a0001        break           0x1

0000000000000664 <.L345^B1>:
 664:   53ff63ff        b               -160    # 5c4 <.L344^B1>
 668:   0280040c        addi.w          $t0, $zero, 1
 66c:   00006d8d        cpucfg          $t1, $t0

With this patch:

0000000000000000 <cpu_probe>:
 ...
 65c:   44000980        bnez            $t0, 8  # 664 <.L345^B1>

0000000000000660 <.L10001^B2>:
 660:   002a0001        break           0x1

0000000000000664 <.L345^B1>:
 664:   0280040c        addi.w          $t0, $zero, 1
 668:   00006d8d        cpucfg          $t1, $t0

Cc: stable@...r.kernel.org # 6.9+
Reported-by: kernel test robot <lkp@...el.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202407221208.6SSBeN9H-lkp@intel.com/
Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
---
 arch/loongarch/Kconfig                |  1 +
 arch/loongarch/include/asm/compiler.h | 13 +++++++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 arch/loongarch/include/asm/compiler.h

diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index 70f169210b52..3af0da76d103 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -102,6 +102,7 @@ config LOONGARCH
 	select GPIOLIB
 	select HAS_IOPORT
 	select HAVE_ARCH_AUDITSYSCALL
+	select HAVE_ARCH_COMPILER_H
 	select HAVE_ARCH_JUMP_LABEL
 	select HAVE_ARCH_JUMP_LABEL_RELATIVE
 	select HAVE_ARCH_KASAN
diff --git a/arch/loongarch/include/asm/compiler.h b/arch/loongarch/include/asm/compiler.h
new file mode 100644
index 000000000000..4f6adb8d533e
--- /dev/null
+++ b/arch/loongarch/include/asm/compiler.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Loongson Technology Corporation Limited
+ */
+#ifndef _ASM_COMPILER_H
+#define _ASM_COMPILER_H
+
+#ifdef barrier_before_unreachable
+#undef barrier_before_unreachable
+#define barrier_before_unreachable() do { } while (0)
+#endif
+
+#endif /* _ASM_COMPILER_H */
-- 
2.42.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ