David Woodhouse | 76b0438 | 2018-01-11 21:46:25 +0000 | [diff] [blame] | 1 | /* 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 Gross | 5e21a3e | 2021-03-11 15:23:06 +0100 | [diff] [blame] | 7 | #include <asm/alternative.h> |
David Woodhouse | 76b0438 | 2018-01-11 21:46:25 +0000 | [diff] [blame] | 8 | #include <asm/export.h> |
| 9 | #include <asm/nospec-branch.h> |
Peter Zijlstra | cc1ac9c | 2020-04-16 14:34:26 +0200 | [diff] [blame] | 10 | #include <asm/unwind_hints.h> |
| 11 | #include <asm/frame.h> |
David Woodhouse | 76b0438 | 2018-01-11 21:46:25 +0000 | [diff] [blame] | 12 | |
Peter Zijlstra | 9bc0bb5 | 2021-03-26 16:12:15 +0100 | [diff] [blame] | 13 | .section .text.__x86.indirect_thunk |
| 14 | |
Peter Zijlstra | 11925185 | 2021-03-26 16:12:02 +0100 | [diff] [blame] | 15 | .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 Woodhouse | 76b0438 | 2018-01-11 21:46:25 +0000 | [diff] [blame] | 29 | .macro THUNK reg |
David Woodhouse | 76b0438 | 2018-01-11 21:46:25 +0000 | [diff] [blame] | 30 | |
Peter Zijlstra | cc1ac9c | 2020-04-16 14:34:26 +0200 | [diff] [blame] | 31 | .align 32 |
Peter Zijlstra | 9bc0bb5 | 2021-03-26 16:12:15 +0100 | [diff] [blame] | 32 | |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 33 | SYM_FUNC_START(__x86_indirect_thunk_\reg) |
Peter Zijlstra | cc1ac9c | 2020-04-16 14:34:26 +0200 | [diff] [blame] | 34 | |
Peter Zijlstra | 11925185 | 2021-03-26 16:12:02 +0100 | [diff] [blame] | 35 | 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 | |
| 39 | SYM_FUNC_END(__x86_indirect_thunk_\reg) |
Peter Zijlstra | cc1ac9c | 2020-04-16 14:34:26 +0200 | [diff] [blame] | 40 | |
David Woodhouse | 76b0438 | 2018-01-11 21:46:25 +0000 | [diff] [blame] | 41 | .endm |
| 42 | |
| 43 | /* |
| 44 | * Despite being an assembler file we can't just use .irp here |
| 45 | * because __KSYM_DEPS__ only uses the C preprocessor and would |
| 46 | * only see one instance of "__x86_indirect_thunk_\reg" rather |
| 47 | * than one per register with the correct names. So we do it |
| 48 | * the simple and nasty way... |
Peter Zijlstra | ca3f0d8 | 2020-04-22 17:03:22 +0200 | [diff] [blame] | 49 | * |
| 50 | * Worse, you can only have a single EXPORT_SYMBOL per line, |
| 51 | * and CPP can't insert newlines, so we have to repeat everything |
| 52 | * at least twice. |
David Woodhouse | 76b0438 | 2018-01-11 21:46:25 +0000 | [diff] [blame] | 53 | */ |
David Woodhouse | 76b0438 | 2018-01-11 21:46:25 +0000 | [diff] [blame] | 54 | |
Peter Zijlstra | ca3f0d8 | 2020-04-22 17:03:22 +0200 | [diff] [blame] | 55 | #define __EXPORT_THUNK(sym) _ASM_NOKPROBE(sym); EXPORT_SYMBOL(sym) |
| 56 | #define EXPORT_THUNK(reg) __EXPORT_THUNK(__x86_indirect_thunk_ ## reg) |
| 57 | |
Peter Zijlstra | ca3f0d8 | 2020-04-22 17:03:22 +0200 | [diff] [blame] | 58 | #define GEN(reg) THUNK reg |
| 59 | #include <asm/GEN-for-each-reg.h> |
Peter Zijlstra | ca3f0d8 | 2020-04-22 17:03:22 +0200 | [diff] [blame] | 60 | #undef GEN |
Peter Zijlstra | b6d3d99 | 2021-10-26 14:01:39 +0200 | [diff] [blame^] | 61 | |
Peter Zijlstra | ca3f0d8 | 2020-04-22 17:03:22 +0200 | [diff] [blame] | 62 | #define GEN(reg) EXPORT_THUNK(reg) |
| 63 | #include <asm/GEN-for-each-reg.h> |
Peter Zijlstra | b6d3d99 | 2021-10-26 14:01:39 +0200 | [diff] [blame^] | 64 | #undef GEN |