Skip to content

Commit

Permalink
x86: Prepare inline-asm for straight-line-speculation
Browse files Browse the repository at this point in the history
[ Upstream commit b17c2ba ]

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
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Peter Zijlstra authored and gregkh committed May 15, 2022
1 parent 14b476e commit a467f69
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions arch/x86/include/asm/linkage.h
Expand Up @@ -18,6 +18,10 @@
#define __ALIGN_STR __stringify(__ALIGN)
#endif

#else /* __ASSEMBLY__ */

#define ASM_RET "ret\n\t"

#endif /* __ASSEMBLY__ */

#endif /* _ASM_X86_LINKAGE_H */
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/paravirt.h
Expand Up @@ -665,7 +665,7 @@ bool __raw_callee_save___native_vcpu_is_preempted(long cpu);
"call " #func ";" \
PV_RESTORE_ALL_CALLER_REGS \
FRAME_END \
"ret;" \
ASM_RET \
".size " PV_THUNK_NAME(func) ", .-" PV_THUNK_NAME(func) ";" \
".popsection")

Expand Down
4 changes: 2 additions & 2 deletions arch/x86/include/asm/qspinlock_paravirt.h
Expand Up @@ -48,15 +48,15 @@ asm (".pushsection .text;"
"jne .slowpath;"
"pop %rdx;"
FRAME_END
"ret;"
ASM_RET
".slowpath: "
"push %rsi;"
"movzbl %al,%esi;"
"call " PV_UNLOCK_SLOWPATH ";"
"pop %rsi;"
"pop %rdx;"
FRAME_END
"ret;"
ASM_RET
".size " PV_UNLOCK ", .-" PV_UNLOCK ";"
".popsection");

Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/alternative.c
Expand Up @@ -537,7 +537,7 @@ asm (
" .type int3_magic, @function\n"
"int3_magic:\n"
" movl $1, (%" _ASM_ARG1 ")\n"
" ret\n"
ASM_RET
" .size int3_magic, .-int3_magic\n"
" .popsection\n"
);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/kprobes/core.c
Expand Up @@ -1044,7 +1044,7 @@ asm(
RESTORE_REGS_STRING
" popfl\n"
#endif
" ret\n"
ASM_RET
".size kretprobe_trampoline, .-kretprobe_trampoline\n"
);
NOKPROBE_SYMBOL(kretprobe_trampoline);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/paravirt.c
Expand Up @@ -41,7 +41,7 @@ extern void _paravirt_nop(void);
asm (".pushsection .entry.text, \"ax\"\n"
".global _paravirt_nop\n"
"_paravirt_nop:\n\t"
"ret\n\t"
ASM_RET
".size _paravirt_nop, . - _paravirt_nop\n\t"
".type _paravirt_nop, @function\n\t"
".popsection");
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kvm/emulate.c
Expand Up @@ -315,7 +315,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
__FOP_FUNC(#name)

#define __FOP_RET(name) \
"ret \n\t" \
ASM_RET \
".size " name ", .-" name "\n\t"

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

asm(".pushsection .fixup, \"ax\"\n"
"kvm_fastop_exception: xor %esi, %esi; ret\n"
"kvm_fastop_exception: xor %esi, %esi; " ASM_RET
".popsection");

FOP_START(setcc)
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/lib/error-inject.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/linkage.h>
#include <linux/error-injection.h>
#include <linux/kprobes.h>

Expand All @@ -10,7 +11,7 @@ asm(
".type just_return_func, @function\n"
".globl just_return_func\n"
"just_return_func:\n"
" ret\n"
ASM_RET
".size just_return_func, .-just_return_func\n"
);

Expand Down
4 changes: 2 additions & 2 deletions samples/ftrace/ftrace-direct-modify.c
Expand Up @@ -31,15 +31,15 @@ asm (
" call my_direct_func1\n"
" leave\n"
" .size my_tramp1, .-my_tramp1\n"
" ret\n"
ASM_RET
" .type my_tramp2, @function\n"
" .globl my_tramp2\n"
" my_tramp2:"
" pushq %rbp\n"
" movq %rsp, %rbp\n"
" call my_direct_func2\n"
" leave\n"
" ret\n"
ASM_RET
" .size my_tramp2, .-my_tramp2\n"
" .popsection\n"
);
Expand Down
2 changes: 1 addition & 1 deletion samples/ftrace/ftrace-direct-too.c
Expand Up @@ -31,7 +31,7 @@ asm (
" popq %rsi\n"
" popq %rdi\n"
" leave\n"
" ret\n"
ASM_RET
" .size my_tramp, .-my_tramp\n"
" .popsection\n"
);
Expand Down
2 changes: 1 addition & 1 deletion samples/ftrace/ftrace-direct.c
Expand Up @@ -24,7 +24,7 @@ asm (
" call my_direct_func\n"
" popq %rdi\n"
" leave\n"
" ret\n"
ASM_RET
" .size my_tramp, .-my_tramp\n"
" .popsection\n"
);
Expand Down

0 comments on commit a467f69

Please sign in to comment.