Skip to content

Commit ca3f0d8

Browse files
author
Peter Zijlstra
committed
x86: Simplify retpoline declaration
Because of how KSYM works, we need one declaration per line. Seeing how we're going to be doubling the amount of retpoline symbols, simplify the machinery in order to avoid having to copy/paste even more. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 089dd8e commit ca3f0d8

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifdef CONFIG_64BIT
2+
GEN(rax)
3+
GEN(rbx)
4+
GEN(rcx)
5+
GEN(rdx)
6+
GEN(rsi)
7+
GEN(rdi)
8+
GEN(rbp)
9+
GEN(r8)
10+
GEN(r9)
11+
GEN(r10)
12+
GEN(r11)
13+
GEN(r12)
14+
GEN(r13)
15+
GEN(r14)
16+
GEN(r15)
17+
#else
18+
GEN(eax)
19+
GEN(ebx)
20+
GEN(ecx)
21+
GEN(edx)
22+
GEN(esi)
23+
GEN(edi)
24+
GEN(ebp)
25+
#endif

arch/x86/include/asm/asm-prototypes.h

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,12 @@ extern void cmpxchg8b_emu(void);
1717
#endif
1818

1919
#ifdef CONFIG_RETPOLINE
20-
#ifdef CONFIG_X86_32
21-
#define INDIRECT_THUNK(reg) extern asmlinkage void __x86_indirect_thunk_e ## reg(void);
22-
#else
23-
#define INDIRECT_THUNK(reg) extern asmlinkage void __x86_indirect_thunk_r ## reg(void);
24-
INDIRECT_THUNK(8)
25-
INDIRECT_THUNK(9)
26-
INDIRECT_THUNK(10)
27-
INDIRECT_THUNK(11)
28-
INDIRECT_THUNK(12)
29-
INDIRECT_THUNK(13)
30-
INDIRECT_THUNK(14)
31-
INDIRECT_THUNK(15)
32-
#endif
33-
INDIRECT_THUNK(ax)
34-
INDIRECT_THUNK(bx)
35-
INDIRECT_THUNK(cx)
36-
INDIRECT_THUNK(dx)
37-
INDIRECT_THUNK(si)
38-
INDIRECT_THUNK(di)
39-
INDIRECT_THUNK(bp)
20+
21+
#define DECL_INDIRECT_THUNK(reg) \
22+
extern asmlinkage void __x86_indirect_thunk_ ## reg (void);
23+
24+
#undef GEN
25+
#define GEN(reg) DECL_INDIRECT_THUNK(reg)
26+
#include <asm/GEN-for-each-reg.h>
27+
4028
#endif /* CONFIG_RETPOLINE */

arch/x86/lib/retpoline.S

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,20 @@ SYM_FUNC_END(__x86_indirect_thunk_\reg)
2424
* only see one instance of "__x86_indirect_thunk_\reg" rather
2525
* than one per register with the correct names. So we do it
2626
* the simple and nasty way...
27+
*
28+
* Worse, you can only have a single EXPORT_SYMBOL per line,
29+
* and CPP can't insert newlines, so we have to repeat everything
30+
* at least twice.
2731
*/
28-
#define __EXPORT_THUNK(sym) _ASM_NOKPROBE(sym); EXPORT_SYMBOL(sym)
29-
#define EXPORT_THUNK(reg) __EXPORT_THUNK(__x86_indirect_thunk_ ## reg)
30-
#define GENERATE_THUNK(reg) THUNK reg ; EXPORT_THUNK(reg)
31-
32-
GENERATE_THUNK(_ASM_AX)
33-
GENERATE_THUNK(_ASM_BX)
34-
GENERATE_THUNK(_ASM_CX)
35-
GENERATE_THUNK(_ASM_DX)
36-
GENERATE_THUNK(_ASM_SI)
37-
GENERATE_THUNK(_ASM_DI)
38-
GENERATE_THUNK(_ASM_BP)
39-
#ifdef CONFIG_64BIT
40-
GENERATE_THUNK(r8)
41-
GENERATE_THUNK(r9)
42-
GENERATE_THUNK(r10)
43-
GENERATE_THUNK(r11)
44-
GENERATE_THUNK(r12)
45-
GENERATE_THUNK(r13)
46-
GENERATE_THUNK(r14)
47-
GENERATE_THUNK(r15)
48-
#endif
32+
33+
#define __EXPORT_THUNK(sym) _ASM_NOKPROBE(sym); EXPORT_SYMBOL(sym)
34+
#define EXPORT_THUNK(reg) __EXPORT_THUNK(__x86_indirect_thunk_ ## reg)
35+
36+
#undef GEN
37+
#define GEN(reg) THUNK reg
38+
#include <asm/GEN-for-each-reg.h>
39+
40+
#undef GEN
41+
#define GEN(reg) EXPORT_THUNK(reg)
42+
#include <asm/GEN-for-each-reg.h>
43+

0 commit comments

Comments
 (0)