Skip to content

Commit b17c2ba

Browse files
Peter Zijlstrasuryasaimadhu
authored andcommitted
x86: Prepare inline-asm for straight-line-speculation
Replace all ret/retq instructions with ASM_RET in preparation of making it more than a single instruction. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lore.kernel.org/r/20211204134907.964635458@infradead.org
1 parent f94909c commit b17c2ba

11 files changed

Lines changed: 19 additions & 14 deletions

File tree

‎arch/x86/include/asm/linkage.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#define __ALIGN_STR __stringify(__ALIGN)
1919
#endif
2020

21+
#else /* __ASSEMBLY__ */
22+
23+
#define ASM_RET "ret\n\t"
24+
2125
#endif /* __ASSEMBLY__ */
2226

2327
#endif /* _ASM_X86_LINKAGE_H */

‎arch/x86/include/asm/paravirt.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ bool __raw_callee_save___native_vcpu_is_preempted(long cpu);
671671
"call " #func ";" \
672672
PV_RESTORE_ALL_CALLER_REGS \
673673
FRAME_END \
674-
"ret;" \
674+
ASM_RET \
675675
".size " PV_THUNK_NAME(func) ", .-" PV_THUNK_NAME(func) ";" \
676676
".popsection")
677677

‎arch/x86/include/asm/qspinlock_paravirt.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ asm (".pushsection .text;"
4848
"jne .slowpath;"
4949
"pop %rdx;"
5050
FRAME_END
51-
"ret;"
51+
ASM_RET
5252
".slowpath: "
5353
"push %rsi;"
5454
"movzbl %al,%esi;"
5555
"call " PV_UNLOCK_SLOWPATH ";"
5656
"pop %rsi;"
5757
"pop %rdx;"
5858
FRAME_END
59-
"ret;"
59+
ASM_RET
6060
".size " PV_UNLOCK ", .-" PV_UNLOCK ";"
6161
".popsection");
6262

‎arch/x86/kernel/alternative.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ asm (
714714
" .type int3_magic, @function\n"
715715
"int3_magic:\n"
716716
" movl $1, (%" _ASM_ARG1 ")\n"
717-
" ret\n"
717+
ASM_RET
718718
" .size int3_magic, .-int3_magic\n"
719719
" .popsection\n"
720720
);

‎arch/x86/kernel/kprobes/core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ asm(
10511051
" addl $4, %esp\n"
10521052
" popfl\n"
10531053
#endif
1054-
" ret\n"
1054+
ASM_RET
10551055
".size __kretprobe_trampoline, .-__kretprobe_trampoline\n"
10561056
);
10571057
NOKPROBE_SYMBOL(__kretprobe_trampoline);

‎arch/x86/kernel/paravirt.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern void _paravirt_nop(void);
4141
asm (".pushsection .entry.text, \"ax\"\n"
4242
".global _paravirt_nop\n"
4343
"_paravirt_nop:\n\t"
44-
"ret\n\t"
44+
ASM_RET
4545
".size _paravirt_nop, . - _paravirt_nop\n\t"
4646
".type _paravirt_nop, @function\n\t"
4747
".popsection");
@@ -51,7 +51,7 @@ asm (".pushsection .entry.text, \"ax\"\n"
5151
".global paravirt_ret0\n"
5252
"paravirt_ret0:\n\t"
5353
"xor %" _ASM_AX ", %" _ASM_AX ";\n\t"
54-
"ret\n\t"
54+
ASM_RET
5555
".size paravirt_ret0, . - paravirt_ret0\n\t"
5656
".type paravirt_ret0, @function\n\t"
5757
".popsection");

‎arch/x86/kvm/emulate.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
315315
__FOP_FUNC(#name)
316316

317317
#define __FOP_RET(name) \
318-
"ret \n\t" \
318+
ASM_RET \
319319
".size " name ", .-" name "\n\t"
320320

321321
#define FOP_RET(name) \
@@ -435,7 +435,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
435435
__FOP_RET(#op)
436436

437437
asm(".pushsection .fixup, \"ax\"\n"
438-
"kvm_fastop_exception: xor %esi, %esi; ret\n"
438+
"kvm_fastop_exception: xor %esi, %esi; " ASM_RET
439439
".popsection");
440440

441441
FOP_START(setcc)

‎arch/x86/lib/error-inject.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3+
#include <linux/linkage.h>
34
#include <linux/error-injection.h>
45
#include <linux/kprobes.h>
56

@@ -10,7 +11,7 @@ asm(
1011
".type just_return_func, @function\n"
1112
".globl just_return_func\n"
1213
"just_return_func:\n"
13-
" ret\n"
14+
ASM_RET
1415
".size just_return_func, .-just_return_func\n"
1516
);
1617

‎samples/ftrace/ftrace-direct-modify.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ asm (
3131
" call my_direct_func1\n"
3232
" leave\n"
3333
" .size my_tramp1, .-my_tramp1\n"
34-
" ret\n"
34+
ASM_RET
3535
" .type my_tramp2, @function\n"
3636
" .globl my_tramp2\n"
3737
" my_tramp2:"
3838
" pushq %rbp\n"
3939
" movq %rsp, %rbp\n"
4040
" call my_direct_func2\n"
4141
" leave\n"
42-
" ret\n"
42+
ASM_RET
4343
" .size my_tramp2, .-my_tramp2\n"
4444
" .popsection\n"
4545
);

‎samples/ftrace/ftrace-direct-too.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ asm (
3131
" popq %rsi\n"
3232
" popq %rdi\n"
3333
" leave\n"
34-
" ret\n"
34+
ASM_RET
3535
" .size my_tramp, .-my_tramp\n"
3636
" .popsection\n"
3737
);

0 commit comments

Comments
 (0)