Skip to contentSkip to conversation

arm64: Paper over ARM_SMCCC_ARCH_WORKAROUND_3 Clang issue

PATCH In review Marc Zyngier 5 participants 8 messages Mar 9, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: Paper over ARM_SMCCC_ARCH_WORKAROUND_3 Clang issue

Compiling the arm64 kernel with the BHB workarounds and Clang+LTO results in a bunch of:

<instantiation>:4:2: error: invalid fixup for movz/movk instruction
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_3

when compiling arch/arm64/kernel/entry.S, and makes no sense at all.

As it turns out, moving a single include line around makes the problem disappear. Why, you'd ask? Well, I don't have the faintest idea, and I'm running out of patience. So make of that what you want.

Cc James Morse <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Will Deacon <[email protected]>
Cc Catalin Marinas <[email protected]>
---
 include/linux/arm-smccc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/arm-smccc.h +1 -1
index 220c8c60e021..0a341dd9ff61 100644
@@ -5,7 +5,6 @@
 #ifndef __LINUX_ARM_SMCCC_H
 #define __LINUX_ARM_SMCCC_H
 
-#include <linux/init.h>
 #include <uapi/linux/const.h>
 
 /*
@@ -193,6 +192,7 @@
 
 #ifndef __ASSEMBLY__
 
+#include <linux/init.h>
 #include <linux/linkage.h>
 #include <linux/types.h>
 
Signature · 7 lines
2.34.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Acked-by Tested-by on v1 1/1
#1 lore raw

Hi Marc,

Quoted 11 lines · Marc Zyngier

Compiling the arm64 kernel with the BHB workarounds and Clang+LTO results in a bunch of:

<instantiation>:4:2: error: invalid fixup for movz/movk instruction
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_3

when compiling arch/arm64/kernel/entry.S, and makes no sense at all.

As it turns out, moving a single include line around makes the problem disappear. Why, you'd ask? Well, I don't have the faintest idea, and I'm running out of patience. So make of that what you want.

Thanks for this - I've been banging my head against the keyboard too. My attempt is below, maybe that helps the toolchain people pin it down. Catalin doesn't like it as he sensibly wants to keep the sequences together.

Thanks,

James

Build incantation: make LLVM=1 -s -j 56 LD=ld.lld-11 clang --version:
Debian clang version 12.0.0-++20200929085817+962a247aebb-1~exp1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

The 'exp' in debian's clang version spooked me, but I can also reproduce this with debian's clang-11:

make LLVM=1 -s -j 56 LD=ld.lld-11 CC=clang-11

clang-11 --version
Debian clang version 11.0.1-2
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Works, but equally inexplicable.
-----%<------

arch/arm64/include/asm/assembler.h +0 -13
index 6ebdc0f834a7..fd83baf1c552 100644
@@ -880,20 +880,6 @@ alternative_cb_end
 #endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
 	.endm
 -	/* Save/restores x0-x3 to the stack */
