All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] MIPS: Override barrier_before_unreachable() to fix microMIPS
@ 2018-04-17 10:11 James Hogan
  2018-04-17 10:11 ` [PATCH v3 1/3] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h James Hogan
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: James Hogan @ 2018-04-17 10:11 UTC (permalink / raw)
  To: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha
  Cc: linux-arch, linux-kernel, James Hogan, Ralf Baechle, Paul Burton,
	Matthew Fortune, Robert Suchanek

This series overrides barrier_before_unreachable() for MIPS to add an
.insn assembler directive.

Due to the subsequent __builtin_unreachable(), the assembler can't tell
that a label on the empty inline asm is code rather than data, so any
microMIPS branches targetting it (which sadly can't be removed) raise
errors due to the mismatching ISA mode, Adding the .insn in patch 3
tells the assembler that it should be treated as code.

To do this we add a new standard asm/compiler.h for architecture
overrides in patch 2. There are a few existing asm/compiler.h files
already existing, most of which are fairly simple and don't include
anything else (arm, arm64, mips). Unfortunately the alpha one includes
linux/compiler.h though, so it can undefine some inline macros. On
Arnd's suggestion this is converted to use OPTIMIZE_INLINING instead in
patch 1. A build of alpha's defconfig on GCC 7.3 before and after this
series results in the following size differences, which appear harmless
to me:

$ ./scripts/bloat-o-meter vmlinux.1 vmlinux.2
add/remove: 1/1 grow/shrink: 3/0 up/down: 264/-348 (-84)
Function                                     old     new   delta
cap_bprm_set_creds                          1496    1664    +168
cap_issubset                                   -      68     +68
flex_array_put                               328     344     +16
cap_capset                                   488     500     +12
nonroot_raised_pE.constprop                  348       -    -348
Total: Before=5823709, After=5823625, chg -0.00%

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paul Burton <paul.burton@mips.com>
Cc: Matthew Fortune <matthew.fortune@mips.com>
Cc: Robert Suchanek <robert.suchanek@mips.com>
Cc: linux-alpha@vger.kernel.org
Cc: linux-mips@linux-mips.org
Cc: linux-arch@vger.kernel.org

James Hogan (1):
  alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h

Paul Burton (2):
  compiler.h: Allow arch-specific overrides
  MIPS: Workaround GCC __builtin_unreachable reordering bug

 arch/alpha/Kconfig                 |  6 ++++++
 arch/alpha/include/asm/compiler.h  | 11 -----------
 arch/arc/include/asm/Kbuild        |  1 +
 arch/c6x/include/asm/Kbuild        |  1 +
 arch/h8300/include/asm/Kbuild      |  1 +
 arch/hexagon/include/asm/Kbuild    |  1 +
 arch/ia64/include/asm/Kbuild       |  1 +
 arch/m68k/include/asm/Kbuild       |  1 +
 arch/microblaze/include/asm/Kbuild |  1 +
 arch/mips/include/asm/compiler.h   | 23 +++++++++++++++++++++++
 arch/nds32/include/asm/Kbuild      |  1 +
 arch/nios2/include/asm/Kbuild      |  1 +
 arch/openrisc/include/asm/Kbuild   |  1 +
 arch/parisc/include/asm/Kbuild     |  1 +
 arch/powerpc/include/asm/Kbuild    |  1 +
 arch/riscv/include/asm/Kbuild      |  1 +
 arch/s390/include/asm/Kbuild       |  1 +
 arch/sh/include/asm/Kbuild         |  1 +
 arch/sparc/include/asm/Kbuild      |  1 +
 arch/um/include/asm/Kbuild         |  1 +
 arch/unicore32/include/asm/Kbuild  |  1 +
 arch/x86/include/asm/Kbuild        |  1 +
 arch/xtensa/include/asm/Kbuild     |  1 +
 include/asm-generic/compiler.h     |  8 ++++++++
 include/linux/compiler-gcc.h       |  2 ++
 include/linux/compiler_types.h     |  3 +++
 26 files changed, 62 insertions(+), 11 deletions(-)
 create mode 100644 include/asm-generic/compiler.h

base-commit: b284d4d5a6785f8cd07eda2646a95782373cd01e
-- 
git-series 0.9.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 1/3] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h
  2018-04-17 10:11 [PATCH v3 0/3] MIPS: Override barrier_before_unreachable() to fix microMIPS James Hogan
@ 2018-04-17 10:11 ` James Hogan
  2018-05-06 19:33   ` Matt Turner
  2018-04-17 10:11 ` [PATCH v3 2/3] compiler.h: Allow arch-specific overrides James Hogan
  2018-04-17 10:11 ` [PATCH v3 3/3] MIPS: Workaround GCC __builtin_unreachable reordering bug James Hogan
  2 siblings, 1 reply; 11+ messages in thread
From: James Hogan @ 2018-04-17 10:11 UTC (permalink / raw)
  To: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha
  Cc: linux-arch, linux-kernel, James Hogan

Use CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING and CONFIG_OPTIMIZE_INLINING
instead of undefining the inline macros in the alpha specific
asm/compiler.h. This is to allow asm/compiler.h to become a general
header that can be used for overriding linux/compiler*.h.

A build of alpha's defconfig on GCC 7.3 before and after this series
(i.e. this commit and "compiler.h: Allow arch-specific overrides" which
includes asm/compiler.h from linux/compiler_types.h) results in the
following size differences, which appear harmless to me:

$ ./scripts/bloat-o-meter vmlinux.1 vmlinux.2
add/remove: 1/1 grow/shrink: 3/0 up/down: 264/-348 (-84)
Function                                     old     new   delta
cap_bprm_set_creds                          1496    1664    +168
cap_issubset                                   -      68     +68
flex_array_put                               328     344     +16
cap_capset                                   488     500     +12
nonroot_raised_pE.constprop                  348       -    -348
Total: Before=5823709, After=5823625, chg -0.00%

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: James Hogan <jhogan@kernel.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
---
Changes in v3 (James):
- New patch in v3.
---
 arch/alpha/Kconfig                |  6 ++++++
 arch/alpha/include/asm/compiler.h | 11 -----------
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index b2022885ced8..b296ba9bd8b7 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -81,6 +81,12 @@ config PGTABLE_LEVELS
 	int
 	default 3
 
+config ARCH_SUPPORTS_OPTIMIZED_INLINING
+	def_bool y
+
+config OPTIMIZE_INLINING
+	def_bool y
+
 source "init/Kconfig"
 source "kernel/Kconfig.freezer"
 
diff --git a/arch/alpha/include/asm/compiler.h b/arch/alpha/include/asm/compiler.h
index 5159ba259d65..ae645959018a 100644
--- a/arch/alpha/include/asm/compiler.h
+++ b/arch/alpha/include/asm/compiler.h
@@ -4,15 +4,4 @@
 
 #include <uapi/asm/compiler.h>
 
-/* Some idiots over in <linux/compiler.h> thought inline should imply
-   always_inline.  This breaks stuff.  We'll include this file whenever
-   we run into such problems.  */
-
-#include <linux/compiler.h>
-#undef inline
-#undef __inline__
-#undef __inline
-#undef __always_inline
-#define __always_inline		inline __attribute__((always_inline))
-
 #endif /* __ALPHA_COMPILER_H */
-- 
git-series 0.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 2/3] compiler.h: Allow arch-specific overrides
  2018-04-17 10:11 [PATCH v3 0/3] MIPS: Override barrier_before_unreachable() to fix microMIPS James Hogan
  2018-04-17 10:11 ` [PATCH v3 1/3] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h James Hogan
