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

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 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.

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!

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: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
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: user-mode-linux-devel@lists.sourceforge.net
Cc: linux-mips@linux-mips.org
Cc: linux-arch@vger.kernel.org

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   | 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/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     |  8 ++++++++
 include/linux/compiler-gcc.h       |  2 ++
 include/linux/compiler_types.h     |  3 +++
 27 files changed, 63 insertions(+), 11 deletions(-)
 create mode 100644 include/asm-generic/compiler.h

base-commit: 6d08b06e67cd117f6992c46611dfb4ce267cd71e
-- 
git-series 0.9.1

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

* [PATCH v4 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h
  2018-05-11 21:46 [PATCH v4 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS James Hogan
@ 2018-05-11 21:46 ` James Hogan
  2018-05-11 21:47 ` [PATCH v4 2/4] um: Add generated/ to MODE_INCLUDE James Hogan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: James Hogan @ 2018-05-11 21:46 UTC (permalink / raw)
  To: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha, Jeff Dike, Richard Weinberger,
	user-mode-linux-devel
  Cc: 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>
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 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] 7+ messages in thread

* [PATCH v4 2/4] um: Add generated/ to MODE_INCLUDE
  2018-05-11 21:46 [PATCH v4 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS James Hogan
  2018-05-11 21:46 ` [PATCH v4 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h James Hogan
@ 2018-05-11 21:47 ` James Hogan
  2018-05-14  9:26   ` James Hogan
  2018-05-11 21:47 ` [PATCH v4 3/4] compiler.h: Allow arch-specific overrides James Hogan
  2018-05-11 21:47 ` [PATCH v4 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug James Hogan
  3 siblings, 1 reply; 7+ messages in thread
From: James Hogan @ 2018-05-11 21:47 UTC (permalink / raw)
  To: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha, Jeff Dike, Richard Weinberger,
	user-mode-linux-devel
  Cc: James Hogan

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
---
Changes in v4 (James):
- 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)
 
-- 
git-series 0.9.1

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

* [PATCH v4 3/4] compiler.h: Allow arch-specific overrides
  2018-05-11 21:46 [PATCH v4 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS James Hogan
  2018-05-11 21:46 ` [PATCH v4 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h James Hogan
  2018-05-11 21:47 ` [PATCH v4 2/4] um: Add generated/ to MODE_INCLUDE James Hogan
@ 2018-05-11 21:47 ` James Hogan
  2018-05-11 21:47 ` [PATCH v4 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug James Hogan
  3 siblings, 0 replies; 7+ messages in thread
From: James Hogan @ 2018-05-11 21:47 UTC (permalink / raw)
  To: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha, Jeff Dike, Richard Weinberger,
	user-mode-linux-devel
  Cc: James Hogan, Paul Burton, Ralf Baechle, linux-arch

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 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).

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..081593903904
--- /dev/null
+++ b/include/asm-generic/compiler.h
@@ -0,0 +1,8 @@
+#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 b4bf73f5e38f..1f673a28960d 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] 7+ messages in thread

* [PATCH v4 4/4] MIPS: Workaround GCC __builtin_unreachable reordering bug
  2018-05-11 21:46 [PATCH v4 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS James Hogan
                   ` (2 preceding siblings ...)
  2018-05-11 21:47 ` [PATCH v4 3/4] compiler.h: Allow arch-specific overrides James Hogan
@ 2018-05-11 21:47 ` James Hogan
  3 siblings, 0 replies; 7+ messages in thread
From: James Hogan @ 2018-05-11 21:47 UTC (permalink / raw)
  To: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha, Jeff Dike, Richard Weinberger,
	user-mode-linux-devel
  Cc: 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] 7+ messages in thread

* Re: [PATCH v4 2/4] um: Add generated/ to MODE_INCLUDE
  2018-05-11 21:47 ` [PATCH v4 2/4] um: Add generated/ to MODE_INCLUDE James Hogan
@ 2018-05-14  9:26   ` James Hogan
  2018-08-09 17:51     ` Paul Burton
  0 siblings, 1 reply; 7+ messages in thread
From: James Hogan @ 2018-05-14  9:26 UTC (permalink / raw)
  To: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha, Jeff Dike, Richard Weinberger,
	user-mode-linux-devel


[-- Attachment #1.1: Type: text/plain, Size: 1919 bytes --]

On Fri, May 11, 2018 at 10:47:00PM +0100, James Hogan wrote:
> 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

Hmm, I thought I'd fixed this, but again the kbuild test robot
complains:

On Sat, May 12, 2018 at 09:47:40AM +0800, kbuild test robot wrote:
> bisected to: aea47daf8a396e512e0cfe11d9c05798749db172  compiler.h: Allow arch-specific overrides
> commit date: 2 days ago
> config: um-x86_64_defconfig (attached as .config)
> compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
> reproduce:
>         git checkout aea47daf8a396e512e0cfe11d9c05798749db172
>         # save the attached .config to linux build tree
>         make ARCH=um SUBARCH=x86_64
> 
> All errors (new ones prefixed by >>):
> 
>    In file included from arch/um/include/shared/init.h:44:0,
>                     from arch/um/kernel/config.c:8:
> >> include/linux/compiler_types.h:58:10: fatal error: asm/compiler.h: No such file or directory
>     #include <asm/compiler.h>
>              ^~~~~~~~~~~~~~~~
>    compilation terminated.
> 
> vim +58 include/linux/compiler_types.h
> 
>     56	
>     57	/* Allow architectures to override some definitions where necessary */
>   > 58	#include <asm/compiler.h>
>     59	

Can anybody else reproduce that or have ideas why its still happening? I
don't seem to be able to.

Its from my mips-next-test branch here (that isn't in linux-next):
git://git.kernel.org/pub/scm/linux/kernel/git/jhogan/mips.git

Cheers
James

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

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

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

* Re: [PATCH v4 2/4] um: Add generated/ to MODE_INCLUDE
  2018-05-14  9:26   ` James Hogan
@ 2018-08-09 17:51     ` Paul Burton
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Burton @ 2018-08-09 17:51 UTC (permalink / raw)
  To: James Hogan, Fengguang Wu
  Cc: linux-mips, Arnd Bergmann, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, linux-alpha, Jeff Dike, Richard Weinberger,
	user-mode-linux-devel

Hi James / Fengguang,

On Mon, May 14, 2018 at 10:26:34AM +0100, James Hogan wrote:
> Hmm, I thought I'd fixed this, but again the kbuild test robot
> complains:
> 
> On Sat, May 12, 2018 at 09:47:40AM +0800, kbuild test robot wrote:
> > bisected to: aea47daf8a396e512e0cfe11d9c05798749db172  compiler.h: Allow arch-specific overrides
> > commit date: 2 days ago
> > config: um-x86_64_defconfig (attached as .config)
> > compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
> > reproduce:
> >         git checkout aea47daf8a396e512e0cfe11d9c05798749db172
> >         # save the attached .config to linux build tree
> >         make ARCH=um SUBARCH=x86_64
> > 
> > All errors (new ones prefixed by >>):
> > 
> >    In file included from arch/um/include/shared/init.h:44:0,
> >                     from arch/um/kernel/config.c:8:
> > >> include/linux/compiler_types.h:58:10: fatal error: asm/compiler.h: No such file or directory
> >     #include <asm/compiler.h>
> >              ^~~~~~~~~~~~~~~~
> >    compilation terminated.
> > 
> > vim +58 include/linux/compiler_types.h
> > 
> >     56	
> >     57	/* Allow architectures to override some definitions where necessary */
> >   > 58	#include <asm/compiler.h>
> >     59	
> 
> Can anybody else reproduce that or have ideas why its still happening? I
> don't seem to be able to.
> 
> Its from my mips-next-test branch here (that isn't in linux-next):
> git://git.kernel.org/pub/scm/linux/kernel/git/jhogan/mips.git

I think I figured it out at last - it's because the generated includes
will be in $(objtree) but your patch looked for them in $(srctree).
Fixed in the v6 I just submitted.

Presumably the kbuild test robot is building with O=somewhere, but it
doesn't indicate that in the email which means the command it reports
will reproduce the bug simply doesn't.

I realise this is probably rare in the grand scheme of things, but maybe
it'd be worth mentioning O= in the emails Fengguang?

Thanks,
    Paul

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

end of thread, other threads:[~2018-08-09 17:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-11 21:46 [PATCH v4 0/4] MIPS: Override barrier_before_unreachable() to fix microMIPS James Hogan
2018-05-11 21:46 ` [PATCH v4 1/4] alpha: Use OPTIMIZE_INLINING instead of asm/compiler.h James Hogan
2018-05-11 21:47 ` [PATCH v4 2/4] um: Add generated/ to MODE_INCLUDE James Hogan
2018-05-14  9:26   ` James Hogan
2018-08-09 17:51     ` Paul Burton
2018-05-11 21:47 ` [PATCH v4 3/4] compiler.h: Allow arch-specific overrides James Hogan
2018-05-11 21:47 ` [PATCH v4 4/4] 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.