Skip to contentSkip to conversation

powerpc: Build fixes

PATCH In review Nicholas Piggin 3 participants 13 messages Apr 26, 2023

Subsystems (2)
lore
Share & tools
lore

Nicholas Piggin

author reviewer
#0 lore raw

cover powerpc: Build fixes

This series is against powerpc next. The first two patches are independent build fixes for recent patches. Patches 3-5 separate boot Makefile BOOTCFLAGS and BOOTASFLAGS and stops passing some C code generation flags to the assembler which causes some warnings for llvm. Patches 6-9 are not fixes but a bunch of other improvements I noticed along the way.

Thanks,
Nick

Nicholas Piggin (9):
powerpc: Fix merge conflict between pcrel and copy_thread changes powerpc/64s: Disable pcrel code model on Clang powerpc/boot: Seperate target flags from BOOTCFLAGS powerpc/boot: Seperate CPP flags from BOOTCFLAGS powerpc/boot: Separate BOOTCFLAGS from BOOTASFLAGS powerpc/boot: Clean up Makefile after cflags and asflags separation powerpc/build: Remove -pipe from compilation flags powerpc/64s: Permit d-form memops in asm when building with prefix on
clang
powerpc/64s: Work around llvm-as not recognising pla

 arch/powerpc/Kconfig               | 19 ++++++++-
 arch/powerpc/Makefile              |  2 +-
 arch/powerpc/boot/Makefile         | 62 +++++++++++++++---------------
 arch/powerpc/include/asm/atomic.h  |  8 ++--
 arch/powerpc/include/asm/io.h      |  2 +-
 arch/powerpc/include/asm/ppc_asm.h |  5 +++
 arch/powerpc/include/asm/uaccess.h |  4 +-
 arch/powerpc/kernel/interrupt_64.S |  2 +-
 arch/powerpc/kernel/vector.S       |  6 +++
 9 files changed, 70 insertions(+), 40 deletions(-)
Signature · 1 line
2.40.0
author reviewer
#1 lore raw

PATCH 1/9 powerpc: Fix merge conflict between pcrel and copy_thread changes