-	.macro __mitigate_spectre_bhb_fw
-#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
-	stp	x0, x1, [sp, #-16]!
-	stp	x2, x3, [sp, #-16]!
-	mov	w0, #ARM_SMCCC_ARCH_WORKAROUND_3
-alternative_cb	smccc_patch_fw_mitigation_conduit
-	nop					// Patched to SMC/HVC #0
-alternative_cb_end
-	ldp	x2, x3, [sp], #16
-	ldp	x0, x1, [sp], #16
-#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
-	.endm
-
 	.macro mitigate_spectre_bhb_clear_insn
 #ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
 alternative_cb	spectre_bhb_patch_clearbhb
arch/arm64/kernel/entry.S +13 -0
index 4a3a653df07e..03fbb561dcb3 100644
@@ -659,6 +659,20 @@ alternative_else_nop_endif
 #define BHB_MITIGATION_FW	2
 #define BHB_MITIGATION_INSN	3
 +	/* Save/restores x0-x3 to the stack */
+	.macro __mitigate_spectre_bhb_fw
+#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
+	stp	x0, x1, [sp, #-16]!
+	stp	x2, x3, [sp, #-16]!
+	mov	w0, #ARM_SMCCC_ARCH_WORKAROUND_3
+alternative_cb	smccc_patch_fw_mitigation_conduit
+	nop					// Patched to SMC/HVC #0
+alternative_cb_end
+	ldp	x2, x3, [sp], #16
+	ldp	x0, x1, [sp], #16
+#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
+	.endm
+
 	.macro tramp_ventry, vector_start, regsize, kpti, bhb
 	.align	7
 1:

-----%<------

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw
In reply to Marc Zyngier
Quoted 43 lines · Marc Zyngier

Compiling the arm64 kernel with the BHB workarounds and Clang+LTO results in a bunch of:

<instantiation>:4:2: error: invalid fixup for movz/movk instruction
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_3

when compiling arch/arm64/kernel/entry.S, and makes no sense at all.

As it turns out, moving a single include line around makes the problem disappear. Why, you'd ask? Well, I don't have the faintest idea, and I'm running out of patience. So make of that what you want.

Cc James Morse <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Will Deacon <[email protected]>
Cc Catalin Marinas <[email protected]>
---
 include/linux/arm-smccc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/arm-smccc.h +1 -1
index 220c8c60e021..0a341dd9ff61 100644
@@ -5,7 +5,6 @@
 #ifndef __LINUX_ARM_SMCCC_H
 #define __LINUX_ARM_SMCCC_H
 
-#include <linux/init.h>
 #include <uapi/linux/const.h>
 
 /*
@@ -193,6 +192,7 @@
 
 #ifndef __ASSEMBLY__
 
+#include <linux/init.h>
 #include <linux/linkage.h>
 #include <linux/types.h>
 
Signature · 1 line
2.34.1

I am still looking at this but I wanted to post a preliminary finding. It seems the source of the error is that ARM_SMCCC_ARCH_WORKAROUND_3 is not getting expanded by the preprocessor. If you preprocess arch/arm64/kernel/entry.S without LTO then with LTO, it reveals the attached diff, which shows just "#ARM_SMCCC_ARCH_WORKAROUND_3", rather than "# (((1) << 31) | ((0) << 30) | (((0) & 0x3F) << 24) | ((0x3fff) & 0xFFFF))".

$ make -skj"$(nproc)" ARCH=arm64 LLVM=1 mrproper defconfig arch/arm64/kernel/entry.s

I'll see if I can figure out what is going wrong in the include chain.

Cheers,
Nathan

entry.s.bad renamed from entry.s.good +179 -165
index ab98e34..b331cc4 100644
@@ -35,71 +35,17 @@
 # 6 "./include/linux/compiler.h" 2
 # 266 "./include/linux/compiler.h"
 # 1 "./arch/arm64/include/asm/rwonce.h" 1
-# 71 "./arch/arm64/include/asm/rwonce.h"
-# 1 "./include/asm-generic/rwonce.h" 1
-# 72 "./arch/arm64/include/asm/rwonce.h" 2
-# 267 "./include/linux/compiler.h" 2
-# 6 "./include/linux/init.h" 2
-# 1 "./include/linux/types.h" 1
-
-
-
-
-
-# 1 "./include/uapi/linux/types.h" 1
-
-
-
-
-# 1 "./arch/arm64/include/generated/uapi/asm/types.h" 1
-# 1 "./include/uapi/asm-generic/types.h" 1
-
-
-
-
-
-
-# 1 "./include/asm-generic/int-ll64.h" 1
-# 11 "./include/asm-generic/int-ll64.h"
-# 1 "./include/uapi/asm-generic/int-ll64.h" 1
-# 12 "./include/uapi/asm-generic/int-ll64.h"
-# 1 "./arch/arm64/include/uapi/asm/bitsperlong.h" 1
-# 22 "./arch/arm64/include/uapi/asm/bitsperlong.h"
-# 1 "./include/asm-generic/bitsperlong.h" 1
-
-
-
-
-# 1 "./include/uapi/asm-generic/bitsperlong.h" 1
-# 6 "./include/asm-generic/bitsperlong.h" 2
-# 23 "./arch/arm64/include/uapi/asm/bitsperlong.h" 2
-# 13 "./include/uapi/asm-generic/int-ll64.h" 2
-# 12 "./include/asm-generic/int-ll64.h" 2
-# 8 "./include/uapi/asm-generic/types.h" 2
-# 2 "./arch/arm64/include/generated/uapi/asm/types.h" 2
-# 6 "./include/uapi/linux/types.h" 2
-# 7 "./include/linux/types.h" 2
-# 7 "./include/linux/init.h" 2
-# 9 "./include/linux/arm-smccc.h" 2
-# 1 "./include/uapi/linux/const.h" 1
-# 10 "./include/linux/arm-smccc.h" 2
-# 11 "arch/arm64/kernel/entry.S" 2
-
-# 1 "./include/linux/linkage.h" 1
-
-
-
-
-
-# 1 "./include/linux/stringify.h" 1
-# 7 "./include/linux/linkage.h" 2
-# 1 "./include/linux/export.h" 1
-# 8 "./include/linux/linkage.h" 2
-# 1 "./arch/arm64/include/asm/linkage.h" 1
+# 11 "./arch/arm64/include/asm/rwonce.h"
+# 1 "./arch/arm64/include/asm/alternative-macros.h" 1
 
 
 
 
+# 1 "./arch/arm64/include/generated/asm/cpucaps.h" 1
+# 6 "./arch/arm64/include/asm/alternative-macros.h" 2
+# 1 "./arch/arm64/include/asm/insn-def.h" 1
+# 7 "./arch/arm64/include/asm/alternative-macros.h" 2
+# 80 "./arch/arm64/include/asm/alternative-macros.h"
 # 1 "./arch/arm64/include/asm/assembler.h" 1
 # 15 "./arch/arm64/include/asm/assembler.h"
 # 1 "./include/asm-generic/export.h" 1
@@ -141,108 +87,6 @@ __kstrtab_\name:
 
 
 # 1 "./arch/arm64/include/asm/alternative-macros.h" 1
-
-
-
-
-# 1 "./arch/arm64/include/generated/asm/cpucaps.h" 1
-# 6 "./arch/arm64/include/asm/alternative-macros.h" 2
-# 1 "./arch/arm64/include/asm/insn-def.h" 1
-# 7 "./arch/arm64/include/asm/alternative-macros.h" 2
-# 80 "./arch/arm64/include/asm/alternative-macros.h"
-# 1 "./arch/arm64/include/asm/assembler.h" 1
-# 81 "./arch/arm64/include/asm/alternative-macros.h" 2
-
-.macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len
- .word \orig_offset - .
- .word \alt_offset - .
- .hword \feature
- .byte \orig_len
- .byte \alt_len
-.endm
-
-.macro alternative_insn insn1, insn2, cap, enable = 1
- .if \enable
-661: \insn1
-662: .pushsection .altinstructions, "a"
- altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f
- .popsection
- .subsection 1
-663: \insn2
-664: .org . - (664b-663b) + (662b-661b)
- .org . - (662b-661b) + (664b-663b)
- .previous
- .endif
-.endm
-# 126 "./arch/arm64/include/asm/alternative-macros.h"
-.macro alternative_if_not cap
- .set .Lasm_alt_mode, 0
- .pushsection .altinstructions, "a"
- altinstruction_entry 661f, 663f, \cap, 662f-661f, 664f-663f
- .popsection
-661:
-.endm
-
-.macro alternative_if cap
- .set .Lasm_alt_mode, 1
- .pushsection .altinstructions, "a"
- altinstruction_entry 663f, 661f, \cap, 664f-663f, 662f-661f
- .popsection
- .subsection 1
- .align 2
-661:
-.endm
-
-.macro alternative_cb cb
- .set .Lasm_alt_mode, 0
- .pushsection .altinstructions, "a"
- altinstruction_entry 661f, \cb, 71, 662f-661f, 0
- .popsection
-661:
-.endm
-
-
-
-
-.macro alternative_else
-662:
- .if .Lasm_alt_mode==0
- .subsection 1
- .else
- .previous
- .endif
-663:
-.endm
-
-
-
-
-.macro alternative_endif
-664:
- .org . - (664b-663b) + (662b-661b)
- .org . - (662b-661b) + (664b-663b)
- .if .Lasm_alt_mode==0
- .previous
- .endif
-.endm
-
-
-
-
-.macro alternative_cb_end
-662:
-.endm
-
-
-
-
-
-
-.macro alternative_else_nop_endif
-alternative_else
- nops (662b-661b) / 4
-alternative_endif
-.endm
 # 6 "./arch/arm64/include/asm/alternative.h" 2
 # 18 "./arch/arm64/include/asm/assembler.h" 2
 # 1 "./arch/arm64/include/asm/asm-bug.h" 1
@@ -305,12 +149,30 @@ alternative_endif
 
 
 # 1 "./include/vdso/const.h" 1
+
+
+
+
+# 1 "./include/uapi/linux/const.h" 1
+# 6 "./include/vdso/const.h" 2
 # 5 "./include/linux/const.h" 2
 # 6 "./include/linux/bits.h" 2
 # 1 "./include/vdso/bits.h" 1
 # 7 "./include/linux/bits.h" 2
-# 13 "./arch/arm64/include/asm/sysreg.h" 2
+# 1 "./arch/arm64/include/uapi/asm/bitsperlong.h" 1
+# 22 "./arch/arm64/include/uapi/asm/bitsperlong.h"
+# 1 "./include/asm-generic/bitsperlong.h" 1
+
+
 
+
+# 1 "./include/uapi/asm-generic/bitsperlong.h" 1
+# 6 "./include/asm-generic/bitsperlong.h" 2
+# 23 "./arch/arm64/include/uapi/asm/bitsperlong.h" 2
+# 8 "./include/linux/bits.h" 2
+# 13 "./arch/arm64/include/asm/sysreg.h" 2
+# 1 "./include/linux/stringify.h" 1
+# 14 "./arch/arm64/include/asm/sysreg.h" 2
 # 1 "./include/linux/kasan-tags.h" 1
 # 15 "./arch/arm64/include/asm/sysreg.h" 2
 
@@ -365,8 +227,35 @@ alternative_endif
 # 2 "./include/uapi/linux/errno.h" 2
 # 6 "./include/linux/errno.h" 2
 # 9 "./arch/arm64/include/asm/debug-monitors.h" 2
+# 1 "./include/linux/types.h" 1
+
+
+
 
 
+# 1 "./include/uapi/linux/types.h" 1
+
+
+
+
+# 1 "./arch/arm64/include/generated/uapi/asm/types.h" 1
+# 1 "./include/uapi/asm-generic/types.h" 1
+
+
+
+
+
+
+# 1 "./include/asm-generic/int-ll64.h" 1
+# 11 "./include/asm-generic/int-ll64.h"
+# 1 "./include/uapi/asm-generic/int-ll64.h" 1
+# 12 "./include/asm-generic/int-ll64.h" 2
+# 8 "./include/uapi/asm-generic/types.h" 2
+# 2 "./arch/arm64/include/generated/uapi/asm/types.h" 2
+# 6 "./include/uapi/linux/types.h" 2
+# 7 "./include/linux/types.h" 2
+# 10 "./arch/arm64/include/asm/debug-monitors.h" 2
+
 # 1 "./arch/arm64/include/asm/esr.h" 1
 # 10 "./arch/arm64/include/asm/esr.h"
 # 1 "./arch/arm64/include/asm/memory.h" 1
@@ -389,6 +278,12 @@ alternative_endif
 # 1 "./arch/arm64/include/asm/insn.h" 1
 # 10 "./arch/arm64/include/asm/insn.h"
 # 1 "./include/linux/build_bug.h" 1
+
+
+
+
+# 1 "./include/linux/compiler.h" 1
+# 6 "./include/linux/build_bug.h" 2
 # 11 "./arch/arm64/include/asm/insn.h" 2
 # 13 "./arch/arm64/include/asm/debug-monitors.h" 2
 # 1 "./arch/arm64/include/asm/ptrace.h" 1
@@ -409,6 +304,9 @@ alternative_endif
 # 26 "./arch/arm64/include/asm/assembler.h" 2
 
 # 1 "./arch/arm64/include/asm/thread_info.h" 1
+# 11 "./arch/arm64/include/asm/thread_info.h"
+# 1 "./include/linux/compiler.h" 1
+# 12 "./arch/arm64/include/asm/thread_info.h" 2
 # 28 "./arch/arm64/include/asm/assembler.h" 2
 
 
@@ -1089,7 +987,7 @@ alternative_cb_end
 
  stp x0, x1, [sp, #-16]!
  stp x2, x3, [sp, #-16]!
- mov w0, #(((1) << 31) | ((0) << 30) | (((0) & 0x3F) << 24) | ((0x3fff) & 0xFFFF))
+ mov w0, #ARM_SMCCC_ARCH_WORKAROUND_3
 alternative_cb smccc_patch_fw_mitigation_conduit
  nop
 alternative_cb_end
@@ -1097,6 +995,122 @@ alternative_cb_end
  ldp x0, x1, [sp], #16
 
  .endm
+# 81 "./arch/arm64/include/asm/alternative-macros.h" 2
+
+.macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len
+ .word \orig_offset - .
+ .word \alt_offset - .
+ .hword \feature
+ .byte \orig_len
+ .byte \alt_len
+.endm
+
+.macro alternative_insn insn1, insn2, cap, enable = 1
+ .if \enable
+661: \insn1
+662: .pushsection .altinstructions, "a"
+ altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f
+ .popsection
+ .subsection 1
+663: \insn2
+664: .org . - (664b-663b) + (662b-661b)
+ .org . - (662b-661b) + (664b-663b)
+ .previous
+ .endif
+.endm
+# 126 "./arch/arm64/include/asm/alternative-macros.h"
+.macro alternative_if_not cap
+ .set .Lasm_alt_mode, 0
+ .pushsection .altinstructions, "a"
+ altinstruction_entry 661f, 663f, \cap, 662f-661f, 664f-663f
+ .popsection
+661:
+.endm
+
+.macro alternative_if cap
+ .set .Lasm_alt_mode, 1
+ .pushsection .altinstructions, "a"
+ altinstruction_entry 663f, 661f, \cap, 664f-663f, 662f-661f
+ .popsection
+ .subsection 1
+ .align 2
+661:
+.endm
+
+.macro alternative_cb cb
+ .set .Lasm_alt_mode, 0
+ .pushsection .altinstructions, "a"
+ altinstruction_entry 661f, \cb, 71, 662f-661f, 0
+ .popsection
+661:
+.endm
+
+
+
+
+.macro alternative_else
+662:
+ .if .Lasm_alt_mode==0
+ .subsection 1
+ .else
+ .previous
+ .endif
+663:
+.endm
+
+
+
+
+.macro alternative_endif
+664:
+ .org . - (664b-663b) + (662b-661b)
+ .org . - (662b-661b) + (664b-663b)
+ .if .Lasm_alt_mode==0
+ .previous
+ .endif
+.endm
+
+
+
+
+.macro alternative_cb_end
+662:
+.endm
+
+
+
+
+
+
+.macro alternative_else_nop_endif
+alternative_else
+ nops (662b-661b) / 4
+alternative_endif
+.endm
+# 12 "./arch/arm64/include/asm/rwonce.h" 2
+# 71 "./arch/arm64/include/asm/rwonce.h"
+# 1 "./include/asm-generic/rwonce.h" 1
+# 72 "./arch/arm64/include/asm/rwonce.h" 2
+# 267 "./include/linux/compiler.h" 2
+# 6 "./include/linux/init.h" 2
+# 9 "./include/linux/arm-smccc.h" 2
+# 11 "arch/arm64/kernel/entry.S" 2
+
+# 1 "./include/linux/linkage.h" 1
+
+
+
+
+
+
+# 1 "./include/linux/export.h" 1
+# 8 "./include/linux/linkage.h" 2
+# 1 "./arch/arm64/include/asm/linkage.h" 1
+
+
+
+
+# 1 "./arch/arm64/include/asm/assembler.h" 1
 # 6 "./arch/arm64/include/asm/linkage.h" 2
 # 9 "./include/linux/linkage.h" 2
 # 13 "arch/arm64/kernel/entry.S" 2
#3 lore raw
Quoted 42 lines · Nathan Chancellor
Quoted 41 lines · Marc Zyngier

Compiling the arm64 kernel with the BHB workarounds and Clang+LTO results in a bunch of:

<instantiation>:4:2: error: invalid fixup for movz/movk instruction
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_3

when compiling arch/arm64/kernel/entry.S, and makes no sense at all.

As it turns out, moving a single include line around makes the problem disappear. Why, you'd ask? Well, I don't have the faintest idea, and I'm running out of patience. So make of that what you want.

Cc James Morse <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Will Deacon <[email protected]>
Cc Catalin Marinas <[email protected]>
---
 include/linux/arm-smccc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/arm-smccc.h +1 -1
index 220c8c60e021..0a341dd9ff61 100644
@@ -5,7 +5,6 @@
 #ifndef __LINUX_ARM_SMCCC_H
 #define __LINUX_ARM_SMCCC_H
 
-#include <linux/init.h>
 #include <uapi/linux/const.h>
 
 /*
@@ -193,6 +192,7 @@
 
 #ifndef __ASSEMBLY__
 
+#include <linux/init.h>
 #include <linux/linkage.h>
 #include <linux/types.h>
 
Quoted 9 lines
Quoted 2 lines
Signature · 1 line
2.34.1

I am still looking at this but I wanted to post a preliminary finding. It seems the source of the error is that ARM_SMCCC_ARCH_WORKAROUND_3 is not getting expanded by the preprocessor. If you preprocess arch/arm64/kernel/entry.S without LTO then with LTO, it reveals the attached diff, which shows just "#ARM_SMCCC_ARCH_WORKAROUND_3", rather than "# (((1) << 31) | ((0) << 30) | (((0) & 0x3F) << 24) | ((0x3fff) & 0xFFFF))".

CONFIG_LTO=y causes the following include chain:

include/linux/arm-smccc.h
include/linux/init.h
include/linux/compiler.h
arch/arm64/include/asm/rwonce.h
arch/arm64/include/asm/alternative-macros.h
arch/arm64/include/asm/assembler.h

assembler.h has the use of ARM_SMCCC_ARCH_WORKAROUND_3 but the init.h include in arm-smccc.h happens before the definition, so it does not get expanded. This completely hacky patch proves that, as the error goes away with it:

include/linux/arm-smccc.h +2 -1
index 220c8c60e021..6cf6bcf00647 100644
@@ -5,7 +5,6 @@
 #ifndef __LINUX_ARM_SMCCC_H
 #define __LINUX_ARM_SMCCC_H
 
-#include <linux/init.h>
 #include <uapi/linux/const.h>
 
 /*
@@ -97,6 +96,8 @@
 			   ARM_SMCCC_SMC_32,				\
 			   0, 0x3fff)
 
+#include <linux/init.h>
+
 #define ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID				\
 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
 			   ARM_SMCCC_SMC_32,				\

This diff seems like a somewhat proper solution, as __READ_ONCE() cannot be used in assembly, but I am open to other suggestions.

arch/arm64/include/asm/rwonce.h +2 -2
index 1bce62fa908a..56f7b1d4d54b 100644
@@ -5,7 +5,7 @@
 #ifndef __ASM_RWONCE_H
 #define __ASM_RWONCE_H
 
-#ifdef CONFIG_LTO
+#if defined(CONFIG_LTO) && !defined(__ASSEMBLY__)
 
 #include <linux/compiler_types.h>
 #include <asm/alternative-macros.h>
@@ -66,7 +66,7 @@
 })
 
 #endif	/* !BUILD_VDSO */
-#endif	/* CONFIG_LTO */
+#endif	/* CONFIG_LTO && !__ASSEMBLY__ */
 
 #include <asm-generic/rwonce.h>
 

Cheers,
Nathan

Acked-by
#4 lore raw

Hi Nathan,

Quoted 13 lines · Nathan Chancellor
Quoted 12 lines · Nathan Chancellor
Quoted 11 lines · Marc Zyngier

Compiling the arm64 kernel with the BHB workarounds and Clang+LTO results in a bunch of:

<instantiation>:4:2: error: invalid fixup for movz/movk instruction
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_3

when compiling arch/arm64/kernel/entry.S, and makes no sense at all.

As it turns out, moving a single include line around makes the problem disappear. Why, you'd ask? Well, I don't have the faintest idea, and I'm running out of patience. So make of that what you want.

[...]

Quoted 7 lines

CONFIG_LTO=y causes the following include chain:

include/linux/arm-smccc.h
include/linux/init.h
include/linux/compiler.h

arch/arm64/include/asm/rwonce.h

Gah, a header file that does something completely different under LTO!

Quoted 6 lines

arch/arm64/include/asm/alternative-macros.h
arch/arm64/include/asm/assembler.h

assembler.h has the use of ARM_SMCCC_ARCH_WORKAROUND_3 but the init.h include in arm-smccc.h happens before the definition, so it does not get expanded.

Thanks for getting to the bottom of this! The error message had me stumped.

...

Quoted 17 lines

This diff seems like a somewhat proper solution, as __READ_ONCE() cannot be used in assembly, but I am open to other suggestions.

arch/arm64/include/asm/rwonce.h +1 -1
index 1bce62fa908a..56f7b1d4d54b 100644
@@ -5,7 +5,7 @@
 #ifndef __ASM_RWONCE_H
 #define __ASM_RWONCE_H
 
-#ifdef CONFIG_LTO
+#if defined(CONFIG_LTO) && !defined(__ASSEMBLY__)
 
 #include <linux/compiler_types.h>
 #include <asm/alternative-macros.h>

arch/arm64/include/asm/rwonce.h line 71

Quoted 7 lines
arch/arm64/include/asm/rwonce.h +1 -1
@@ -66,7 +66,7 @@
 })
 
 #endif	/* !BUILD_VDSO */
-#endif	/* CONFIG_LTO */
+#endif	/* CONFIG_LTO && !__ASSEMBLY__ */
 
 #include <asm-generic/rwonce.h>

This looks like the smallest/cleanest fix.

I guess ultimately we should split things like arm-smccc.h into multiple files...

Thanks,

James

maintainer
#5 lore raw
In reply to Nathan Chancellor
Quoted 17 lines · Nathan Chancellor

This diff seems like a somewhat proper solution, as __READ_ONCE() cannot be used in assembly, but I am open to other suggestions.

arch/arm64/include/asm/rwonce.h +1 -1
index 1bce62fa908a..56f7b1d4d54b 100644
@@ -5,7 +5,7 @@
 #ifndef __ASM_RWONCE_H
 #define __ASM_RWONCE_H
 
-#ifdef CONFIG_LTO
+#if defined(CONFIG_LTO) && !defined(__ASSEMBLY__)
 
 #include <linux/compiler_types.h>
 #include <asm/alternative-macros.h>

arch/arm64/include/asm/rwonce.h line 69

Quoted 5 lines
arch/arm64/include/asm/rwonce.h +1 -1
@@ -66,7 +66,7 @@
 })
 
 #endif	/* !BUILD_VDSO */
