* [PATCH v5 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS
@ 2018-08-08 22:52 Paul Burton
2018-08-08 22:52 ` [PATCH v5 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h Paul Burton
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Paul Burton @ 2018-08-08 22:52 UTC (permalink / raw)
To: linux-mips
Cc: Arnd Bergmann, Richard Henderson, Ivan Kokshaysky, Matt Turner,
Jeff Dike, Richard Weinberger, James Hogan, Ralf Baechle,
linux-alpha, user-mode-linux-devel, linux-arch, Paul Burton
This series overrides barrier_before_unreachable() for MIPS to add a
.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 targeting it (which sadly can't be removed) raise
errors due to the mismatching ISA mode, Adding the .insn in patch 4
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 3. 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%
Also um needs the generated/ include directory adding to the include
paths in patch 2 so that an asm-generic wrapper asm/compiler.h can be
included from automatically included headers.
Applies cleanly atop v4.18-rc8.
Changes in v5 (Paul):
- Rebase atop v4.18-rc8.
Changes in v4 (James):
- Fix asm-generic/compiler.h include from check, compiler_types.h is
included on the command line so linux/compiler.h may not be included
(kbuild test robot).
- New patch 2 to fix um (kbuild test robot).
Changes in v3 (James):
- New patch 1.
- Rebase after 4.17 arch removal and update commit messages.
- 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!
James Hogan (2):
alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h
um: Add generated/ to MODE_INCLUDE
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 | 30 ++++++++++++++++++++++++++++++
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/Makefile | 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 | 10 ++++++++++
include/linux/compiler-gcc.h | 2 ++
include/linux/compiler_types.h | 3 +++
27 files changed, 72 insertions(+), 11 deletions(-)
create mode 100644 include/asm-generic/compiler.h
--
2.18.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v5 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h
2018-08-08 22:52 [PATCH v5 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
@ 2018-08-08 22:52 ` Paul Burton
2018-08-08 22:52 ` [PATCH v5 2/4] um: Add generated/ to MODE_INCLUDE Paul Burton
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Paul Burton @ 2018-08-08 22:52 UTC (permalink / raw)
To: linux-mips
Cc: Arnd Bergmann, Richard Henderson, Ivan Kokshaysky, Matt Turner,
Jeff Dike, Richard Weinberger, James Hogan, Ralf Baechle,
linux-alpha, user-mode-linux-devel, linux-arch, Paul Burton
From: James Hogan <jhogan@kernel.org>
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>
Signed-off-by: Paul Burton <paul.burton@mips.com>
Acked-by: Matt Turner <mattst88@gmail.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: linux-alpha@vger.kernel.org
---
Changes in v5: None
Changes in v4: None
Changes in v3:
- 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 04a4a138ed13..649b41621520 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -74,6 +74,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 */
--
2.18.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v5 2/4] um: Add generated/ to MODE_INCLUDE
2018-08-08 22:52 [PATCH v5 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
2018-08-08 22:52 ` [PATCH v5 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h Paul Burton
@ 2018-08-08 22:52 ` Paul Burton
2018-08-08 22:52 ` [PATCH v5 3/4] compiler.h: Allow arch-specific overrides Paul Burton
2018-08-08 22:52 ` [PATCH v5 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug Paul Burton
3 siblings, 0 replies; 5+ messages in thread
From: Paul Burton @ 2018-08-08 22:52 UTC (permalink / raw)
To: linux-mips
Cc: Arnd Bergmann, Richard Henderson, Ivan Kokshaysky, Matt Turner,
Jeff Dike, Richard Weinberger, James Hogan, Ralf Baechle,
linux-alpha, user-mode-linux-devel, linux-arch, Paul Burton
From: James Hogan <jhogan@kernel.org>
Add the um specific generated includes directory to MODE_INCLUDE so that
asm/compiler.h can be used for overriding linux/compiler*.h which is
included automatically, with um using a generated asm-generic wrapper at
arch/um/include/generated/asm/compiler.h.
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: James Hogan <jhogan@kernel.org>
Signed-off-by: Paul Burton <paul.burton@mips.com>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: user-mode-linux-devel@lists.sourceforge.net
---
I've been unable to reproduce the error the kbuild test robot reported
for v4 [1], so I'm hoping it may disappear with the rebased series or at
least give me more information if not...
[1] https://www.linux-mips.org/archives/linux-mips/2018-05/msg00094.html
Changes in v5: None
Changes in v4:
- New patch in v4.
arch/um/Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/um/Makefile b/arch/um/Makefile
index e54dda8a0363..543d12d230ab 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -30,6 +30,7 @@ core-y += $(ARCH_DIR)/kernel/ \
$(ARCH_DIR)/os-$(OS)/
MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/shared/skas
+MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/generated
HEADER_ARCH := $(SUBARCH)
--
2.18.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v5 3/4] compiler.h: Allow arch-specific overrides
2018-08-08 22:52 [PATCH v5 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
2018-08-08 22:52 ` [PATCH v5 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h Paul Burton
2018-08-08 22:52 ` [PATCH v5 2/4] um: Add generated/ to MODE_INCLUDE Paul Burton
@ 2018-08-08 22:52 ` Paul Burton
2018-08-08 22:52 ` [PATCH v5 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug Paul Burton
3 siblings, 0 replies; 5+ messages in thread
From: Paul Burton @ 2018-08-08 22:52 UTC (permalink / raw)
To: linux-mips
Cc: Arnd Bergmann, Richard Henderson, Ivan Kokshaysky, Matt Turner,
Jeff Dike, Richard Weinberger, James Hogan, Ralf Baechle,
linux-alpha, user-mode-linux-devel, linux-arch, Paul Burton
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>
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 v5:
- Rebase atop v4.18-rc8.
- Add SPDX-License-Identifier to asm-generic/compiler.h.
Changes in v4:
- Fix asm-generic/compiler.h include from check, compiler_types.h is
included on the command line so linux/compiler.h may not be included
(kbuild test robot).
Changes in v3:
- Rebase after 4.17 arch removal.
- Use asm/compiler.h instead of compiler-gcc.h (Arnd).
- Drop stable tag for now.
Changes in v2:
- 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 | 10 ++++++++++
include/linux/compiler-gcc.h | 2 ++
include/linux/compiler_types.h | 3 +++
23 files changed, 35 insertions(+)
create mode 100644 include/asm-generic/compiler.h
diff --git a/arch/arc/include/asm/Kbuild b/arch/arc/include/asm/Kbuild
index feed50ce89fa..55c955621deb 100644
--- a/arch/arc/include/asm/Kbuild
+++ b/arch/arc/include/asm/Kbuild
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
generic-y += bugs.h
generic-y += compat.h
+generic-y += compiler.h
generic-y += device.h
generic-y += div64.h
generic-y += dma-mapping.h
diff --git a/arch/c6x/include/asm/Kbuild b/arch/c6x/include/asm/Kbuild
index 33a2c94fed0d..0bbdfe6481fd 100644
--- a/arch/c6x/include/asm/Kbuild
+++ b/arch/c6x/include/asm/Kbuild
@@ -2,6 +2,7 @@ generic-y += atomic.h
generic-y += barrier.h
generic-y += bugs.h
generic-y += compat.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 a5d0b2991f47..09c6d8cac8be 100644
--- a/arch/h8300/include/asm/Kbuild
+++ b/arch/h8300/include/asm/Kbuild
@@ -4,6 +4,7 @@ generic-y += bugs.h
generic-y += cacheflush.h
generic-y += checksum.h
generic-y += compat.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 dd2fd9c0d292..ef5f1ca92d64 100644
--- a/arch/hexagon/include/asm/Kbuild
+++ b/arch/hexagon/include/asm/Kbuild
@@ -3,6 +3,7 @@ generic-y += barrier.h
generic-y += bug.h
generic-y += bugs.h
generic-y += compat.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 557bbc8ba9f5..5c5a5721fe89 100644
--- a/arch/ia64/include/asm/Kbuild
+++ b/arch/ia64/include/asm/Kbuild
@@ -1,4 +1,5 @@
generic-y += compat.h
+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 4d8d68c4e3dd..e920ada07719 100644
--- a/arch/m68k/include/asm/Kbuild
+++ b/arch/m68k/include/asm/Kbuild
@@ -1,5 +1,6 @@
generic-y += barrier.h
generic-y += compat.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 fe6a6c6e5003..01317fc236e3 100644
--- a/arch/microblaze/include/asm/Kbuild
+++ b/arch/microblaze/include/asm/Kbuild
@@ -3,6 +3,7 @@ generic-y += bitops.h
generic-y += bug.h
generic-y += bugs.h
generic-y += compat.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 dbc4e5422550..a5f2b9058b4c 100644
--- a/arch/nds32/include/asm/Kbuild
+++ b/arch/nds32/include/asm/Kbuild
@@ -10,6 +10,7 @@ generic-y += clkdev.h
generic-y += cmpxchg.h
generic-y += cmpxchg-local.h
generic-y += compat.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 64ed3d656956..a157f2049d74 100644
--- a/arch/nios2/include/asm/Kbuild
+++ b/arch/nios2/include/asm/Kbuild
@@ -5,6 +5,7 @@ generic-y += bug.h
generic-y += bugs.h
generic-y += cmpxchg.h
generic-y += compat.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 65964d390b10..54849e38da6f 100644
--- a/arch/openrisc/include/asm/Kbuild
+++ b/arch/openrisc/include/asm/Kbuild
@@ -3,6 +3,7 @@ generic-y += bug.h
generic-y += bugs.h
generic-y += checksum.h
generic-y += compat.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 576ffdca06ba..f6a7fcd72d37 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 46dd82ab2c29..dd49f6b7f036 100644
--- a/arch/sh/include/asm/Kbuild
+++ b/arch/sh/include/asm/Kbuild
@@ -1,4 +1,5 @@
generic-y += compat.h
+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 410b263ef5c8..e944aac9b198 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 b10dde6cb793..14b4f6f09816 100644
--- a/arch/um/include/asm/Kbuild
+++ b/arch/um/include/asm/Kbuild
@@ -2,6 +2,7 @@ generic-y += barrier.h
generic-y += bpf_perf_event.h
generic-y += bug.h
generic-y += compat.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 bfc7abe77905..614a0d99e02e 100644
--- a/arch/unicore32/include/asm/Kbuild
+++ b/arch/unicore32/include/asm/Kbuild
@@ -1,6 +1,7 @@
generic-y += atomic.h
generic-y += bugs.h
generic-y += compat.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 e5e1e61c538c..bf08e8a4fb57 100644
--- a/arch/xtensa/include/asm/Kbuild
+++ b/arch/xtensa/include/asm/Kbuild
@@ -1,5 +1,6 @@
generic-y += bug.h
generic-y += compat.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..0653ff193b40
--- /dev/null
+++ b/include/asm-generic/compiler.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_COMPILER_TYPES_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 573f5a7d42d4..5caf71f15c71 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -233,7 +233,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 a8ba6b04152c..c66b9222fcf0 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
--
2.18.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v5 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug
2018-08-08 22:52 [PATCH v5 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
` (2 preceding siblings ...)
2018-08-08 22:52 ` [PATCH v5 3/4] compiler.h: Allow arch-specific overrides Paul Burton
@ 2018-08-08 22:52 ` Paul Burton
3 siblings, 0 replies; 5+ messages in thread
From: Paul Burton @ 2018-08-08 22:52 UTC (permalink / raw)
To: linux-mips
Cc: Arnd Bergmann, Richard Henderson, Ivan Kokshaysky, Matt Turner,
Jeff Dike, Richard Weinberger, James Hogan, Ralf Baechle,
linux-alpha, user-mode-linux-devel, linux-arch, Paul Burton,
Matthew Fortune, Robert Suchanek
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 already 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
Add a MIPS-specific definition of barrier_before_unreachable() which
includes the .insn directive in order to satisfy the assembler that
branch targets are in fact code.
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>
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
---
Changes in v5:
- Comment & commit message tweaks.
Changes in v4: None
Changes in v3:
- Forward port to v4.17-rc and update commit message.
- Drop stable tag for now.
Changes in v2:
- Remove generic-y entry.
arch/mips/include/asm/compiler.h | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/arch/mips/include/asm/compiler.h b/arch/mips/include/asm/compiler.h
index e081a265f422..1e9548faf9c7 100644
--- a/arch/mips/include/asm/compiler.h
+++ b/arch/mips/include/asm/compiler.h
@@ -8,6 +8,36 @@
#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
+ *
+ * GCC also handles stack allocation suboptimally when calling noreturn
+ * functions or calling __builtin_unreachable():
+ *
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365
+ *
+ * We work around both of these issues by placing a volatile asm statement,
+ * which GCC is prevented from reordering past, prior to __builtin_unreachable
+ * calls.
+ *
+ * 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"
--
2.18.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-08-09 1:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-08 22:52 [PATCH v5 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
2018-08-08 22:52 ` [PATCH v5 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h Paul Burton
2018-08-08 22:52 ` [PATCH v5 2/4] um: Add generated/ to MODE_INCLUDE Paul Burton
2018-08-08 22:52 ` [PATCH v5 3/4] compiler.h: Allow arch-specific overrides Paul Burton
2018-08-08 22:52 ` [PATCH v5 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug Paul Burton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).