Fix a conflict between commit 4e991e3c16a35 ("powerpc: add CFUNC assembly label annotation") and commit b504b6aade040 ("powerpc:
differentiate kthread from user kernel thread start").

---
 arch/powerpc/kernel/interrupt_64.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/interrupt_64.S +1 -1
index 6730d676284c..bd863702d812 100644
@@ -756,7 +756,7 @@ _GLOBAL(ret_from_kernel_user_thread)
 	b	.Lsyscall_exit
 
 _GLOBAL(start_kernel_thread)
-	bl	schedule_tail
+	bl	CFUNC(schedule_tail)
 	mtctr	r14
 	mr	r3,r15
 #ifdef CONFIG_PPC64_ELF_ABI_V2
Signature · 1 line
2.40.0
author reviewer
#2 lore raw

PATCH 2/9 powerpc/64s: Disable pcrel code model on Clang

In reply to Nicholas Piggin

Clang has a bug that casues the pcrel code model not to be used when any of -msoft-float, -mno-altivec, or -mno-vsx are set. Leaving these off causes FP/vector instructions to be generated, causing crashes. So disable pcrel for clang for now.

---
 arch/powerpc/Kconfig | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/Kconfig +6 -1
index 7a0f25a09759..261e9453b43c 100644
@@ -8,7 +8,12 @@ config CC_HAS_PREFIXED
 	def_bool PPC64 && $(cc-option, -mcpu=power10 -mprefixed)
 
 config CC_HAS_PCREL
-	def_bool PPC64 && $(cc-option, -mcpu=power10 -mpcrel)
+	# Clang has a bug (https://github.com/llvm/llvm-project/issues/62372)
+	# where pcrel code is not generated if -msoft-float, -mno-altivec, or
+	# -mno-vsx options are also given. Without these options, fp/vec
+	# instructions are generated from regular kernel code. So Clang can't
+	# do pcrel yet.
+	def_bool PPC64 && CC_IS_GCC &&  $(cc-option, -mcpu=power10 -mpcrel)
 
 config 32BIT
 	bool
Signature · 1 line
2.40.0
author reviewer
#3 lore raw

PATCH 3/9 powerpc/boot: Seperate target flags from BOOTCFLAGS

In reply to Nicholas Piggin

Add BOOTTARGETFLAGS variable with target / ABI options common to CFLAGS and AFLAGS.

---
 arch/powerpc/boot/Makefile | 40 ++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 19 deletions(-)
arch/powerpc/boot/Makefile +21 -19
index 85cde5bf04b7..84a5b630c739 100644
@@ -41,36 +41,48 @@ BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
 		 $(LINUXINCLUDE)
 
 ifdef CONFIG_PPC64_BOOT_WRAPPER
-BOOTCFLAGS	+= -m64
+BOOTTARGETFLAGS	:= -m64
 ifdef CONFIG_PPC64_ELF_ABI_V2
-BOOTCFLAGS	+= $(call cc-option,-mabi=elfv2)
+BOOTTARGETFLAGS	+= $(call cc-option,-mabi=elfv2)
 endif
 else
-BOOTCFLAGS	+= -m32
+BOOTTARGETFLAGS	:= -m32
 endif
 
 ifdef CONFIG_TARGET_CPU_BOOL
-BOOTCFLAGS	+= -mcpu=$(CONFIG_TARGET_CPU)
+BOOTTARGETFLAGS	+= -mcpu=$(CONFIG_TARGET_CPU)
 else ifdef CONFIG_PPC64_BOOT_WRAPPER
 ifdef CONFIG_CPU_LITTLE_ENDIAN
-BOOTCFLAGS	+= -mcpu=powerpc64le
+BOOTTARGETFLAGS	+= -mcpu=powerpc64le
 else
-BOOTCFLAGS	+= -mcpu=powerpc64
+BOOTTARGETFLAGS	+= -mcpu=powerpc64
 endif
 endif
 
+$(obj)/4xx.o: BOOTTARGETFLAGS += -mcpu=405
+$(obj)/ebony.o: BOOTTARGETFLAGS += -mcpu=440
+$(obj)/cuboot-hotfoot.o: BOOTTARGETFLAGS += -mcpu=405
+$(obj)/cuboot-taishan.o: BOOTTARGETFLAGS += -mcpu=440
+$(obj)/cuboot-katmai.o: BOOTTARGETFLAGS += -mcpu=440
+$(obj)/cuboot-acadia.o: BOOTTARGETFLAGS += -mcpu=405
+$(obj)/treeboot-iss4xx.o: BOOTTARGETFLAGS += -mcpu=405
+$(obj)/treeboot-currituck.o: BOOTTARGETFLAGS += -mcpu=405
+$(obj)/treeboot-akebono.o: BOOTTARGETFLAGS += -mcpu=405
+
 BOOTCFLAGS	+= -isystem $(shell $(BOOTCC) -print-file-name=include)
 
 ifdef CONFIG_CPU_BIG_ENDIAN
-BOOTCFLAGS	+= -mbig-endian
+BOOTTARGETFLAGS	+= -mbig-endian
 else
-BOOTCFLAGS	+= -mlittle-endian
+BOOTTARGETFLAGS	+= -mlittle-endian
 endif
 
-BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTCFLAGS) -nostdinc
+BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTTARGETFLAGS) $(BOOTCFLAGS) -nostdinc
 
 BOOTARFLAGS	:= -crD
 
+BOOTCFLAGS	+= $(BOOTTARGETFLAGS)
+
 ifdef CONFIG_CC_IS_CLANG
 BOOTCFLAGS += $(CLANG_FLAGS)
 BOOTAFLAGS += $(CLANG_FLAGS)
@@ -89,16 +101,6 @@ BOOTCFLAGS	+= -I$(objtree)/$(obj) -I$(srctree)/$(obj)
 
 DTC_FLAGS	?= -p 1024
 
-$(obj)/4xx.o: BOOTCFLAGS += -mcpu=405
-$(obj)/ebony.o: BOOTCFLAGS += -mcpu=440
-$(obj)/cuboot-hotfoot.o: BOOTCFLAGS += -mcpu=405
-$(obj)/cuboot-taishan.o: BOOTCFLAGS += -mcpu=440
-$(obj)/cuboot-katmai.o: BOOTCFLAGS += -mcpu=440
-$(obj)/cuboot-acadia.o: BOOTCFLAGS += -mcpu=405
-$(obj)/treeboot-iss4xx.o: BOOTCFLAGS += -mcpu=405
-$(obj)/treeboot-currituck.o: BOOTCFLAGS += -mcpu=405
-$(obj)/treeboot-akebono.o: BOOTCFLAGS += -mcpu=405
-
 # The pre-boot decompressors pull in a lot of kernel headers and other source
 # files. This creates a bit of a dependency headache since we need to copy
 # these files into the build dir, fix up any includes and ensure that dependent
