Skip to content

Commit 0474d5d

Browse files
anadavIngo Molnar
authored andcommitted
x86/extable: Macrofy inline assembly code to work around GCC inlining bugs
As described in: 77b0bf5: ("kbuild/Makefile: Prepare for using macros in inline assembly code to work around asm() related GCC inlining bugs") GCC's inlining heuristics are broken with common asm() patterns used in kernel code, resulting in the effective disabling of inlining. The workaround is to set an assembly macro and call it from the inline assembly block - which is also a minor cleanup for the exception table code. Text size goes up a bit: text data bss dec hex filename 18162555 10226288 2957312 31346155 1de4deb ./vmlinux before 18162879 10226256 2957312 31346447 1de4f0f ./vmlinux after (+292) But this allows the inlining of functions such as nested_vmx_exit_reflected(), set_segment_reg(), __copy_xstate_to_user() which is a net benefit. Tested-by: Kees Cook <keescook@chromium.org> Signed-off-by: Nadav Amit <namit@vmware.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20181005202718.229565-2-namit@vmware.com Link: https://lore.kernel.org/lkml/20181003213100.189959-9-namit@vmware.com/T/#u Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 02678a5 commit 0474d5d

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

arch/x86/include/asm/asm.h

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,25 @@
120120
/* Exception table entry */
121121
#ifdef __ASSEMBLY__
122122
# define _ASM_EXTABLE_HANDLE(from, to, handler) \
123-
.pushsection "__ex_table","a" ; \
124-
.balign 4 ; \
125-
.long (from) - . ; \
126-
.long (to) - . ; \
127-
.long (handler) - . ; \
123+
ASM_EXTABLE_HANDLE from to handler
124+
125+
.macro ASM_EXTABLE_HANDLE from:req to:req handler:req
126+
.pushsection "__ex_table","a"
127+
.balign 4
128+
.long (\from) - .
129+
.long (\to) - .
130+
.long (\handler) - .
128131
.popsection
132+
.endm
133+
#else /* __ASSEMBLY__ */
134+
135+
# define _ASM_EXTABLE_HANDLE(from, to, handler) \
136+
"ASM_EXTABLE_HANDLE from=" #from " to=" #to \
137+
" handler=\"" #handler "\"\n\t"
138+
139+
/* For C file, we already have NOKPROBE_SYMBOL macro */
140+
141+
#endif /* __ASSEMBLY__ */
129142

130143
# define _ASM_EXTABLE(from, to) \
131144
_ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
@@ -148,6 +161,7 @@
148161
_ASM_PTR (entry); \
149162
.popsection
150163

164+
#ifdef __ASSEMBLY__
151165
.macro ALIGN_DESTINATION
152166
/* check for bad alignment of destination */
153167
movl %edi,%ecx
@@ -171,34 +185,7 @@
171185
_ASM_EXTABLE_UA(100b, 103b)
172186
_ASM_EXTABLE_UA(101b, 103b)
173187
.endm
174-
175-
#else
176-
# define _EXPAND_EXTABLE_HANDLE(x) #x
177-
# define _ASM_EXTABLE_HANDLE(from, to, handler) \
178-
" .pushsection \"__ex_table\",\"a\"\n" \
179-
" .balign 4\n" \
180-
" .long (" #from ") - .\n" \
181-
" .long (" #to ") - .\n" \
182-
" .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n" \
183-
" .popsection\n"
184-
185-
# define _ASM_EXTABLE(from, to) \
186-
_ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
187-
188-
# define _ASM_EXTABLE_UA(from, to) \
189-
_ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess)
190-
191-
# define _ASM_EXTABLE_FAULT(from, to) \
192-
_ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
193-
194-
# define _ASM_EXTABLE_EX(from, to) \
195-
_ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
196-
197-
# define _ASM_EXTABLE_REFCOUNT(from, to) \
198-
_ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount)
199-
200-
/* For C file, we already have NOKPROBE_SYMBOL macro */
201-
#endif
188+
#endif /* __ASSEMBLY__ */
202189

203190
#ifndef __ASSEMBLY__
204191
/*

arch/x86/kernel/macros.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
#include <asm/alternative-asm.h>
1212
#include <asm/bug.h>
1313
#include <asm/paravirt.h>
14+
#include <asm/asm.h>

0 commit comments

Comments
 (0)