@ 2018-04-17 10:11 ` James Hogan
  2018-04-17 19:19     ` kbuild test robot
  2018-04-17 10:11 ` [PATCH v3 3/3] MIPS: Workaround GCC __builtin_unreachable reordering bug James Hogan
  2 siblings, 1 reply; 11+ messages in thread
From: James Hogan @ 2018-04-17 10:11 UTC (permalink / raw)
  To: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha
  Cc: linux-arch, linux-kernel, James Hogan, Paul Burton, Ralf Baechle

From: Paul Burton <paul.burton@mips.com>

Include an arch-specific asm/compiler.h and allow for it to define a
custom version of barrier_before_unreachable(), which is needed to
workaround several issues on the MIPS architecture.

This patch includes an effectively empty asm-generic implementation of
asm/compiler.h for all architectures except alpha, arm, arm64, and mips
(which already have an asm/compiler.h) and leaves the architecture
specifics to a further patch.

Signed-off-by: Paul Burton <paul.burton@mips.com>
[jhogan@kernel.org: Forward port and use asm/compiler.h instead of
 asm/compiler-gcc.h]
Signed-off-by: James Hogan <jhogan@kernel.org>
Reviewed-by: Paul Burton <paul.burton@mips.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-arch@vger.kernel.org
Cc: linux-mips@linux-mips.org
---
Changes in v3 (James):
- Rebase after 4.17 arch removal.
- Use asm/compiler.h instead of compiler-gcc.h (Arnd).
- Drop stable tag for now.

Changes in v2 (Paul):
- Add generic-y entries to arch Kbuild files. Oops!
---
 arch/arc/include/asm/Kbuild        | 1 +
 arch/c6x/include/asm/Kbuild        | 1 +
 arch/h8300/include/asm/Kbuild      | 1 +
 arch/hexagon/include/asm/Kbuild    | 1 +
 arch/ia64/include/asm/Kbuild       | 1 +
 arch/m68k/include/asm/Kbuild       | 1 +
 arch/microblaze/include/asm/Kbuild | 1 +
 arch/nds32/include/asm/Kbuild      | 1 +
 arch/nios2/include/asm/Kbuild      | 1 +
 arch/openrisc/include/asm/Kbuild   | 1 +
 arch/parisc/include/asm/Kbuild     | 1 +
 arch/powerpc/include/asm/Kbuild    | 1 +
 arch/riscv/include/asm/Kbuild      | 1 +
 arch/s390/include/asm/Kbuild       | 1 +
 arch/sh/include/asm/Kbuild         | 1 +
 arch/sparc/include/asm/Kbuild      | 1 +
 arch/um/include/asm/Kbuild         | 1 +
 arch/unicore32/include/asm/Kbuild  | 1 +
 arch/x86/include/asm/Kbuild        | 1 +
 arch/xtensa/include/asm/Kbuild     | 1 +
 include/asm-generic/compiler.h     | 8 ++++++++
 include/linux/compiler-gcc.h       | 2 ++
 include/linux/compiler_types.h     | 3 +++
 23 files changed, 33 insertions(+)
 create mode 100644 include/asm-generic/compiler.h

diff --git a/arch/arc/include/asm/Kbuild b/arch/arc/include/asm/Kbuild
index 4bd5d4369e05..61ba443ad252 100644
--- a/arch/arc/include/asm/Kbuild
+++ b/arch/arc/include/asm/Kbuild
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 generic-y += bugs.h
+generic-y += compiler.h
 generic-y += device.h
 generic-y += div64.h
 generic-y += emergency-restart.h
diff --git a/arch/c6x/include/asm/Kbuild b/arch/c6x/include/asm/Kbuild
index fd4c840de837..ddfa28f80955 100644
--- a/arch/c6x/include/asm/Kbuild
+++ b/arch/c6x/include/asm/Kbuild
@@ -1,6 +1,7 @@
 generic-y += atomic.h
 generic-y += barrier.h
 generic-y += bugs.h
+generic-y += compiler.h
 generic-y += current.h
 generic-y += device.h
 generic-y += div64.h
diff --git a/arch/h8300/include/asm/Kbuild b/arch/h8300/include/asm/Kbuild
index 14bac06b7116..bf06091a6034 100644
--- a/arch/h8300/include/asm/Kbuild
+++ b/arch/h8300/include/asm/Kbuild
@@ -3,6 +3,7 @@ generic-y += barrier.h
 generic-y += bugs.h
 generic-y += cacheflush.h
 generic-y += checksum.h
+generic-y += compiler.h
 generic-y += current.h
 generic-y += delay.h
 generic-y += device.h
diff --git a/arch/hexagon/include/asm/Kbuild b/arch/hexagon/include/asm/Kbuild
index e9743f689fb8..dccedfd7559e 100644
--- a/arch/hexagon/include/asm/Kbuild
+++ b/arch/hexagon/include/asm/Kbuild
@@ -2,6 +2,7 @@
 generic-y += barrier.h
 generic-y += bug.h
 generic-y += bugs.h
+generic-y += compiler.h
 generic-y += current.h
 generic-y += device.h
 generic-y += div64.h
diff --git a/arch/ia64/include/asm/Kbuild b/arch/ia64/include/asm/Kbuild
index 6dd867873364..886bae7b001f 100644
--- a/arch/ia64/include/asm/Kbuild
+++ b/arch/ia64/include/asm/Kbuild
@@ -1,3 +1,4 @@
+generic-y += compiler.h
 generic-y += exec.h
 generic-y += irq_work.h
 generic-y += mcs_spinlock.h
diff --git a/arch/m68k/include/asm/Kbuild b/arch/m68k/include/asm/Kbuild
index 88a9d27df1ac..089cd9b3c9fd 100644
--- a/arch/m68k/include/asm/Kbuild
+++ b/arch/m68k/include/asm/Kbuild
@@ -1,4 +1,5 @@
 generic-y += barrier.h
+generic-y += compiler.h
 generic-y += device.h
 generic-y += emergency-restart.h
 generic-y += exec.h
diff --git a/arch/microblaze/include/asm/Kbuild b/arch/microblaze/include/asm/Kbuild
index 3c80a5a308ed..920ee0afc627 100644
--- a/arch/microblaze/include/asm/Kbuild
+++ b/arch/microblaze/include/asm/Kbuild
@@ -2,6 +2,7 @@ generic-y += barrier.h
 generic-y += bitops.h
 generic-y += bug.h
 generic-y += bugs.h
+generic-y += compiler.h
 generic-y += device.h
 generic-y += div64.h
 generic-y += emergency-restart.h
diff --git a/arch/nds32/include/asm/Kbuild b/arch/nds32/include/asm/Kbuild
index 06bdf8167f5a..5536db1084f4 100644
--- a/arch/nds32/include/asm/Kbuild
+++ b/arch/nds32/include/asm/Kbuild
@@ -9,6 +9,7 @@ generic-y += checksum.h
 generic-y += clkdev.h
 generic-y += cmpxchg.h
 generic-y += cmpxchg-local.h
+generic-y += compiler.h
 generic-y += cputime.h
 generic-y += device.h
 generic-y += div64.h
diff --git a/arch/nios2/include/asm/Kbuild b/arch/nios2/include/asm/Kbuild
index d232da2cbb38..7a351811b525 100644
--- a/arch/nios2/include/asm/Kbuild
+++ b/arch/nios2/include/asm/Kbuild
@@ -4,6 +4,7 @@ generic-y += bitops.h
 generic-y += bug.h
 generic-y += bugs.h
 generic-y += cmpxchg.h
+generic-y += compiler.h
 generic-y += current.h
 generic-y += device.h
 generic-y += div64.h
diff --git a/arch/openrisc/include/asm/Kbuild b/arch/openrisc/include/asm/Kbuild
index f05c722a21f8..809c2e188884 100644
--- a/arch/openrisc/include/asm/Kbuild
+++ b/arch/openrisc/include/asm/Kbuild
@@ -2,6 +2,7 @@ generic-y += barrier.h
 generic-y += bug.h
 generic-y += bugs.h
 generic-y += checksum.h
+generic-y += compiler.h
 generic-y += current.h
 generic-y += device.h
 generic-y += div64.h
diff --git a/arch/parisc/include/asm/Kbuild b/arch/parisc/include/asm/Kbuild
index 2013d639e735..e458cba4f5ae 100644
--- a/arch/parisc/include/asm/Kbuild
+++ b/arch/parisc/include/asm/Kbuild
@@ -1,4 +1,5 @@
 generic-y += barrier.h
+generic-y += compiler.h
 generic-y += current.h
 generic-y += device.h
 generic-y += div64.h
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 3196d227e351..636a1dae6adc 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -1,3 +1,4 @@
+generic-y += compiler.h
 generic-y += div64.h
 generic-y += export.h
 generic-y += irq_regs.h
diff --git a/arch/riscv/include/asm/Kbuild b/arch/riscv/include/asm/Kbuild
index 1e5fd280fb4d..58e8ed54a870 100644
--- a/arch/riscv/include/asm/Kbuild
+++ b/arch/riscv/include/asm/Kbuild
@@ -1,6 +1,7 @@
 generic-y += bugs.h
 generic-y += cacheflush.h
 generic-y += checksum.h
+generic-y += compiler.h
 generic-y += cputime.h
 generic-y += device.h
 generic-y += div64.h
diff --git a/arch/s390/include/asm/Kbuild b/arch/s390/include/asm/Kbuild
index e3239772887a..689993a319d6 100644
--- a/arch/s390/include/asm/Kbuild
+++ b/arch/s390/include/asm/Kbuild
@@ -6,6 +6,7 @@ generated-y += unistd_nr.h
 
 generic-y += asm-offsets.h
 generic-y += cacheflush.h
+generic-y += compiler.h
 generic-y += device.h
 generic-y += dma-contiguous.h
 generic-y += dma-mapping.h
diff --git a/arch/sh/include/asm/Kbuild b/arch/sh/include/asm/Kbuild
index 1efcce74997b..3074c98526bc 100644
--- a/arch/sh/include/asm/Kbuild
+++ b/arch/sh/include/asm/Kbuild
@@ -1,3 +1,4 @@
+generic-y += compiler.h
 generic-y += current.h
 generic-y += delay.h
 generic-y += div64.h
diff --git a/arch/sparc/include/asm/Kbuild b/arch/sparc/include/asm/Kbuild
index ac67828da201..d0b551d14ebd 100644
--- a/arch/sparc/include/asm/Kbuild
+++ b/arch/sparc/include/asm/Kbuild
@@ -1,6 +1,7 @@
 # User exported sparc header files
 
 
+generic-y += compiler.h
 generic-y += div64.h
 generic-y += emergency-restart.h
 generic-y += exec.h
diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild
index bb5a196c3061..ccf8a2f5cb08 100644
--- a/arch/um/include/asm/Kbuild
+++ b/arch/um/include/asm/Kbuild
@@ -1,6 +1,7 @@
 generic-y += barrier.h
 generic-y += bpf_perf_event.h
 generic-y += bug.h
+generic-y += compiler.h
 generic-y += current.h
 generic-y += delay.h
 generic-y += device.h
diff --git a/arch/unicore32/include/asm/Kbuild b/arch/unicore32/include/asm/Kbuild
index 6f70c76c81fc..a90a693da5c2 100644
--- a/arch/unicore32/include/asm/Kbuild
+++ b/arch/unicore32/include/asm/Kbuild
@@ -1,5 +1,6 @@
 generic-y += atomic.h
 generic-y += bugs.h
+generic-y += compiler.h
 generic-y += current.h
 generic-y += device.h
 generic-y += div64.h
diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index de690c2d2e33..de4246599536 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -6,6 +6,7 @@ generated-y += unistd_32_ia32.h
 generated-y += unistd_64_x32.h
 generated-y += xen-hypercalls.h
 
+generic-y += compiler.h
 generic-y += dma-contiguous.h
 generic-y += early_ioremap.h
 generic-y += mcs_spinlock.h
diff --git a/arch/xtensa/include/asm/Kbuild b/arch/xtensa/include/asm/Kbuild
index 436b20337168..048341532d48 100644
--- a/arch/xtensa/include/asm/Kbuild
+++ b/arch/xtensa/include/asm/Kbuild
@@ -1,4 +1,5 @@
 generic-y += bug.h
+generic-y += compiler.h
 generic-y += device.h
 generic-y += div64.h
 generic-y += dma-contiguous.h
diff --git a/include/asm-generic/compiler.h b/include/asm-generic/compiler.h
new file mode 100644
index 000000000000..64f920d745ce
--- /dev/null
+++ b/include/asm-generic/compiler.h
@@ -0,0 +1,8 @@
+#ifndef __LINUX_COMPILER_H
+#error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
+#endif
+
+/*
+ * We have nothing architecture-specific to do here, simply leave everything to
+ * the generic linux/compiler.h.
+ */
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index e2c7f4369eff..2ff47f4efccb 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -218,7 +218,9 @@
  *
  * Adding an empty inline assembly before it works around the problem
  */
+#ifndef barrier_before_unreachable
 #define barrier_before_unreachable() asm volatile("")
+#endif
 
 /*
  * Mark a position in code as unreachable.  This can be used to
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 6b79a9bba9a7..a20be5fce3c8 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -54,6 +54,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
 
 #ifdef __KERNEL__
 
+/* Allow architectures to override some definitions where necessary */
+#include <asm/compiler.h>
+
 #ifdef __GNUC__
 #include <linux/compiler-gcc.h>
 #endif
-- 
git-series 0.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 3/3] MIPS: Workaround GCC __builtin_unreachable reordering bug
  2018-04-17 10:11 [PATCH v3 0/3] MIPS: Override barrier_before_unreachable() to fix microMIPS James Hogan
  2018-04-17 10:11 ` [PATCH v3 1/3] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h James Hogan
  2018-04-17 10:11 ` [PATCH v3 2/3] compiler.h: Allow arch-specific overrides James Hogan
@ 2018-04-17 10:11 ` James Hogan
  2 siblings, 0 replies; 11+ messages in thread