Signature · 1 line
2.40.0
author reviewer
#4 lore raw

PATCH 4/9 powerpc/boot: Seperate CPP flags from BOOTCFLAGS

In reply to Nicholas Piggin

Add BOOTCPPFLAGS variable for the CPP options required by C and AS.

---
 arch/powerpc/boot/Makefile | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
arch/powerpc/boot/Makefile +7 -7
index 84a5b630c739..bfeb7a9fef9c 100644
@@ -32,13 +32,15 @@ else
     BOOTAR := $(AR)
 endif
 
+BOOTCPPFLAGS	:= -nostdinc $(LINUXINCLUDE)
+BOOTCPPFLAGS	+= -isystem $(shell $(BOOTCC) -print-file-name=include)
+
 BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
 		 -fno-strict-aliasing -O2 -msoft-float -mno-altivec -mno-vsx \
 		 $(call cc-option,-mno-prefixed) $(call cc-option,-mno-pcrel) \
 		 $(call cc-option,-mno-mma) \
 		 $(call cc-option,-mno-spe) $(call cc-option,-mspe=no) \
-		 -pipe -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
-		 $(LINUXINCLUDE)
+		 -pipe -fomit-frame-pointer -fno-builtin -fPIC
 
 ifdef CONFIG_PPC64_BOOT_WRAPPER
 BOOTTARGETFLAGS	:= -m64
@@ -69,15 +71,13 @@ $(obj)/treeboot-iss4xx.o: BOOTTARGETFLAGS += -mcpu=405
 $(obj)/treeboot-currituck.o: BOOTTARGETFLAGS += -mcpu=405
 $(obj)/treeboot-akebono.o: BOOTTARGETFLAGS += -mcpu=405
 
-BOOTCFLAGS	+= -isystem $(shell $(BOOTCC) -print-file-name=include)
-
 ifdef CONFIG_CPU_BIG_ENDIAN
 BOOTTARGETFLAGS	+= -mbig-endian
 else
 BOOTTARGETFLAGS	+= -mlittle-endian
 endif
 
-BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTTARGETFLAGS) $(BOOTCFLAGS) -nostdinc
+BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTTARGETFLAGS) $(BOOTCFLAGS)
 
 BOOTARFLAGS	:= -crD
 
@@ -224,10 +224,10 @@ clean-files := $(zlib-) $(zlibheader-) $(zliblinuxheader-) \
 		empty.c zImage.coff.lds zImage.ps3.lds zImage.lds
 
 quiet_cmd_bootcc = BOOTCC  $@
-      cmd_bootcc = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
+      cmd_bootcc = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTCPPFLAGS) $(BOOTCFLAGS) -c -o $@ $<
 
 quiet_cmd_bootas = BOOTAS  $@
-      cmd_bootas = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
+      cmd_bootas = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTCPPFLAGS) $(BOOTAFLAGS) -c -o $@ $<
 
 quiet_cmd_bootar = BOOTAR  $@
       cmd_bootar = $(BOOTAR) $(BOOTARFLAGS) $@.$$$$ $(real-prereqs); mv $@.$$$$ $@
Signature · 1 line
2.40.0
author reviewer
#5 lore raw

PATCH 5/9 powerpc/boot: Separate BOOTCFLAGS from BOOTASFLAGS

In reply to Nicholas Piggin

BOOTCFLAGS no longer contains anything that BOOTASFLAGS needs (except -pipe). Separate them to avoid fragility with cross-contamination of flags which has caused several build problems.

---
 arch/powerpc/boot/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/boot/Makefile +1 -1
index bfeb7a9fef9c..99f56c94177f 100644
@@ -77,7 +77,7 @@ else
 BOOTTARGETFLAGS	+= -mlittle-endian
 endif
 
-BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTTARGETFLAGS) $(BOOTCFLAGS)
+BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTTARGETFLAGS) -pipe
 
 BOOTARFLAGS	:= -crD
 
Signature · 1 line
2.40.0
author reviewer
#7 lore raw

PATCH 6/9 powerpc/boot: Clean up Makefile after cflags and asflags separation