-#endif	/* CONFIG_LTO */
+#endif	/* CONFIG_LTO && !__ASSEMBLY__ */

Thanks Nathan. Would you please send a proper patch for this? I'd go with your proposal as it seems more related to LTO than Marc's patch ;).

Signature · 1 line
Catalin
#6 lore raw
Quoted 20 lines · Catalin Marinas
Quoted 19 lines · Nathan Chancellor

This diff seems like a somewhat proper solution, as __READ_ONCE() cannot be used in assembly, but I am open to other suggestions.

arch/arm64/include/asm/rwonce.h +1 -1
index 1bce62fa908a..56f7b1d4d54b 100644
@@ -5,7 +5,7 @@
 #ifndef __ASM_RWONCE_H
 #define __ASM_RWONCE_H
 
-#ifdef CONFIG_LTO
+#if defined(CONFIG_LTO) && !defined(__ASSEMBLY__)
 
 #include <linux/compiler_types.h>
 #include <asm/alternative-macros.h>
@@ -66,7 +66,7 @@
 })
 
Quoted 6 lines

arch/arm64/include/asm/rwonce.h line 69

Quoted 3 lines
arch/arm64/include/asm/rwonce.h +1 -1
 #endif	/* !BUILD_VDSO */
-#endif	/* CONFIG_LTO */
+#endif	/* CONFIG_LTO && !__ASSEMBLY__ */