From: James Hogan @ 2018-04-17 10:11 UTC (permalink / raw)
  To: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha
  Cc: linux-arch, linux-kernel, James Hogan, Paul Burton,
	Matthew Fortune, Robert Suchanek, Ralf Baechle

From: Paul Burton <paul.burton@mips.com>

Older versions of GCC for the MIPS architecture suffer from a bug which
can lead to instructions from beyond an unreachable statement being
incorrectly reordered into earlier branch delay slots if the unreachable
statement is the only content of a case in a switch statement. This can
lead to seemingly random behaviour, such as invalid memory accesses from
incorrectly reordered loads or stores, and link failures on microMIPS
builds.

See this potential GCC fix for details:

    https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00360.html

This bug can be worked around by placing a volatile asm statement, which
GCC is prevented from reordering past, prior to the
__builtin_unreachable call. This was actually done for other reasons by
commit 173a3efd3edb ("bug.h: work around GCC PR82365 in BUG()"), but
without the MIPS specific .insn, which broke microMIPS builds on newer
GCC 7.2 toolchains with errors like the following:

    arch/mips/mm/dma-default.s:3265: Error: branch to a symbol in another ISA mode
    arch/mips/mm/dma-default.s:5027: Error: branch to a symbol in another ISA mode

The original bug affects at least a maltasmvp_defconfig kernel built
from the v4.4 tag using GCC 4.9.2 (from a Codescape SDK 2015.06-05
toolchain), with the result being an address exception taken after log
messages about the L1 caches (during probe of the L2 cache):

    Initmem setup node 0 [mem 0x0000000080000000-0x000000009fffffff]
    VPE topology {2,2} total 4
    Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
    Primary data cache 64kB, 4-way, PIPT, no aliases, linesize 32 bytes
    <AdEL exception here>