In reply to Nicholas Piggin

Tidy pass over boot Makefile. Move variables together where possible.

---
 arch/powerpc/boot/Makefile | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
arch/powerpc/boot/Makefile +13 -13
index 99f56c94177f..0982a7025e66 100644
@@ -32,16 +32,6 @@ else
     BOOTAR := $(AR)
 endif
 
-BOOTCPPFLAGS	:= -nostdinc $(LINUXINCLUDE)
-BOOTCPPFLAGS	+= -isystem $(shell $(BOOTCC) -print-file-name=include)
-
-BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-		 -fno-strict-aliasing -O2 -msoft-float -mno-altivec -mno-vsx \
-		 $(call cc-option,-mno-prefixed) $(call cc-option,-mno-pcrel) \
-		 $(call cc-option,-mno-mma) \
-		 $(call cc-option,-mno-spe) $(call cc-option,-mspe=no) \
-		 -pipe -fomit-frame-pointer -fno-builtin -fPIC
-
 ifdef CONFIG_PPC64_BOOT_WRAPPER
 BOOTTARGETFLAGS	:= -m64
 ifdef CONFIG_PPC64_ELF_ABI_V2
@@ -77,11 +67,21 @@ else
 BOOTTARGETFLAGS	+= -mlittle-endian
 endif
 
-BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTTARGETFLAGS) -pipe
+BOOTCPPFLAGS	:= -nostdinc $(LINUXINCLUDE)
+BOOTCPPFLAGS	+= -isystem $(shell $(BOOTCC) -print-file-name=include)
 
-BOOTARFLAGS	:= -crD
+BOOTCFLAGS	:= -pipe $(BOOTTARGETFLAGS) \
+		   -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
+		   -fno-strict-aliasing -O2 -msoft-float -mno-altivec -mno-vsx \
+		   $(call cc-option,-mno-prefixed) \
+		   $(call cc-option,-mno-pcrel) \
+		   $(call cc-option,-mno-mma) \
+		   $(call cc-option,-mno-spe) $(call cc-option,-mspe=no) \
+		   -fomit-frame-pointer -fno-builtin -fPIC
 
-BOOTCFLAGS	+= $(BOOTTARGETFLAGS)
+BOOTAFLAGS	:= -pipe $(BOOTTARGETFLAGS) -D__ASSEMBLY__
+
+BOOTARFLAGS	:= -crD
 
 ifdef CONFIG_CC_IS_CLANG
 BOOTCFLAGS += $(CLANG_FLAGS)
Signature · 1 line
2.40.0
author reviewer
#8 lore raw

PATCH 6/9 powerpc/boot: clean up Makefile flags

In reply to Nicholas Piggin

Tidy pass over boot Makefile. Move variables together where possible.

---
 arch/powerpc/boot/Makefile | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
arch/powerpc/boot/Makefile +13 -13
index 99f56c94177f..0982a7025e66 100644
@@ -32,16 +32,6 @@ else
     BOOTAR := $(AR)
 endif
 
-BOOTCPPFLAGS	:= -nostdinc $(LINUXINCLUDE)
-BOOTCPPFLAGS	+= -isystem $(shell $(BOOTCC) -print-file-name=include)
-
-BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-		 -fno-strict-aliasing -O2 -msoft-float -mno-altivec -mno-vsx \
-		 $(call cc-option,-mno-prefixed) $(call cc-option,-mno-pcrel) \
-		 $(call cc-option,-mno-mma) \
-		 $(call cc-option,-mno-spe) $(call cc-option,-mspe=no) \
-		 -pipe -fomit-frame-pointer -fno-builtin -fPIC
-
 ifdef CONFIG_PPC64_BOOT_WRAPPER
 BOOTTARGETFLAGS	:= -m64
 ifdef CONFIG_PPC64_ELF_ABI_V2
@@ -77,11 +67,21 @@ else
 BOOTTARGETFLAGS	+= -mlittle-endian
 endif
 
-BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTTARGETFLAGS) -pipe
+BOOTCPPFLAGS	:= -nostdinc $(LINUXINCLUDE)
+BOOTCPPFLAGS	+= -isystem $(shell $(BOOTCC) -print-file-name=include)
 
