1 From e16c2983fba0fa6763e43ad10916be35e3d8dc05 Mon Sep 17 00:00:00 2001
2 From: Steve Wahl <steve.wahl@hpe.com>
3 Date: Thu, 5 Sep 2019 15:23:46 -0500
4 Subject: x86/purgatory: Change compiler flags from -mcmodel=kernel to -mcmodel=large to fix kexec relocation errors
6 From: Steve Wahl <steve.wahl@hpe.com>
8 commit e16c2983fba0fa6763e43ad10916be35e3d8dc05 upstream.
10 The last change to this Makefile caused relocation errors when loading
11 a kdump kernel. Restore -mcmodel=large (not -mcmodel=kernel),
12 -ffreestanding, and -fno-zero-initialized-bsss, without reverting to
13 the former practice of resetting KBUILD_CFLAGS.
15 Purgatory.ro is a standalone binary that is not linked against the
16 rest of the kernel. Its image is copied into an array that is linked
17 to the kernel, and from there kexec relocates it wherever it desires.
19 With the previous change to compiler flags, the error "kexec: Overflow
20 in relocation type 11 value 0x11fffd000" was encountered when trying
21 to load the crash kernel. This is from kexec code trying to relocate
22 the purgatory.ro object.
24 From the error message, relocation type 11 is R_X86_64_32S. The
27 "The R_X86_64_32 and R_X86_64_32S relocations truncate the
28 computed value to 32-bits. The linker must verify that the
29 generated value for the R_X86_64_32 (R_X86_64_32S) relocation
30 zero-extends (sign-extends) to the original 64-bit value."
32 This type of relocation doesn't work when kexec chooses to place the
33 purgatory binary in memory that is not reachable with 32 bit
36 The compiler flag -mcmodel=kernel allows those type of relocations to
37 be emitted, so revert to using -mcmodel=large as was done before.
39 Also restore the -ffreestanding and -fno-zero-initialized-bss flags
40 because they are appropriate for a stand alone piece of object code
41 which doesn't explicitly zero the bss, and one other report has said
42 undefined symbols are encountered without -ffreestanding.
44 These identical compiler flag changes need to happen for every object
45 that becomes part of the purgatory.ro object, so gather them together
46 first into PURGATORY_CFLAGS_REMOVE and PURGATORY_CFLAGS, and then
47 apply them to each of the objects that have C source. Do not apply
48 any of these flags to kexec-purgatory.o, which is not part of the
49 standalone object but part of the kernel proper.
51 Tested-by: Vaibhav Rustagi <vaibhavrustagi@google.com>
52 Tested-by: Andreas Smas <andreas@lonelycoder.com>
53 Signed-off-by: Steve Wahl <steve.wahl@hpe.com>
54 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
55 Cc: Borislav Petkov <bp@alien8.de>
56 Cc: H. Peter Anvin <hpa@zytor.com>
57 Cc: Linus Torvalds <torvalds@linux-foundation.org>
59 Cc: Peter Zijlstra <peterz@infradead.org>
60 Cc: Thomas Gleixner <tglx@linutronix.de>
61 Cc: clang-built-linux@googlegroups.com
62 Cc: dimitri.sivanich@hpe.com
63 Cc: mike.travis@hpe.com
64 Cc: russ.anderson@hpe.com
65 Fixes: b059f801a937 ("x86/purgatory: Use CFLAGS_REMOVE rather than reset KBUILD_CFLAGS")
66 Link: https://lkml.kernel.org/r/20190905202346.GA26595@swahl-linux
67 Signed-off-by: Ingo Molnar <mingo@kernel.org>
68 Cc: Andreas Smas <andreas@lonelycoder.com>
69 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
72 arch/x86/purgatory/Makefile | 35 +++++++++++++++++++----------------
73 1 file changed, 19 insertions(+), 16 deletions(-)
75 --- a/arch/x86/purgatory/Makefile
76 +++ b/arch/x86/purgatory/Makefile
77 @@ -18,37 +18,40 @@ targets += purgatory.ro
81 +# These are adjustments to the compiler flags used for objects that
82 +# make up the standalone purgatory.ro
84 +PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
85 +PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss
87 # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
88 # in turn leaves some undefined symbols like __fentry__ in purgatory and not
89 # sure how to relocate those.
90 ifdef CONFIG_FUNCTION_TRACER
91 -CFLAGS_REMOVE_sha256.o += $(CC_FLAGS_FTRACE)
92 -CFLAGS_REMOVE_purgatory.o += $(CC_FLAGS_FTRACE)
93 -CFLAGS_REMOVE_string.o += $(CC_FLAGS_FTRACE)
94 -CFLAGS_REMOVE_kexec-purgatory.o += $(CC_FLAGS_FTRACE)
95 +PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE)
98 ifdef CONFIG_STACKPROTECTOR
99 -CFLAGS_REMOVE_sha256.o += -fstack-protector
100 -CFLAGS_REMOVE_purgatory.o += -fstack-protector
101 -CFLAGS_REMOVE_string.o += -fstack-protector
102 -CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector
103 +PURGATORY_CFLAGS_REMOVE += -fstack-protector
106 ifdef CONFIG_STACKPROTECTOR_STRONG
107 -CFLAGS_REMOVE_sha256.o += -fstack-protector-strong
108 -CFLAGS_REMOVE_purgatory.o += -fstack-protector-strong
109 -CFLAGS_REMOVE_string.o += -fstack-protector-strong
110 -CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector-strong
111 +PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong
114 ifdef CONFIG_RETPOLINE
115 -CFLAGS_REMOVE_sha256.o += $(RETPOLINE_CFLAGS)
116 -CFLAGS_REMOVE_purgatory.o += $(RETPOLINE_CFLAGS)
117 -CFLAGS_REMOVE_string.o += $(RETPOLINE_CFLAGS)
118 -CFLAGS_REMOVE_kexec-purgatory.o += $(RETPOLINE_CFLAGS)
119 +PURGATORY_CFLAGS_REMOVE += $(RETPOLINE_CFLAGS)
122 +CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE)
123 +CFLAGS_purgatory.o += $(PURGATORY_CFLAGS)
125 +CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE)
126 +CFLAGS_sha256.o += $(PURGATORY_CFLAGS)
128 +CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE)
129 +CFLAGS_string.o += $(PURGATORY_CFLAGS)
131 $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
132 $(call if_changed,ld)