This is early enough that the kernel exception vectors are not in use,
so any further output depends upon the bootloader. This is reproducible
in QEMU where no further output occurs - ie. the system hangs here.
Given the nature of the bug it may potentially be hit with differing
symptoms.

Fixes: 173a3efd3edb ("bug.h: work around GCC PR82365 in BUG()")
Signed-off-by: Paul Burton <paul.burton@mips.com>
[jhogan@kernel.org: Forward port and use asm/compiler.h instead of
 asm/compiler-gcc.h]
Signed-off-by: James Hogan <jhogan@kernel.org>
Reviewed-by: Paul Burton <paul.burton@mips.com>
Cc: Matthew Fortune <matthew.fortune@mips.com>
Cc: Robert Suchanek <robert.suchanek@mips.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-mips@linux-mips.org
---
This is an alternative approach to this earlier patch which seems to
have been rejected:

    https://patchwork.linux-mips.org/patch/12556/
    https://marc.info/?l=linux-mips&m=145555921408274&w=2

Changes in v3 (James):
- Forward port to v4.17-rc and update commit message.
- Drop stable tag for now.

Changes in v2 (Paul):
- Remove generic-y entry.
---
 arch/mips/include/asm/compiler.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/mips/include/asm/compiler.h b/arch/mips/include/asm/compiler.h