-BOOTARFLAGS	:= -crD
+BOOTCFLAGS	:= -pipe $(BOOTTARGETFLAGS) \
+		   -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
+		   -fno-strict-aliasing -O2 -msoft-float -mno-altivec -mno-vsx \
+		   $(call cc-option,-mno-prefixed) \
+		   $(call cc-option,-mno-pcrel) \
+		   $(call cc-option,-mno-mma) \
+		   $(call cc-option,-mno-spe) $(call cc-option,-mspe=no) \
+		   -fomit-frame-pointer -fno-builtin -fPIC
 
-BOOTCFLAGS	+= $(BOOTTARGETFLAGS)
+BOOTAFLAGS	:= -pipe $(BOOTTARGETFLAGS) -D__ASSEMBLY__
+
+BOOTARFLAGS	:= -crD
 
 ifdef CONFIG_CC_IS_CLANG
 BOOTCFLAGS += $(CLANG_FLAGS)
Signature · 1 line
2.40.0
author reviewer
#9 lore raw

PATCH 7/9 powerpc/build: Remove -pipe from compilation flags

In reply to Nicholas Piggin

x86 removed -pipe in commit 437e88ab8f9e2 ("x86/build: Remove -pipe from KBUILD_CFLAGS") and the newer arm64 and riscv seem to have never used it, so that seems to be the way the world's going.

Compile performance building defconfig on a POWER10 PowerNV system was in the noise after 10 builds each. No point in adding options unless they help something, so remove it.

---
 arch/powerpc/Makefile      | 2 +-
 arch/powerpc/boot/Makefile | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/Makefile +1 -1
index dca73f673d70..76fc7cc26780 100644
@@ -166,7 +166,7 @@ asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
 KBUILD_CPPFLAGS	+= -I $(srctree)/arch/$(ARCH) $(asinstr)
 KBUILD_AFLAGS	+= $(AFLAGS-y)
 KBUILD_CFLAGS	+= $(call cc-option,-msoft-float)
-KBUILD_CFLAGS	+= -pipe $(CFLAGS-y)
+KBUILD_CFLAGS	+= $(CFLAGS-y)
 CPP		= $(CC) -E $(KBUILD_CFLAGS)
 
 CHECKFLAGS	+= -m$(BITS) -D__powerpc__ -D__powerpc$(BITS)__
arch/powerpc/boot/Makefile +2 -2
index 0982a7025e66..1c9951153bae 100644
@@ -70,7 +70,7 @@ endif
 BOOTCPPFLAGS	:= -nostdinc $(LINUXINCLUDE)
 BOOTCPPFLAGS	+= -isystem $(shell $(BOOTCC) -print-file-name=include)
 
-BOOTCFLAGS	:= -pipe $(BOOTTARGETFLAGS) \
+BOOTCFLAGS	:= $(BOOTTARGETFLAGS) \
 		   -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
 		   -fno-strict-aliasing -O2 -msoft-float -mno-altivec -mno-vsx \
 		   $(call cc-option,-mno-prefixed) \
@@ -79,7 +79,7 @@ BOOTCFLAGS	:= -pipe $(BOOTTARGETFLAGS) \
 		   $(call cc-option,-mno-spe) $(call cc-option,-mspe=no) \
 		   -fomit-frame-pointer -fno-builtin -fPIC
 
-BOOTAFLAGS	:= -pipe $(BOOTTARGETFLAGS) -D__ASSEMBLY__
+BOOTAFLAGS	:= $(BOOTTARGETFLAGS) -D__ASSEMBLY__
 
 BOOTARFLAGS	:= -crD
 
Signature · 1 line
2.40.0
author reviewer
#10 lore raw

PATCH 8/9 powerpc/64s: Permit d-form memops in asm when building with prefix on clang

In reply to Nicholas Piggin

GCC appears to have a bug where it generates immediate offsets beyond the 16-bit range of d-form memory operations in extended inline asm when prefix instructions are enabled. So simpler fallback asm is implemented for CONFIG_PPC_KERNEL_PREFIXED builds for now.

Clang does not have this bug, so this hack can be restricted to GCC.

---
 arch/powerpc/Kconfig               | 7 +++++++
 arch/powerpc/include/asm/atomic.h  | 8 ++++----
 arch/powerpc/include/asm/io.h      | 2 +-
 arch/powerpc/include/asm/uaccess.h | 4 ++--
 4 files changed, 14 insertions(+), 7 deletions(-)
