blob: cf0b39f97adc8a353168187e9482b588b8d28440 [file] [log] [blame]
David Woodhouse76b04382018-01-11 21:46:25 +00001/* SPDX-License-Identifier: GPL-2.0 */
2
3#include <linux/stringify.h>
4#include <linux/linkage.h>
5#include <asm/dwarf2.h>
6#include <asm/cpufeatures.h>
Juergen Gross5e21a3e2021-03-11 15:23:06 +01007#include <asm/alternative.h>
David Woodhouse76b04382018-01-11 21:46:25 +00008#include <asm/export.h>
9#include <asm/nospec-branch.h>
Peter Zijlstracc1ac9c2020-04-16 14:34:26 +020010#include <asm/unwind_hints.h>
11#include <asm/frame.h>
David Woodhouse76b04382018-01-11 21:46:25 +000012
Peter Zijlstra9bc0bb52021-03-26 16:12:15 +010013 .section .text.__x86.indirect_thunk
14
Peter Zijlstra119251852021-03-26 16:12:02 +010015.macro RETPOLINE reg
16 ANNOTATE_INTRA_FUNCTION_CALL
17 call .Ldo_rop_\@
18.Lspec_trap_\@:
19 UNWIND_HINT_EMPTY
20 pause
21 lfence
22 jmp .Lspec_trap_\@
23.Ldo_rop_\@:
24 mov %\reg, (%_ASM_SP)
25 UNWIND_HINT_FUNC
26 ret
27.endm
28
David Woodhouse76b04382018-01-11 21:46:25 +000029.macro THUNK reg
David Woodhouse76b04382018-01-11 21:46:25 +000030
Peter Zijlstra1a6f7442021-10-26 14:01:41 +020031 .align RETPOLINE_THUNK_SIZE
32SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL)
33 UNWIND_HINT_EMPTY
Peter Zijlstracc1ac9c2020-04-16 14:34:26 +020034
Peter Zijlstra119251852021-03-26 16:12:02 +010035 ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \
36 __stringify(RETPOLINE \reg), X86_FEATURE_RETPOLINE, \
37 __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_AMD
38
David Woodhouse76b04382018-01-11 21:46:25 +000039.endm
40
41/*
42 * Despite being an assembler file we can't just use .irp here
43 * because __KSYM_DEPS__ only uses the C preprocessor and would
44 * only see one instance of "__x86_indirect_thunk_\reg" rather
45 * than one per register with the correct names. So we do it
46 * the simple and nasty way...
Peter Zijlstraca3f0d82020-04-22 17:03:22 +020047 *
48 * Worse, you can only have a single EXPORT_SYMBOL per line,
49 * and CPP can't insert newlines, so we have to repeat everything
50 * at least twice.
David Woodhouse76b04382018-01-11 21:46:25 +000051 */
David Woodhouse76b04382018-01-11 21:46:25 +000052
Peter Zijlstraca3f0d82020-04-22 17:03:22 +020053#define __EXPORT_THUNK(sym) _ASM_NOKPROBE(sym); EXPORT_SYMBOL(sym)
54#define EXPORT_THUNK(reg) __EXPORT_THUNK(__x86_indirect_thunk_ ## reg)
55
Peter Zijlstra1a6f7442021-10-26 14:01:41 +020056 .align RETPOLINE_THUNK_SIZE
57SYM_CODE_START(__x86_indirect_thunk_array)
58
Peter Zijlstraca3f0d82020-04-22 17:03:22 +020059#define GEN(reg) THUNK reg
60#include <asm/GEN-for-each-reg.h>
Peter Zijlstraca3f0d82020-04-22 17:03:22 +020061#undef GEN
Peter Zijlstrab6d3d992021-10-26 14:01:39 +020062
Peter Zijlstra1a6f7442021-10-26 14:01:41 +020063 .align RETPOLINE_THUNK_SIZE
64SYM_CODE_END(__x86_indirect_thunk_array)
65
Peter Zijlstraca3f0d82020-04-22 17:03:22 +020066#define GEN(reg) EXPORT_THUNK(reg)
67#include <asm/GEN-for-each-reg.h>
Peter Zijlstrab6d3d992021-10-26 14:01:39 +020068#undef GEN