index e081a265f422..ff2a412899d4 100644
--- a/arch/mips/include/asm/compiler.h
+++ b/arch/mips/include/asm/compiler.h
@@ -8,6 +8,29 @@
 #ifndef _ASM_COMPILER_H
 #define _ASM_COMPILER_H
 
+/*
+ * With GCC v4.5 onwards can use __builtin_unreachable to indicate to the
+ * compiler that a particular code path will never be hit. This allows it to be
+ * optimised out of the generated binary.
+ *
+ * Unfortunately GCC from at least v4.9.2 to current head of tree as of May
+ * 2016 suffer from a bug that can lead to instructions from beyond an
+ * unreachable statement being incorrectly reordered into earlier delay slots
+ * if the unreachable statement is the only content of a case in a switch
+ * statement. This can lead to seemingly random behaviour, such as invalid
+ * memory accesses from incorrectly reordered loads or stores. See this
+ * potential GCC fix for details:
+ *
+ *   https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00360.html
+ *
+ * We work around this by placing a volatile asm statement, which GCC is
+ * prevented from reordering past, prior to the __builtin_unreachable call. The
+ * .insn statement is required to ensure that any branches to the statement,
+ * which sadly must be kept due to the asm statement, are known to be branches
+ * to code and satisfy linker requirements for microMIPS kernels.
+ */
+#define barrier_before_unreachable() asm volatile(".insn")
+
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
 #define GCC_IMM_ASM() "n"
 #define GCC_REG_ACCUM "$0"