Thanks Nathan. Would you please send a proper patch for this? I'd go with your proposal as it seems more related to LTO than Marc's patch ;).

Done, thanks Catalin and James for your input!

https://lore.kernel.org/r/[email protected]/

Cheers,
Nathan

Reviewed-by on v1 1/1
#7 lore raw
In reply to Marc Zyngier
Quoted 11 lines · Marc Zyngier

Compiling the arm64 kernel with the BHB workarounds and Clang+LTO results in a bunch of:

<instantiation>:4:2: error: invalid fixup for movz/movk instruction
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_3

when compiling arch/arm64/kernel/entry.S, and makes no sense at all.

As it turns out, moving a single include line around makes the problem disappear. Why, you'd ask? Well, I don't have the faintest idea, and I'm running out of patience. So make of that what you want.

Alternatively, this is a perfectly valid cleanup, reducing the scope of a header inclusion to the C prototype that actually needs it, thus reducing header bloat for assembly files that don't. Which happens to also have a pleasant side-effect in avoiding an inexplicable LTO nonsense :D

Even just in terms of that cleanup,

FWIW, my gut feeling is that LTO has somehow blurred the lines between different expansions of _AC() in ARM_SMCCC_ARCH_WORKAROUND_3 that it remembers from other compilation units that it's busy munging together, and confused itself.

Robin.

Quoted 22 lines
Cc James Morse <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Will Deacon <[email protected]>
Cc Catalin Marinas <[email protected]>
---
  include/linux/arm-smccc.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/arm-smccc.h +0 -1
index 220c8c60e021..0a341dd9ff61 100644
@@ -5,7 +5,6 @@
  #ifndef __LINUX_ARM_SMCCC_H
  #define __LINUX_ARM_SMCCC_H
 
-#include <linux/init.h>
  #include <uapi/linux/const.h>
 
  /*

include/linux/arm-smccc.h line 198

Quoted 7 lines
include/linux/arm-smccc.h +1 -0
@@ -193,6 +192,7 @@
 
  #ifndef __ASSEMBLY__
 
+#include <linux/init.h>
  #include <linux/linkage.h>
  #include <linux/types.h>
 

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel