mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-31 08:28:13 +00:00
e463a09af2
Make use of an upcoming GCC feature to mitigate straight-line-speculation for x86: https://gcc.gnu.org/g:53a643f8568067d7700a9f2facc8ba39974973d3 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102952 https://bugs.llvm.org/show_bug.cgi?id=52323 It's built tested on x86_64-allyesconfig using GCC-12 and GCC-11. Maintenance overhead of this should be fairly low due to objtool validation. Size overhead of all these additional int3 instructions comes to: text data bss dec hex filename 22267751 6933356 2011368 31212475 1dc43bb defconfig-build/vmlinux 22804126 6933356 1470696 31208178 1dc32f2 defconfig-build/vmlinux.sls Or roughly 2.4% additional text. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lore.kernel.org/r/20211204134908.140103474@infradead.org
48 lines
1.9 KiB
C
48 lines
1.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _ASM_STATIC_CALL_H
|
|
#define _ASM_STATIC_CALL_H
|
|
|
|
#include <asm/text-patching.h>
|
|
|
|
/*
|
|
* For CONFIG_HAVE_STATIC_CALL_INLINE, this is a temporary trampoline which
|
|
* uses the current value of the key->func pointer to do an indirect jump to
|
|
* the function. This trampoline is only used during boot, before the call
|
|
* sites get patched by static_call_update(). The name of this trampoline has
|
|
* a magical aspect: objtool uses it to find static call sites so it can create
|
|
* the .static_call_sites section.
|
|
*
|
|
* For CONFIG_HAVE_STATIC_CALL, this is a permanent trampoline which
|
|
* does a direct jump to the function. The direct jump gets patched by
|
|
* static_call_update().
|
|
*
|
|
* Having the trampoline in a special section forces GCC to emit a JMP.d32 when
|
|
* it does tail-call optimization on the call; since you cannot compute the
|
|
* relative displacement across sections.
|
|
*/
|
|
|
|
#define __ARCH_DEFINE_STATIC_CALL_TRAMP(name, insns) \
|
|
asm(".pushsection .static_call.text, \"ax\" \n" \
|
|
".align 4 \n" \
|
|
".globl " STATIC_CALL_TRAMP_STR(name) " \n" \
|
|
STATIC_CALL_TRAMP_STR(name) ": \n" \
|
|
insns " \n" \
|
|
".byte 0x53, 0x43, 0x54 \n" \
|
|
".type " STATIC_CALL_TRAMP_STR(name) ", @function \n" \
|
|
".size " STATIC_CALL_TRAMP_STR(name) ", . - " STATIC_CALL_TRAMP_STR(name) " \n" \
|
|
".popsection \n")
|
|
|
|
#define ARCH_DEFINE_STATIC_CALL_TRAMP(name, func) \
|
|
__ARCH_DEFINE_STATIC_CALL_TRAMP(name, ".byte 0xe9; .long " #func " - (. + 4)")
|
|
|
|
#define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) \
|
|
__ARCH_DEFINE_STATIC_CALL_TRAMP(name, "ret; int3; nop; nop; nop")
|
|
|
|
|
|
#define ARCH_ADD_TRAMP_KEY(name) \
|
|
asm(".pushsection .static_call_tramp_key, \"a\" \n" \
|
|
".long " STATIC_CALL_TRAMP_STR(name) " - . \n" \
|
|
".long " STATIC_CALL_KEY_STR(name) " - . \n" \
|
|
".popsection \n")
|
|
|
|
#endif /* _ASM_STATIC_CALL_H */
|