-- 
git-series 0.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 2/3] compiler.h: Allow arch-specific overrides
  2018-04-17 10:11 ` [PATCH v3 2/3] compiler.h: Allow arch-specific overrides James Hogan
  2018-04-17 19:19     ` kbuild test robot
@ 2018-04-17 19:19     ` kbuild test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kbuild test robot @ 2018-04-17 19:19 UTC (permalink / raw)
  To: James Hogan
  Cc: kbuild-all, linux-mips, Arnd Bergmann, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha, linux-arch,
	linux-kernel, James Hogan, Paul Burton, Ralf Baechle

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

Hi Paul,

I love your patch! Yet something to improve:

[auto build test ERROR on ]

url:    https://github.com/0day-ci/linux/commits/James-Hogan/MIPS-Override-barrier_before_unreachable-to-fix-microMIPS/20180418-025742
base:    
config: i386-tinyconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   In file included from ./arch/x86/include/generated/asm/compiler.h:1:0,
                    from include/linux/compiler_types.h:58,
                    from <command-line>:0:
>> include/asm-generic/compiler.h:2:2: error: #error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
    #error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
     ^~~~~
   make[2]: *** [kernel/bounds.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [sub-make] Error 2

vim +2 include/asm-generic/compiler.h

   > 2	#error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
     3	#endif
     4	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 6287 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 2/3] compiler.h: Allow arch-specific overrides
@ 2018-04-17 19:19     ` kbuild test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kbuild test robot @ 2018-04-17 19:19 UTC (permalink / raw)
  Cc: kbuild-all, linux-mips, Arnd Bergmann, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha, linux-arch,
	linux-kernel, James Hogan, Paul Burton, Ralf Baechle

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

Hi Paul,

I love your patch! Yet something to improve:

[auto build test ERROR on ]

url:    https://github.com/0day-ci/linux/commits/James-Hogan/MIPS-Override-barrier_before_unreachable-to-fix-microMIPS/20180418-025742
base:    
config: i386-tinyconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   In file included from ./arch/x86/include/generated/asm/compiler.h:1:0,
                    from include/linux/compiler_types.h:58,
                    from <command-line>:0:
>> include/asm-generic/compiler.h:2:2: error: #error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
    #error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
     ^~~~~
   make[2]: *** [kernel/bounds.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [sub-make] Error 2

vim +2 include/asm-generic/compiler.h

   > 2	#error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
     3	#endif
     4	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 6287 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 2/3] compiler.h: Allow arch-specific overrides
