* [PATCH v6 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS
@ 2018-08-09 17:44 Paul Burton
2018-08-09 17:44 ` [PATCH v6 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h Paul Burton
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Paul Burton @ 2018-08-09 17:44 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, linux-um,
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 v6 (Paul):
- Fix patch 2 to find the generated headers in $(objtree).
- Remove CC's for defunct MIPS email addresses (Matthew & Robert).
- CC linux-um@lists.infradead.org.
Changes in v5 (Paul):
- Rebase atop v4.18-rc8.
- Comment & commit message tweaks.
- Add SPDX-License-Identifier to asm-generic/compiler.h.
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] 9+ messages in thread
* [PATCH v6 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h
2018-08-09 17:44 [PATCH v6 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
@ 2018-08-09 17:44 ` Paul Burton
2018-08-09 17:44 ` [PATCH v6 2/4] um: Add generated/ to MODE_INCLUDE Paul Burton
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Paul Burton @ 2018-08-09 17:44 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, linux-um,
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>
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
Signed-off-by: Paul Burton <paul.burton@mips.com>
---
Changes in v6: None
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] 9+ messages in thread
* [PATCH v6 2/4] um: Add generated/ to MODE_INCLUDE
2018-08-09 17:44 [PATCH v6 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
2018-08-09 17:44 ` [PATCH v6 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h Paul Burton
@ 2018-08-09 17:44 ` Paul Burton
2018-08-09 17:44 ` [PATCH v6 3/4] compiler.h: Allow arch-specific overrides Paul Burton
2018-08-09 17:44 ` [PATCH v6 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug Paul Burton
3 siblings, 0 replies; 9+ messages in thread
From: Paul Burton @ 2018-08-09 17:44 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, linux-um,
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>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: user-mode-linux-devel@lists.sourceforge.net
Cc: linux-um@lists.infradead.org
Signed-off-by: Paul Burton <paul.burton@mips.com>
---
Changes in v6:
- s/srctree/objtree/ to fix build issues when building out of tree.
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..fec1252160db 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$(objtree)/$(ARCH_DIR)/include/generated
HEADER_ARCH := $(SUBARCH)
--
2.18.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v6 3/4] compiler.h: Allow arch-specific overrides
2018-08-09 17:44 [PATCH v6 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
2018-08-09 17:44 ` [PATCH v6 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h Paul Burton
2018-08-09 17:44 ` [PATCH v6 2/4] um: Add generated/ to MODE_INCLUDE Paul Burton
@ 2018-08-09 17:44 ` Paul Burton
2018-08-09 18:08 ` Arnd Bergmann
2018-08-09 17:44 ` [PATCH v6 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug Paul Burton
3 siblings, 1 reply; 9+ messages in thread
From: Paul Burton @ 2018-08-09 17:44 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, linux-um,
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>
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
Cc: linux-um@lists.infradead.org
---
Changes in v6: None
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] 9+ messages in thread
* [PATCH v6 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug
2018-08-09 17:44 [PATCH v6 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
` (2 preceding siblings ...)
2018-08-09 17:44 ` [PATCH v6 3/4] compiler.h: Allow arch-specific overrides Paul Burton
@ 2018-08-09 17:44 ` Paul Burton
2018-08-09 18:12 ` Arnd Bergmann
3 siblings, 1 reply; 9+ messages in thread
From: Paul Burton @ 2018-08-09 17:44 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, linux-um,
Paul Burton
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>
Reviewed-by: Paul Burton <paul.burton@mips.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-mips@linux-mips.org
---
Changes in v6: None
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] 9+ messages in thread
* Re: [PATCH v6 3/4] compiler.h: Allow arch-specific overrides
2018-08-09 17:44 ` [PATCH v6 3/4] compiler.h: Allow arch-specific overrides Paul Burton
@ 2018-08-09 18:08 ` Arnd Bergmann
0 siblings, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2018-08-09 18:08 UTC (permalink / raw)
To: Paul Burton
Cc: open list:RALINK MIPS ARCHITECTURE, Richard Henderson,
Ivan Kokshaysky, Matt Turner, Jeff Dike, Richard Weinberger,
James Hogan, Ralf Baechle, linux-alpha, uml-devel, linux-arch,
linux-um
On Thu, Aug 9, 2018 at 7:45 PM Paul Burton <paul.burton@mips.com> wrote:
>
> 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
> Cc: linux-um@lists.infradead.org
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug
2018-08-09 17:44 ` [PATCH v6 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug Paul Burton
@ 2018-08-09 18:12 ` Arnd Bergmann
2018-08-09 18:56 ` Paul Burton
0 siblings, 1 reply; 9+ messages in thread
From: Arnd Bergmann @ 2018-08-09 18:12 UTC (permalink / raw)
To: Paul Burton
Cc: open list:RALINK MIPS ARCHITECTURE, Richard Henderson,
Ivan Kokshaysky, Matt Turner, Jeff Dike, Richard Weinberger,
James Hogan, Ralf Baechle, linux-alpha, uml-devel, linux-arch,
linux-um
On Thu, Aug 9, 2018 at 7:45 PM Paul Burton <paul.burton@mips.com> wrote:
> +/*
> + * 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
Has anything happened to address this in gcc in the meantime?
Could you update this text to reflect whatever is in current gcc-9?
Arnd
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug
2018-08-09 18:12 ` Arnd Bergmann
@ 2018-08-09 18:56 ` Paul Burton
2018-08-10 17:05 ` [PATCH v7 " Paul Burton
0 siblings, 1 reply; 9+ messages in thread
From: Paul Burton @ 2018-08-09 18:56 UTC (permalink / raw)
To: Arnd Bergmann, Matthew Fortune
Cc: open list:RALINK MIPS ARCHITECTURE, Richard Henderson,
Ivan Kokshaysky, Matt Turner, Jeff Dike, Richard Weinberger,
James Hogan, Ralf Baechle, linux-alpha, uml-devel, linux-arch,
linux-um
Hi Arnd,
On Thu, Aug 09, 2018 at 08:12:27PM +0200, Arnd Bergmann wrote:
> On Thu, Aug 9, 2018 at 7:45 PM Paul Burton <paul.burton@mips.com> wrote:
>
> > +/*
> > + * 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
>
> Has anything happened to address this in gcc in the meantime?
> Could you update this text to reflect whatever is in current gcc-9?
Good question. I can reproduce the problem using the test case from [1]
using both GCC 6.4.0 & 7.3.0, but 8.1.0 generates wildly different code
which looks good.
Nothing relevant is listed in the release notes for GCC 8.x though, and
I can't see anything obvious in gcc's commit logs. It doesn't looks like
the fix Robert suggested went in. So I don't know whether current GCC's
have resolved the problem or just get lucky enough not to hit it with
the existing testcase.
I've copied Matthew (GCC MIPS maintainer) in case he has any relevant
information.
Thanks,
Paul
[1] https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00360.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v7 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug
2018-08-09 18:56 ` Paul Burton
@ 2018-08-10 17:05 ` Paul Burton
0 siblings, 0 replies; 9+ messages in thread
From: Paul Burton @ 2018-08-10 17:05 UTC (permalink / raw)
To: linux-mips, Arnd Bergmann
Cc: Richard Henderson, Ivan Kokshaysky, Matt Turner, Jeff Dike,
Richard Weinberger, James Hogan, Ralf Baechle, linux-alpha,
user-mode-linux-devel, linux-arch, linux-um, Paul Burton
Some 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: Ralf Baechle <ralf@linux-mips.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-mips@linux-mips.org
---
Changes in v7:
- Elaborate on affected GCC versions in comment.
Changes in v6: None
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 | 34 ++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/arch/mips/include/asm/compiler.h b/arch/mips/include/asm/compiler.h
index e081a265f422..4c06b41cd258 100644
--- a/arch/mips/include/asm/compiler.h
+++ b/arch/mips/include/asm/compiler.h
@@ -8,6 +8,40 @@
#ifndef _ASM_COMPILER_H
#define _ASM_COMPILER_H
+/*
+ * With GCC 4.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 at least GCC 4.6.3 through 7.3.0 inclusive 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
+ *
+ * It is unclear whether GCC 8 onwards suffer from the same issue - nothing
+ * relevant is mentioned in GCC 8 release notes and nothing obviously relevant
+ * stands out in GCC commit logs, but these newer GCC versions generate very
+ * different code for the testcase which doesn't exhibit the bug.
+ *
+ * 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] 9+ messages in thread
end of thread, other threads:[~2018-08-10 19:36 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-09 17:44 [PATCH v6 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS Paul Burton
2018-08-09 17:44 ` [PATCH v6 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h Paul Burton
2018-08-09 17:44 ` [PATCH v6 2/4] um: Add generated/ to MODE_INCLUDE Paul Burton
2018-08-09 17:44 ` [PATCH v6 3/4] compiler.h: Allow arch-specific overrides Paul Burton
2018-08-09 18:08 ` Arnd Bergmann
2018-08-09 17:44 ` [PATCH v6 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug Paul Burton
2018-08-09 18:12 ` Arnd Bergmann
2018-08-09 18:56 ` Paul Burton
2018-08-10 17:05 ` [PATCH v7 " 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).