arch/powerpc/Kconfig +7 -0
index 261e9453b43c..39cd8d3ff846 100644
@@ -7,6 +7,13 @@ config CC_HAS_ELFV2
 config CC_HAS_PREFIXED
 	def_bool PPC64 && $(cc-option, -mcpu=power10 -mprefixed)
 
+config CC_HAS_BROKEN_DFORM_MEMOP_ASM
+	# GCC has a bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108239)
+	# when compiling with prefixed instructions that causes it to generate
+	# out-of-range offsets for d-form loads and stores from memory
+	# operands.
+	def_bool CC_HAS_PREFIXED && CC_IS_GCC
+
 config CC_HAS_PCREL
 	# Clang has a bug (https://github.com/llvm/llvm-project/issues/62372)
 	# where pcrel code is not generated if -msoft-float, -mno-altivec, or
arch/powerpc/include/asm/atomic.h +4 -4
index 47228b177478..f15c9e54e261 100644
@@ -28,7 +28,7 @@ static __inline__ int arch_atomic_read(const atomic_t *v)
 	int t;
 
 	/* -mprefixed can generate offsets beyond range, fall back hack */
-	if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED))
+	if (IS_ENABLED(CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM))
 		__asm__ __volatile__("lwz %0,0(%1)" : "=r"(t) : "b"(&v->counter));
 	else
 		__asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m<>"(v->counter));
@@ -39,7 +39,7 @@ static __inline__ int arch_atomic_read(const atomic_t *v)
 static __inline__ void arch_atomic_set(atomic_t *v, int i)
 {
 	/* -mprefixed can generate offsets beyond range, fall back hack */
-	if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED))
+	if (IS_ENABLED(CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM))
 		__asm__ __volatile__("stw %1,0(%2)" : "=m"(v->counter) : "r"(i), "b"(&v->counter));
 	else
 		__asm__ __volatile__("stw%U0%X0 %1,%0" : "=m<>"(v->counter) : "r"(i));
@@ -206,7 +206,7 @@ static __inline__ s64 arch_atomic64_read(const atomic64_t *v)
 	s64 t;
 
 	/* -mprefixed can generate offsets beyond range, fall back hack */
-	if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED))
+	if (IS_ENABLED(CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM))
 		__asm__ __volatile__("ld %0,0(%1)" : "=r"(t) : "b"(&v->counter));
 	else
 		__asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m<>"(v->counter));
@@ -217,7 +217,7 @@ static __inline__ s64 arch_atomic64_read(const atomic64_t *v)
 static __inline__ void arch_atomic64_set(atomic64_t *v, s64 i)
 {
 	/* -mprefixed can generate offsets beyond range, fall back hack */
-	if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED))
+	if (IS_ENABLED(CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM))
 		__asm__ __volatile__("std %1,0(%2)" : "=m"(v->counter) : "r"(i), "b"(&v->counter));
 	else
 		__asm__ __volatile__("std%U0%X0 %1,%0" : "=m<>"(v->counter) : "r"(i));
arch/powerpc/include/asm/io.h +1 -1
index f1e657c9bbe8..2e6061f26c09 100644
@@ -98,7 +98,7 @@ extern bool isa_io_special;
  */
 
 /* -mprefixed can generate offsets beyond range, fall back hack */