@ 2018-04-17 19:19     ` kbuild test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kbuild test robot @ 2018-04-17 19:19 UTC (permalink / raw)
  To: James Hogan
  Cc: kbuild-all, linux-mips, Arnd Bergmann, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha, linux-arch,
	linux-kernel, Paul Burton, Ralf Baechle

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

Hi Paul,

I love your patch! Yet something to improve:

[auto build test ERROR on ]

url:    https://github.com/0day-ci/linux/commits/James-Hogan/MIPS-Override-barrier_before_unreachable-to-fix-microMIPS/20180418-025742
base:    
config: i386-tinyconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   In file included from ./arch/x86/include/generated/asm/compiler.h:1:0,
                    from include/linux/compiler_types.h:58,
                    from <command-line>:0:
>> include/asm-generic/compiler.h:2:2: error: #error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
    #error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
     ^~~~~
   make[2]: *** [kernel/bounds.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [sub-make] Error 2

vim +2 include/asm-generic/compiler.h

   > 2	#error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
     3	#endif
     4	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 6287 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 2/3] compiler.h: Allow arch-specific overrides
  2018-04-17 19:19     ` kbuild test robot
  (?)
  (?)
@ 2018-04-17 21:04     ` James Hogan
  -1 siblings, 0 replies; 11+ messages in thread
From: James Hogan @ 2018-04-17 21:04 UTC (permalink / raw)
  To: kbuild test robot
  Cc: kbuild-all, linux-mips, Arnd Bergmann, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha, linux-arch,
	linux-kernel, Paul Burton, Ralf Baechle

[-- Attachment #1: Type: text/plain, Size: 682 bytes --]

Hi kbuild test robot,

On Wed, Apr 18, 2018 at 03:19:47AM +0800, kbuild test robot wrote:
>    In file included from ./arch/x86/include/generated/asm/compiler.h:1:0,
>                     from include/linux/compiler_types.h:58,
>                     from <command-line>:0:
> >> include/asm-generic/compiler.h:2:2: error: #error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."
>     #error "Please don't include <asm/compiler.h> directly, include <linux/compiler.h> instead."

Whoops, I love your bug report.

I'll change asm-generic/compiler.h to look for __LINUX_COMPILER_TYPES_H
instead of __LINUX_COMPILER_H and resend soon.

Thanks!
James


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/3] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h
  2018-04-17 10:11 ` [PATCH v3 1/3] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h James Hogan
@ 2018-05-06 19:33   ` Matt Turner
  2018-05-07  8:42     ` James Hogan
  0 siblings, 1 reply; 11+ messages in thread
From: Matt Turner @ 2018-05-06 19:33 UTC (permalink / raw)
  To: James Hogan
  Cc: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	linux-alpha, linux-arch, LKML

On Tue, Apr 17, 2018 at 3:11 AM, James Hogan <jhogan@kernel.org> wrote:
> Use CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING and CONFIG_OPTIMIZE_INLINING
> instead of undefining the inline macros in the alpha specific
> asm/compiler.h. This is to allow asm/compiler.h to become a general
> header that can be used for overriding linux/compiler*.h.
>
> A build of alpha's defconfig on GCC 7.3 before and after this series
> (i.e. this commit and "compiler.h: Allow arch-specific overrides" which
> includes asm/compiler.h from linux/compiler_types.h) results in the
> following size differences, which appear harmless to me:
>
> $ ./scripts/bloat-o-meter vmlinux.1 vmlinux.2
> add/remove: 1/1 grow/shrink: 3/0 up/down: 264/-348 (-84)
> Function                                     old     new   delta
> cap_bprm_set_creds                          1496    1664    +168
> cap_issubset                                   -      68     +68
> flex_array_put                               328     344     +16
> cap_capset                                   488     500     +12
> nonroot_raised_pE.constprop                  348       -    -348
> Total: Before=5823709, After=5823625, chg -0.00%
>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: James Hogan <jhogan@kernel.org>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: linux-alpha@vger.kernel.org

Looks fine to me.

Acked-by: Matt Turner <mattst88@gmail.com>

Should I take it through the alpha tree?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/3] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h
  2018-05-06 19:33   ` Matt Turner
@ 2018-05-07  8:42     ` James Hogan
  2018-05-07 16:03       ` Matt Turner
  0 siblings, 1 reply; 11+ messages in thread
From: James Hogan @ 2018-05-07  8:42 UTC (permalink / raw)
  To: Matt Turner
  Cc: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	linux-alpha, linux-arch, LKML

[-- Attachment #1: Type: text/plain, Size: 1952 bytes --]

On Sun, May 06, 2018 at 12:33:21PM -0700, Matt Turner wrote:
> On Tue, Apr 17, 2018 at 3:11 AM, James Hogan <jhogan@kernel.org> wrote:
> > Use CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING and CONFIG_OPTIMIZE_INLINING
> > instead of undefining the inline macros in the alpha specific
> > asm/compiler.h. This is to allow asm/compiler.h to become a general
> > header that can be used for overriding linux/compiler*.h.
> >
> > A build of alpha's defconfig on GCC 7.3 before and after this series
> > (i.e. this commit and "compiler.h: Allow arch-specific overrides" which
> > includes asm/compiler.h from linux/compiler_types.h) results in the
> > following size differences, which appear harmless to me:
> >
> > $ ./scripts/bloat-o-meter vmlinux.1 vmlinux.2
> > add/remove: 1/1 grow/shrink: 3/0 up/down: 264/-348 (-84)
> > Function                                     old     new   delta
> > cap_bprm_set_creds                          1496    1664    +168
> > cap_issubset                                   -      68     +68
> > flex_array_put                               328     344     +16
> > cap_capset                                   488     500     +12
> > nonroot_raised_pE.constprop                  348       -    -348
> > Total: Before=5823709, After=5823625, chg -0.00%
> >
> > Suggested-by: Arnd Bergmann <arnd@arndb.de>
> > Signed-off-by: James Hogan <jhogan@kernel.org>
> > Cc: Richard Henderson <rth@twiddle.net>
> > Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> > Cc: Matt Turner <mattst88@gmail.com>
> > Cc: linux-alpha@vger.kernel.org
> 
> Looks fine to me.
> 
> Acked-by: Matt Turner <mattst88@gmail.com>

Thanks

> 
> Should I take it through the alpha tree?

I'll take all 3 through the MIPS tree if thats okay with you, as its a
prerequisite to allowing MIPS to override stuff in linux/compiler-gcc.h
using asm/compiler.h, which is needed to fix build breakage in 4.17.

Thanks
James

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/3] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h
  2018-05-07  8:42     ` James Hogan
@ 2018-05-07 16:03       ` Matt Turner
  0 siblings, 0 replies; 11+ messages in thread
From: Matt Turner @ 2018-05-07 16:03 UTC (permalink / raw)
  To: James Hogan
  Cc: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	linux-alpha, linux-arch, LKML

On Mon, May 7, 2018 at 1:42 AM, James Hogan <jhogan@kernel.org> wrote:
> On Sun, May 06, 2018 at 12:33:21PM -0700, Matt Turner wrote:
>> On Tue, Apr 17, 2018 at 3:11 AM, James Hogan <jhogan@kernel.org> wrote:
>> > Use CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING and CONFIG_OPTIMIZE_INLINING
>> > instead of undefining the inline macros in the alpha specific
>> > asm/compiler.h. This is to allow asm/compiler.h to become a general
>> > header that can be used for overriding linux/compiler*.h.
>> >
>> > A build of alpha's defconfig on GCC 7.3 before and after this series
>> > (i.e. this commit and "compiler.h: Allow arch-specific overrides" which
>> > includes asm/compiler.h from linux/compiler_types.h) results in the
>> > following size differences, which appear harmless to me:
>> >
>> > $ ./scripts/bloat-o-meter vmlinux.1 vmlinux.2
>> > add/remove: 1/1 grow/shrink: 3/0 up/down: 264/-348 (-84)
>> > Function                                     old     new   delta
>> > cap_bprm_set_creds                          1496    1664    +168
>> > cap_issubset                                   -      68     +68
>> > flex_array_put                               328     344     +16
>> > cap_capset                                   488     500     +12
>> > nonroot_raised_pE.constprop                  348       -    -348
>> > Total: Before=5823709, After=5823625, chg -0.00%
>> >
>> > Suggested-by: Arnd Bergmann <arnd@arndb.de>
>> > Signed-off-by: James Hogan <jhogan@kernel.org>
>> > Cc: Richard Henderson <rth@twiddle.net>
>> > Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
>> > Cc: Matt Turner <mattst88@gmail.com>
>> > Cc: linux-alpha@vger.kernel.org
>>
>> Looks fine to me.
>>
>> Acked-by: Matt Turner <mattst88@gmail.com>
>
> Thanks
>
>>
>> Should I take it through the alpha tree?
>
> I'll take all 3 through the MIPS tree if thats okay with you, as its a
> prerequisite to allowing MIPS to override stuff in linux/compiler-gcc.h
> using asm/compiler.h, which is needed to fix build breakage in 4.17.

Thanks. That works for me.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-05-07 16:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-17 10:11 [PATCH v3 0/3] MIPS: Override barrier_before_unreachable() to fix microMIPS James Hogan
2018-04-17 10:11 ` [PATCH v3 1/3] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h James Hogan
2018-05-06 19:33   ` Matt Turner
2018-05-07  8:42     ` James Hogan
2018-05-07 16:03       ` Matt Turner
2018-04-17 10:11 ` [PATCH v3 2/3] compiler.h: Allow arch-specific overrides James Hogan
2018-04-17 19:19   ` kbuild test robot
2018-04-17 19:19     ` kbuild test robot
2018-04-17 19:19     ` kbuild test robot
2018-04-17 21:04     ` James Hogan
2018-04-17 10:11 ` [PATCH v3 3/3] MIPS: Workaround GCC __builtin_unreachable reordering bug James Hogan

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.