-#ifdef CONFIG_PPC_KERNEL_PREFIXED
+#ifdef CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM
 #define DEF_MMIO_IN_X(name, size, insn)				\
 static inline u##size name(const volatile u##size __iomem *addr)	\
 {									\
arch/powerpc/include/asm/uaccess.h +2 -2
index a2d255aa9627..6fdca4cddcf3 100644
@@ -72,7 +72,7 @@ __pu_failed:							\
  * are no aliasing issues.
  */
 /* -mprefixed can generate offsets beyond range, fall back hack */
-#ifdef CONFIG_PPC_KERNEL_PREFIXED
+#ifdef CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM
 #define __put_user_asm_goto(x, addr, label, op)			\
 	asm_volatile_goto(					\
 		"1:	" op " %0,0(%1)	# put_user\n"		\
@@ -144,7 +144,7 @@ do {								\
 #ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT
 
 /* -mprefixed can generate offsets beyond range, fall back hack */
-#ifdef CONFIG_PPC_KERNEL_PREFIXED
+#ifdef CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM
 #define __get_user_asm_goto(x, addr, label, op)			\
 	asm_volatile_goto(					\
 		"1:	"op" %0,0(%1)	# get_user\n"		\
Signature · 1 line
2.40.0
author reviewer
#11 lore raw

PATCH 9/9 powerpc/64s: Work around llvm-as not recognising pla

In reply to Nicholas Piggin

llvm-as does not recognise the pla mnemonic, which is used for pcrel address generation. Use the equivalent paddi opcode instead. Clang can not build working pcrel kernels yet, but this patch does allow it to build a non-working pcrel kernel with llvm-as.

This could be unconditional or use a raw encoding, but this gives a placeholder to track the issue.

---
 arch/powerpc/Kconfig               | 5 +++++
 arch/powerpc/include/asm/ppc_asm.h | 5 +++++
 arch/powerpc/kernel/vector.S       | 6 ++++++
 3 files changed, 16 insertions(+)
arch/powerpc/Kconfig +5 -0
index 39cd8d3ff846..2f7840577f7f 100644
@@ -22,6 +22,11 @@ config CC_HAS_PCREL
 	# do pcrel yet.
 	def_bool PPC64 && CC_IS_GCC &&  $(cc-option, -mcpu=power10 -mpcrel)
 
+config AS_HAS_MISSING_PLA_INSN
+	# llvm-as is missing some extended mnemonics including pla
+	# (https://github.com/llvm/llvm-project/issues/62373).
+	def_bool AS_IS_LLVM
+
 config 32BIT
 	bool
 	default y if PPC32
arch/powerpc/include/asm/ppc_asm.h +5 -0
index 5f05a984b103..736202ebc1be 100644
@@ -380,8 +380,13 @@ GLUE(.,name):
 	rldimi	reg, tmp, 32, 0
 
 #ifdef CONFIG_PPC_KERNEL_PCREL
+#ifdef CONFIG_AS_HAS_MISSING_PLA_INSN
+#define LOAD_REG_ADDR(reg,name)			\
+	paddi	reg,0,name@pcrel,1
+#else
 #define LOAD_REG_ADDR(reg,name)			\
 	pla	reg,name@pcrel
+#endif
 
 #else
 #define LOAD_REG_ADDR(reg,name)			\
arch/powerpc/kernel/vector.S +6 -0
index fcc0ad6d9c7b..c2feaea5e673 100644
@@ -178,9 +178,15 @@ fphalf:
 	.quad	0x3fe0000000000000	/* 0.5 */
 
 #ifdef CONFIG_PPC_KERNEL_PCREL
+#ifdef CONFIG_AS_HAS_MISSING_PLA_INSN
+#define LDCONST(fr, name)		\
+	paddi	r11,0,name@pcrel,1;	\
+	lfd	fr,0(r11)
+#else
 #define LDCONST(fr, name)		\
 	pla	r11,name@pcrel;		\
 	lfd	fr,0(r11)
+#endif
 #else
 #define LDCONST(fr, name)		\
 	addis	r11,r2,name@toc@ha;	\
Signature · 1 line
2.40.0
#12 lore raw

Re: (subset) [PATCH 0/9] powerpc: Build fixes

In reply to Nicholas Piggin
Quoted 8 lines · Nicholas Piggin

This series is against powerpc next. The first two patches are independent build fixes for recent patches. Patches 3-5 separate boot Makefile BOOTCFLAGS and BOOTASFLAGS and stops passing some C code generation flags to the assembler which causes some warnings for llvm. Patches 6-9 are not fixes but a bunch of other improvements I noticed along the way.

[...]

Patches 1& 2 applied to powerpc/next.

[1/9] powerpc: Fix merge conflict between pcrel and copy_thread changes

      https://git.kernel.org/powerpc/c/0c993300d52bf5ce9b951c3b6b25d0d14acc49a9
[2/9] powerpc/64s: Disable pcrel code model on Clang
      https://git.kernel.org/powerpc/c/169f8997968ab620d750d9a45e15c5288d498356

cheers

#6 lore raw

Re: [PATCH 5/9] powerpc/boot: Separate BOOTCFLAGS from BOOTASFLAGS

In reply to Nicholas Piggin
Quoted 2 lines · Nicholas Piggin

I was all "what is Nick talking about", and had to follow the link to remember that old discussion at all.

Patch obviously looks fine to me, I'll presumably be getting it at some future point as part of a ppc pull request.

Linus